Search in sources :

Example 36 with ExtendedModelMap

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

the class AuditSetUpControllerTest method testDisplayPageAuditUploadSetUpWithWrongContractId.

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

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

the class PageListControllerTest method testDisplayPageListWithUnknownAuditId.

/**
     * The mockWebResourceDataService contains only 2 WebResource. One has 
     * Id=1 and is a Page instance, the second has Id=2 and is a Site instance.
     * If a webresource with an id different from 1 or 2 is requested, the
     * ForbiddenPageException is caught
     * 
     * @throws Exception 
     */
public void testDisplayPageListWithUnknownAuditId() throws Exception {
    System.out.println("testDisplayPageListWithUnknownAuditId");
    setUpMockAuditDataService(UNKNOWN_AUDIT_ID);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(UNKNOWN_AUDIT_ID));
    try {
        instance.displayPageList(request, new MockHttpServletResponse(), new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fbe) {
        // The auditDataService catch the NoResultException and return null.
        // Then if the audit is null, a ForbiddenPageException is caught
        assertTrue(true);
    }
}
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 38 with ExtendedModelMap

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

the class PageListControllerTest method testDisplayPageListWithoutAuditId.

/**
     * The servlet is supposed to embed the audit id the page is 
     * about. If not, the ForbiddenPageException is caught.
     * @throws Exception 
     */
public void testDisplayPageListWithoutAuditId() throws Exception {
    System.out.println("testDisplayPageListWithoutAuditId");
    // about. If not, the access denied page is returned
    try {
        instance.displayPageList(new MockHttpServletRequest(), new MockHttpServletResponse(), new ExtendedModelMap());
        assertTrue(false);
    } catch (AuditParameterMissingException fbe) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AuditParameterMissingException(org.asqatasun.webapp.exception.AuditParameterMissingException)

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