use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.
the class BaseViewTests method renderWithStaticAttributesNoCollision.
/**
* Test attribute passing, NOT CSV parsing.
*/
@Test
public void renderWithStaticAttributesNoCollision() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("foo", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
tv.render(model, requestContext);
checkContainsAll(model, tv.model);
checkContainsAll(p, tv.model);
assertThat(tv.initialized).isTrue();
}
use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.
the class BaseViewTests method dynamicModelOverridesStaticAttributesIfCollision.
@Test
public void dynamicModelOverridesStaticAttributesIfCollision() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
HttpServletRequest request = new MockHttpServletRequest();
HttpServletResponse response = new MockHttpServletResponse();
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
Properties p = new Properties();
p.setProperty("one", "bar");
p.setProperty("something", "else");
tv.setAttributes(p);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
tv.render(model, requestContext);
// Check it contains all
checkContainsAll(model, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.
the class CorsFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
RequestContext context = RequestContextHolder.get();
if (context == null) {
WebApplicationContext webApplicationContext = ServletUtils.findWebApplicationContext(request);
context = new ServletRequestContext(webApplicationContext, request, response);
RequestContextHolder.set(context);
}
try {
CorsConfiguration corsConfiguration = this.configSource.getCorsConfiguration(context);
if (!processor.process(corsConfiguration, context) || CorsUtils.isPreFlightRequest(context)) {
return;
}
// handle next
filterChain.doFilter(request, response);
} finally {
RequestContextHolder.remove();
}
}
use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.
the class UrlFilenameViewControllerTests method withPrefix.
@PathPatternsParameterizedTest
void withPrefix(Function<String, RequestContext> requestFactory) throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
controller.setPrefix("mypre_");
RequestContext request = requestFactory.apply("/index.html");
ModelAndView mv = controller.handleRequest(request);
assertThat(mv.getViewName()).isEqualTo("mypre_index");
assertThat(mv.getModel().isEmpty()).isTrue();
}
use of cn.taketoday.web.RequestContext in project today-infrastructure by TAKETODAY.
the class UrlFilenameViewControllerTests method withPrefixAndSuffix.
@PathPatternsParameterizedTest
void withPrefixAndSuffix(Function<String, RequestContext> requestFactory) throws Exception {
UrlFilenameViewController controller = new UrlFilenameViewController();
controller.setPrefix("mypre_");
controller.setSuffix("_mysuf");
RequestContext request = requestFactory.apply("/index.html");
ModelAndView mv = controller.handleRequest(request);
assertThat(mv.getViewName()).isEqualTo("mypre_index_mysuf");
assertThat(mv.getModel().isEmpty()).isTrue();
}
Aggregations