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"));
}
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();
}
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);
}
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);
}
}
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);
}
}
Aggregations