use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ContentNegotiatingViewResolverTests method resolveViewNameRedirectView.
@Test
public void resolveViewNameRedirectView() throws Exception {
request.addHeader("Accept", "application/json");
request.setRequestURI("/test");
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
webAppContext.setServletContext(new MockServletContext());
webAppContext.refresh();
UrlBasedViewResolver urlViewResolver = new InternalResourceViewResolver();
urlViewResolver.setApplicationContext(webAppContext);
ViewResolver xmlViewResolver = mock(ViewResolver.class);
viewResolver.setViewResolvers(Arrays.<ViewResolver>asList(xmlViewResolver, urlViewResolver));
View xmlView = mock(View.class, "application_xml");
View jsonView = mock(View.class, "application_json");
viewResolver.setDefaultViews(Arrays.asList(jsonView));
viewResolver.afterPropertiesSet();
String viewName = "redirect:anotherTest";
Locale locale = Locale.ENGLISH;
given(xmlViewResolver.resolveViewName(viewName, locale)).willReturn(xmlView);
given(jsonView.getContentType()).willReturn("application/json");
View actualView = viewResolver.resolveViewName(viewName, locale);
assertEquals("Invalid view", RedirectView.class, actualView.getClass());
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class ScriptTemplateViewTests method resourceLoaderPath.
// SPR-14210
@Test
public void resourceLoaderPath() throws Exception {
MockServletContext servletContext = new MockServletContext();
this.wac.setServletContext(servletContext);
this.wac.refresh();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
MockHttpServletResponse response = new MockHttpServletResponse();
Map<String, Object> model = new HashMap<>();
InvocableScriptEngine engine = mock(InvocableScriptEngine.class);
when(engine.invokeFunction(any(), any(), any(), any())).thenReturn("foo");
this.view.setEngine(engine);
this.view.setRenderFunction("render");
this.view.setApplicationContext(this.wac);
this.view.setUrl("org/springframework/web/servlet/view/script/empty.txt");
this.view.render(model, request, response);
assertEquals("foo", response.getContentAsString());
response = new MockHttpServletResponse();
this.view.setResourceLoaderPath("classpath:org/springframework/web/servlet/view/script/");
this.view.setUrl("empty.txt");
this.view.render(model, request, response);
assertEquals("foo", response.getContentAsString());
response = new MockHttpServletResponse();
this.view.setResourceLoaderPath("classpath:org/springframework/web/servlet/view/script");
this.view.setUrl("empty.txt");
this.view.render(model, request, response);
assertEquals("foo", response.getContentAsString());
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class TilesConfigurerTests method simpleBootstrap.
@Test
public void simpleBootstrap() {
MockServletContext servletContext = new MockServletContext();
TilesConfigurer tc = new TilesConfigurer();
tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
tc.setCheckRefresh(true);
tc.setServletContext(servletContext);
tc.afterPropertiesSet();
ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);
BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
Request requestContext = new ServletRequest(container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));
tc.destroy();
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class GroovyMarkupViewTests method setup.
@Before
public void setup() {
this.webAppContext = mock(WebApplicationContext.class);
this.servletContext = new MockServletContext();
this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext);
}
use of org.springframework.mock.web.test.MockServletContext in project spring-framework by spring-projects.
the class JRubyScriptTemplateTests method setup.
@Before
public void setup() {
this.webAppContext = mock(WebApplicationContext.class);
this.servletContext = new MockServletContext();
this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webAppContext);
}
Aggregations