use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorMockTests method handleReturnValueProduces.
@Test
public void handleReturnValueProduces() throws Throwable {
String body = "Foo";
servletRequest.addHeader("Accept", "text/*");
HandlerMatchingMetadata metadata = mock(HandlerMatchingMetadata.class);
given(metadata.getProducibleMediaTypes()).willReturn(new MediaType[] { MediaType.TEXT_HTML });
webRequest.setMatchingMetadata(metadata);
given(stringMessageConverter.canWrite(String.class, MediaType.TEXT_HTML)).willReturn(true);
processor.handleReturnValue(webRequest, handlerMethod6, body);
verify(stringMessageConverter).write(eq(body), eq(MediaType.TEXT_HTML), isA(HttpOutputMessage.class));
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class PathVariableMapMethodArgumentResolverTests method resolveArgument.
@Test
public void resolveArgument() throws Throwable {
applyTemplateVars();
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name1", "value1");
uriTemplateVars.put("name2", "value2");
RequestPath requestPath = RequestPath.parse("/mock/value1/value2", null);
PathPattern pathPattern = PathPatternParser.defaultInstance.parse("/mock/{name1}/{name2}");
HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(new Object(), "/mock", requestPath, pathPattern, PathPatternParser.defaultInstance);
webRequest.setMatchingMetadata(matchingMetadata);
Object result = resolver.resolveArgument(webRequest, paramMap);
assertThat(result).isEqualTo(uriTemplateVars);
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class RedirectViewUriTemplateTests method uriTemplateReuseCurrentRequestVars.
@Test
void uriTemplateReuseCurrentRequestVars() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("key1", "value1");
model.put("name", "value2");
model.put("key3", "value3");
Map<String, String> currentRequestUriTemplateVars = new HashMap<>();
currentRequestUriTemplateVars.put("var1", "v1");
currentRequestUriTemplateVars.put("name", "v2");
currentRequestUriTemplateVars.put("var3", "v3");
HandlerMatchingMetadata metadata = new HandlerMatchingMetadata(context) {
@Override
public Map<String, String> getUriVariables() {
return currentRequestUriTemplateVars;
}
};
context.setMatchingMetadata(metadata);
String url = "https://url.somewhere.com";
RedirectView redirectView = new RedirectView(url + "/{key1}/{var1}/{name}");
redirectView.renderMergedOutputModel(model, context);
assertThat(this.response.getRedirectedUrl()).isEqualTo((url + "/value1/v1/value2?key3=value3"));
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework by TAKETODAY.
the class ContentNegotiatingViewResolverTests method getMediaTypeAcceptHeaderWithProduces.
@Test
public void getMediaTypeAcceptHeaderWithProduces() throws Exception {
HandlerMatchingMetadata matchingMetadata = new HandlerMatchingMetadata(requestContext);
matchingMetadata.setProducibleMediaTypes(new MediaType[] { MediaType.APPLICATION_XHTML_XML });
requestContext.setMatchingMetadata(matchingMetadata);
request.addHeader("Accept", "text/html,application/xml;q=0.9,application/xhtml+xml,*/*;q=0.8");
viewResolver.afterPropertiesSet();
List<MediaType> result = viewResolver.getMediaTypes(requestContext);
assertThat(result.get(0)).as("Invalid content type").isEqualTo(new MediaType("application", "xhtml+xml"));
}
use of cn.taketoday.web.HandlerMatchingMetadata in project today-framework 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();
}
Aggregations