diff --git a/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersConfiguration.java b/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersAutoConfiguration.java similarity index 69% rename from springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersConfiguration.java rename to springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersAutoConfiguration.java index 3fd2dc76d..1cc2b5d32 100644 --- a/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersConfiguration.java +++ b/springwolf-add-ons/springwolf-common-model-converters/src/main/java/io/github/stavshamir/springwolf/common_converters/configuration/CommonModelConvertersAutoConfiguration.java @@ -5,8 +5,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -@Configuration -public class CommonModelConvertersConfiguration { +/** + * Spring AutoConfiguration adding an {@link MonetaryAmountConverter} Bean to the spring context. + */ +@Configuration(proxyBeanMethods = false) +public class CommonModelConvertersAutoConfiguration { @Bean public MonetaryAmountConverter monetaryAmountConverter() { diff --git a/springwolf-add-ons/springwolf-common-model-converters/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springwolf-add-ons/springwolf-common-model-converters/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..f2839d7e3 --- /dev/null +++ b/springwolf-add-ons/springwolf-common-model-converters/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.stavshamir.springwolf.common_converters.configuration.CommonModelConvertersAutoConfiguration diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java index 73ff13ac6..8958ed1b5 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfAutoConfiguration.java @@ -1,29 +1,81 @@ // SPDX-License-Identifier: Apache-2.0 package io.github.stavshamir.springwolf; +import io.github.stavshamir.springwolf.asyncapi.AsyncApiCustomizer; +import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; +import io.github.stavshamir.springwolf.asyncapi.ChannelsService; +import io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiService; +import io.github.stavshamir.springwolf.asyncapi.DefaultChannelsService; +import io.github.stavshamir.springwolf.asyncapi.SpringwolfInitApplicationListener; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.DefaultAsyncApiDocketService; import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; +import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import io.github.stavshamir.springwolf.schemas.example.ExampleGenerator; +import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; +import io.swagger.v3.core.converter.ModelConverter; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigurationExcludeFilter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.TypeExcludeFilter; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +import java.util.List; +import java.util.Optional; /** - * Spring Boot auto-configuration which loads all spring-beans for springwolf core and eventually loaded plugins. - *

- * This configuration uses the spring @{@link ComponentScan} mechanism to detect and load the necessary beans. Both - * the core components as well as all plugin components are located underneath the base package 'io.github.stavshamir.springwolf' - * so existing springwolf plugins are automatically loaded together with the springwolf core beans. + * Spring Boot auto-configuration which loads all spring-beans for springwolf core module. *

- * To disable this auto-configuration, set the environment property {@code springwolf.enabled=false}. + * To disable springwolf support, set the environment property {@code springwolf.enabled=false}. */ @AutoConfiguration -@ComponentScan( - basePackages = {"io.github.stavshamir.springwolf"}, - excludeFilters = { - @ComponentScan.Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), - @ComponentScan.Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) - }) +@Import({SpringwolfWebConfiguration.class, SpringwolfScannerConfiguration.class}) @ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) -public class SpringwolfAutoConfiguration {} +public class SpringwolfAutoConfiguration { + + @Bean + public SpringwolfConfigProperties springwolfConfigProperties() { + return new SpringwolfConfigProperties(); + } + + @Bean + public SpringwolfInitApplicationListener springwolfInitApplicationListener( + AsyncApiService asyncApiService, SpringwolfConfigProperties configProperties) { + return new SpringwolfInitApplicationListener(asyncApiService, configProperties); + } + + @Bean + public AsyncApiService asyncApiService( + AsyncApiDocketService asyncApiDocketService, + ChannelsService channelsService, + SchemasService schemasService, + List customizers) { + return new DefaultAsyncApiService(asyncApiDocketService, channelsService, schemasService, customizers); + } + + @Bean + public ChannelsService channelsService(List channelsScanners) { + return new DefaultChannelsService(channelsScanners); + } + + @Bean + public SchemasService schemasService(List modelConverters, ExampleGenerator exampleGenerator) { + return new DefaultSchemasService(modelConverters, exampleGenerator); + } + + @Bean + public AsyncApiDocketService asyncApiDocketService( + Optional optionalAsyncApiDocket, SpringwolfConfigProperties springwolfConfigProperties) { + return new DefaultAsyncApiDocketService(optionalAsyncApiDocket, springwolfConfigProperties); + } + + @Bean + @ConditionalOnMissingBean + public ExampleGenerator exampleGenerator() { + return new ExampleJsonGenerator(); + } +} diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfScannerConfiguration.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfScannerConfiguration.java new file mode 100644 index 000000000..da0483786 --- /dev/null +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfScannerConfiguration.java @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf; + +import io.github.stavshamir.springwolf.asyncapi.scanners.beans.BeanMethodsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.beans.DefaultBeanMethodsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ConsumerOperationDataScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.ProducerOperationDataScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListenerAnnotationScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncPublisherAnnotationScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.MessageBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.OperationBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ConfigurationClassScanner; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import org.springframework.core.env.Environment; + +import java.util.List; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED; + +/** + * Spring configuration defining the core scanner beans. + */ +@Configuration(proxyBeanMethods = false) +public class SpringwolfScannerConfiguration { + + @Bean + public ComponentClassScanner componentClassScanner( + AsyncApiDocketService asyncApiDocketService, Environment environment) { + return new ComponentClassScanner(asyncApiDocketService, environment); + } + + @Bean + public ConfigurationClassScanner configurationClassScanner( + AsyncApiDocketService asyncApiDocketService, Environment environment) { + return new ConfigurationClassScanner(asyncApiDocketService, environment); + } + + @Bean + public BeanMethodsScanner beanMethodsScanner(ConfigurationClassScanner configurationClassScanner) { + return new DefaultBeanMethodsScanner(configurationClassScanner); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.MANUAL_DEFINED) + public ConsumerOperationDataScanner consumerOperationDataScanner( + AsyncApiDocketService asyncApiDocketService, SchemasService schemasService) { + return new ConsumerOperationDataScanner(asyncApiDocketService, schemasService); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.MANUAL_DEFINED) + public ProducerOperationDataScanner producerOperationDataScanner( + AsyncApiDocketService asyncApiDocketService, SchemasService schemasService) { + return new ProducerOperationDataScanner(asyncApiDocketService, schemasService); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.ASYNC_ANNOTATION) + public AsyncListenerAnnotationScanner asyncListenerAnnotationScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List operationBindingProcessors, + List messageBindingProcessors) { + return new AsyncListenerAnnotationScanner( + componentClassScanner, schemasService, operationBindingProcessors, messageBindingProcessors); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.ASYNC_ANNOTATION) + public AsyncPublisherAnnotationScanner asyncPublisherAnnotationScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List operationBindingProcessors, + List messageBindingProcessors) { + return new AsyncPublisherAnnotationScanner( + componentClassScanner, schemasService, operationBindingProcessors, messageBindingProcessors); + } +} diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfWebConfiguration.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfWebConfiguration.java new file mode 100644 index 000000000..c55cbcabe --- /dev/null +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/SpringwolfWebConfiguration.java @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf; + +import io.github.stavshamir.springwolf.asyncapi.AsyncApiSerializerService; +import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; +import io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiSerializerService; +import io.github.stavshamir.springwolf.asyncapi.controller.ActuatorAsyncApiController; +import io.github.stavshamir.springwolf.asyncapi.controller.AsyncApiController; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED; + +/** + * Spring-Configuration defining the web controller beans. + */ +@Configuration(proxyBeanMethods = false) +public class SpringwolfWebConfiguration { + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "false", matchIfMissing = true) + public AsyncApiController asyncApiController( + AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) { + return new AsyncApiController(asyncApiService, asyncApiSerializerService); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "true") + public ActuatorAsyncApiController actuatorAsyncApiController( + AsyncApiService asyncApiService, AsyncApiSerializerService asyncApiSerializerService) { + return new ActuatorAsyncApiController(asyncApiService, asyncApiSerializerService); + } + + @Bean + public AsyncApiSerializerService asyncApiSerializerService() { + return new DefaultAsyncApiSerializerService(); + } +} diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerService.java index 6139c5f56..e67e76d11 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiSerializerService.java @@ -13,9 +13,7 @@ import io.swagger.v3.core.util.Json; import io.swagger.v3.core.util.Yaml; import jakarta.annotation.PostConstruct; -import org.springframework.stereotype.Service; -@Service public class DefaultAsyncApiSerializerService implements AsyncApiSerializerService { private ObjectMapper jsonMapper = Json.mapper(); diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiService.java index 578843c01..eb948fee0 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultAsyncApiService.java @@ -9,13 +9,11 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; @Slf4j -@Service @RequiredArgsConstructor public class DefaultAsyncApiService implements AsyncApiService { diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultChannelsService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultChannelsService.java index fd21f7b6c..7bce43aff 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultChannelsService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/DefaultChannelsService.java @@ -6,7 +6,6 @@ import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @@ -16,7 +15,6 @@ * Service to detect AsyncAPI channels in the current spring context. */ @Slf4j -@Service @RequiredArgsConstructor public class DefaultChannelsService implements ChannelsService { @@ -36,7 +34,7 @@ public Map findChannels() { Map channels = scanner.scan(); foundChannelItems.addAll(channels.entrySet()); } catch (Exception e) { - log.error("An error was encountered during channel scanning with {}: {}", scanner, e.getMessage()); + log.error("An error was encountered during channel scanning with {}: {}", scanner, e.getMessage(), e); } } return ChannelMerger.merge(foundChannelItems); diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/SpringwolfInitApplicationListener.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/SpringwolfInitApplicationListener.java index b438ab8aa..fc55c772b 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/SpringwolfInitApplicationListener.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/SpringwolfInitApplicationListener.java @@ -8,7 +8,6 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; -import org.springframework.stereotype.Service; /** * Spring ApplicationListener listening on {@link ApplicationReadyEvent}. Triggers the AsyncAPI creation. @@ -17,7 +16,6 @@ */ @Slf4j @RequiredArgsConstructor -@Service public class SpringwolfInitApplicationListener implements ApplicationListener, InitializingBean { private final AsyncApiService asyncApiService; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/ActuatorAsyncApiController.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/ActuatorAsyncApiController.java index 4c0072a37..af6cb7686 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/ActuatorAsyncApiController.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/ActuatorAsyncApiController.java @@ -8,18 +8,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED; - -@Component @Slf4j @RestControllerEndpoint(id = "springwolf") @RequiredArgsConstructor -@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "true") public class ActuatorAsyncApiController { private final AsyncApiService asyncApiService; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/AsyncApiController.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/AsyncApiController.java index f78737c9d..e07da27f2 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/AsyncApiController.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/AsyncApiController.java @@ -7,17 +7,13 @@ import io.github.stavshamir.springwolf.asyncapi.types.AsyncAPI; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED; - @Slf4j @RestController @RequiredArgsConstructor -@ConditionalOnProperty(name = SPRINGWOLF_ENDPOINT_ACTUATOR_ENABLED, havingValue = "false", matchIfMissing = true) public class AsyncApiController { private final AsyncApiService asyncApiService; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/beans/DefaultBeanMethodsScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/beans/DefaultBeanMethodsScanner.java index e653e458d..23a6a1d8b 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/beans/DefaultBeanMethodsScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/beans/DefaultBeanMethodsScanner.java @@ -4,7 +4,6 @@ import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ConfigurationClassScanner; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Service; import java.lang.reflect.Method; import java.util.Arrays; @@ -14,7 +13,6 @@ import static java.util.stream.Collectors.toSet; -@Service @RequiredArgsConstructor public class DefaultBeanMethodsScanner implements BeanMethodsScanner { diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java index 7d005910d..7f9b3d6bb 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractClassLevelListenerScanner.java @@ -14,8 +14,8 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.schemas.SchemasService; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -35,15 +35,14 @@ import static java.util.stream.Collectors.toSet; @Slf4j +@RequiredArgsConstructor public abstract class AbstractClassLevelListenerScanner< ClassAnnotation extends Annotation, MethodAnnotation extends Annotation> implements ChannelsScanner { - @Autowired - private ComponentClassScanner componentClassScanner; + private final ComponentClassScanner componentClassScanner; - @Autowired - private SchemasService schemasService; + private final SchemasService schemasService; private static final Comparator> byPublishOperationName = Comparator.comparing(it -> it.getValue().getPublish().getOperationId()); diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java index 1eaba6038..3bbb6af54 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/AbstractMethodLevelListenerScanner.java @@ -13,8 +13,8 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.schemas.SchemasService; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -29,13 +29,12 @@ import static java.util.stream.Collectors.toSet; @Slf4j +@RequiredArgsConstructor public abstract class AbstractMethodLevelListenerScanner implements ChannelsScanner { - @Autowired - private ComponentClassScanner componentClassScanner; + private final ComponentClassScanner componentClassScanner; - @Autowired - private SchemasService schemasService; + private final SchemasService schemasService; @Override public Map scan() { diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java index 4fafec7b3..dbcae7099 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AbstractOperationDataScanner.java @@ -5,7 +5,6 @@ import com.asyncapi.v2._6_0.model.channel.operation.Operation; import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; import io.github.stavshamir.springwolf.asyncapi.types.OperationData; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.Message; @@ -14,7 +13,6 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import io.swagger.v3.oas.annotations.media.Schema; import lombok.extern.slf4j.Slf4j; -import org.springframework.core.annotation.Order; import org.springframework.util.StringUtils; import java.util.HashMap; @@ -28,7 +26,6 @@ import static java.util.stream.Collectors.toSet; @Slf4j -@Order(value = ChannelPriority.MANUAL_DEFINED) public abstract class AbstractOperationDataScanner implements ChannelsScanner { protected abstract SchemasService getSchemaService(); diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScanner.java index 836d65e95..fefaffea7 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ConsumerOperationDataScanner.java @@ -6,18 +6,12 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED; - @Slf4j @RequiredArgsConstructor -@Component -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_CONSUMER_DATA_ENABLED, matchIfMissing = true) public class ConsumerOperationDataScanner extends AbstractOperationDataScanner { private final AsyncApiDocketService asyncApiDocketService; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScanner.java index faa691777..0de186c44 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/ProducerOperationDataScanner.java @@ -6,18 +6,12 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED; - @Slf4j @RequiredArgsConstructor -@Component -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_PRODUCER_DATA_ENABLED, matchIfMissing = true) public class ProducerOperationDataScanner extends AbstractOperationDataScanner { private final AsyncApiDocketService asyncApiDocketService; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScanner.java index 715ff8f87..1b3a5ce51 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncListenerAnnotationScanner.java @@ -3,7 +3,6 @@ import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AbstractOperationDataScanner; import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; @@ -13,10 +12,7 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; @@ -26,13 +22,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED; - @Slf4j @RequiredArgsConstructor -@Component -@Order(value = ChannelPriority.ASYNC_ANNOTATION) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_LISTENER_ENABLED, matchIfMissing = true) public class AsyncListenerAnnotationScanner extends AbstractOperationDataScanner implements EmbeddedValueResolverAware { private StringValueResolver resolver; private final ComponentClassScanner componentClassScanner; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScanner.java index 765a35971..a6a269ad6 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/annotation/AsyncPublisherAnnotationScanner.java @@ -3,7 +3,6 @@ import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AbstractOperationDataScanner; import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; @@ -13,10 +12,7 @@ import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; @@ -25,13 +21,8 @@ import java.util.Map; import java.util.stream.Stream; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED; - @Slf4j @RequiredArgsConstructor -@Component -@Order(value = ChannelPriority.ASYNC_ANNOTATION) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_ASYNC_PUBLISHER_ENABLED, matchIfMissing = true) public class AsyncPublisherAnnotationScanner extends AbstractOperationDataScanner implements EmbeddedValueResolverAware { private StringValueResolver resolver; diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/AbstractAnnotatedClassScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/AbstractAnnotatedClassScanner.java index 450983f71..e7ec47758 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/AbstractAnnotatedClassScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/AbstractAnnotatedClassScanner.java @@ -2,6 +2,7 @@ package io.github.stavshamir.springwolf.asyncapi.scanners.classes; import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -16,17 +17,12 @@ import static java.util.stream.Collectors.toSet; @Slf4j +@RequiredArgsConstructor public abstract class AbstractAnnotatedClassScanner implements ClassScanner { private final AsyncApiDocketService asyncApiDocketService; - private final Optional environment; - - public AbstractAnnotatedClassScanner( - AsyncApiDocketService asyncApiDocketService, Optional environment) { - this.asyncApiDocketService = asyncApiDocketService; - this.environment = environment; - } + private final Environment environment; /** * @return The class object of the annotation to scan. @@ -40,9 +36,8 @@ public Set> scan() { throw new IllegalArgumentException("Base package must not be blank"); } - ClassPathScanningCandidateComponentProvider provider = environment - .map(env -> new ClassPathScanningCandidateComponentProvider(false, env)) - .orElseGet(() -> new ClassPathScanningCandidateComponentProvider(false)); + ClassPathScanningCandidateComponentProvider provider = + new ClassPathScanningCandidateComponentProvider(false, environment); provider.addIncludeFilter(new AnnotationTypeFilter(getAnnotationClass())); diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScanner.java index 00ede8181..a6be1c3f2 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScanner.java @@ -4,14 +4,10 @@ import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; -import java.util.Optional; - -@Service public class ComponentClassScanner extends AbstractAnnotatedClassScanner implements ClassScanner { - public ComponentClassScanner(AsyncApiDocketService asyncApiDocketService, Optional environment) { + public ComponentClassScanner(AsyncApiDocketService asyncApiDocketService, Environment environment) { super(asyncApiDocketService, environment); } diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ConfigurationClassScanner.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ConfigurationClassScanner.java index d393b6fad..a59f8d17e 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ConfigurationClassScanner.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ConfigurationClassScanner.java @@ -4,14 +4,10 @@ import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import org.springframework.stereotype.Service; -import java.util.Optional; - -@Service public class ConfigurationClassScanner extends AbstractAnnotatedClassScanner implements ClassScanner { - public ConfigurationClassScanner(AsyncApiDocketService asyncApiDocketService, Optional environment) { + public ConfigurationClassScanner(AsyncApiDocketService asyncApiDocketService, Environment environment) { super(asyncApiDocketService, environment); } diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java index 3cf44125f..5d096ddbe 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketService.java @@ -7,13 +7,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.lang.Nullable; -import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.util.Optional; @Slf4j -@Service @RequiredArgsConstructor public class DefaultAsyncApiDocketService implements AsyncApiDocketService { @@ -25,21 +23,17 @@ public class DefaultAsyncApiDocketService implements AsyncApiDocketService { /** * Docket definition in application.properties */ - private final Optional configProperties; + private final SpringwolfConfigProperties configProperties; @Override public AsyncApiDocket getAsyncApiDocket() { if (customDocket.isPresent()) { log.debug("Reading springwolf configuration from custom defined @Bean AsyncApiDocket"); return customDocket.get(); - } else if (configProperties.isPresent()) { + } else { log.debug("Reading springwolf configuration from application.properties files"); - return parseApplicationConfigProperties(configProperties.get()); + return parseApplicationConfigProperties(configProperties); } - throw new IllegalArgumentException("No springwolf configuration found. " - + "Either define the properties in the application.properties under the " - + SpringwolfConfigConstants.SPRINGWOLF_CONFIG_PREFIX + " prefix " - + "or add a @Bean AsyncApiDocket to the spring context"); } private AsyncApiDocket parseApplicationConfigProperties(SpringwolfConfigProperties configProperties) { diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java index 751097c33..727e61d33 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfConfigProperties.java @@ -7,17 +7,13 @@ import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; import lombok.Getter; import lombok.Setter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; import java.util.Map; -@Configuration @ConfigurationProperties(prefix = SpringwolfConfigConstants.SPRINGWOLF_CONFIG_PREFIX) -@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) @Getter @Setter public class SpringwolfConfigProperties { diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java index 2f54eed99..300145e4e 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasService.java @@ -9,17 +9,14 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; @Slf4j -@Service public class DefaultSchemasService implements SchemasService { private final ModelConverters converter = ModelConverters.getInstance(); @@ -28,9 +25,9 @@ public class DefaultSchemasService implements SchemasService { private final Map definitions = new HashMap<>(); private Map finalizedDefinitions = null; - public DefaultSchemasService( - Optional> externalModelConverters, ExampleGenerator exampleGenerator) { - externalModelConverters.ifPresent(converters -> converters.forEach(converter::addConverter)); + public DefaultSchemasService(List externalModelConverters, ExampleGenerator exampleGenerator) { + + externalModelConverters.forEach(converter::addConverter); this.exampleGenerator = exampleGenerator; } diff --git a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/example/ExampleJsonGenerator.java b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/example/ExampleJsonGenerator.java index cf7250efa..528172667 100644 --- a/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/example/ExampleJsonGenerator.java +++ b/springwolf-core/src/main/java/io/github/stavshamir/springwolf/schemas/example/ExampleJsonGenerator.java @@ -11,7 +11,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.HashSet; @@ -22,7 +21,6 @@ import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants.SPRINGWOLF_SCHEMA_EXAMPLE_GENERATOR; -@Component @Slf4j @ConditionalOnProperty(name = SPRINGWOLF_SCHEMA_EXAMPLE_GENERATOR, havingValue = "buildin-json", matchIfMissing = true) public class ExampleJsonGenerator implements ExampleGenerator { diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringContextControllerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringContextControllerIntegrationTest.java index f1711fe49..6f1ae845c 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringContextControllerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringContextControllerIntegrationTest.java @@ -2,6 +2,7 @@ package io.github.stavshamir.springwolf.asyncapi.controller; import com.fasterxml.jackson.core.JsonProcessingException; +import io.github.stavshamir.springwolf.SpringwolfWebConfiguration; import io.github.stavshamir.springwolf.fixtures.MinimalTestContextConfiguration; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -21,7 +22,7 @@ public class SpringContextControllerIntegrationTest { @ExtendWith(SpringExtension.class) @Nested - @Import(value = {AsyncApiController.class, ActuatorAsyncApiController.class}) + @Import(SpringwolfWebConfiguration.class) @MinimalTestContextConfiguration class SpringwolfOnApplicationPortConfigurationTest { @@ -48,7 +49,7 @@ void testContextWithApplicationProperties() throws JsonProcessingException { @Nested @ExtendWith(SpringExtension.class) @MinimalTestContextConfiguration - @Import(value = {AsyncApiController.class, ActuatorAsyncApiController.class}) + @Import(SpringwolfWebConfiguration.class) @TestPropertySource( properties = {"springwolf.endpoint.actuator.enabled=true", "management.endpoints.web.exposure.include=*"}) class SpringwolfOnManagementPortConfigurationTest { diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScanner.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScanner.java index b863f35d5..3a364995a 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScanner.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/TestMethodLevelListenerScanner.java @@ -4,6 +4,8 @@ import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.EqualsAndHashCode; import java.lang.reflect.Method; @@ -12,6 +14,10 @@ public class TestMethodLevelListenerScanner extends AbstractMethodLevelListenerScanner { + public TestMethodLevelListenerScanner(ComponentClassScanner componentClassScanner, SchemasService schemasService) { + super(componentClassScanner, schemasService); + } + @Override protected Class getListenerAnnotationClass() { return TestMethodLevelListenerScannerIntegrationTest.TestChannelListener.class; diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScannerIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScannerIntegrationTest.java index 0a07e963e..b85b5563a 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScannerIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/ComponentClassScannerIntegrationTest.java @@ -6,23 +6,28 @@ import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = {ComponentClassScanner.class}) +@SpringBootTest +@ContextConfiguration( + classes = { + ComponentClassScanner.class, + TestComponent.class, + TestConditionalComponent.class, + TestOtherConditionalComponent.class + }) @DirtiesContext class ComponentClassScannerIntegrationTest { @MockBean @@ -51,9 +56,7 @@ void getComponents() { Set> components = componentsScanner.scan(); assertThat(components) - .contains(ComponentClassScanner.class) - .contains(ConfigurationClassScanner.class) - .doesNotContain(ClassScanner.class) + .contains(TestComponent.class) .doesNotContain(TestConditionalComponent.class) .doesNotContain(TestOtherConditionalComponent.class); } @@ -66,10 +69,8 @@ void getComponentsIncludesConditional() { Set> components = componentsScanner.scan(); assertThat(components) - .contains(ComponentClassScanner.class) - .contains(ConfigurationClassScanner.class) + .contains(TestComponent.class) .contains(TestConditionalComponent.class) - .doesNotContain(ClassScanner.class) .doesNotContain(TestOtherConditionalComponent.class); } } diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestComponent.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestComponent.java new file mode 100644 index 000000000..dfaacc64c --- /dev/null +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestComponent.java @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.scanners.classes; + +import org.springframework.stereotype.Component; + +@Component +public class TestComponent {} diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestOtherConditionalComponent.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestOtherConditionalComponent.java index e40278a37..e44a4f01f 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestOtherConditionalComponent.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/classes/TestOtherConditionalComponent.java @@ -2,8 +2,6 @@ package io.github.stavshamir.springwolf.asyncapi.scanners.classes; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Component; -@Component @ConditionalOnProperty("missing-property") public class TestOtherConditionalComponent {} diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketServiceTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketServiceTest.java index 38b93302f..c4a14f312 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketServiceTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/DefaultAsyncApiDocketServiceTest.java @@ -12,7 +12,6 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.util.Maps.newHashMap; class DefaultAsyncApiDocketServiceTest { @@ -42,7 +41,7 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() { // when DefaultAsyncApiDocketService docketConfiguration = - new DefaultAsyncApiDocketService(Optional.empty(), Optional.of(properties)); + new DefaultAsyncApiDocketService(Optional.empty(), properties); AsyncApiDocket asyncApiDocket = docketConfiguration.getAsyncApiDocket(); // then @@ -54,14 +53,4 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() { assertThat(asyncApiDocket.getInfo().getLicense()).isEqualTo(info.getLicense()); assertThat(asyncApiDocket.getInfo().getContact()).isEqualTo(info.getContact()); } - - @Test - void testNoConfigurationShouldThrowException() { - assertThatThrownBy(() -> { - DefaultAsyncApiDocketService docketConfiguration = - new DefaultAsyncApiDocketService(Optional.empty(), Optional.empty()); - docketConfiguration.getAsyncApiDocket(); - }) - .isInstanceOf(IllegalArgumentException.class); - } } diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java index 350926649..eb18ed0aa 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/schemas/DefaultSchemasServiceTest.java @@ -23,7 +23,6 @@ import java.time.OffsetDateTime; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -33,7 +32,7 @@ class DefaultSchemasServiceTest { private final ExampleGenerator exampleGenerator = new ExampleJsonGenerator(); - private final SchemasService schemasService = new DefaultSchemasService(Optional.empty(), exampleGenerator); + private final SchemasService schemasService = new DefaultSchemasService(List.of(), exampleGenerator); private static final ObjectMapper objectMapper = Json.mapper().enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS); diff --git a/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/amqp/consumers/ExampleConsumer.java b/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/amqp/consumers/ExampleConsumer.java index 1a43ad1fa..6ebb65de4 100644 --- a/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/amqp/consumers/ExampleConsumer.java +++ b/springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/amqp/consumers/ExampleConsumer.java @@ -11,9 +11,9 @@ import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; -@Service +@Component @Slf4j @RequiredArgsConstructor public class ExampleConsumer { diff --git a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleClassLevelKafkaListener.java b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleClassLevelKafkaListener.java index 59881167d..d6b09c6de 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleClassLevelKafkaListener.java +++ b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleClassLevelKafkaListener.java @@ -10,13 +10,13 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.annotation.KafkaHandler; import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import javax.money.MonetaryAmount; import static org.springframework.kafka.support.mapping.AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME; -@Service +@Component @Slf4j @KafkaListener(topics = "multi-payload-topic") public class ExampleClassLevelKafkaListener { diff --git a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java index c0d4cc539..784f6b5eb 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java +++ b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/stavshamir/springwolf/example/kafka/consumers/ExampleConsumer.java @@ -7,11 +7,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; import java.util.List; -@Service +@Component @RequiredArgsConstructor @Slf4j public class ExampleConsumer { diff --git a/springwolf-examples/springwolf-sqs-example/src/main/java/io/github/stavshamir/springwolf/example/sqs/consumers/ExampleConsumer.java b/springwolf-examples/springwolf-sqs-example/src/main/java/io/github/stavshamir/springwolf/example/sqs/consumers/ExampleConsumer.java index b73f63311..118cbcab5 100644 --- a/springwolf-examples/springwolf-sqs-example/src/main/java/io/github/stavshamir/springwolf/example/sqs/consumers/ExampleConsumer.java +++ b/springwolf-examples/springwolf-sqs-example/src/main/java/io/github/stavshamir/springwolf/example/sqs/consumers/ExampleConsumer.java @@ -7,9 +7,9 @@ import io.github.stavshamir.springwolf.example.sqs.producers.AnotherProducer; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Component; -@Service +@Component @RequiredArgsConstructor @Slf4j public class ExampleConsumer { diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpAutoConfiguration.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpAutoConfiguration.java new file mode 100644 index 000000000..400a2baee --- /dev/null +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpAutoConfiguration.java @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.amqp; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; +import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfAmqpController; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigProperties; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; +import io.github.stavshamir.springwolf.producer.SpringwolfAmqpProducer; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.lang.NonNull; + +import java.util.List; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_CONFIG_PREFIX; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED; + +/** + * Autoconfiguration for the springwolf amqp plugin. + */ +@AutoConfiguration +@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) +@Import({SpringwolfAmqpScannerConfiguration.class}) +public class SpringwolfAmqpAutoConfiguration { + + @Bean + public SpringwolfAmqpConfigProperties springwolfAmqpConfigProperties() { + return new SpringwolfAmqpConfigProperties(); + } + + @Bean + @ConditionalOnProperty(prefix = SPRINGWOLF_AMQP_CONFIG_PREFIX, name = SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED) + public SpringwolfAmqpProducer springwolfAmqpProducer( + AsyncApiService asyncApiService, @NonNull List rabbitTemplates) { + return new SpringwolfAmqpProducer(asyncApiService, rabbitTemplates); + } + + @Bean + @ConditionalOnProperty(prefix = SPRINGWOLF_AMQP_CONFIG_PREFIX, name = SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED) + public SpringwolfAmqpController springwolfAmqpController( + AsyncApiDocketService asyncApiDocketService, + SpringwolfAmqpProducer springwolfAmqpProducer, + ObjectMapper objectMapper) { + return new SpringwolfAmqpController(asyncApiDocketService, springwolfAmqpProducer, objectMapper); + } +} diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpScannerConfiguration.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpScannerConfiguration.java new file mode 100644 index 000000000..286875f40 --- /dev/null +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/amqp/SpringwolfAmqpScannerConfiguration.java @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.amqp; + +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.ClassLevelRabbitListenerScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.MethodLevelRabbitListenerScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AmqpMessageBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.AmqpOperationBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.Exchange; +import org.springframework.amqp.core.Queue; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + +import java.util.List; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED; + +/** + * Spring configuration defining the scanner beans for this amqp plugin. + */ +@Configuration(proxyBeanMethods = false) +public class SpringwolfAmqpScannerConfiguration { + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.AUTO_DISCOVERED) + public ClassLevelRabbitListenerScanner classLevelRabbitListenerScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List queues, + List exchanges, + List bindings) { + return new ClassLevelRabbitListenerScanner(componentClassScanner, schemasService, queues, exchanges, bindings); + } + + @Bean + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED, matchIfMissing = true) + @Order(value = ChannelPriority.AUTO_DISCOVERED) + public MethodLevelRabbitListenerScanner methodLevelRabbitListenerScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List queues, + List exchanges, + List bindings) { + return new MethodLevelRabbitListenerScanner(componentClassScanner, schemasService, queues, exchanges, bindings); + } + + @Bean + public AmqpMessageBindingProcessor amqpMessageBindingProcessor() { + return new AmqpMessageBindingProcessor(); + } + + @Bean + public AmqpOperationBindingProcessor amqpOperationBindingProcessor() { + return new AmqpOperationBindingProcessor(); + } +} diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfAmqpController.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfAmqpController.java index 2d12c59eb..013ee756f 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfAmqpController.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfAmqpController.java @@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,14 +19,10 @@ import java.text.MessageFormat; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED; - @Slf4j @RestController @RequestMapping("/springwolf/amqp") @RequiredArgsConstructor -@ConditionalOnProperty(prefix = SPRINGWOLF_AMQP_CONFIG_PREFIX, name = SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED) public class SpringwolfAmqpController implements InitializingBean { private final AsyncApiDocketService asyncApiDocketService; diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScanner.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScanner.java index 78d1309a7..c60d37f5b 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScanner.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelRabbitListenerScanner.java @@ -4,38 +4,37 @@ import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.Exchange; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Service; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.List; import java.util.Map; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED; - @Slf4j -@Service -@Order(value = ChannelPriority.AUTO_DISCOVERED) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED, matchIfMissing = true) public class ClassLevelRabbitListenerScanner extends AbstractClassLevelListenerScanner implements ChannelsScanner, EmbeddedValueResolverAware { private final RabbitListenerUtil.RabbitListenerUtilContext context; private StringValueResolver resolver; - public ClassLevelRabbitListenerScanner(List queues, List exchanges, List bindings) { + public ClassLevelRabbitListenerScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List queues, + List exchanges, + List bindings) { + super(componentClassScanner, schemasService); context = RabbitListenerUtil.RabbitListenerUtilContext.create(queues, exchanges, bindings); } diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScanner.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScanner.java index 986f19cf9..0c123acf0 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScanner.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelRabbitListenerScanner.java @@ -4,36 +4,35 @@ import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.Exchange; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Service; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.List; import java.util.Map; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED; - @Slf4j -@Service -@Order(value = ChannelPriority.AUTO_DISCOVERED) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_RABBIT_LISTENER_ENABLED, matchIfMissing = true) public class MethodLevelRabbitListenerScanner extends AbstractMethodLevelListenerScanner implements ChannelsScanner, EmbeddedValueResolverAware { private final RabbitListenerUtil.RabbitListenerUtilContext context; private StringValueResolver resolver; - public MethodLevelRabbitListenerScanner(List queues, List exchanges, List bindings) { + public MethodLevelRabbitListenerScanner( + ComponentClassScanner componentClassScanner, + SchemasService schemasService, + List queues, + List exchanges, + List bindings) { + super(componentClassScanner, schemasService); context = RabbitListenerUtil.RabbitListenerUtilContext.create(queues, exchanges, bindings); } diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpMessageBindingProcessor.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpMessageBindingProcessor.java index ba2ee9523..978312ea2 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpMessageBindingProcessor.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpMessageBindingProcessor.java @@ -5,14 +5,12 @@ import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AmqpAsyncOperationBinding; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.MessageBindingProcessor; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.stereotype.Component; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Optional; -@Component public class AmqpMessageBindingProcessor implements MessageBindingProcessor, EmbeddedValueResolverAware { private StringValueResolver resolver; diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpOperationBindingProcessor.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpOperationBindingProcessor.java index 67077b002..8fd2b2676 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpOperationBindingProcessor.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/AmqpOperationBindingProcessor.java @@ -4,11 +4,9 @@ import com.asyncapi.v2.binding.operation.amqp.AMQPOperationBinding; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.AbstractOperationBindingProcessor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AmqpAsyncOperationBinding; -import org.springframework.stereotype.Component; import java.util.Arrays; -@Component public class AmqpOperationBindingProcessor extends AbstractOperationBindingProcessor { @Override protected ProcessedOperationBinding mapToOperationBinding(AmqpAsyncOperationBinding bindingAnnotation) { diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfAmqpConfigProperties.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfAmqpConfigProperties.java index dc796db05..2b19164b6 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfAmqpConfigProperties.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfAmqpConfigProperties.java @@ -3,18 +3,14 @@ import lombok.Getter; import lombok.Setter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; /** * This class is used to create metadata for auto-completion in spring configuration properties/yaml by using * the spring-boot-configuration-processor. */ -@Configuration @ConfigurationProperties(prefix = SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_CONFIG_PREFIX) -@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) @Getter @Setter public class SpringwolfAmqpConfigProperties { diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfAmqpProducer.java b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfAmqpProducer.java index 75b5e562b..7285c6569 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfAmqpProducer.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfAmqpProducer.java @@ -9,19 +9,12 @@ import io.github.stavshamir.springwolf.asyncapi.types.AsyncAPI; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Optional; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigConstants.SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED; - @Slf4j -@Service -@ConditionalOnProperty(prefix = SPRINGWOLF_AMQP_CONFIG_PREFIX, name = SPRINGWOLF_AMQP_PLUGIN_PUBLISHING_ENABLED) public class SpringwolfAmqpProducer { private final AsyncApiService asyncApiService; diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springwolf-plugins/springwolf-amqp-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..270935ea5 --- /dev/null +++ b/springwolf-plugins/springwolf-amqp-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.stavshamir.springwolf.asyncapi.amqp.SpringwolfAmqpAutoConfiguration diff --git a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfAmqpProducerConfigurationIntegrationTest.java b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfAmqpProducerConfigurationIntegrationTest.java index 3d6ef8f9d..99b3dc009 100644 --- a/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfAmqpProducerConfigurationIntegrationTest.java +++ b/springwolf-plugins/springwolf-amqp-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfAmqpProducerConfigurationIntegrationTest.java @@ -2,17 +2,16 @@ package io.github.stavshamir.springwolf.configuration; import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; -import io.github.stavshamir.springwolf.asyncapi.ChannelsService; +import io.github.stavshamir.springwolf.asyncapi.amqp.SpringwolfAmqpAutoConfiguration; import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfAmqpController; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfAmqpConfigProperties; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; import io.github.stavshamir.springwolf.producer.SpringwolfAmqpProducer; +import io.github.stavshamir.springwolf.schemas.SchemasService; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBeans; import org.springframework.test.context.ContextConfiguration; @@ -26,14 +25,7 @@ public class SpringwolfAmqpProducerConfigurationIntegrationTest { @ExtendWith(SpringExtension.class) - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfAmqpProducer.class, - SpringwolfAmqpController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties(value = {SpringwolfConfigProperties.class, SpringwolfAmqpConfigProperties.class}) + @ContextConfiguration(classes = {SpringwolfAmqpAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -44,7 +36,14 @@ public class SpringwolfAmqpProducerConfigurationIntegrationTest { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.amqp.publishing.enabled=true" }) - @MockBeans(value = {@MockBean(AsyncApiService.class), @MockBean(RabbitTemplate.class)}) + @MockBeans( + value = { + @MockBean(AsyncApiService.class), + @MockBean(RabbitTemplate.class), + @MockBean(ComponentClassScanner.class), + @MockBean(SchemasService.class), + @MockBean(AsyncApiDocketService.class) + }) @Nested class AmqpProducerWillBeCreatedIfEnabledTest { @Autowired @@ -61,14 +60,7 @@ void springwolfAmqpProducerShouldBePresentInSpringContext() { } @ExtendWith(SpringExtension.class) - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfAmqpProducer.class, - SpringwolfAmqpController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties(value = {SpringwolfConfigProperties.class, SpringwolfAmqpConfigProperties.class}) + @ContextConfiguration(classes = {SpringwolfAmqpAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -79,7 +71,13 @@ void springwolfAmqpProducerShouldBePresentInSpringContext() { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.amqp.publishing.enabled=false" }) - @MockBeans(value = {@MockBean(ChannelsService.class), @MockBean(RabbitTemplate.class)}) + @MockBeans( + value = { + @MockBean(AsyncApiService.class), + @MockBean(RabbitTemplate.class), + @MockBean(ComponentClassScanner.class), + @MockBean(SchemasService.class) + }) @Nested class AmqpProducerWillNotBeCreatedIfDisabledTest { @Autowired diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/build.gradle b/springwolf-plugins/springwolf-cloud-stream-plugin/build.gradle index bf9538520..dd71fb375 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/build.gradle +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/build.gradle @@ -24,6 +24,7 @@ dependencies { implementation "org.springframework:spring-context" implementation "org.springframework.cloud:spring-cloud-stream" + implementation "org.springframework.boot:spring-boot-autoconfigure" annotationProcessor "org.projectlombok:lombok:${lombokVersion}" diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/cloudstream/SpringwolfCloudStreamAutoConfiguration.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/cloudstream/SpringwolfCloudStreamAutoConfiguration.java new file mode 100644 index 000000000..0a32ee491 --- /dev/null +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/cloudstream/SpringwolfCloudStreamAutoConfiguration.java @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.cloudstream; + +import io.github.stavshamir.springwolf.asyncapi.scanners.beans.BeanMethodsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.cloudstream.CloudStreamFunctionChannelsScanner; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.stream.config.BindingServiceProperties; +import org.springframework.context.annotation.Bean; + +/** + * Autoconfiguration for the springwolf cloudstream plugin. + */ +@AutoConfiguration +@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) +public class SpringwolfCloudStreamAutoConfiguration { + + @Bean + public CloudStreamFunctionChannelsScanner cloudStreamFunctionChannelsScanner( + AsyncApiDocketService asyncApiDocketService, + BeanMethodsScanner beanMethodsScanner, + SchemasService schemasService, + BindingServiceProperties cloudstreamBindingServiceProperties) { + return new CloudStreamFunctionChannelsScanner( + asyncApiDocketService, beanMethodsScanner, schemasService, cloudstreamBindingServiceProperties); + } +} diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScanner.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScanner.java index a5c8c89be..bc2905375 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScanner.java +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScanner.java @@ -5,7 +5,7 @@ import com.asyncapi.v2._6_0.model.channel.operation.Operation; import com.asyncapi.v2._6_0.model.server.Server; import com.asyncapi.v2.binding.message.MessageBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.beans.DefaultBeanMethodsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.beans.BeanMethodsScanner; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; import io.github.stavshamir.springwolf.asyncapi.types.channel.bindings.EmptyChannelBinding; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.bindings.EmptyOperationBinding; @@ -20,7 +20,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cloud.stream.config.BindingServiceProperties; -import org.springframework.stereotype.Service; import java.lang.reflect.Method; import java.util.Map; @@ -29,12 +28,11 @@ import static java.util.stream.Collectors.toMap; @Slf4j -@Service @RequiredArgsConstructor public class CloudStreamFunctionChannelsScanner implements ChannelsScanner { private final AsyncApiDocketService asyncApiDocketService; - private final DefaultBeanMethodsScanner beanMethodsScanner; + private final BeanMethodsScanner beanMethodsScanner; private final SchemasService schemasService; private final BindingServiceProperties cloudStreamBindingsProperties; diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..b892d0eca --- /dev/null +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.stavshamir.springwolf.asyncapi.cloudstream.SpringwolfCloudStreamAutoConfiguration diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScannerIntegrationTest.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScannerIntegrationTest.java index 21b78f8f6..04cbd9927 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/cloudstream/CloudStreamFunctionChannelsScannerIntegrationTest.java @@ -16,6 +16,7 @@ import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference; import io.github.stavshamir.springwolf.configuration.AsyncApiDocket; import io.github.stavshamir.springwolf.configuration.DefaultAsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; import io.github.stavshamir.springwolf.schemas.DefaultSchemasService; import io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator; import org.apache.kafka.streams.kstream.KStream; @@ -48,7 +49,8 @@ DefaultSchemasService.class, ExampleJsonGenerator.class, DefaultAsyncApiDocketService.class, - CloudStreamFunctionChannelsScanner.class + CloudStreamFunctionChannelsScanner.class, + SpringwolfConfigProperties.class }) @Import(CloudStreamFunctionChannelsScannerIntegrationTest.Configuration.class) class CloudStreamFunctionChannelsScannerIntegrationTest { diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfKafkaController.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfKafkaController.java index 56da4e4e0..05b6785d4 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfKafkaController.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfKafkaController.java @@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,14 +19,10 @@ import java.text.MessageFormat; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED; - @Slf4j @RestController @RequestMapping("/springwolf/kafka") @RequiredArgsConstructor -@ConditionalOnProperty(prefix = SPRINGWOLF_KAFKA_CONFIG_PREFIX, name = SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED) public class SpringwolfKafkaController implements InitializingBean { private final AsyncApiDocketService asyncApiDocketService; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaAutoConfiguration.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaAutoConfiguration.java new file mode 100644 index 000000000..e6c47ec14 --- /dev/null +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaAutoConfiguration.java @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.kafka; + +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +/** + * Autoconfiguration for the springwolf kafka plugin. + */ +@AutoConfiguration +@Import({SpringwolfKafkaScannerConfiguration.class, SpringwolfKafkaProducerConfiguration.class}) +@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) +public class SpringwolfKafkaAutoConfiguration { + + @Bean + public SpringwolfKafkaConfigProperties springwolfKafkaConfigProperties() { + return new SpringwolfKafkaConfigProperties(); + } +} diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaProducerConfiguration.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaProducerConfiguration.java new file mode 100644 index 000000000..4b38b81b5 --- /dev/null +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaProducerConfiguration.java @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.kafka; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfKafkaController; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties; +import io.github.stavshamir.springwolf.producer.SpringwolfKafkaProducer; +import io.github.stavshamir.springwolf.producer.SpringwolfKafkaTemplateFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_CONFIG_PREFIX; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty( + prefix = SPRINGWOLF_KAFKA_CONFIG_PREFIX, + name = SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED, + havingValue = "true") +public class SpringwolfKafkaProducerConfiguration { + + @Bean + public SpringwolfKafkaController springwolfKafkaController( + AsyncApiDocketService asyncApiDocketService, + SpringwolfKafkaProducer springwolfKafkaProducer, + ObjectMapper objectMapper) { + return new SpringwolfKafkaController(asyncApiDocketService, springwolfKafkaProducer, objectMapper); + } + + @Bean + public SpringwolfKafkaProducer springwolfKafkaProducer(SpringwolfKafkaTemplateFactory producerTemplateFactory) { + return new SpringwolfKafkaProducer(producerTemplateFactory.buildKafkaTemplate()); + } + + @Bean + public SpringwolfKafkaTemplateFactory springwolfKafkaTemplateFactory( + SpringwolfKafkaConfigProperties springwolfKafkaConfigProperties) { + return new SpringwolfKafkaTemplateFactory(springwolfKafkaConfigProperties); + } +} diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaScannerConfiguration.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaScannerConfiguration.java new file mode 100644 index 000000000..39bcde6a7 --- /dev/null +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/kafka/SpringwolfKafkaScannerConfiguration.java @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.kafka; + +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.ClassLevelKafkaListenerScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.MethodLevelKafkaListenerScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.KafkaMessageBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.KafkaOperationBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED; + +/** + * spring configuration defining the scanner beans for the kafka plugin + */ +@Configuration(proxyBeanMethods = false) +public class SpringwolfKafkaScannerConfiguration { + + @Bean + @Order(value = ChannelPriority.AUTO_DISCOVERED) + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED, matchIfMissing = true) + public ClassLevelKafkaListenerScanner classLevelKafkaListenerScanner( + ComponentClassScanner componentClassScanner, SchemasService schemasService) { + return new ClassLevelKafkaListenerScanner(componentClassScanner, schemasService); + } + + @Bean + @Order(value = ChannelPriority.AUTO_DISCOVERED) + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED, matchIfMissing = true) + public MethodLevelKafkaListenerScanner methodLevelKafkaListenerScanner( + ComponentClassScanner componentClassScanner, SchemasService schemasService) { + return new MethodLevelKafkaListenerScanner(componentClassScanner, schemasService); + } + + @Bean + public KafkaMessageBindingProcessor kafkaMessageBindingProcessor() { + return new KafkaMessageBindingProcessor(); + } + + @Bean + public KafkaOperationBindingProcessor kafkaOperationBindingProcessor() { + return new KafkaOperationBindingProcessor(); + } +} diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScanner.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScanner.java index 93f250045..82386b774 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScanner.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/ClassLevelKafkaListenerScanner.java @@ -4,36 +4,32 @@ import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders; import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeadersForSpringKafkaBuilder; -import lombok.RequiredArgsConstructor; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; import org.springframework.kafka.annotation.KafkaHandler; import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Service; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.Map; import static io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.SpringPayloadAnnotationTypeExtractor.getPayloadType; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED; @Slf4j -@Service -@RequiredArgsConstructor -@Order(value = ChannelPriority.AUTO_DISCOVERED) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED, matchIfMissing = true) public class ClassLevelKafkaListenerScanner extends AbstractClassLevelListenerScanner implements ChannelsScanner, EmbeddedValueResolverAware { private StringValueResolver resolver; + public ClassLevelKafkaListenerScanner(ComponentClassScanner componentClassScanner, SchemasService schemasService) { + super(componentClassScanner, schemasService); + } + @Override public void setEmbeddedValueResolver(StringValueResolver resolver) { this.resolver = resolver; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScanner.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScanner.java index ac71f1810..7d9e0888b 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScanner.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelKafkaListenerScanner.java @@ -4,32 +4,27 @@ import com.asyncapi.v2.binding.channel.ChannelBinding; import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; -import lombok.RequiredArgsConstructor; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; import org.springframework.kafka.annotation.KafkaListener; -import org.springframework.stereotype.Service; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.Map; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED; - @Slf4j -@Service -@RequiredArgsConstructor -@Order(value = ChannelPriority.AUTO_DISCOVERED) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_KAFKA_LISTENER_ENABLED, matchIfMissing = true) public class MethodLevelKafkaListenerScanner extends AbstractMethodLevelListenerScanner implements ChannelsScanner, EmbeddedValueResolverAware { private StringValueResolver resolver; + public MethodLevelKafkaListenerScanner(ComponentClassScanner componentClassScanner, SchemasService schemasService) { + super(componentClassScanner, schemasService); + } + @Override public void setEmbeddedValueResolver(StringValueResolver resolver) { this.resolver = resolver; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaMessageBindingProcessor.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaMessageBindingProcessor.java index 0cf27bb91..e30a25fcd 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaMessageBindingProcessor.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaMessageBindingProcessor.java @@ -8,7 +8,6 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.StringSchema; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import org.springframework.util.StringValueResolver; @@ -16,7 +15,6 @@ import java.util.Arrays; import java.util.Optional; -@Component public class KafkaMessageBindingProcessor implements MessageBindingProcessor, EmbeddedValueResolverAware { private StringValueResolver resolver; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaOperationBindingProcessor.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaOperationBindingProcessor.java index bf6fc85b8..6be7185a9 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaOperationBindingProcessor.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/KafkaOperationBindingProcessor.java @@ -6,10 +6,8 @@ import io.github.stavshamir.springwolf.asyncapi.scanners.channels.AbstractOperationBindingProcessor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.KafkaListenerUtil; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding; -import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; -@Component public class KafkaOperationBindingProcessor extends AbstractOperationBindingProcessor { @Override protected ProcessedOperationBinding mapToOperationBinding(KafkaAsyncOperationBinding bindingAnnotation) { diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfiguration.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfiguration.java deleted file mode 100644 index 958b0ebbc..000000000 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfiguration.java +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -package io.github.stavshamir.springwolf.configuration; - -import io.github.stavshamir.springwolf.producer.SpringwolfKafkaProducer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED; - -@Configuration -@ConditionalOnProperty( - prefix = SPRINGWOLF_KAFKA_CONFIG_PREFIX, - name = SPRINGWOLF_KAFKA_PLUGIN_PUBLISHING_ENABLED, - havingValue = "true") -public class SpringwolfKafkaProducerConfiguration { - - @Bean - public SpringwolfKafkaProducer springwolfKafkaProducer( - @Autowired SpringwolfKafkaTemplateFactory producerTemplateFactory) { - return new SpringwolfKafkaProducer(producerTemplateFactory.buildKafkaTemplate()); - } -} diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfKafkaConfigProperties.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfKafkaConfigProperties.java index 0be5f1ea0..2f9648559 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfKafkaConfigProperties.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfKafkaConfigProperties.java @@ -3,11 +3,9 @@ import lombok.Getter; import lombok.Setter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.kafka.KafkaProperties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigConstants.SPRINGWOLF_KAFKA_CONFIG_PREFIX; @@ -16,9 +14,7 @@ * This class is used to create metadata for auto-completion in spring configuration properties/yaml by using * the spring-boot-configuration-processor. */ -@Configuration @ConfigurationProperties(prefix = SPRINGWOLF_KAFKA_CONFIG_PREFIX) -@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) @Getter @Setter public class SpringwolfKafkaConfigProperties { diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactory.java b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactory.java similarity index 91% rename from springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactory.java rename to springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactory.java index ba6fa45a2..be700e1bc 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactory.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactory.java @@ -1,17 +1,16 @@ // SPDX-License-Identifier: Apache-2.0 -package io.github.stavshamir.springwolf.configuration; +package io.github.stavshamir.springwolf.producer; +import io.github.stavshamir.springwolf.asyncapi.kafka.SpringwolfKafkaProducerConfiguration; import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties; import lombok.RequiredArgsConstructor; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.kafka.core.DefaultKafkaProducerFactory; import org.springframework.kafka.core.KafkaTemplate; -import org.springframework.stereotype.Component; import java.util.Map; import java.util.Optional; -@Component @RequiredArgsConstructor @ConditionalOnBean(value = SpringwolfKafkaProducerConfiguration.class) public class SpringwolfKafkaTemplateFactory { diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springwolf-plugins/springwolf-kafka-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..41ec4e3da --- /dev/null +++ b/springwolf-plugins/springwolf-kafka-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.stavshamir.springwolf.asyncapi.kafka.SpringwolfKafkaAutoConfiguration diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfigurationIntegrationTest.java b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringWolfKafkaProducerConfigurationIntegrationTest.java similarity index 71% rename from springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfigurationIntegrationTest.java rename to springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringWolfKafkaProducerConfigurationIntegrationTest.java index d2a36d76b..2686c4a72 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaProducerConfigurationIntegrationTest.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringWolfKafkaProducerConfigurationIntegrationTest.java @@ -2,14 +2,16 @@ package io.github.stavshamir.springwolf.configuration; import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfKafkaController; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties; +import io.github.stavshamir.springwolf.asyncapi.kafka.SpringwolfKafkaAutoConfiguration; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; import io.github.stavshamir.springwolf.producer.SpringwolfKafkaProducer; +import io.github.stavshamir.springwolf.schemas.SchemasService; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.MockBeans; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -18,19 +20,11 @@ import static org.assertj.core.api.Assertions.assertThat; -public class SpringwolfKafkaProducerConfigurationIntegrationTest { +public class SpringWolfKafkaProducerConfigurationIntegrationTest { @ExtendWith(SpringExtension.class) @Nested - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfKafkaProducerConfiguration.class, - SpringwolfKafkaTemplateFactory.class, - SpringwolfKafkaController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties(value = {SpringwolfConfigProperties.class, SpringwolfKafkaConfigProperties.class}) + @ContextConfiguration(classes = {SpringwolfKafkaAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -41,6 +35,12 @@ public class SpringwolfKafkaProducerConfigurationIntegrationTest { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.kafka.publishing.enabled=true" }) + @MockBeans( + value = { + @MockBean(ComponentClassScanner.class), + @MockBean(SchemasService.class), + @MockBean(AsyncApiDocketService.class) + }) class KafkaProducerWillBeCreatedIfEnabledTest { @Autowired private Optional springwolfKafkaProducer; @@ -57,18 +57,7 @@ void springwolfKafkaTemplateShouldBePresentInSpringContext() { @ExtendWith(SpringExtension.class) @Nested - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfKafkaProducerConfiguration.class, - SpringwolfKafkaController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties( - value = { - SpringwolfConfigProperties.class, - SpringwolfKafkaConfigProperties.class, - }) + @ContextConfiguration(classes = {SpringwolfKafkaAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -79,6 +68,7 @@ void springwolfKafkaTemplateShouldBePresentInSpringContext() { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.kafka.publishing.enabled=false" }) + @MockBeans(value = {@MockBean(ComponentClassScanner.class), @MockBean(SchemasService.class)}) class KafkaProducerWillNotBeCreatedIfDisabledTest { @Autowired private Optional springwolfKafkaProducer; diff --git a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactoryTest.java b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactoryTest.java similarity index 97% rename from springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactoryTest.java rename to springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactoryTest.java index aa665392a..fadd4e448 100644 --- a/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfKafkaTemplateFactoryTest.java +++ b/springwolf-plugins/springwolf-kafka-plugin/src/test/java/io/github/stavshamir/springwolf/producer/SpringwolfKafkaTemplateFactoryTest.java @@ -1,5 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 -package io.github.stavshamir.springwolf.configuration; +package io.github.stavshamir.springwolf.producer; import io.github.stavshamir.springwolf.configuration.properties.SpringwolfKafkaConfigProperties; import org.junit.jupiter.api.Test; diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfSqsController.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfSqsController.java index 7102486e5..2296b534b 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfSqsController.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/controller/SpringwolfSqsController.java @@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -20,14 +19,10 @@ import java.text.MessageFormat; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED; - @Slf4j @RestController @RequestMapping("/springwolf/sqs") @RequiredArgsConstructor -@ConditionalOnProperty(prefix = SPRINGWOLF_SQS_CONFIG_PREFIX, name = SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED) public class SpringwolfSqsController implements InitializingBean { private final AsyncApiDocketService asyncApiDocketService; diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScanner.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScanner.java index 95a6d438f..74766bd90 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScanner.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/annotation/MethodLevelSqsListenerScanner.java @@ -5,29 +5,26 @@ import com.asyncapi.v2.binding.message.MessageBinding; import com.asyncapi.v2.binding.operation.OperationBinding; import io.awspring.cloud.sqs.annotation.SqsListener; -import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Service; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.Map; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED; - @Slf4j -@Service -@Order(value = ChannelPriority.AUTO_DISCOVERED) -@ConditionalOnProperty(name = SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED, matchIfMissing = true) public class MethodLevelSqsListenerScanner extends AbstractMethodLevelListenerScanner implements ChannelsScanner, EmbeddedValueResolverAware { private StringValueResolver resolver; + public MethodLevelSqsListenerScanner(ComponentClassScanner componentClassScanner, SchemasService schemasService) { + super(componentClassScanner, schemasService); + } + @Override public void setEmbeddedValueResolver(StringValueResolver resolver) { this.resolver = resolver; diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsMessageBindingProcessor.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsMessageBindingProcessor.java index cb992682e..3dd0c257e 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsMessageBindingProcessor.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsMessageBindingProcessor.java @@ -5,14 +5,12 @@ import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.MessageBindingProcessor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.SqsAsyncOperationBinding; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.stereotype.Component; import org.springframework.util.StringValueResolver; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Optional; -@Component public class SqsMessageBindingProcessor implements MessageBindingProcessor, EmbeddedValueResolverAware { private StringValueResolver resolver; diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsOperationBindingProcessor.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsOperationBindingProcessor.java index 3764c7d7b..8997ece7a 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsOperationBindingProcessor.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/operationdata/SqsOperationBindingProcessor.java @@ -4,9 +4,7 @@ import com.asyncapi.v2.binding.operation.sqs.SQSOperationBinding; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.AbstractOperationBindingProcessor; import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.SqsAsyncOperationBinding; -import org.springframework.stereotype.Component; -@Component public class SqsOperationBindingProcessor extends AbstractOperationBindingProcessor { @Override diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsAutoConfiguration.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsAutoConfiguration.java new file mode 100644 index 000000000..48ec89df0 --- /dev/null +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsAutoConfiguration.java @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.sqs; + +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigConstants; +import io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigProperties; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; + +/** + * Autoconfiguration for the springwolf sqs plugin. + */ +@AutoConfiguration +@Import({SpringwolfSqsScannerConfiguration.class, SpringwolfSqsWebConfiguration.class}) +@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) +public class SpringwolfSqsAutoConfiguration { + + @Bean + public SpringwolfSqsConfigProperties springwolfSqsConfigProperties() { + return new SpringwolfSqsConfigProperties(); + } +} diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsScannerConfiguration.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsScannerConfiguration.java new file mode 100644 index 000000000..06d437e19 --- /dev/null +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsScannerConfiguration.java @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.sqs; + +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelPriority; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.annotation.MethodLevelSqsListenerScanner; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.SqsMessageBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.SqsOperationBindingProcessor; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.schemas.SchemasService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED; + +/** + * spring configuration defining the scanner beans for the kafka plugin + */ +@Configuration(proxyBeanMethods = false) +public class SpringwolfSqsScannerConfiguration { + + @Bean + @Order(value = ChannelPriority.AUTO_DISCOVERED) + @ConditionalOnProperty(name = SPRINGWOLF_SCANNER_SQS_LISTENER_ENABLED, matchIfMissing = true) + public MethodLevelSqsListenerScanner methodLevelSqsListenerScanner( + ComponentClassScanner componentClassScanner, SchemasService schemasService) { + return new MethodLevelSqsListenerScanner(componentClassScanner, schemasService); + } + + @Bean + public SqsMessageBindingProcessor sqsMessageBindingProcessor() { + return new SqsMessageBindingProcessor(); + } + + @Bean + public SqsOperationBindingProcessor sqsOperationBindingProcessor() { + return new SqsOperationBindingProcessor(); + } +} diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsWebConfiguration.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsWebConfiguration.java new file mode 100644 index 000000000..48c7bfc86 --- /dev/null +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/asyncapi/sqs/SpringwolfSqsWebConfiguration.java @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +package io.github.stavshamir.springwolf.asyncapi.sqs; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.awspring.cloud.sqs.operations.SqsTemplate; +import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfSqsController; +import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService; +import io.github.stavshamir.springwolf.producer.SpringwolfSqsProducer; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_CONFIG_PREFIX; +import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = SPRINGWOLF_SQS_CONFIG_PREFIX, name = SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED) +public class SpringwolfSqsWebConfiguration { + + @Bean + public SpringwolfSqsProducer springwolfSqsProducer(List sqsTemplates) { + return new SpringwolfSqsProducer(sqsTemplates); + } + + @Bean + public SpringwolfSqsController springwolfSqsController( + AsyncApiDocketService asyncApiDocketService, + SpringwolfSqsProducer springwolfSqsProducer, + ObjectMapper objectMapper) { + return new SpringwolfSqsController(asyncApiDocketService, springwolfSqsProducer, objectMapper); + } +} diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfSqsConfigProperties.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfSqsConfigProperties.java index 87ca3ebf6..b7ec8e706 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfSqsConfigProperties.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/configuration/properties/SpringwolfSqsConfigProperties.java @@ -3,18 +3,14 @@ import lombok.Getter; import lombok.Setter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; import org.springframework.lang.Nullable; /** * This class is used to create metadata for auto-completion in spring configuration properties/yaml by using * the spring-boot-configuration-processor. */ -@Configuration @ConfigurationProperties(prefix = SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_CONFIG_PREFIX) -@ConditionalOnProperty(name = SpringwolfConfigConstants.SPRINGWOLF_ENABLED, matchIfMissing = true) @Getter @Setter public class SpringwolfSqsConfigProperties { diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfSqsProducer.java b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfSqsProducer.java index 1c4dbe6ed..5d70ce31e 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfSqsProducer.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/java/io/github/stavshamir/springwolf/producer/SpringwolfSqsProducer.java @@ -3,18 +3,11 @@ import io.awspring.cloud.sqs.operations.SqsTemplate; import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_CONFIG_PREFIX; -import static io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigConstants.SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED; - @Slf4j -@Service -@ConditionalOnProperty(prefix = SPRINGWOLF_SQS_CONFIG_PREFIX, name = SPRINGWOLF_SQS_PLUGIN_PUBLISHING_ENABLED) public class SpringwolfSqsProducer { private final Optional template; diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/springwolf-plugins/springwolf-sqs-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..8c1900109 --- /dev/null +++ b/springwolf-plugins/springwolf-sqs-plugin/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +io.github.stavshamir.springwolf.asyncapi.sqs.SpringwolfSqsAutoConfiguration diff --git a/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfSqsProducerConfigurationIntegrationTest.java b/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfSqsProducerConfigurationIntegrationTest.java index 8a306fa0d..d202aa816 100644 --- a/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfSqsProducerConfigurationIntegrationTest.java +++ b/springwolf-plugins/springwolf-sqs-plugin/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfSqsProducerConfigurationIntegrationTest.java @@ -5,14 +5,14 @@ import io.github.stavshamir.springwolf.asyncapi.AsyncApiService; import io.github.stavshamir.springwolf.asyncapi.ChannelsService; import io.github.stavshamir.springwolf.asyncapi.controller.SpringwolfSqsController; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfConfigProperties; -import io.github.stavshamir.springwolf.configuration.properties.SpringwolfSqsConfigProperties; +import io.github.stavshamir.springwolf.asyncapi.scanners.classes.ComponentClassScanner; +import io.github.stavshamir.springwolf.asyncapi.sqs.SpringwolfSqsAutoConfiguration; import io.github.stavshamir.springwolf.producer.SpringwolfSqsProducer; +import io.github.stavshamir.springwolf.schemas.SchemasService; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBeans; import org.springframework.test.context.ContextConfiguration; @@ -26,14 +26,7 @@ public class SpringwolfSqsProducerConfigurationIntegrationTest { @ExtendWith(SpringExtension.class) - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfSqsProducer.class, - SpringwolfSqsController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties(value = {SpringwolfConfigProperties.class, SpringwolfSqsConfigProperties.class}) + @ContextConfiguration(classes = {SpringwolfSqsAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -44,7 +37,14 @@ public class SpringwolfSqsProducerConfigurationIntegrationTest { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.sqs.publishing.enabled=true" }) - @MockBeans(value = {@MockBean(AsyncApiService.class), @MockBean(SqsTemplate.class)}) + @MockBeans( + value = { + @MockBean(ComponentClassScanner.class), + @MockBean(SchemasService.class), + @MockBean(AsyncApiDocketService.class), + @MockBean(AsyncApiService.class), + @MockBean(SqsTemplate.class) + }) @Nested class SqsProducerWillBeCreatedIfEnabledTest { @Autowired @@ -61,14 +61,7 @@ void springwolfSqsProducerShouldBePresentInSpringContext() { } @ExtendWith(SpringExtension.class) - @ContextConfiguration( - classes = { - DefaultAsyncApiDocketService.class, - SpringwolfSqsProducer.class, - SpringwolfSqsController.class, - ObjectMapperTestConfiguration.class - }) - @EnableConfigurationProperties(value = {SpringwolfConfigProperties.class, SpringwolfSqsConfigProperties.class}) + @ContextConfiguration(classes = {SpringwolfSqsAutoConfiguration.class, ObjectMapperTestConfiguration.class}) @TestPropertySource( properties = { "springwolf.enabled=true", @@ -79,7 +72,13 @@ void springwolfSqsProducerShouldBePresentInSpringContext() { "springwolf.docket.servers.test-protocol.url=some-server:1234", "springwolf.plugin.sqs.publishing.enabled=false" }) - @MockBeans(value = {@MockBean(ChannelsService.class), @MockBean(SqsTemplate.class)}) + @MockBeans( + value = { + @MockBean(ComponentClassScanner.class), + @MockBean(SchemasService.class), + @MockBean(ChannelsService.class), + @MockBean(SqsTemplate.class) + }) @Nested class SqsProducerWillNotBeCreatedIfDisabledTest { @Autowired