Skip to content

Commit

Permalink
Merge pull request #2 from timonback/feature/replace-componentscan
Browse files Browse the repository at this point in the history
Addition to PR #386
  • Loading branch information
tvahrst authored Oct 7, 2023
2 parents dd5aaae + 92f8b9d commit c78de27
Show file tree
Hide file tree
Showing 38 changed files with 27 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +15,6 @@
* Service to detect AsyncAPI channels in the current spring context.
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class DefaultChannelsService implements ChannelsService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -17,7 +16,6 @@
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class SpringwolfInitApplicationListener implements ApplicationListener<ApplicationReadyEvent>, InitializingBean {

private final AsyncApiService asyncApiService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

@Component
@Slf4j
@RestControllerEndpoint(id = "springwolf")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +13,6 @@

import static java.util.stream.Collectors.toSet;

@Service
@RequiredArgsConstructor
public class DefaultBeanMethodsScanner implements BeanMethodsScanner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import io.github.stavshamir.springwolf.schemas.SchemasService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Component
public class ConsumerOperationDataScanner extends AbstractOperationDataScanner {

private final AsyncApiDocketService asyncApiDocketService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import io.github.stavshamir.springwolf.schemas.SchemasService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Component
public class ProducerOperationDataScanner extends AbstractOperationDataScanner {

private final AsyncApiDocketService asyncApiDocketService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import lombok.extern.slf4j.Slf4j;
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;
Expand All @@ -27,7 +26,6 @@

@Slf4j
@RequiredArgsConstructor
@Component
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public class AsyncListenerAnnotationScanner extends AbstractOperationDataScanner implements EmbeddedValueResolverAware {
private StringValueResolver resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import lombok.extern.slf4j.Slf4j;
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;
Expand All @@ -26,7 +25,6 @@

@Slf4j
@RequiredArgsConstructor
@Component
@Order(value = ChannelPriority.ASYNC_ANNOTATION)
public class AsyncPublisherAnnotationScanner extends AbstractOperationDataScanner
implements EmbeddedValueResolverAware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class ComponentClassScanner extends AbstractAnnotatedClassScanner<Component> implements ClassScanner {

public ComponentClassScanner(AsyncApiDocketService asyncApiDocketService, Environment environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

@Service
public class ConfigurationClassScanner extends AbstractAnnotatedClassScanner<Configuration> implements ClassScanner {

public ConfigurationClassScanner(AsyncApiDocketService asyncApiDocketService, Environment environment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand All @@ -18,7 +17,6 @@
import java.util.Set;

@Slf4j
@Service
public class DefaultSchemasService implements SchemasService {

private final ModelConverters converter = ModelConverters.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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.HashSet;
import java.util.List;
Expand All @@ -20,7 +19,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,9 +56,7 @@ void getComponents() {
Set<Class<?>> components = componentsScanner.scan();

assertThat(components)
.contains(ComponentClassScanner.class)
.contains(ConfigurationClassScanner.class)
.doesNotContain(ClassScanner.class)
.contains(TestComponent.class)
.doesNotContain(TestConditionalComponent.class)
.doesNotContain(TestOtherConditionalComponent.class);
}
Expand All @@ -66,10 +69,8 @@ void getComponentsIncludesConditional() {
Set<Class<?>> components = componentsScanner.scan();

assertThat(components)
.contains(ComponentClassScanner.class)
.contains(ConfigurationClassScanner.class)
.contains(TestComponent.class)
.contains(TestConditionalComponent.class)
.doesNotContain(ClassScanner.class)
.doesNotContain(TestOtherConditionalComponent.class);
}
}
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import org.springframework.amqp.rabbit.annotation.RabbitListener;
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;

@Slf4j
@Service
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public class ClassLevelRabbitListenerScanner extends AbstractClassLevelListenerScanner<RabbitListener, RabbitHandler>
implements ChannelsScanner, EmbeddedValueResolverAware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
import org.springframework.amqp.rabbit.annotation.RabbitListener;
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;

@Slf4j
@Service
@Order(value = ChannelPriority.AUTO_DISCOVERED)
public class MethodLevelRabbitListenerScanner extends AbstractMethodLevelListenerScanner<RabbitListener>
implements ChannelsScanner, EmbeddedValueResolverAware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AmqpAsyncOperationBinding> {
@Override
protected ProcessedOperationBinding mapToOperationBinding(AmqpAsyncOperationBinding bindingAnnotation) {
Expand Down
Loading

0 comments on commit c78de27

Please sign in to comment.