use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class ReactiveTypeHandlerTests method mediaTypes.
@Test
public void mediaTypes() throws Exception {
// Media type from request
this.servletRequest.addHeader("Accept", "text/event-stream");
testSseResponse(true);
// Media type from "produces" attribute
Set<MediaType> types = Collections.singleton(MediaType.TEXT_EVENT_STREAM);
HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(webRequest);
matchingMetadata.setProducibleMediaTypes(new MediaType[] { MediaType.TEXT_EVENT_STREAM });
webRequest.setMatchingMetadata(matchingMetadata);
testSseResponse(true);
// No media type preferences
testSseResponse(false);
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class BaseViewTests method dynamicModelOverridesPathVariables.
@Test
public void dynamicModelOverridesPathVariables() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
Map<String, String> pathVars = new HashMap<>();
pathVars.put("one", "bar");
pathVars.put("something", "else");
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
HandlerMatchingMetadata metadata = new HandlerMatchingMetadata(requestContext) {
@Override
public Map<String, String> getUriVariables() {
return pathVars;
}
};
requestContext.setMatchingMetadata(metadata);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, requestContext);
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.HandlerMatchingMetadata in project today-infrastructure by TAKETODAY.
the class BaseViewTests method pathVarsOverrideStaticAttributes.
@Test
public void pathVarsOverrideStaticAttributes() 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 pathVars = new HashMap<>();
pathVars.put("one", new HashMap<>());
pathVars.put("two", new Object());
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
HandlerMatchingMetadata metadata = new HandlerMatchingMetadata(requestContext) {
@Override
public Map<String, String> getUriVariables() {
return pathVars;
}
};
requestContext.setMatchingMetadata(metadata);
tv.render(new HashMap<>(), requestContext);
checkContainsAll(pathVars, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-infrastructure by TAKETODAY.
the class BaseViewTests method dynamicModelOverridesPathVariables.
@Test
public void dynamicModelOverridesPathVariables() throws Exception {
WebServletApplicationContext wac = mock(WebServletApplicationContext.class);
given(wac.getServletContext()).willReturn(new MockServletContext());
TestView tv = new TestView(wac);
tv.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
Map<String, String> pathVars = new HashMap<>();
pathVars.put("one", "bar");
pathVars.put("something", "else");
RequestContext requestContext = ServletUtils.getRequestContext(request, response);
HandlerMatchingMetadata metadata = new HandlerMatchingMetadata(requestContext) {
@Override
public Map<String, String> getUriVariables() {
return pathVars;
}
};
requestContext.setMatchingMetadata(metadata);
Map<String, Object> model = new HashMap<>();
model.put("one", new HashMap<>());
model.put("two", new Object());
tv.render(model, requestContext);
checkContainsAll(model, tv.model);
assertThat(tv.model.size()).isEqualTo(3);
assertThat(tv.model.get("something")).isEqualTo("else");
assertThat(tv.initialized).isTrue();
}
Aggregations