Search in sources :

Example 31 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException 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 32 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException 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 33 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException 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)

Example 34 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException 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 35 with ForbiddenPageException

use of org.asqatasun.webapp.exception.ForbiddenPageException 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)

Aggregations

ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)35 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Secured (org.springframework.security.access.annotation.Secured)13 Contract (org.asqatasun.webapp.entity.contract.Contract)12 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)11 Audit (org.asqatasun.entity.audit.Audit)10 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)8 WebResource (org.asqatasun.entity.subject.WebResource)6 User (org.asqatasun.webapp.entity.user.User)5 Site (org.asqatasun.entity.subject.Site)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Page (org.asqatasun.entity.subject.Page)2 Act (org.asqatasun.webapp.entity.contract.Act)2 Scenario (org.asqatasun.webapp.entity.scenario.Scenario)2 Model (org.springframework.ui.Model)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1