rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject svn commit: r1189776 [3/3] - in /incubator/rave/sandbox/rave-extensions: ./ .idea/ .idea/copyright/ .idea/inspectionProfiles/ .idea/libraries/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/rave/ src...
Date Thu, 27 Oct 2011 14:29:07 GMT
Added: incubator/rave/sandbox/rave-extensions/src/test/java/org/apache/rave/portal/security/impl/DefaultSSOLoginHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/sandbox/rave-extensions/src/test/java/org/apache/rave/portal/security/impl/DefaultSSOLoginHandlerTest.java?rev=1189776&view=auto
==============================================================================
--- incubator/rave/sandbox/rave-extensions/src/test/java/org/apache/rave/portal/security/impl/DefaultSSOLoginHandlerTest.java
(added)
+++ incubator/rave/sandbox/rave-extensions/src/test/java/org/apache/rave/portal/security/impl/DefaultSSOLoginHandlerTest.java
Thu Oct 27 14:29:04 2011
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rave.portal.security.impl;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.rave.portal.model.Authority;
+import org.apache.rave.portal.model.NewUser;
+import org.apache.rave.portal.model.User;
+import org.apache.rave.portal.security.impl.DefaultSSOLoginHandler;
+import org.apache.rave.portal.service.AuthorityService;
+import org.apache.rave.portal.service.NewAccountService;
+import org.apache.rave.portal.service.UserService;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * Test for {@link org.apache.rave.portal.security.impl.DefaultSSOLoginHandler}
+ */
+public class DefaultSSOLoginHandlerTest {
+
+    private DefaultSSOLoginHandler loginHandler;
+    private NewAccountService newAccountService;
+    private UserService userService;
+    private AuthorityService authorityService;
+
+    @Before
+    public void setup() {
+        newAccountService = createNiceMock(NewAccountService.class);
+        userService = createMock(UserService.class);
+        authorityService = createMock(AuthorityService.class);
+        loginHandler = new DefaultSSOLoginHandler(newAccountService, userService, authorityService);
+        loginHandler.setSsoHeaderEmail("EMAIL");
+        loginHandler.setAutoCreateUser(true);
+        loginHandler.setDefaultUserRole("ROLE_USER");
+        loginHandler.setDefaultPageLayout("columns_2");
+    }
+
+    @Test
+    public void testNewUserLogin_createUser() throws Exception {
+        HttpServletRequest mockRequest = new MockHttpServletRequest();
+        mockRequest.setAttribute("EMAIL", "mrsmith@example.com");
+
+        NewUser newUser = new NewUser();
+        newUser.setUsername("mrsmith");
+        newUser.setEmail("mrsmith@example.com");
+        newUser.setPageLayout("columns_2");
+        User user = new User(1L, "mrsmith");
+
+        Authority authority= new Authority();
+        authority.setAuthority("ROLE_USER");
+
+        expect(authorityService.getAuthorityByName("ROLE_USER")).andReturn(authority);
+        expect(userService.getUserByUsername("mrsmith")).andReturn(user);
+        userService.updateUserProfile(user);
+        expectLastCall();
+        replay(newAccountService, authorityService, userService);
+        loginHandler.newUserLogin("mrsmith", mockRequest);
+        verify(newAccountService, authorityService, userService);
+
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void testNewUserLogin_creationDisabled() throws Exception {
+        loginHandler.setAutoCreateUser(false);
+        HttpServletRequest mockRequest = new MockHttpServletRequest();
+        loginHandler.newUserLogin("mrjones", mockRequest);
+        assertTrue("Expecting an exception", false);
+    }
+}



Mime
View raw message