List of usage examples for org.springframework.mock.web MockHttpSession MockHttpSession
public MockHttpSession()
From source file:fragment.web.UsersControllerTest.java
@Test public void testCreateUserwithBlackListedEmail() throws Exception { Configuration configuration = configurationService .locateConfigurationByName("com.citrix.cpbm.accountManagement.onboarding.emailDomain.blacklist"); configuration.setValue("test.com"); configurationService.update(configuration); User user = userDAO.find(3L);/*w w w . j a va2 s. co m*/ asUser(user); UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("subodh@test.com"); newUser.setUsername("Subodh"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); BindingResult bindingResult = validate(form); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("submitButtonEmail", "Finish"); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy .newInstance(controller.getTenant()); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, mockRequest, new MockHttpSession()); Assert.assertEquals("users.new.step1", view); }
From source file:fragment.web.RegistrationControllerTest.java
@Test public void testWelcomeEmailAndActivationEmailEventsForCorporate() { // Sign up for manual activation account type MockHttpServletRequest mockRequest = getRequestTemplate(HttpMethod.GET, "/portal/register"); UserRegistration registration = new UserRegistration(); registration.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); registration.setAcceptedTerms(true); List<AccountType> accountTypes = accountTypeDAO.getManualRegistrationAccountTypes(); AccountType disposition = null;//ww w .j ava 2 s .co m for (AccountType accountType : accountTypes) { if (accountType.isManualActivation()) { disposition = accountType; } } BindingResult result = null; try { result = setupRegistration(disposition, registration); } catch (Exception e) { e.printStackTrace(); } beforeRegisterCall(mockRequest, registration); controller.register(registration, result, "abc", "abc", map, null, status, mockRequest); // Tenant Activation Event // Assert.assertEquals(1, eventListener.getEvents().size()); // PortalEvent accountActivationRequestEvent = eventListener.getEvents().get(0); // Assert.assertTrue(accountActivationRequestEvent.getPayload() instanceof AccountActivationRequestEvent); eventListener.clear(); // verify email String auth = registration.getUser().getObject().getAuthorization(0); MockHttpSession mockSession = new MockHttpSession(); mockSession.setAttribute("regAuth", auth); mockSession.setAttribute("regParam", registration.getUser().getObject().getParam()); controller.verifyEmail(getRequestTemplate(HttpMethod.GET, "/verify_email"), map, mockSession); // Since tenant is at activated, we will get EmailVerified Event Assert.assertEquals(1, eventListener.getEvents().size()); eventListener.clear(); Tenant tennt = tenantService.get(registration.getTenant().getUuid()); completeBusinessTransactionsForTenant(tennt); tenantService.changeState(registration.getTenant().getUuid(), "ACTIVE", null, "Manual"); PortalEvent tenantActivationEvent = eventListener.getEvents().get(0); Assert.assertTrue(tenantActivationEvent.getPayload() instanceof TenantActivation); eventListener.clear(); }
From source file:fragment.web.UsersControllerTest.java
@Test public void testCreateUserwithBlackListedEmail2() throws Exception { Configuration configuration = configurationService .locateConfigurationByName("com.citrix.cpbm.accountManagement.onboarding.emailDomain.blacklist"); configuration.setValue("test.com"); configurationService.update(configuration); asRoot();//from w w w. ja va2 s . com UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("subodh@test.com"); newUser.setUsername("Subodh"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); BindingResult bindingResult = validate(form); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("submitButtonEmail", "Finish"); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy .newInstance(controller.getTenant()); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, mockRequest, new MockHttpSession()); Assert.assertEquals("users.new.step1", view); }
From source file:fragment.web.UsersControllerTest.java
@Test public void testCreateUserwithSurrogatedTenantBlackListedEmail() throws Exception { Configuration configuration = configurationService .locateConfigurationByName("com.citrix.cpbm.accountManagement.onboarding.emailDomain.blacklist"); configuration.setValue("test.com"); configurationService.update(configuration); asRoot();//from w w w. ja v a 2s. co m // Tenant tenant = getDefaultTenant(); // User user = tenant.getOwner(); UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("subodh@test.com"); newUser.setUsername("Subodh"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); request = new MockHttpServletRequest(); request.setAttribute("isSurrogatedTenant", Boolean.TRUE); BindingResult bindingResult = validate(form); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("submitButtonEmail", "Finish"); Tenant tenant = tenantDAO.find(3L); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy.newInstance(tenant); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, mockRequest, new MockHttpSession()); Assert.assertEquals("users.new.step1", view); }
From source file:fragment.web.UsersControllerTest.java
@Test public void testCreateUserwithSurrogatedTenantBlackListedEmail2() throws Exception { Configuration configuration = configurationService .locateConfigurationByName("com.citrix.cpbm.accountManagement.onboarding.emailDomain.blacklist"); configuration.setValue("test.com"); configurationService.update(configuration); asRoot();//from ww w . ja v a 2 s . c om // Tenant tenant = getDefaultTenant(); // User user = tenant.getOwner(); UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("subodh@test.com"); newUser.setUsername("Subodh"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); BindingResult bindingResult = validate(form); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); // request.setAttribute("isSurrogatedTenant", Boolean.TRUE); mockRequest.addParameter("submitButtonEmail", "Finish"); Tenant tenant = tenantDAO.find(3L); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy.newInstance(tenant); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, mockRequest, new MockHttpSession()); Assert.assertEquals("users.new.step1", view); }
From source file:fragment.web.UsersControllerTest.java
@Test public void testCreateUserMaxUserCount() throws Exception { Configuration configuration = configurationService .locateConfigurationByName("com.citrix.cpbm.accountManagement.onboarding.emailDomain.blacklist"); configuration.setValue("test.com"); configurationService.update(configuration); Tenant tenant = tenantDAO.find(3L);// www.j a v a2 s.c om List<User> userList = tenant.getAllUsers(); int count = userList.size(); long temp = Long.valueOf(count); tenant.setMaxUsers(temp); tenantService.update(tenant); UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("subodh@test.com"); newUser.setUsername("Subodh"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); BindingResult bindingResult = validate(form); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("submitButtonEmail", "Finish"); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy.newInstance(tenant); try { controller.createUserStepTwo(form, bindingResult, proxyTenant, map, mockRequest, new MockHttpSession()); } catch (Exception e) { Assert.assertEquals( "You have reached the maximum number of users. To increase your limit, please contact support", e.getMessage()); logger.debug("###Exiting testCreateUserMaxUserCount"); } }
From source file:fragment.web.UsersControllerTest.java
/** * @Desc Test to create Normal User with Custom Email template * @author vinayv/*w w w . j a va 2s. c o m*/ * @throws Exception */ @Test public void testCreateNormalUserWithCustomEmailTemplate() throws Exception { logger.info("Entering testCreateNormalUserWithCustomEmailTemplate test"); int beforeCount = userDAO.count(); User user = userDAO.find(3L); asUser(user); UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("test@test.com"); newUser.setUsername("testuser"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName("User"); form.setUserProfile(profile.getId()); request.addParameter("submitButtonEmail", "CustomeEmail"); BindingResult bindingResult = validate(form); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy .newInstance(controller.getTenant()); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, request, new MockHttpSession()); Assert.assertEquals("users.newuser.customemail", view); UserForm obtainedForm = (UserForm) map.get("user"); Assert.assertEquals(form.getUser().getUsername(), obtainedForm.getUser().getUsername()); com.citrix.cpbm.access.User obtainedUser = obtainedForm.getUser(); Assert.assertNotNull(obtainedUser); obtainedForm.setCustomEmailSubject("customEmailSubject"); obtainedForm.setEmailText("customEmailText"); bindingResult = validate(obtainedForm); view = controller.createStepThree(obtainedForm, bindingResult, proxyTenant, map, request); Assert.assertEquals("users.newuserregistration.finish", view); int afterCount = userDAO.count(); Assert.assertEquals(beforeCount + 1, afterCount); Assert.assertEquals("User", obtainedUser.getProfile().getName()); logger.info("Exiting testCreateNormalUserWithCustomEmailTemplate test"); }
From source file:fragment.web.UsersControllerTest.java
/** * @Desc Private method to create a user * @author vinayv/* ww w .j a va2 s .c om*/ * @param profileName * @return user object * @throws Exception */ private com.citrix.cpbm.access.User createUserByProfile(String profileName) throws Exception { UserForm form = new UserForm(); form.setCountryList(countryService.getCountries(null, null, null, null, null, null, null)); com.citrix.cpbm.access.User newUser = form.getUser(); newUser.setEmail("test@test.com"); newUser.setUsername("testuser"); newUser.setFirstName("firstName"); newUser.setLastName("lastName"); Profile profile = profileDAO.findByName(profileName); form.setUserProfile(profile.getId()); request.addParameter("submitButtonEmail", "Finish"); BindingResult bindingResult = validate(form); com.citrix.cpbm.access.Tenant proxyTenant = (com.citrix.cpbm.access.Tenant) CustomProxy .newInstance(controller.getTenant()); String view = controller.createUserStepTwo(form, bindingResult, proxyTenant, map, request, new MockHttpSession()); Assert.assertEquals("users.newuserregistration.finish", view); UserForm obtainedForm = (UserForm) map.get("user"); Assert.assertEquals(form.getUser().getUsername(), obtainedForm.getUser().getUsername()); return obtainedForm.getUser(); }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
protected MockHttpSession getAuthenticatedSession(ScimUser user) { MockHttpSession session = new MockHttpSession(); setAuthentication(session, user); return session; }
From source file:org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests.java
@Test public void authorizeEndpointWithPromptNone_WhenNotAuthenticated() throws Exception { String clientId = "testclient" + generator.generate(); BaseClientDetails clientDetails = new BaseClientDetails(clientId, null, "uaa.user,other.scope", "authorization_code,refresh_token", "uaa.resource", TEST_REDIRECT_URI); clientDetails.setAutoApproveScopes(Arrays.asList("uaa.user")); clientDetails.setClientSecret("secret"); clientDetails.addAdditionalInformation(ClientConstants.AUTO_APPROVE, Arrays.asList("other.scope")); clientDetails.addAdditionalInformation(ClientConstants.ALLOWED_PROVIDERS, Arrays.asList("uaa")); clientDetailsService.addClientDetails(clientDetails); MockHttpSession session = new MockHttpSession(); String state = generator.generate(); MvcResult result = getMockMvc()/*from w ww. ja v a 2 s .co m*/ .perform(get("/oauth/authorize").session(session).param(OAuth2Utils.RESPONSE_TYPE, "code") .param(OAuth2Utils.STATE, state).param(OAuth2Utils.CLIENT_ID, clientId) .param(OAuth2Utils.REDIRECT_URI, TEST_REDIRECT_URI) .param(ID_TOKEN_HINT_PROMPT, ID_TOKEN_HINT_PROMPT_NONE)) .andExpect(status().isFound()).andExpect(cookie().maxAge("Current-User", 0)).andReturn(); String url = result.getResponse().getHeader("Location"); assertEquals(UaaUrlUtils.addQueryParameter(TEST_REDIRECT_URI, "error", "login_required"), url); }