Search in sources :

Example 21 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project spring-framework by spring-projects.

the class ModelMethodProcessorTests method handleModelReturnValue.

@Test
public void handleModelReturnValue() throws Exception {
    mavContainer.addAttribute("attr1", "value1");
    Model returnValue = new ExtendedModelMap();
    returnValue.addAttribute("attr2", "value2");
    processor.handleReturnValue(returnValue, returnParamModel, mavContainer, webRequest);
    assertEquals("value1", mavContainer.getModel().get("attr1"));
    assertEquals("value2", mavContainer.getModel().get("attr2"));
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) Test(org.junit.Test)

Example 22 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project spring-framework by spring-projects.

the class FreeMarkerViewTests method render.

@Test
public void render() throws Exception {
    FreeMarkerView view = new FreeMarkerView();
    view.setConfiguration(this.freeMarkerConfig);
    view.setUrl("test.ftl");
    ModelMap model = new ExtendedModelMap();
    model.addAttribute("hello", "hi FreeMarker");
    view.render(model, null, this.exchange).block(Duration.ofMillis(5000));
    StepVerifier.create(this.exchange.getResponse().getBody()).consumeNextWith(buf -> assertEquals("<html><body>hi FreeMarker</body></html>", asString(buf))).expectComplete().verify();
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ModelMap(org.springframework.ui.ModelMap) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Test(org.junit.Test)

Example 23 with ExtendedModelMap

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

the class PageListControllerTest method testDisplayPageList.

/**
     * 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
     * 
     * @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);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 24 with ExtendedModelMap

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

the class PageListControllerTest method testDisplayPageListWithUnauthorizedActScope.

/**
     * 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.
     * 
     * @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);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForbiddenScopeException(org.asqatasun.webapp.exception.ForbiddenScopeException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 25 with ExtendedModelMap

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

the class PageListControllerTest method testDisplayPageListWithPageAudit.

/**
     * The PageList cannot be displayed when the webResource is a Page 
     * instance. The returned view is an access denied in this case.
     * 
     * @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);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

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