Search in sources :

Example 1 with ServletServerHttpResponse

use of cn.taketoday.http.server.ServletServerHttpResponse in project today-infrastructure by TAKETODAY.

the class ReactiveTypeHandlerTests method testEmitterContentType.

private void testEmitterContentType(String expected) throws Exception {
    ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
    ResponseBodyEmitter emitter = handleValue(Flux.empty(), Flux.class, ResolvableType.fromClass(String.class));
    emitter.extendResponse(webRequest);
    assertThat(message.getHeaders().getContentType().toString()).isEqualTo(expected);
    resetRequest();
}
Also used : ServletServerHttpResponse(cn.taketoday.http.server.ServletServerHttpResponse)

Example 2 with ServletServerHttpResponse

use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.

the class ReactiveTypeHandlerTests method writeStreamJson.

@Test
public void writeStreamJson() throws Exception {
    this.servletRequest.addHeader("Accept", "application/x-ndjson");
    Sinks.Many<Bar> sink = Sinks.many().unicast().onBackpressureBuffer();
    ResponseBodyEmitter emitter = handleValue(sink.asFlux(), Flux.class, ResolvableType.fromClass(Bar.class));
    EmitterHandler emitterHandler = new EmitterHandler();
    emitter.initialize(emitterHandler);
    ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
    emitter.extendResponse(message);
    Bar bar1 = new Bar("foo");
    Bar bar2 = new Bar("bar");
    sink.tryEmitNext(bar1);
    sink.tryEmitNext(bar2);
    sink.tryEmitComplete();
    assertThat(message.getHeaders().getContentType().toString()).isEqualTo("application/x-ndjson");
    assertThat(emitterHandler.getValues()).isEqualTo(Arrays.asList(bar1, "\n", bar2, "\n"));
}
Also used : Sinks(reactor.core.publisher.Sinks) ServletServerHttpResponse(cn.taketoday.http.server.ServletServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 3 with ServletServerHttpResponse

use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.

the class ObjectToStringHttpMessageConverterTests method setup.

@BeforeEach
public void setup() {
    ConversionService conversionService = new DefaultConversionService();
    this.converter = new ObjectToStringHttpMessageConverter(conversionService);
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ConversionService(cn.taketoday.core.conversion.ConversionService) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService) ServletServerHttpResponse(cn.taketoday.http.server.ServletServerHttpResponse) DefaultConversionService(cn.taketoday.core.conversion.support.DefaultConversionService) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ServletServerHttpResponse

use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.

the class RequestResponseBodyAdviceChainTests method setup.

@BeforeEach
public void setup() {
    this.body = "body";
    this.contentType = MediaType.TEXT_PLAIN;
    this.paramType = new MethodParameter(ReflectionUtils.getMethod(this.getClass(), "handle", String.class), 0);
    this.returnType = new MethodParameter(ReflectionUtils.getMethod(this.getClass(), "handle", String.class), -1);
    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    this.request = new ServletServerHttpRequest(servletRequest);
    MockHttpServletResponse servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(servletResponse);
    this.requestContext = new ServletRequestContext(null, servletRequest, servletResponse);
}
Also used : ServletServerHttpRequest(cn.taketoday.http.server.ServletServerHttpRequest) MockHttpServletRequest(cn.taketoday.web.testfixture.servlet.MockHttpServletRequest) ServletServerHttpResponse(cn.taketoday.http.server.ServletServerHttpResponse) ServletRequestContext(cn.taketoday.web.servlet.ServletRequestContext) MethodParameter(cn.taketoday.core.MethodParameter) MockHttpServletResponse(cn.taketoday.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ServletServerHttpResponse

use of cn.taketoday.http.server.ServletServerHttpResponse in project today-framework by TAKETODAY.

the class ReactiveTypeHandlerTests method testEmitterContentType.

private void testEmitterContentType(String expected) throws Exception {
    ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
    ResponseBodyEmitter emitter = handleValue(Flux.empty(), Flux.class, ResolvableType.fromClass(String.class));
    emitter.extendResponse(message);
    assertThat(message.getHeaders().getContentType().toString()).isEqualTo(expected);
    resetRequest();
}
Also used : ServletServerHttpResponse(cn.taketoday.http.server.ServletServerHttpResponse)

Aggregations

ServletServerHttpResponse (cn.taketoday.http.server.ServletServerHttpResponse)7 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ConversionService (cn.taketoday.core.conversion.ConversionService)2 DefaultConversionService (cn.taketoday.core.conversion.support.DefaultConversionService)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 Test (org.junit.jupiter.api.Test)2 Sinks (reactor.core.publisher.Sinks)2 MethodParameter (cn.taketoday.core.MethodParameter)1 ServletServerHttpRequest (cn.taketoday.http.server.ServletServerHttpRequest)1 MockHttpServletResponse (cn.taketoday.web.mock.MockHttpServletResponse)1 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)1 MockHttpServletRequest (cn.taketoday.web.testfixture.servlet.MockHttpServletRequest)1