Search in sources :

Example 1 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class WebFluxAutoConfigurationTests method shouldCustomizeCodecs.

@Test
void shouldCustomizeCodecs() {
    this.contextRunner.withUserConfiguration(CustomCodecCustomizers.class).run((context) -> {
        CodecCustomizer codecCustomizer = context.getBean("firstCodecCustomizer", CodecCustomizer.class);
        assertThat(codecCustomizer).isNotNull();
        then(codecCustomizer).should().customize(any(ServerCodecConfigurer.class));
    });
}
Also used : CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) ServerCodecConfigurer(org.springframework.http.codec.ServerCodecConfigurer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class WebClientAutoConfigurationTests method shouldCustomizeClientCodecs.

@Test
void shouldCustomizeClientCodecs() {
    this.contextRunner.withUserConfiguration(CodecConfiguration.class).run((context) -> {
        WebClient.Builder builder = context.getBean(WebClient.Builder.class);
        CodecCustomizer codecCustomizer = context.getBean(CodecCustomizer.class);
        WebClientCodecCustomizer clientCustomizer = context.getBean(WebClientCodecCustomizer.class);
        builder.build();
        assertThat(clientCustomizer).isNotNull();
        then(codecCustomizer).should().customize(any(CodecConfigurer.class));
    });
}
Also used : CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) WebClient(org.springframework.web.reactive.function.client.WebClient) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 3 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class ReactiveMultipartAutoConfigurationTests method shouldConfigureMultipartProperties.

@Test
void shouldConfigureMultipartProperties() {
    this.contextRunner.withPropertyValues("spring.webflux.multipart.streaming:true", "spring.webflux.multipart.max-in-memory-size=1GB", "spring.webflux.multipart.max-headers-size=16KB", "spring.webflux.multipart.max-disk-usage-per-part=100MB", "spring.webflux.multipart.max-parts=7", "spring.webflux.multipart.headers-charset:UTF_16").run((context) -> {
        CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
        DefaultServerCodecConfigurer configurer = new DefaultServerCodecConfigurer();
        customizer.customize(configurer);
        DefaultPartHttpMessageReader partReader = getPartReader(configurer);
        assertThat(partReader).hasFieldOrPropertyWithValue("streaming", true);
        assertThat(partReader).hasFieldOrPropertyWithValue("maxParts", 7);
        assertThat(partReader).hasFieldOrPropertyWithValue("maxHeadersSize", Math.toIntExact(DataSize.ofKilobytes(16).toBytes()));
        assertThat(partReader).hasFieldOrPropertyWithValue("headersCharset", StandardCharsets.UTF_16);
        assertThat(partReader).hasFieldOrPropertyWithValue("maxInMemorySize", Math.toIntExact(DataSize.ofGigabytes(1).toBytes()));
        assertThat(partReader).hasFieldOrPropertyWithValue("maxDiskUsagePerPart", DataSize.ofMegabytes(100).toBytes());
    });
}
Also used : DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) DefaultServerCodecConfigurer(org.springframework.http.codec.support.DefaultServerCodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 4 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class CodecsAutoConfigurationTests method loggingRequestDetailsCustomizerShouldUseHttpProperties.

@Test
void loggingRequestDetailsCustomizerShouldUseHttpProperties() {
    this.contextRunner.withPropertyValues("spring.codec.log-request-details=true").run((context) -> {
        CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
        CodecConfigurer configurer = new DefaultClientCodecConfigurer();
        customizer.customize(configurer);
        assertThat(configurer.defaultCodecs()).hasFieldOrPropertyWithValue("enableLoggingRequestDetails", true);
    });
}
Also used : DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 5 with CodecCustomizer

use of org.springframework.boot.web.codec.CodecCustomizer in project spring-boot by spring-projects.

the class CodecsAutoConfigurationTests method maxInMemorySizeEnforcedInDefaultCodecs.

@Test
void maxInMemorySizeEnforcedInDefaultCodecs() {
    this.contextRunner.withPropertyValues("spring.codec.max-in-memory-size=1MB").run((context) -> {
        CodecCustomizer customizer = context.getBean(CodecCustomizer.class);
        CodecConfigurer configurer = new DefaultClientCodecConfigurer();
        customizer.customize(configurer);
        assertThat(configurer.defaultCodecs()).hasFieldOrPropertyWithValue("maxInMemorySize", 1048576);
    });
}
Also used : DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) CodecCustomizer(org.springframework.boot.web.codec.CodecCustomizer) CodecConfigurer(org.springframework.http.codec.CodecConfigurer) DefaultClientCodecConfigurer(org.springframework.http.codec.support.DefaultClientCodecConfigurer) Test(org.junit.jupiter.api.Test)

Aggregations

CodecCustomizer (org.springframework.boot.web.codec.CodecCustomizer)7 Test (org.junit.jupiter.api.Test)6 CodecConfigurer (org.springframework.http.codec.CodecConfigurer)4 DefaultClientCodecConfigurer (org.springframework.http.codec.support.DefaultClientCodecConfigurer)3 DefaultPartHttpMessageReader (org.springframework.http.codec.multipart.DefaultPartHttpMessageReader)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 AutoConfiguration (org.springframework.boot.autoconfigure.AutoConfiguration)1 EnableAutoConfiguration (org.springframework.boot.autoconfigure.EnableAutoConfiguration)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnWebApplication (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication)1 Type (org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type)1 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)1 PropertyMapper (org.springframework.boot.context.properties.PropertyMapper)1 Bean (org.springframework.context.annotation.Bean)1 Order (org.springframework.core.annotation.Order)1 ServerCodecConfigurer (org.springframework.http.codec.ServerCodecConfigurer)1 DefaultServerCodecConfigurer (org.springframework.http.codec.support.DefaultServerCodecConfigurer)1