Example usage for org.springframework.ui ExtendedModelMap ExtendedModelMap

List of usage examples for org.springframework.ui ExtendedModelMap ExtendedModelMap

Introduction

In this page you can find the example usage for org.springframework.ui ExtendedModelMap ExtendedModelMap.

Prototype

ExtendedModelMap

Source Link

Usage

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * The servlet is supposed to embed the audit id the page is 
 * about. If not, the ForbiddenPageException is caught.
 * @throws Exception /*from  w ww  .j ava2 s . c om*/
 */
public void testDisplayPageListWithoutAuditId() throws Exception {
    System.out.println("testDisplayPageListWithoutAuditId");

    // The servlet is supposed to embed the webresource id the page is 
    // 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);
    }
}

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * if the id cannot be converted as Long, the ForbiddenPageException is 
 * caught.//from  w w  w  . j a  v a2 s .c  o  m
 * 
 * @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()));

    }
}

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * 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//from w w  w.  java  2s  . c  o m
 * 
 * @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);
    }
}

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * The PageList cannot be displayed when the webResource is a Page 
 * instance. The returned view is an access denied in this case.
 * //  w  w  w. j a v  a 2  s . c o m
 * @throws Exception 
 */
public void testDisplayPageListWithPageAudit() throws Exception {
    System.out.println("testDisplayPageListWithPageAudit");

    // The audit with Id 1 is associated with a Page instance 
    setUpMockAuditDataService(PAGE_AUDIT_ID);
    setUpMockUserDataService();
    setUpActDataService(false);
    setUpMockAuthenticationContext();

    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(PAGE_AUDIT_ID));
    try {
        instance.displayPageList(request, response, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fbe) {
        // The exception is caught when testing if audit.getSubject() is 
        // an instance of Page
        assertTrue(true);
    }
}

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * The PageList is displayed when the webResource is a Site instance. 
 * A mechanism is implemented into that controller that enables to display
 * the page only when the scope of the act related with the webResource
 * belongs to a list of authorized scope. In this case the list only contains 
 * DOMAIN as authorized scope, whereas the scope of the audit is 
 * GROUP_OF_PAGE, so the page cannot be displayed.
 * //w  ww .j av  a 2  s. co  m
 * @throws Exception 
 */
public void testDisplayPageListWithUnauthorizedActScope() throws Exception {
    System.out.println("testDisplayPageListWithUnauthorizedActScope");

    setUpMockAuditDataService(UNAUTHORIZED_SCOPE_AUDIT_ID);
    setUpMockUserDataService();
    setUpActDataService(false);
    setUpMockAuthenticationContext();

    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(UNAUTHORIZED_SCOPE_AUDIT_ID));

    List<String> authorizedScopeForPageList = new ArrayList();
    authorizedScopeForPageList.add("DOMAIN");
    instance.setAuthorizedScopeForPageList(authorizedScopeForPageList);

    try {
        instance.displayPageList(request, response, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenScopeException fbe) {
        assertTrue(true);
    }
}

From source file:org.asqatasun.webapp.controller.PageListControllerTest.java

/**
 * The PageList is displayed when the webResource is a Site instance. 
 * When the request has no TgolKeyStore.STATUS_KEY parameter set, 
 * the page that lists the number of page by Http Status Code has to be 
 * returned//from   w ww  . j a va  2  s.  c om
 * 
 * @throws Exception 
 */
public void testDisplayPageList() throws Exception {
    System.out.println("testDisplayPageList");

    setUpMockAuditDataService(SITE_AUDIT_GENERAL_PAGE_LIST_ID);
    setUpMockUserDataService();
    setUpActDataService(true);
    setUpMockAuthenticationContext();
    setUpAuditStatisticsFactory();

    List<String> authorizedScopeForPageList = new ArrayList();
    authorizedScopeForPageList.add("DOMAIN");
    instance.setAuthorizedScopeForPageList(authorizedScopeForPageList);

    HttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    String expResult = TgolKeyStore.PAGE_LIST_VIEW_NAME;
    request.addParameter(TgolKeyStore.AUDIT_ID_KEY, String.valueOf(SITE_AUDIT_GENERAL_PAGE_LIST_ID));
    String result = instance.displayPageList(request, response, new ExtendedModelMap());
    assertEquals(expResult, result);
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of setUpSignUpPage method, of class SignUpController.
 *///from  w  w  w  .j a v a  2  s.co m
public void testSetUpSignUpPage() {
    System.out.println("setUpSignUpPage");

    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    String result = instance.setUpSignUpPage(model);
    // the returned view is the sign-up view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of submitForm method, of class SignUpController.
 * @throws java.lang.Exception/*  w  ww  .j  a  va2 s  .c  o  m*/
 */
public void testSubmitForm() throws Exception {
    System.out.println("submitForm");

    setUpMockRoleDataService();
    setUpUserDataService();
    setUpMockExposablePropertyPlaceholderConfigurer();
    setUpValidatorAndBindingResult();
    setUpMockEmailSender();

    // Set up instance dependences
    Model model = new ExtendedModelMap();

    // the returned UserSignUpCommand is seen as valid regarding the validator
    // the CONFIRMATION sign-up page is displayed
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_REDIRECT_NAME;
    String result = instance.submitSignUpForm(mockValidCreateUserCommand, mockValidBindingResult, model);
    assertEquals(expResult, result);

    // the returned UserSignUpCommand is seen as invalid regarding the validator
    // the sign-up form is displayed again

    expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    result = instance.submitSignUpForm(mockInvalidCreateUserCommand, mockInvalidBindingResult, model);
    assertEquals(expResult, result);
    assertSame(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY), mockInvalidCreateUserCommand);
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of setUpSignUpConfirmationPage method, of class SignUpController.
 *//*ww  w  .  j a va  2  s  .  c  o  m*/
public void testSetUpSignUpConfirmationPage() {
    System.out.println("setUpSignUpConfirmationPage");
    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_NAME;
    String result = instance.setUpSignUpConfirmationPage(model);
    // the returned view is the sign-up confirmation view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}

From source file:org.kuali.mobility.shared.controllers.FileControllerTest.java

@Test
public void testIndex() {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    Model uiModel = new ExtendedModelMap();

    when(getFileService().findAllFiles()).thenReturn(new ArrayList<File>());

    String viewName;//from  w w  w. j ava2 s . co  m
    try {
        viewName = getController().index(request, uiModel);
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
        viewName = null;
    }
    assertTrue("View not what was expected.", INDEX.equals(viewName));
}