Skip to content

Commit

Permalink
chore(core): review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed Jun 21, 2024
1 parent 735c21e commit 2131798
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public AsyncAnnotationChannelsScanner(
ComponentsService componentsService,
AsyncApiDocketService asyncApiDocketService,
PayloadClassExtractor payloadClassExtractor,
PayloadAsyncOperationService payloadService,
PayloadAsyncOperationService payloadAsyncOperationService,
List<OperationBindingProcessor> operationBindingProcessors,
List<MessageBindingProcessor> messageBindingProcessors) {
super(
asyncAnnotationProvider,
payloadClassExtractor,
payloadService,
payloadAsyncOperationService,
componentsService,
operationBindingProcessors,
messageBindingProcessors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ public class SpringAnnotationMethodLevelChannelsScanner<MethodAnnotation extends
extends MethodLevelAnnotationScanner<MethodAnnotation> implements SpringAnnotationChannelsScannerDelegator {

private final Class<MethodAnnotation> methodAnnotationClass;
private final PayloadMethodService payloadService;
private final PayloadMethodService payloadMethodService;
private final HeaderClassExtractor headerClassExtractor;

public SpringAnnotationMethodLevelChannelsScanner(
Class<MethodAnnotation> methodAnnotationClass,
BindingFactory<MethodAnnotation> bindingFactory,
AsyncHeadersBuilder asyncHeadersBuilder,
PayloadMethodService payloadService,
PayloadMethodService payloadMethodService,
HeaderClassExtractor headerClassExtractor,
ComponentsService componentsService) {
super(bindingFactory, asyncHeadersBuilder, componentsService);
this.methodAnnotationClass = methodAnnotationClass;
this.payloadService = payloadService;
this.payloadMethodService = payloadMethodService;
this.headerClassExtractor = headerClassExtractor;
}

Expand All @@ -62,7 +62,7 @@ private Map.Entry<String, ChannelObject> mapMethodToChannel(Method method) {

MethodAnnotation annotation = AnnotationScannerUtil.findAnnotationOrThrow(methodAnnotationClass, method);

NamedSchemaObject payloadSchema = payloadService.extractSchema(method);
NamedSchemaObject payloadSchema = payloadMethodService.extractSchema(method);
SchemaObject headerSchema = headerClassExtractor.extractHeader(method, payloadSchema);
ChannelObject channelItem = buildChannelItem(annotation, payloadSchema, headerSchema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class AsyncAnnotationScanner<A extends Annotation> implements Em

protected final AsyncAnnotationProvider<A> asyncAnnotationProvider;
protected final PayloadClassExtractor payloadClassExtractor;
protected final PayloadAsyncOperationService payloadService;
protected final PayloadAsyncOperationService payloadAsyncOperationService;
protected final ComponentsService componentsService;
protected final List<OperationBindingProcessor> operationBindingProcessors;
protected final List<MessageBindingProcessor> messageBindingProcessors;
Expand Down Expand Up @@ -92,7 +92,7 @@ protected Operation buildOperation(AsyncOperation asyncOperation, Method method,
}

protected MessageObject buildMessage(AsyncOperation operationData, Method method) {
NamedSchemaObject payloadSchema = payloadService.extractSchema(operationData, method);
NamedSchemaObject payloadSchema = payloadAsyncOperationService.extractSchema(operationData, method);

SchemaObject headerSchema = AsyncAnnotationUtil.getAsyncHeaders(operationData, resolver);
String headerSchemaName = this.componentsService.registerSchema(headerSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class ClassLevelAnnotationScanner<
protected final Class<MethodAnnotation> methodAnnotationClass;
protected final BindingFactory<ClassAnnotation> bindingFactory;
protected final AsyncHeadersBuilder asyncHeadersBuilder;
protected final PayloadMethodService payloadService;
protected final PayloadMethodService payloadMethodService;
protected final HeaderClassExtractor headerClassExtractor;
protected final ComponentsService componentsService;

Expand Down Expand Up @@ -71,7 +71,7 @@ protected Map<String, MessageReference> buildMessages(
SpringAnnotationClassLevelOperationsScanner.MessageType messageType) {
Set<MessageObject> messages = methods.stream()
.map((Method method) -> {
NamedSchemaObject payloadSchema = payloadService.extractSchema(method);
NamedSchemaObject payloadSchema = payloadMethodService.extractSchema(method);
SchemaObject headerSchema = headerClassExtractor.extractHeader(method, payloadSchema);
return buildMessage(classAnnotation, payloadSchema, headerSchema);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public AsyncAnnotationOperationsScanner(
ClassScanner classScanner,
ComponentsService componentsService,
PayloadClassExtractor payloadClassExtractor,
PayloadAsyncOperationService payloadService,
PayloadAsyncOperationService payloadAsyncOperationService,
List<OperationBindingProcessor> operationBindingProcessors,
List<MessageBindingProcessor> messageBindingProcessors) {
super(
asyncAnnotationProvider,
payloadClassExtractor,
payloadService,
payloadAsyncOperationService,
componentsService,
operationBindingProcessors,
messageBindingProcessors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public SpringAnnotationClassLevelOperationsScanner(
Class<MethodAnnotation> methodAnnotationClass,
BindingFactory<ClassAnnotation> bindingFactory,
AsyncHeadersBuilder asyncHeadersBuilder,
PayloadMethodService payloadService,
PayloadMethodService payloadMethodService,
HeaderClassExtractor headerClassExtractor,
ComponentsService componentsService) {
super(
classAnnotationClass,
methodAnnotationClass,
bindingFactory,
asyncHeadersBuilder,
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public class SpringAnnotationMethodLevelOperationsScanner<MethodAnnotation exten
extends MethodLevelAnnotationScanner<MethodAnnotation> implements SpringAnnotationOperationsScannerDelegator {

private final Class<MethodAnnotation> methodAnnotationClass;
private final PayloadMethodParameterService payloadService;
private final PayloadMethodParameterService payloadMethodParameterService;
private final HeaderClassExtractor headerClassExtractor;

public SpringAnnotationMethodLevelOperationsScanner(
Class<MethodAnnotation> methodAnnotationClass,
BindingFactory<MethodAnnotation> bindingFactory,
AsyncHeadersBuilder asyncHeadersBuilder,
PayloadMethodParameterService payloadService,
PayloadMethodParameterService payloadMethodParameterService,
HeaderClassExtractor headerClassExtractor,
ComponentsService componentsService) {
super(bindingFactory, asyncHeadersBuilder, componentsService);
this.methodAnnotationClass = methodAnnotationClass;
this.payloadService = payloadService;
this.payloadMethodParameterService = payloadMethodParameterService;
this.headerClassExtractor = headerClassExtractor;
}

Expand All @@ -67,7 +67,7 @@ private Map.Entry<String, Operation> mapMethodToOperation(Method method) {

String channelName = bindingFactory.getChannelName(annotation);
String operationId = channelName + "_" + OperationAction.RECEIVE + "_" + method.getName();
NamedSchemaObject payloadSchema = payloadService.extractSchema(method);
NamedSchemaObject payloadSchema = payloadMethodParameterService.extractSchema(method);
SchemaObject headerSchema = headerClassExtractor.extractHeader(method, payloadSchema);

Operation operation = buildOperation(annotation, payloadSchema, headerSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class SpringAnnotationClassLevelChannelsScannerIntegrationTest {
BindingFactory<TestClassListener> bindingFactory;

@Autowired
PayloadMethodService payloadService;
PayloadMethodService payloadMethodService;

@Autowired
HeaderClassExtractor headerClassExtractor;
Expand All @@ -91,7 +91,7 @@ void setUp() {
TestMethodListener.class,
this.bindingFactory,
new AsyncHeadersNotDocumented(),
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

class SpringAnnotationClassLevelChannelsScannerTest {

private final PayloadMethodService payloadService = mock();
private final PayloadMethodService payloadMethodService = mock();
private final HeaderClassExtractor headerClassExtractor = mock(HeaderClassExtractor.class);
private final BindingFactory<TestClassListener> bindingFactory = mock(BindingFactory.class);
private final ComponentsService componentsService = mock(ComponentsService.class);
Expand All @@ -50,7 +50,7 @@ class SpringAnnotationClassLevelChannelsScannerTest {
TestMethodListener.class,
bindingFactory,
new AsyncHeadersNotDocumented(),
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);

Expand All @@ -71,7 +71,7 @@ void setUp() {
doReturn(defaultChannelBinding).when(bindingFactory).buildChannelBinding(any());
doReturn(defaultMessageBinding).when(bindingFactory).buildMessageBinding(any(), any());

when(payloadService.extractSchema(any()))
when(payloadMethodService.extractSchema(any()))
.thenReturn(new NamedSchemaObject(String.class.getName(), new SchemaObject()));
doAnswer(invocation -> AsyncHeadersNotDocumented.NOT_DOCUMENTED.getTitle())
.when(componentsService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SpringAnnotationMethodLevelChannelsScannerIntegrationTest {
BindingFactory<TestChannelListener> bindingFactory;

@Autowired
PayloadMethodService payloadService;
PayloadMethodService payloadMethodService;

@Autowired
HeaderClassExtractor headerClassExtractor;
Expand All @@ -91,7 +91,7 @@ void setUp() {
TestChannelListener.class,
this.bindingFactory,
new AsyncHeadersNotDocumented(),
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@

class SpringAnnotationMethodLevelChannelsScannerTest {

private final PayloadMethodService payloadService = mock();
private final PayloadMethodService payloadMethodService = mock();
private final HeaderClassExtractor headerClassExtractor = mock(HeaderClassExtractor.class);
private final BindingFactory<TestListener> bindingFactory = mock(BindingFactory.class);
private final ComponentsService componentsService = mock(ComponentsService.class);
SpringAnnotationMethodLevelChannelsScanner<TestListener> scanner = new SpringAnnotationMethodLevelChannelsScanner<>(
TestListener.class,
bindingFactory,
new AsyncHeadersNotDocumented(),
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);

Expand All @@ -70,19 +70,19 @@ void setUp() throws NoSuchMethodException {
doReturn(defaultChannelBinding).when(bindingFactory).buildChannelBinding(any());
doReturn(defaultMessageBinding).when(bindingFactory).buildMessageBinding(any(), any());

when(payloadService.extractSchema(any()))
when(payloadMethodService.extractSchema(any()))
.thenReturn(new NamedSchemaObject(String.class.getName(), new SchemaObject()));
doAnswer(invocation -> AsyncHeadersNotDocumented.NOT_DOCUMENTED.getTitle())
.when(componentsService)
.registerSchema(any(SchemaObject.class));

var stringMethod =
ClassWithMultipleTestListenerAnnotation.class.getDeclaredMethod("methodWithAnnotation", String.class);
when(payloadService.extractSchema(stringMethod))
when(payloadMethodService.extractSchema(stringMethod))
.thenReturn(new NamedSchemaObject(String.class.getName(), new SchemaObject()));
var simpleFooMethod = ClassWithMultipleTestListenerAnnotation.class.getDeclaredMethod(
"anotherMethodWithAnnotation", SimpleFoo.class);
when(payloadService.extractSchema(simpleFooMethod))
when(payloadMethodService.extractSchema(simpleFooMethod))
.thenReturn(new NamedSchemaObject(SimpleFoo.class.getName(), new SchemaObject()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.springwolf.core.asyncapi.scanners.common.payload.internal.PayloadClassExtractor;
import io.github.springwolf.core.asyncapi.scanners.common.payload.internal.PayloadService;
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand All @@ -25,9 +26,15 @@ class PayloadAsyncOperationServiceTest {
private PayloadClassExtractor payloadClassExtractor = mock(PayloadClassExtractor.class);
private ComponentsService componentsService = mock(ComponentsService.class);
private SpringwolfConfigProperties properties = mock(SpringwolfConfigProperties.class);
private PayloadService payloadService = new PayloadService(componentsService, properties);
private PayloadAsyncOperationService payloadAsyncOperationService =
new PayloadAsyncOperationService(payloadClassExtractor, payloadService);

private PayloadService payloadService;
private PayloadAsyncOperationService payloadAsyncOperationService;

@BeforeEach
void setUp() {
payloadService = new PayloadService(componentsService, properties);
payloadAsyncOperationService = new PayloadAsyncOperationService(payloadClassExtractor, payloadService);
}

@Test
public void shouldUsePayloadFromAsyncOperationAnnotation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.github.springwolf.core.asyncapi.scanners.common.payload.internal.PayloadClassExtractor;
import io.github.springwolf.core.asyncapi.scanners.common.payload.internal.PayloadService;
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand All @@ -21,9 +22,15 @@ class PayloadMethodParameterServiceTest {
private ComponentsService componentsService = mock(ComponentsService.class);
private SpringwolfConfigProperties.ConfigDocket docket = mock(SpringwolfConfigProperties.ConfigDocket.class);
private SpringwolfConfigProperties properties = mock(SpringwolfConfigProperties.class);
private PayloadService payloadService = new PayloadService(componentsService, properties);
private PayloadMethodParameterService payloadMethodParameterService =
new PayloadMethodParameterService(payloadClassExtractor, payloadService);

private PayloadService payloadService;
private PayloadMethodParameterService payloadMethodParameterService;

@BeforeEach
void setUp() {
payloadService = new PayloadService(componentsService, properties);
payloadMethodParameterService = new PayloadMethodParameterService(payloadClassExtractor, payloadService);
}

@Test
public void shouldExtractPayloadFromMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.springwolf.core.asyncapi.components.ComponentsService;
import io.github.springwolf.core.asyncapi.scanners.common.payload.internal.PayloadService;
import io.github.springwolf.core.configuration.properties.SpringwolfConfigProperties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
Expand All @@ -19,8 +20,15 @@ class PayloadMethodReturnServiceTest {
private ComponentsService componentsService = mock(ComponentsService.class);
private SpringwolfConfigProperties.ConfigDocket docket = mock(SpringwolfConfigProperties.ConfigDocket.class);
private SpringwolfConfigProperties properties = mock(SpringwolfConfigProperties.class);
private PayloadService payloadService = new PayloadService(componentsService, properties);
private PayloadMethodReturnService payloadMethodReturnService = new PayloadMethodReturnService(payloadService);

private PayloadService payloadService;
private PayloadMethodReturnService payloadMethodReturnService;

@BeforeEach
void setUp() {
payloadService = new PayloadService(componentsService, properties);
payloadMethodReturnService = new PayloadMethodReturnService(payloadService);
}

@Test
public void shouldExtractPayloadFromMethod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

class SpringAnnotationClassLevelOperationsScannerTest {

private final PayloadMethodService payloadService = mock();
private final PayloadMethodService payloadMethodService = mock();
private final HeaderClassExtractor headerClassExtractor = mock(HeaderClassExtractor.class);
private final BindingFactory<TestClassListener> bindingFactory = mock(BindingFactory.class);
private final ComponentsService componentsService = mock(ComponentsService.class);
Expand All @@ -52,7 +52,7 @@ class SpringAnnotationClassLevelOperationsScannerTest {
TestMethodListener.class,
bindingFactory,
new AsyncHeadersNotDocumented(),
payloadService,
payloadMethodService,
headerClassExtractor,
componentsService);

Expand All @@ -73,7 +73,7 @@ void setUp() {
doReturn(defaultChannelBinding).when(bindingFactory).buildChannelBinding(any());
doReturn(defaultMessageBinding).when(bindingFactory).buildMessageBinding(any(), any());

when(payloadService.extractSchema(any()))
when(payloadMethodService.extractSchema(any()))
.thenReturn(new NamedSchemaObject(String.class.getName(), new SchemaObject()));
doAnswer(invocation -> AsyncHeadersNotDocumented.NOT_DOCUMENTED.getTitle())
.when(componentsService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"components": {
"schemas": {
"AnotherPayloadDto": {
"title": "AnotherPayloadDto",
"type": "object",
"properties": {
"example": {
Expand Down Expand Up @@ -102,6 +103,7 @@
]
},
"ExamplePayloadDto": {
"title": "ExamplePayloadDto",
"type": "object",
"properties": {
"someEnum": {
Expand Down Expand Up @@ -146,6 +148,7 @@
]
},
"GooglePubSubPayloadDto": {
"title": "GooglePubSubPayloadDto",
"type": "object",
"properties": {
"someLong": {
Expand Down
Loading

0 comments on commit 2131798

Please sign in to comment.