use of cn.taketoday.core.MethodParameter in project today-framework by TAKETODAY.
the class ErrorsMethodArgumentResolverTests method setup.
@BeforeEach
public void setup() throws Exception {
paramErrors = new ResolvableMethodParameter(new MethodParameter(getClass().getDeclaredMethod("handle", Errors.class), 0));
bindingResult = new WebDataBinder(new Object(), "attr").getBindingResult();
webRequest = new ServletRequestContext(null, new MockHttpServletRequest(), null);
}
use of cn.taketoday.core.MethodParameter in project today-framework by TAKETODAY.
the class HttpEntityMethodProcessorTests method resolveArgumentTypeVariable.
@Test
public void resolveArgumentTypeVariable() throws Exception {
Method method = MySimpleParameterizedController.class.getMethod("handleDto", HttpEntity.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
String content = "{\"name\" : \"Jad\"}";
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
HttpEntityMethodProcessor processor = new HttpEntityMethodProcessor(converters, null);
@SuppressWarnings("unchecked") HttpEntity<SimpleBean> result = (HttpEntity<SimpleBean>) processor.resolveArgument(webRequest, new ResolvableMethodParameter(methodParam));
assertThat(result).isNotNull();
assertThat(result.getBody().getName()).isEqualTo("Jad");
}
use of cn.taketoday.core.MethodParameter in project today-framework by TAKETODAY.
the class HttpEntityMethodProcessorTests method handleReturnValueWithETagAndETagFilter.
// SPR-13423
@Test
public void handleReturnValueWithETagAndETagFilter() throws Exception {
String eTagValue = "\"deadb33f8badf00d\"";
String content = "body";
Method method = getClass().getDeclaredMethod("handle");
MethodParameter returnType = new MethodParameter(method, -1);
FilterChain chain = (req, res) -> {
ResponseEntity<String> returnValue = ResponseEntity.ok().eTag(eTagValue).body(content);
try {
ServletRequestContext requestToUse = new ServletRequestContext(null, (HttpServletRequest) req, (HttpServletResponse) res);
new HttpEntityMethodProcessor(Collections.singletonList(new StringHttpMessageConverter()), null).handleReturnValue(requestToUse, new HandlerMethod(this, method), returnValue);
assertThat(this.servletResponse.getContentAsString()).as("Response body was cached? It should be written directly to the raw response").isEqualTo(content);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
};
this.servletRequest.setMethod("GET");
new ShallowEtagHeaderFilter().doFilter(this.servletRequest, this.servletResponse, chain);
assertThat(this.servletResponse.getStatus()).isEqualTo(200);
assertThat(this.servletResponse.getHeader(HttpHeaders.ETAG)).isEqualTo(eTagValue);
assertThat(this.servletResponse.getContentAsString()).isEqualTo(content);
}
use of cn.taketoday.core.MethodParameter in project today-framework by TAKETODAY.
the class HttpEntityMethodProcessorTests method setup.
@BeforeEach
public void setup() throws Exception {
Method method = getClass().getDeclaredMethod("handle", HttpEntity.class, HttpEntity.class);
paramList = new ResolvableMethodParameter(new MethodParameter(method, 0));
paramSimpleBean = new ResolvableMethodParameter(new MethodParameter(method, 1));
servletRequest = new MockHttpServletRequest();
servletResponse = new MockHttpServletResponse();
servletRequest.setMethod("POST");
webRequest = new ServletRequestContext(null, servletRequest, servletResponse);
}
use of cn.taketoday.core.MethodParameter in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorMockTests method setup.
@BeforeEach
@SuppressWarnings("unchecked")
public void setup() throws Throwable {
stringMessageConverter = mock(HttpMessageConverter.class);
given(stringMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
given(stringMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.TEXT_PLAIN));
resourceMessageConverter = mock(HttpMessageConverter.class);
given(resourceMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
given(resourceMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.ALL));
resourceRegionMessageConverter = mock(HttpMessageConverter.class);
given(resourceRegionMessageConverter.getSupportedMediaTypes()).willReturn(Collections.singletonList(MediaType.ALL));
given(resourceRegionMessageConverter.getSupportedMediaTypes(any())).willReturn(Collections.singletonList(MediaType.ALL));
processor = new RequestResponseBodyMethodProcessor(Arrays.asList(stringMessageConverter, resourceMessageConverter, resourceRegionMessageConverter));
servletRequest = new MockHttpServletRequest();
servletRequest.setMethod("POST");
servletResponse = new MockHttpServletResponse();
webRequest = new ServletRequestContext(null, servletRequest, servletResponse);
Method methodHandle1 = getClass().getMethod("handle1", String.class, Integer.TYPE);
paramRequestBodyString = new ResolvableMethodParameter(new MethodParameter(methodHandle1, 0));
paramInt = new ResolvableMethodParameter(new MethodParameter(methodHandle1, 1));
paramValidBean = new ResolvableMethodParameter(new MethodParameter(getClass().getMethod("handle2", SimpleBean.class), 0));
paramStringNotRequired = new ResolvableMethodParameter(new MethodParameter(getClass().getMethod("handle3", String.class), 0));
paramOptionalString = new ResolvableMethodParameter(new MethodParameter(getClass().getMethod("handle4", Optional.class), 0));
Method handle5 = getClass().getMethod("handle5");
Method handle6 = getClass().getMethod("handle6");
Method handle7 = getClass().getMethod("handle7");
returnTypeString = new MethodParameter(methodHandle1, -1);
returnTypeInt = new MethodParameter(handle5, -1);
returnTypeStringProduces = new MethodParameter(handle6, -1);
returnTypeResource = new MethodParameter(handle7, -1);
handlerMethod1 = new HandlerMethod(this, methodHandle1);
handlerMethod5 = new HandlerMethod(this, handle5);
handlerMethod6 = new HandlerMethod(this, handle6);
handlerMethod7 = new HandlerMethod(this, handle7);
}
Aggregations