Search in sources :

Example 1 with ResponseBodyResultHandler

use of org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method responseBodyResultHandler.

@Test
public void responseBodyResultHandler() {
    ApplicationContext context = loadConfig(WebFluxConfig.class);
    String name = "responseBodyResultHandler";
    ResponseBodyResultHandler handler = context.getBean(name, ResponseBodyResultHandler.class);
    assertThat(handler).isNotNull();
    assertThat(handler.getOrder()).isEqualTo(100);
    List<HttpMessageWriter<?>> writers = handler.getMessageWriters();
    assertThat(writers.size()).isEqualTo(13);
    assertHasMessageWriter(writers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
    assertHasMessageWriter(writers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
    assertHasMessageWriter(writers, forClass(String.class), TEXT_PLAIN);
    assertHasMessageWriter(writers, forClass(Resource.class), IMAGE_PNG);
    assertHasMessageWriter(writers, forClass(Message.class), new MediaType("application", "x-protobuf"));
    assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_XML);
    assertHasMessageWriter(writers, forClass(TestBean.class), APPLICATION_JSON);
    assertHasMessageWriter(writers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile"));
    assertHasMessageWriter(writers, forClass(TestBean.class), null);
    name = "webFluxContentTypeResolver";
    RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
    assertThat(handler.getContentTypeResolver()).isSameAs(resolver);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ResponseBodyResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) Message(com.google.protobuf.Message) Resource(org.springframework.core.io.Resource) MediaType(org.springframework.http.MediaType) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with ResponseBodyResultHandler

use of org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method responseBodyResultHandlerWithPrimaryUsesQualifiedReactiveAdapterRegistry.

@Test
void responseBodyResultHandlerWithPrimaryUsesQualifiedReactiveAdapterRegistry() {
    load(registerPrimaryBean("testReactiveAdapterRegistry", ReactiveAdapterRegistry.class));
    ResponseBodyResultHandler responseBodyResultHandler = this.context.getBean(ResponseBodyResultHandler.class);
    assertThat(responseBodyResultHandler.getAdapterRegistry()).isSameAs(this.context.getBean("webFluxAdapterRegistry"));
    assertThat(this.context.getBeansOfType(ReactiveAdapterRegistry.class)).containsOnlyKeys("webFluxAdapterRegistry", "testReactiveAdapterRegistry");
}
Also used : ResponseBodyResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with ResponseBodyResultHandler

use of org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method responseBodyResultHandlerWithPrimaryUsesQualifiedRequestedContentTypeResolver.

@Test
void responseBodyResultHandlerWithPrimaryUsesQualifiedRequestedContentTypeResolver() {
    load(registerPrimaryBean("testContentTypeResolver", RequestedContentTypeResolver.class));
    ResponseBodyResultHandler responseBodyResultHandler = this.context.getBean(ResponseBodyResultHandler.class);
    assertThat(responseBodyResultHandler.getContentTypeResolver()).isSameAs(this.context.getBean("webFluxContentTypeResolver"));
    assertThat(this.context.getBeansOfType(RequestedContentTypeResolver.class)).containsOnlyKeys("webFluxContentTypeResolver", "testContentTypeResolver");
}
Also used : ResponseBodyResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) Test(org.junit.jupiter.api.Test)

Example 4 with ResponseBodyResultHandler

use of org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method responseBodyResultHandlerUsesWebFluxInfrastructureByDefault.

@Test
void responseBodyResultHandlerUsesWebFluxInfrastructureByDefault() {
    load(context -> {
    });
    ResponseBodyResultHandler responseBodyResultHandler = this.context.getBean(ResponseBodyResultHandler.class);
    assertThat(responseBodyResultHandler.getAdapterRegistry()).isSameAs(this.context.getBean("webFluxAdapterRegistry"));
    assertThat(responseBodyResultHandler.getContentTypeResolver()).isSameAs(this.context.getBean("webFluxContentTypeResolver"));
}
Also used : ResponseBodyResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 ResponseBodyResultHandler (org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler)4 RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)2 Message (com.google.protobuf.Message)1 ByteBuffer (java.nio.ByteBuffer)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)1 Resource (org.springframework.core.io.Resource)1 MediaType (org.springframework.http.MediaType)1 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)1