Search in sources :

Example 31 with ExtendedModelMap

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

the class UserManagementControllerTest method testDisplayAdminPage.

/**
     * Test of displayAdminPage method, of class UserManagementController.
     */
public void testDisplayAdminPage() {
    System.out.println("displayAdminPage");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Model model = new ExtendedModelMap();
    String result = instance.displayAdminPage(request, response, model);
    assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
}
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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 32 with ExtendedModelMap

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

the class UserManagementControllerTest method testSubmitEditUserForm.

/**
     * Test of submitEditUserForm method, of class UserManagementController.
     */
public void testSubmitEditUserForm() throws Exception {
    System.out.println("submitEditUserForm");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, true, 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.setEmail("user@test.com");
    createUserCommand.setLastName("newName");
    createUserCommand.setFirstName("newFirstName");
    createUserCommand.setPhoneNumber("0102030405");
    createUserCommand.setActivated(false);
    createUserCommand.setAdmin(true);
    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.ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("user@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.webapp.entity.user.User) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Model(org.springframework.ui.Model) CreateUserFormValidator(org.asqatasun.webapp.validator.CreateUserFormValidator) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 33 with ExtendedModelMap

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

the class UserManagementControllerTest method testDeleteUserConfirmation.

/**
     * Test of deleteUserConfirmation method, of class UserManagementController.
     */
public void testDeleteUserConfirmation() {
    System.out.println("deleteUserConfirmation");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(true, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Model model = new ExtendedModelMap();
    String idToRemove = "idToRemove";
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, idToRemove);
    try {
        instance.displayDeleteUserConfirmation(request, response, model);
        assertTrue(false);
    } catch (ForbiddenUserException fue) {
        assertTrue(true);
    }
    idToRemove = "4";
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, idToRemove);
    String result = instance.displayDeleteUserConfirmation(request, response, model);
    assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, Long.valueOf(6));
    result = instance.displayDeleteUserConfirmation(request, response, model);
    assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
    request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, Long.valueOf(5));
    result = instance.displayDeleteUserConfirmation(request, response, model);
    assertEquals(TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME, result);
    assertTrue(model.asMap().isEmpty());
    assertEquals("user@test.com", request.getSession().getAttribute(TgolKeyStore.DELETED_USER_NAME_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)

Example 34 with ExtendedModelMap

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

the class UserManagementControllerTest method testDeleteUserPage.

/**
     * Test of deleteUserPage method, of class UserManagementController.
     */
public void testDeleteUserPage() {
    System.out.println("deleteUserPage");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, false, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    Model model = new ExtendedModelMap();
    String idToRemove = "idToRemove";
    try {
        instance.displayDeleteUserPage(idToRemove, request, response, model);
        assertTrue(false);
    } catch (ForbiddenUserException fue) {
        assertTrue(true);
    }
    idToRemove = "4";
    String result = instance.displayDeleteUserPage(idToRemove, request, response, model);
    assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
    idToRemove = "6";
    result = instance.displayDeleteUserPage(idToRemove, request, response, model);
    assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
    idToRemove = "5";
    result = instance.displayDeleteUserPage(idToRemove, request, response, model);
    assertEquals(TgolKeyStore.DELETE_USER_VIEW_NAME, result);
    assertEquals("user@test.com", model.asMap().get(TgolKeyStore.USER_NAME_TO_DELETE_KEY));
    assertEquals(Long.valueOf(5), request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY));
    assertEquals(1, model.asMap().size());
}
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)

Example 35 with ExtendedModelMap

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

the class AuditSetUpControllerTest method testDisplayPageAuditPageSetUpWithWrongContractId.

public void testDisplayPageAuditPageSetUpWithWrongContractId() {
    System.out.println("testDisplayPageAuditPageSetUpWithWrongContractId");
    // set-up
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(1, "Contract1");
    // the contract Id cannot be converted as a Long. An exception is caught
    try {
        instance.displayPageAuditSetUp("Not a number", null, null, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Aggregations

ExtendedModelMap (org.springframework.ui.ExtendedModelMap)39 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