use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class StreamingResponseBodyReturnValueHandlerTests method responseEntityNoContent.
@Test
public void responseEntityNoContent() throws Exception {
MethodParameter returnType = returnType(TestController.class, "handleResponseEntity");
ResponseEntity<?> emitter = ResponseEntity.noContent().build();
this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);
assertFalse(this.request.isAsyncStarted());
assertEquals(204, this.response.getStatus());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class StreamingResponseBodyReturnValueHandlerTests method responseEntity.
@Test
public void responseEntity() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
MethodParameter returnType = returnType(TestController.class, "handleResponseEntity");
ResponseEntity<StreamingResponseBody> emitter = ResponseEntity.ok().header("foo", "bar").body(outputStream -> {
outputStream.write("foo".getBytes(StandardCharsets.UTF_8));
latch.countDown();
});
this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);
assertTrue(this.request.isAsyncStarted());
assertEquals(200, this.response.getStatus());
assertEquals("bar", this.response.getHeader("foo"));
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals("foo", this.response.getContentAsString());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class StreamingResponseBodyReturnValueHandlerTests method streamingResponseBody.
@Test
public void streamingResponseBody() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
MethodParameter returnType = returnType(TestController.class, "handle");
StreamingResponseBody streamingBody = outputStream -> {
outputStream.write("foo".getBytes(StandardCharsets.UTF_8));
latch.countDown();
};
this.handler.handleReturnValue(streamingBody, returnType, this.mavContainer, this.webRequest);
assertTrue(this.request.isAsyncStarted());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals("foo", this.response.getContentAsString());
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class StreamingResponseBodyReturnValueHandlerTests method responseEntityWithHeadersAndNoContent.
@Test
public void responseEntityWithHeadersAndNoContent() throws Exception {
ResponseEntity<?> emitter = ResponseEntity.noContent().header("foo", "bar").build();
MethodParameter returnType = returnType(TestController.class, "handleResponseEntity");
this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);
assertEquals(Collections.singletonList("bar"), this.response.getHeaders("foo"));
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class UriComponentsBuilderMethodArgumentResolverTests method setup.
@Before
public void setup() throws Exception {
this.resolver = new UriComponentsBuilderMethodArgumentResolver();
this.servletRequest = new MockHttpServletRequest();
this.webRequest = new ServletWebRequest(this.servletRequest);
Method method = this.getClass().getDeclaredMethod("handle", UriComponentsBuilder.class, ServletUriComponentsBuilder.class, int.class);
this.builderParam = new MethodParameter(method, 0);
this.servletBuilderParam = new MethodParameter(method, 1);
this.intParam = new MethodParameter(method, 2);
}
Aggregations