From 433aafec5affecc571d49284070e3fc351b02637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Fri, 16 Jul 2021 19:43:19 -0500 Subject: [PATCH] feat: add spring-boot support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eddú Meléndez --- bom/pom.xml | 25 +++++ examples/restful-ws-spring-boot/README.md | 2 +- examples/spring-function/pom.xml | 16 +-- .../examples/spring/DemoApplication.java | 33 ------ examples/spring-reactive/pom.xml | 18 +-- .../examples/spring/DemoApplication.java | 18 +-- examples/spring-rsocket/pom.xml | 13 +-- .../examples/spring/DemoApplication.java | 21 +--- pom.xml | 20 ++++ spring-boot/autoconfigure/pom.xml | 104 ++++++++++++++++++ .../CloudEventsHttpAutoConfiguration.java | 30 +++++ .../CloudEventsCodecAutoConfiguration.java | 33 ++++++ .../CloudEventsStrategyAutoConfiguration.java | 37 +++++++ ...itional-spring-configuration-metadata.json | 22 ++++ .../main/resources/META-INF/spring.factories | 4 + .../CloudEventsHttpAutoConfigurationTest.java | 31 ++++++ ...CloudEventsCodecAutoConfigurationTest.java | 31 ++++++ ...udEventsStrategyAutoConfigurationTest.java | 39 +++++++ spring-boot/rsocket-starter/pom.xml | 57 ++++++++++ spring-boot/starter/pom.xml | 57 ++++++++++ spring-boot/web-starter/pom.xml | 62 +++++++++++ spring-boot/webflux-starter/pom.xml | 62 +++++++++++ 22 files changed, 622 insertions(+), 113 deletions(-) create mode 100644 spring-boot/autoconfigure/pom.xml create mode 100644 spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfiguration.java create mode 100644 spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfiguration.java create mode 100644 spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfiguration.java create mode 100644 spring-boot/autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 spring-boot/autoconfigure/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfigurationTest.java create mode 100644 spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfigurationTest.java create mode 100644 spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfigurationTest.java create mode 100644 spring-boot/rsocket-starter/pom.xml create mode 100644 spring-boot/starter/pom.xml create mode 100644 spring-boot/web-starter/pom.xml create mode 100644 spring-boot/webflux-starter/pom.xml diff --git a/bom/pom.xml b/bom/pom.xml index c7b6eaaff..63503a62a 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -81,6 +81,31 @@ cloudevents-spring ${project.version} + + io.cloudevents + cloudevents-spring-boot-autoconfigure + ${project.version} + + + io.cloudevents + cloudevents-rsocket-spring-boot-starter + ${project.version} + + + io.cloudevents + cloudevents-spring-boot-starter + ${project.version} + + + io.cloudevents + cloudevents-web-spring-boot-starter + ${project.version} + + + io.cloudevents + cloudevents-webflux-spring-boot-starter + ${project.version} + io.cloudevents io.cloudevents.sql diff --git a/examples/restful-ws-spring-boot/README.md b/examples/restful-ws-spring-boot/README.md index df59a9eea..b5953ba73 100644 --- a/examples/restful-ws-spring-boot/README.md +++ b/examples/restful-ws-spring-boot/README.md @@ -11,7 +11,7 @@ mvn spring-boot:run You can try sending a request using `curl`: ```shell -curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \ ~ +curl -X POST -v -d '{"username": "slinkydeveloper", "firstName": "Francesco", "lastName": "Guardiani", "age": 23}' \ -H'Content-type: application/json' \ -H'Ce-id: 1' \ -H'Ce-source: cloud-event-example' \ diff --git a/examples/spring-function/pom.xml b/examples/spring-function/pom.xml index bd9c0ecb8..abb0b63ac 100644 --- a/examples/spring-function/pom.xml +++ b/examples/spring-function/pom.xml @@ -33,23 +33,9 @@ spring-cloud-function-web 3.1.1 - - org.springframework.boot - spring-boot-starter-webflux - - - io.cloudevents - cloudevents-spring - ${project.version} - - - io.cloudevents - cloudevents-http-basic - ${project.version} - io.cloudevents - cloudevents-json-jackson + cloudevents-webflux-spring-boot-starter ${project.version} diff --git a/examples/spring-function/src/main/java/io/cloudevents/examples/spring/DemoApplication.java b/examples/spring-function/src/main/java/io/cloudevents/examples/spring/DemoApplication.java index 2c999774c..b42af18fb 100644 --- a/examples/spring-function/src/main/java/io/cloudevents/examples/spring/DemoApplication.java +++ b/examples/spring-function/src/main/java/io/cloudevents/examples/spring/DemoApplication.java @@ -6,16 +6,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.codec.CodecCustomizer; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.codec.CodecConfigurer; import io.cloudevents.CloudEvent; import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.spring.messaging.CloudEventMessageConverter; -import io.cloudevents.spring.webflux.CloudEventHttpMessageReader; -import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter; @SpringBootApplication public class DemoApplication { @@ -34,31 +28,4 @@ public Function events() { .build(); } - /** - * Configure a MessageConverter for Spring Cloud Function to pick up and use to - * convert to and from CloudEvent and Message. - */ - @Configuration - public static class CloudEventMessageConverterConfiguration { - @Bean - public CloudEventMessageConverter cloudEventMessageConverter() { - return new CloudEventMessageConverter(); - } - } - - /** - * Configure an HTTP reader and writer so that we can process CloudEvents over - * HTTP via Spring Webflux. - */ - @Configuration - public static class CloudEventHandlerConfiguration implements CodecCustomizer { - - @Override - public void customize(CodecConfigurer configurer) { - configurer.customCodecs().register(new CloudEventHttpMessageReader()); - configurer.customCodecs().register(new CloudEventHttpMessageWriter()); - } - - } - } diff --git a/examples/spring-reactive/pom.xml b/examples/spring-reactive/pom.xml index 06313d9ea..0fc3002e8 100644 --- a/examples/spring-reactive/pom.xml +++ b/examples/spring-reactive/pom.xml @@ -28,23 +28,9 @@ - - org.springframework.boot - spring-boot-starter-webflux - - - io.cloudevents - cloudevents-spring - ${project.version} - - - io.cloudevents - cloudevents-http-basic - ${project.version} - io.cloudevents - cloudevents-json-jackson + cloudevents-webflux-spring-boot-starter ${project.version} @@ -63,5 +49,5 @@ - + diff --git a/examples/spring-reactive/src/main/java/io/cloudevents/examples/spring/DemoApplication.java b/examples/spring-reactive/src/main/java/io/cloudevents/examples/spring/DemoApplication.java index a5dd693d4..ac41a2b25 100644 --- a/examples/spring-reactive/src/main/java/io/cloudevents/examples/spring/DemoApplication.java +++ b/examples/spring-reactive/src/main/java/io/cloudevents/examples/spring/DemoApplication.java @@ -6,17 +6,12 @@ import io.cloudevents.CloudEvent; import io.cloudevents.core.builder.CloudEventBuilder; import io.cloudevents.spring.http.CloudEventHttpUtils; -import io.cloudevents.spring.webflux.CloudEventHttpMessageReader; -import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter; import reactor.core.publisher.Mono; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.codec.CodecCustomizer; -import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.http.codec.CodecConfigurer; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -53,15 +48,4 @@ public Mono event(@RequestBody Mono body) { .build()); } - @Configuration - public static class CloudEventHandlerConfiguration implements CodecCustomizer { - - @Override - public void customize(CodecConfigurer configurer) { - configurer.customCodecs().register(new CloudEventHttpMessageReader()); - configurer.customCodecs().register(new CloudEventHttpMessageWriter()); - } - - } - -} \ No newline at end of file +} diff --git a/examples/spring-rsocket/pom.xml b/examples/spring-rsocket/pom.xml index 348b4ab64..4b54bc34a 100644 --- a/examples/spring-rsocket/pom.xml +++ b/examples/spring-rsocket/pom.xml @@ -28,18 +28,9 @@ - - org.springframework.boot - spring-boot-starter-rsocket - - - io.cloudevents - cloudevents-spring - ${project.version} - io.cloudevents - cloudevents-json-jackson + cloudevents-rsocket-spring-boot-starter ${project.version} @@ -58,5 +49,5 @@ - + diff --git a/examples/spring-rsocket/src/main/java/io/cloudevents/examples/spring/DemoApplication.java b/examples/spring-rsocket/src/main/java/io/cloudevents/examples/spring/DemoApplication.java index bc80f83fd..3d8319d45 100644 --- a/examples/spring-rsocket/src/main/java/io/cloudevents/examples/spring/DemoApplication.java +++ b/examples/spring-rsocket/src/main/java/io/cloudevents/examples/spring/DemoApplication.java @@ -5,17 +5,11 @@ import io.cloudevents.CloudEvent; import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.spring.codec.CloudEventDecoder; -import io.cloudevents.spring.codec.CloudEventEncoder; import reactor.core.publisher.Mono; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.core.annotation.Order; import org.springframework.messaging.handler.annotation.MessageMapping; -import org.springframework.messaging.rsocket.RSocketStrategies.Builder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -38,17 +32,4 @@ public Mono event(@RequestBody Mono body) { .build()); } - @Bean - @Order(-1) - public RSocketStrategiesCustomizer cloudEventsCustomizer() { - return new RSocketStrategiesCustomizer() { - @Override - public void customize(Builder strategies) { - strategies.encoder(new CloudEventEncoder()); - strategies.decoder(new CloudEventDecoder()); - } - }; - - } - -} \ No newline at end of file +} diff --git a/pom.xml b/pom.xml index f63d8a47a..1797aea26 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,11 @@ http/restful-ws kafka spring + spring-boot/autoconfigure + spring-boot/rsocket-starter + spring-boot/starter + spring-boot/web-starter + spring-boot/webflux-starter sql bom @@ -92,8 +97,22 @@ 3.16.1 5.7.0 + 2.5.9 + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + import + pom + + + + + site @@ -168,6 +187,7 @@ https://qpid.apache.org/releases/qpid-proton-j-0.33.7/api/ https://fasterxml.github.io/jackson-databind/javadoc/2.10/ + cloudevents-spring-boot-starter diff --git a/spring-boot/autoconfigure/pom.xml b/spring-boot/autoconfigure/pom.xml new file mode 100644 index 000000000..599908562 --- /dev/null +++ b/spring-boot/autoconfigure/pom.xml @@ -0,0 +1,104 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 2.4.0-SNAPSHOT + ../../pom.xml + + + cloudevents-spring-boot-autoconfigure + CloudEvents - Spring Boot Autoconfigure + jar + + + io.cloudevents.springboot.autoconfigure + + + + + + io.cloudevents + cloudevents-core + ${project.version} + + + + io.cloudevents + cloudevents-spring + ${project.version} + + + + org.springframework.boot + spring-boot-autoconfigure + true + + + + org.springframework.boot + spring-boot-autoconfigure-processor + true + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-rsocket + true + + + + org.springframework.boot + spring-boot-starter-webflux + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-web + test + + + + io.cloudevents + cloudevents-core + tests + test-jar + ${project.version} + test + + + + diff --git a/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfiguration.java b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfiguration.java new file mode 100644 index 000000000..4cfc23a36 --- /dev/null +++ b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfiguration.java @@ -0,0 +1,30 @@ +package io.cloudevents.springboot.autoconfigure.http; + +import io.cloudevents.CloudEvent; +import io.cloudevents.spring.messaging.CloudEventMessageConverter; +import io.cloudevents.spring.mvc.CloudEventHttpMessageConverter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.converter.MessageConverter; + +/** + * @author Eddú Meléndez + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({CloudEvent.class, CloudEventHttpMessageConverter.class, MessageConverter.class}) +@AutoConfigureBefore(WebMvcAutoConfiguration.class) +@ConditionalOnProperty(name = "cloudevents.spring.web.enabled", havingValue = "true", matchIfMissing = true) +public class CloudEventsHttpAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public CloudEventMessageConverter cloudEventMessageConverter() { + return new CloudEventMessageConverter(); + } + +} diff --git a/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfiguration.java b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfiguration.java new file mode 100644 index 000000000..5c0b9e452 --- /dev/null +++ b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfiguration.java @@ -0,0 +1,33 @@ +package io.cloudevents.springboot.autoconfigure.http.codec; + +import io.cloudevents.CloudEvent; +import io.cloudevents.spring.webflux.CloudEventHttpMessageReader; +import io.cloudevents.spring.webflux.CloudEventHttpMessageWriter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration; +import org.springframework.boot.web.codec.CodecCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Eddú Meléndez + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({CloudEvent.class, CloudEventHttpMessageReader.class}) +@AutoConfigureBefore(CodecsAutoConfiguration.class) +@ConditionalOnProperty(name = "cloudevents.spring.webflux.enabled", havingValue = "true", matchIfMissing = true) +public class CloudEventsCodecAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public CodecCustomizer cloudEventsCodecCustomizer() { + return configurer -> { + configurer.customCodecs().register(new CloudEventHttpMessageReader()); + configurer.customCodecs().register(new CloudEventHttpMessageWriter()); + }; + } + +} diff --git a/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfiguration.java b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfiguration.java new file mode 100644 index 000000000..428a7a069 --- /dev/null +++ b/spring-boot/autoconfigure/src/main/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfiguration.java @@ -0,0 +1,37 @@ +package io.cloudevents.springboot.autoconfigure.rsocket; + +import io.cloudevents.CloudEvent; +import io.cloudevents.spring.codec.CloudEventDecoder; +import io.cloudevents.spring.codec.CloudEventEncoder; +import io.rsocket.RSocket; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; +import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.messaging.rsocket.RSocketStrategies; + +/** + * @author Eddú Meléndez + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnClass({CloudEvent.class, CloudEventEncoder.class, RSocket.class, RSocketStrategies.class, RSocketStrategiesCustomizer.class}) +@AutoConfigureBefore(RSocketStrategiesAutoConfiguration.class) +@ConditionalOnProperty(name = "cloudevents.spring.rsocket.enabled", havingValue = "true", matchIfMissing = true) +public class CloudEventsStrategyAutoConfiguration { + + @Bean + @Order(-1) + @ConditionalOnMissingBean + public RSocketStrategiesCustomizer cloudEventsRSocketStrategiesCustomizer() { + return strategies -> { + strategies.encoder(new CloudEventEncoder()); + strategies.decoder(new CloudEventDecoder()); + }; + } + +} diff --git a/spring-boot/autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot/autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 000000000..b9e2b57aa --- /dev/null +++ b/spring-boot/autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,22 @@ +{ + "properties": [ + { + "defaultValue": true, + "name": "cloudevents.spring.rsocket.enabled", + "description": "Enables CloudEvents Spring RSocket integration.", + "type": "java.lang.Boolean" + }, + { + "defaultValue": true, + "name": "cloudevents.spring.web.enabled", + "description": "Enables CloudEvents Spring Web integration.", + "type": "java.lang.Boolean" + }, + { + "defaultValue": true, + "name": "cloudevents.spring.webflux.enabled", + "description": "Enables CloudEvents Spring WebFlux integration.", + "type": "java.lang.Boolean" + } + ] +} diff --git a/spring-boot/autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot/autoconfigure/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..48cb4ee98 --- /dev/null +++ b/spring-boot/autoconfigure/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +io.cloudevents.springboot.autoconfigure.http.CloudEventsHttpAutoConfiguration,\ +io.cloudevents.springboot.autoconfigure.http.codec.CloudEventsCodecAutoConfiguration,\ +io.cloudevents.springboot.autoconfigure.rsocket.CloudEventsStrategyAutoConfiguration diff --git a/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfigurationTest.java b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfigurationTest.java new file mode 100644 index 000000000..9f5617ca8 --- /dev/null +++ b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/CloudEventsHttpAutoConfigurationTest.java @@ -0,0 +1,31 @@ +package io.cloudevents.springboot.autoconfigure.http; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CloudEventsHttpAutoConfiguration} + * + * @author Eddú Meléndez + */ +class CloudEventsHttpAutoConfigurationTest { + + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(CloudEventsHttpAutoConfiguration.class, WebMvcAutoConfiguration.class)); + + @Test + void autoconfigurationDisabled() { + this.contextRunner.withPropertyValues("cloudevents.spring.web.enabled:false") + .run(context -> assertThat(context).doesNotHaveBean("cloudEventMessageConverter")); + } + + @Test + void cloudEventsMessageConverterIsAutoConfigured() { + this.contextRunner.run(context -> assertThat(context).hasBean("cloudEventMessageConverter")); + } + +} diff --git a/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfigurationTest.java b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfigurationTest.java new file mode 100644 index 000000000..e528a31a2 --- /dev/null +++ b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/http/codec/CloudEventsCodecAutoConfigurationTest.java @@ -0,0 +1,31 @@ +package io.cloudevents.springboot.autoconfigure.http.codec; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration; +import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CloudEventsCodecAutoConfiguration} + * + * @author Eddú Meléndez + */ +class CloudEventsCodecAutoConfigurationTest { + + private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(CloudEventsCodecAutoConfiguration.class, CodecsAutoConfiguration.class)); + + @Test + void autoconfigurationDisabled() { + this.contextRunner.withPropertyValues("cloudevents.spring.webflux.enabled:false") + .run(context -> assertThat(context).doesNotHaveBean("cloudEventsCodecCustomizer")); + } + + @Test + void cloudEventsCodecCustomizerIsAutoConfigured() { + this.contextRunner.run(context -> assertThat(context).hasBean("cloudEventsCodecCustomizer")); + } + +} diff --git a/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfigurationTest.java b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfigurationTest.java new file mode 100644 index 000000000..e55b13612 --- /dev/null +++ b/spring-boot/autoconfigure/src/test/java/io/cloudevents/springboot/autoconfigure/rsocket/CloudEventsStrategyAutoConfigurationTest.java @@ -0,0 +1,39 @@ +package io.cloudevents.springboot.autoconfigure.rsocket; + +import io.cloudevents.spring.codec.CloudEventDecoder; +import io.cloudevents.spring.codec.CloudEventEncoder; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.messaging.rsocket.RSocketStrategies; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CloudEventsStrategyAutoConfiguration} + * + * @author Eddú Meléndez + */ +class CloudEventsStrategyAutoConfigurationTest { + + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(CloudEventsStrategyAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class)); + + @Test + void autoconfigurationDisabled() { + this.contextRunner.withPropertyValues("cloudevents.spring.rsocket.enabled:false") + .run(context -> assertThat(context).doesNotHaveBean("cloudEventsRSocketStrategiesCustomizer")); + } + + @Test + void shouldUseCloudEventsRSocketStrategiesCustomizer() { + this.contextRunner.run(context -> { + assertThat(context).getBeans(RSocketStrategies.class).hasSize(1); + RSocketStrategies strategies = context.getBean(RSocketStrategies.class); + assertThat(strategies.decoders()).hasAtLeastOneElementOfType(CloudEventDecoder.class); + assertThat(strategies.encoders()).hasAtLeastOneElementOfType(CloudEventEncoder.class); + }); + } + +} diff --git a/spring-boot/rsocket-starter/pom.xml b/spring-boot/rsocket-starter/pom.xml new file mode 100644 index 000000000..01ae63b43 --- /dev/null +++ b/spring-boot/rsocket-starter/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 2.4.0-SNAPSHOT + ../../pom.xml + + + cloudevents-rsocket-spring-boot-starter + CloudEvents RSocket - Spring Boot Starter + jar + + + io.cloudevents.rsocket.springboot.starter + + + + + + io.cloudevents + cloudevents-spring-boot-starter + ${project.version} + + + + org.springframework.boot + spring-boot-starter-rsocket + + + + io.cloudevents + cloudevents-json-jackson + ${project.version} + + + + diff --git a/spring-boot/starter/pom.xml b/spring-boot/starter/pom.xml new file mode 100644 index 000000000..498a912a4 --- /dev/null +++ b/spring-boot/starter/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 2.4.0-SNAPSHOT + ../../pom.xml + + + cloudevents-spring-boot-starter + CloudEvents - Spring Boot Starter + jar + + + io.cloudevents.springboot.starter + + + + + + org.springframework.boot + spring-boot-starter + + + + io.cloudevents + cloudevents-spring-boot-autoconfigure + ${project.version} + + + + io.cloudevents + cloudevents-spring + ${project.version} + + + + diff --git a/spring-boot/web-starter/pom.xml b/spring-boot/web-starter/pom.xml new file mode 100644 index 000000000..783b1020e --- /dev/null +++ b/spring-boot/web-starter/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 2.4.0-SNAPSHOT + ../../pom.xml + + + cloudevents-web-spring-boot-starter + CloudEvents - Spring Boot Starter + jar + + + io.cloudevents.web.springboot.starter + + + + + + io.cloudevents + cloudevents-spring-boot-starter + ${project.version} + + + + org.springframework.boot + spring-boot-starter-web + + + + io.cloudevents + cloudevents-http-basic + ${project.version} + + + io.cloudevents + cloudevents-json-jackson + ${project.version} + + + + diff --git a/spring-boot/webflux-starter/pom.xml b/spring-boot/webflux-starter/pom.xml new file mode 100644 index 000000000..877671e0b --- /dev/null +++ b/spring-boot/webflux-starter/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + + io.cloudevents + cloudevents-parent + 2.4.0-SNAPSHOT + ../../pom.xml + + + cloudevents-webflux-spring-boot-starter + CloudEvents - Spring Boot Starter + jar + + + io.cloudevents.webflux.springboot.starter + + + + + + io.cloudevents + cloudevents-spring-boot-starter + ${project.version} + + + + org.springframework.boot + spring-boot-starter-webflux + + + + io.cloudevents + cloudevents-http-basic + ${project.version} + + + io.cloudevents + cloudevents-json-jackson + ${project.version} + + + +