use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ModelAndViewResolverMethodReturnValueHandlerTests method handleNull.
@Test
public void handleNull() throws Exception {
MethodParameter returnType = new MethodParameter(getClass().getDeclaredMethod("testBeanReturnValue"), -1);
handler.handleReturnValue(null, returnType, mavContainer, request);
assertNull(mavContainer.getView());
assertNull(mavContainer.getViewName());
assertTrue(mavContainer.getModel().isEmpty());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method resolveParameterizedWithTypeVariableArgument.
// SPR-14470
@Test
public void resolveParameterizedWithTypeVariableArgument() throws Exception {
Method method = MyParameterizedControllerWithList.class.getMethod("handleDto", List.class);
HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedControllerWithList(), method);
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
String content = "[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]";
this.servletRequest.setContent(content.getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked") List<SimpleBean> result = (List<SimpleBean>) processor.resolveArgument(methodParam, container, request, factory);
assertNotNull(result);
assertEquals("Jad", result.get(0).getName());
assertEquals("Robert", result.get(1).getName());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method jacksonSubType.
// SPR-13318
@Test
public void jacksonSubType() throws Exception {
Method method = JacksonController.class.getMethod("handleSubType");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
Object returnValue = new JacksonController().handleSubType();
processor.handleReturnValue(returnValue, methodReturnType, this.container, this.request);
String content = this.servletResponse.getContentAsString();
assertTrue(content.contains("\"id\":123"));
assertTrue(content.contains("\"name\":\"foo\""));
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ResponseBodyEmitterReturnValueHandlerTests method sseEmitter.
@Test
public void sseEmitter() throws Exception {
MethodParameter returnType = returnType("handleSse");
SseEmitter emitter = new SseEmitter();
handleReturnValue(emitter, returnType);
assertTrue(this.request.isAsyncStarted());
assertEquals(200, this.response.getStatus());
assertEquals("text/event-stream;charset=UTF-8", this.response.getContentType());
SimpleBean bean1 = new SimpleBean();
bean1.setId(1L);
bean1.setName("Joe");
SimpleBean bean2 = new SimpleBean();
bean2.setId(2L);
bean2.setName("John");
emitter.send(SseEmitter.event().comment("a test").name("update").id("1").reconnectTime(5000L).data(bean1).data(bean2));
assertEquals(":a test\n" + "event:update\n" + "id:1\n" + "retry:5000\n" + "data:{\"id\":1,\"name\":\"Joe\"}\n" + "data:{\"id\":2,\"name\":\"John\"}\n" + "\n", this.response.getContentAsString());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class ResponseBodyEmitterReturnValueHandlerTests method responseEntitySse.
@Test
public void responseEntitySse() throws Exception {
MethodParameter returnType = returnType("handleResponseEntitySse");
ResponseEntity<SseEmitter> entity = ResponseEntity.ok().header("foo", "bar").body(new SseEmitter());
handleReturnValue(entity, returnType);
assertTrue(this.request.isAsyncStarted());
assertEquals(200, this.response.getStatus());
assertEquals("text/event-stream;charset=UTF-8", this.response.getContentType());
assertEquals("bar", this.response.getHeader("foo"));
}
Aggregations