Search in sources :

Example 26 with ExtendedModelMap

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

the class PageListControllerTest method testDisplayPageListWithWrongAuditId.

/**
     * if the id cannot be converted as Long, the ForbiddenPageException is 
     * caught.
     * 
     * @throws Exception 
     */
public void testDisplayPageListWithWrongAuditId() throws Exception {
    System.out.println("testDisplayPageListWithWrongAuditId");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TgolKeyStore.AUDIT_ID_KEY, "wrongId");
    try {
        instance.displayPageList(request, new MockHttpServletResponse(), new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fbe) {
        assertTrue(StringUtils.equals("java.lang.NumberFormatException: For input string: \"wrongId\"", fbe.getCause().toString()));
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 27 with ExtendedModelMap

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

the class AuditSetUpControllerTest method testDisplayPageAuditPageSetUpWithUnauthorisedFunctionality.

public void testDisplayPageAuditPageSetUpWithUnauthorisedFunctionality() {
    System.out.println("testDisplayPageAuditPageSetUpWithUnauthorisedFunctionality");
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(2, "Contract1");
    setUpEmptyViewFunctionalityBindingMap();
    // regarding the viewFunctionalityBindingMap. An exception is caught
    try {
        instance.displayPageAuditSetUp("2", null, null, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 28 with ExtendedModelMap

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

the class AuditSetUpControllerTest method testDisplayPageAuditSiteSetUpWithWrongContractId.

public void testDisplayPageAuditSiteSetUpWithWrongContractId() {
    System.out.println("testDisplayPageAuditSiteSetUpWithWrongContractId");
    // set-up
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(1, "Contract1");
    // the contract Id cannot be converted as a Long. An exception is caught
    try {
        instance.displaySiteAuditSetUp("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)

Example 29 with ExtendedModelMap

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

the class ContractControllerTest method testDisplayContractExpiredPage_4args.

public void testDisplayContractExpiredPage_4args() {
    System.out.println("displayContractExpiredPage");
    setUpUserDataService(true);
    setUpContractDataService(0);
    setUpActDataService(0, 0, 0, 0, 0);
    setUpLocaleResolver();
    setUpActionHandler(0);
    setUpMockAuthenticationContext();
    // contractId cannot be converted as a long, the ForbiddenUserException 
    // is caught
    String contractId = "wrongId";
    HttpServletRequest request = null;
    HttpServletResponse response = null;
    Model model = new ExtendedModelMap();
    try {
        instance.displayContractPage(contractId, request, response, model);
        // if the exception is not caught, the test is on error
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
    try {
        instance.displayContractPage(contractId, request, response, model);
        // if the exception is not caught, the test is on error
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 30 with ExtendedModelMap

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

the class UserManagementControllerTest method testAddUserAdminPage.

/**
     * Test of addUserAdminPage method, of class UserManagementController.
     */
public void testAddUserAdminPage() {
    System.out.println("addUserAdminPage");
    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.displayAddUserAdminPage(request, response, model);
    assertEquals(TgolKeyStore.ADD_USER_VIEW_NAME, result);
    assertEquals(1, model.asMap().size());
    CreateUserCommand cuc = ((CreateUserCommand) model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY));
    assertNotNull(cuc);
    assertFalse(cuc.getActivated());
    assertFalse(cuc.getAdmin());
    assertNull(cuc.getEmail());
    assertEquals("http://", cuc.getSiteUrl());
    assertNull(cuc.getPhoneNumber());
    assertNull(cuc.getLastName());
    assertNull(cuc.getFirstName());
    assertNull(cuc.getPassword());
    assertNull(cuc.getConfirmPassword());
}
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) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

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