Search in sources :

Example 11 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class HomeControllerTest method testDisplayHomePage.

/**
     * Test of displayHomePage method, of class HomeController.
     */
public void testDisplayHomePage() {
    System.out.println("displayHomePage");
    setUpUserDataService();
    setUpMockAuthenticationContext();
    setUpContractDataService();
    setUpActDataService();
    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.HOME_VIEW_NAME;
    String result = instance.displayHomePage(model);
    assertEquals(expResult, result);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Example 12 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method testEditUserAdminPage.

/**
     * Test of editUserAdminPage method, of class UserManagementController.
     */
public void testEditUserAdminPage() {
    System.out.println("editUserAdminPage");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    String userId = "";
    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Model model = new ExtendedModelMap();
    try {
        instance.displayEditUserAdminPage(userId, request, response, model);
        assertTrue(false);
    } catch (ForbiddenUserException nue) {
        assertTrue(true);
    }
    userId = "4";
    String result = instance.displayEditUserAdminPage(userId, request, response, model);
    assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
    CreateUserCommand cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
    assertNotNull(cuc);
    assertTrue(cuc.getActivated());
    assertTrue(cuc.getAdmin());
    assertEquals("admin@test.com", cuc.getEmail());
    assertEquals("http://www.admin.com", cuc.getSiteUrl());
    assertEquals("0123456789", cuc.getPhoneNumber());
    assertEquals("nameAdmin", cuc.getLastName());
    assertEquals("firstNameAdmin", cuc.getFirstName());
    assertEquals(Long.valueOf(4), request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY));
    userId = "5";
    result = instance.displayEditUserAdminPage(userId, request, response, model);
    assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
    cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
    assertNotNull(cuc);
    assertFalse(cuc.getActivated());
    assertFalse(cuc.getAdmin());
    assertEquals("user@test.com", cuc.getEmail());
    assertEquals("http://www.user.com", cuc.getSiteUrl());
    assertEquals("9876543210", cuc.getPhoneNumber());
    assertEquals("nameUser", cuc.getLastName());
    assertEquals("firstNameUser", cuc.getFirstName());
    assertEquals(Long.valueOf(5), request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY));
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForbiddenUserException(org.asqatasun.webapp.exception.ForbiddenUserException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 13 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method testSubmitEditUserChangeToExistingUserForm.

/**
     * Test of submitEditUserForm method, of class UserManagementController.
     */
public void testSubmitEditUserChangeToExistingUserForm() throws Exception {
    System.out.println("SubmitEditUserChangeToExistingUserForm");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
    createUserFormValidator.setUserDataService(mockUserDataService);
    instance.setCreateUserFormValidator(createUserFormValidator);
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    createUserCommand.setSiteUrl("http://www.newSite.com/");
    createUserCommand.setEmail("admin@test.com");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, Long.valueOf(5));
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
    assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result);
    assertTrue(bindingResult.hasErrors());
    assertEquals(1, bindingResult.getFieldErrors().size());
    assertNotNull(bindingResult.getFieldErrors("email"));
    assertEquals(1, bindingResult.getFieldErrors("email").size());
    assertEquals("sign-up.existingAccountWithEmail", bindingResult.getFieldErrors("email").get(0).getCode());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) CreateUserFormValidator(org.asqatasun.webapp.validator.CreateUserFormValidator) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 14 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class UserManagementControllerTest method testSubmitAddUserFormWithErrors.

/**
     * Test of submitAddUserForm method, of class UserManagementController.
     */
public void testSubmitAddUserFormWithErrors() throws Exception {
    System.out.println("SubmitAddUserFormWithErrors");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
    createUserFormValidator.setUserDataService(mockUserDataService);
    instance.setCreateUserFormValidator(createUserFormValidator);
    // First the form is sent back empty
    CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
    assertTrue(bindingResult.hasErrors());
    assertEquals(3, bindingResult.getFieldErrors().size());
    assertNotNull(bindingResult.getFieldErrors("email"));
    assertEquals(1, bindingResult.getFieldErrors("email").size());
    assertEquals("sign-up.missingEmail", bindingResult.getFieldErrors("email").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("password"));
    assertEquals(1, bindingResult.getFieldErrors("password").size());
    assertEquals("sign-up.missingPassword", bindingResult.getFieldErrors("password").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
    assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
    assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
    // First the form is sent back with passwords that don't match
    createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    createUserCommand.setEmail("user@test.com");
    createUserCommand.setPassword("password");
    createUserCommand.setConfirmPassword("confirmation");
    bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    model = new ExtendedModelMap();
    result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
    assertTrue(bindingResult.hasErrors());
    assertEquals(3, bindingResult.getFieldErrors().size());
    assertNotNull(bindingResult.getFieldErrors("email"));
    assertEquals(1, bindingResult.getFieldErrors("email").size());
    assertEquals("sign-up.existingAccountWithEmail", bindingResult.getFieldErrors("email").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("password"));
    assertEquals(1, bindingResult.getFieldErrors("password").size());
    assertEquals("sign-up.passwordNotIdentical", bindingResult.getFieldErrors("password").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
    assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
    assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
    // Then the url is not conform but in this context it is not tested, so ignored
    // The Email1 is not conform regardin the pattern EMAIL_CHECKER_REGEXP
    // The passwords match but don't respect the constraints
    createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    createUserCommand.setEmail("null");
    createUserCommand.setPassword("password");
    createUserCommand.setConfirmPassword("password");
    bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    model = new ExtendedModelMap();
    result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
    assertTrue(bindingResult.hasErrors());
    assertEquals(3, bindingResult.getFieldErrors().size());
    assertNotNull(bindingResult.getFieldErrors("email"));
    assertEquals(1, bindingResult.getFieldErrors("email").size());
    assertEquals("sign-up.invalidEmail", bindingResult.getFieldErrors("email").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("password"));
    assertEquals(1, bindingResult.getFieldErrors("password").size());
    assertEquals("sign-up.invalidPassword", bindingResult.getFieldErrors("password").get(0).getCode());
    assertNotNull(bindingResult.getFieldErrors("generalErrorMsg"));
    assertEquals(1, bindingResult.getFieldErrors("generalErrorMsg").size());
    assertEquals("sign-up.mandatoryField", bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) CreateUserFormValidator(org.asqatasun.webapp.validator.CreateUserFormValidator) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 15 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class LoginControllerTest method testDisplayAccessDeniedPage.

/**
     * Test of displayAccessDeniedPage method, of class LoginController.
     */
public void testDisplayAccessDeniedPage() {
    System.out.println("displayAccessDeniedPage");
    Model model = new ExtendedModelMap();
    LoginController instance = new LoginController();
    String expResult = TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
    String result = instance.displayAccessDeniedPage(model);
    assertEquals(expResult, result);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Aggregations

ExtendedModelMap (org.springframework.ui.ExtendedModelMap)38 Model (org.springframework.ui.Model)24 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)11 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)10 CreateUserFormValidator (org.asqatasun.webapp.validator.CreateUserFormValidator)6 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)6 BindingResult (org.springframework.validation.BindingResult)6 User (org.asqatasun.webapp.entity.user.User)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)3 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 Enumeration (java.util.Enumeration)1