From 399e2e15fcc76c0a0c7fa692df204283568da05a Mon Sep 17 00:00:00 2001 From: Timon Back Date: Fri, 13 Dec 2024 14:25:31 +0100 Subject: [PATCH] refactor(core): simplify OperationsInClassScanner interface (#1120) Possible because Operation@operationId added. Continuation of 0eaa374f0a9e5cd9f33daeaec7a52bb4150a6a4e --- .../operations/DefaultOperationsService.java | 4 +-- .../scanners/operations/OperationMerger.java | 14 ++++---- .../operations/OperationsInClassScanner.java | 3 +- .../OperationsInClassScannerAdapter.java | 4 +-- ...AnnotationClassLevelOperationsScanner.java | 7 ++-- ...nnotationMethodLevelOperationsScanner.java | 8 ++--- ...AnnotationClassLevelOperationsScanner.java | 7 ++-- ...nnotationMethodLevelOperationsScanner.java | 7 ++-- ...faultOperationsServiceIntegrationTest.java | 19 +++++----- .../operations/OperationMergerTest.java | 36 +++++++++---------- .../OperationsInClassScannerAdapterTest.java | 19 +++++----- ...tationClassLevelOperationsScannerTest.java | 3 +- ...ationMethodLevelOperationsScannerTest.java | 3 +- ...tationClassLevelOperationsScannerTest.java | 5 ++- ...ationMethodLevelOperationsScannerTest.java | 5 ++- .../CloudStreamFunctionOperationsScanner.java | 10 ++---- 16 files changed, 69 insertions(+), 85 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java index 35c36000b..0dca9d503 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsService.java @@ -27,12 +27,12 @@ public class DefaultOperationsService implements OperationsService { */ @Override public Map findOperations() { - List> foundOperations = new ArrayList<>(); + List foundOperations = new ArrayList<>(); for (OperationsScanner scanner : operationScanners) { try { Map channels = scanner.scan(); - foundOperations.addAll(channels.entrySet()); + foundOperations.addAll(channels.values()); } catch (Exception e) { log.error("An error was encountered during operation scanning with {}: {}", scanner, e.getMessage(), e); } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMerger.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMerger.java index b0d33b779..e0237b26e 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMerger.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMerger.java @@ -25,18 +25,18 @@ private OperationMerger() {} * If an operation is null, the next non-null operation is used * Messages within operations are merged * - * @param operationEntries Ordered pairs of operation name to Operation + * @param operations Ordered pairs of operation name to Operation * @return A map of operationId to a single Operation */ - public static Map mergeOperations(List> operationEntries) { + public static Map mergeOperations(List operations) { Map mergedOperations = new HashMap<>(); - for (Map.Entry entry : operationEntries) { - if (!mergedOperations.containsKey(entry.getKey())) { - mergedOperations.put(entry.getKey(), entry.getValue()); + for (Operation operation : operations) { + if (!mergedOperations.containsKey(operation.getOperationId())) { + mergedOperations.put(operation.getOperationId(), operation); } else { - Operation operation = mergeOperation(mergedOperations.get(entry.getKey()), entry.getValue()); - mergedOperations.put(entry.getKey(), operation); + Operation mergedOperation = mergeOperation(mergedOperations.get(operation.getOperationId()), operation); + mergedOperations.put(operation.getOperationId(), mergedOperation); } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScanner.java index fd1de7856..200299d93 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScanner.java @@ -3,9 +3,8 @@ import io.github.springwolf.asyncapi.v3.model.operation.Operation; -import java.util.Map; import java.util.stream.Stream; public interface OperationsInClassScanner { - Stream> scan(Class clazz); + Stream scan(Class clazz); } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapter.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapter.java index ee36102ab..26cad6e95 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapter.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapter.java @@ -21,12 +21,12 @@ public class OperationsInClassScannerAdapter implements OperationsScanner { public Map scan() { Set> components = classScanner.scan(); - List> operations = mapToOperations(components); + List operations = mapToOperations(components); return OperationMerger.mergeOperations(operations); } - private List> mapToOperations(Set> components) { + private List mapToOperations(Set> components) { return components.stream().flatMap(classProcessor::scan).toList(); } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScanner.java index e971fa8b6..0deb535f0 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScanner.java @@ -16,7 +16,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -32,7 +31,7 @@ public class AsyncAnnotationClassLevelOperationsScanner customizers; @Override - public Stream> scan(Class clazz) { + public Stream scan(Class clazz) { Set> methodAndAnnotation = AnnotationScannerUtil.findAnnotatedMethods( clazz, classAnnotationClass, AllMethods.class, (cl, m) -> { ClassAnnotation classAnnotation = @@ -48,7 +47,7 @@ public Stream> scan(Class clazz) { return mapClassToOperation(clazz, methodAndAnnotation); } - private Stream> mapClassToOperation( + private Stream mapClassToOperation( Class component, Set> annotatedMethods) { ClassAnnotation classAnnotation = AnnotationUtil.findFirstAnnotationOrThrow(classAnnotationClass, component); AsyncOperation asyncOperation = asyncAnnotationProvider.getAsyncOperation(classAnnotation); @@ -58,6 +57,6 @@ private Stream> mapClassToOperation( Operation operation = asyncAnnotationOperationsService.buildOperation(asyncOperation, methods); annotatedMethods.forEach( method -> customizers.forEach(customizer -> customizer.customize(operation, method.method()))); - return Stream.of(Map.entry(operation.getOperationId(), operation)); + return Stream.of(operation); } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScanner.java index 86a520b13..7fcec7dd9 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScanner.java @@ -13,7 +13,6 @@ import java.lang.annotation.Annotation; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Stream; @@ -27,19 +26,18 @@ public class AsyncAnnotationMethodLevelOperationsScanner customizers; @Override - public Stream> scan(Class clazz) { + public Stream scan(Class clazz) { return AnnotationScannerUtil.findAnnotatedMethods(clazz, this.asyncAnnotationProvider.getAnnotation()) .map(this::mapMethodToOperation); } - private Map.Entry mapMethodToOperation( - MethodAndAnnotation methodAndAnnotation) { + private Operation mapMethodToOperation(MethodAndAnnotation methodAndAnnotation) { AsyncOperation operationAnnotation = this.asyncAnnotationProvider.getAsyncOperation(methodAndAnnotation.annotation()); Operation operation = asyncAnnotationOperationService.buildOperation( operationAnnotation, Set.of(methodAndAnnotation.method())); customizers.forEach(customizer -> customizer.customize(operation, methodAndAnnotation.method())); - return Map.entry(operation.getOperationId(), operation); + return operation; } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScanner.java index 805d5e016..bf44efdd5 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScanner.java @@ -13,7 +13,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -30,12 +29,12 @@ public class SpringAnnotationClassLevelOperationsScanner< private final List customizers; @Override - public Stream> scan(Class clazz) { + public Stream scan(Class clazz) { return AnnotationScannerUtil.findAnnotatedMethods( clazz, classAnnotationClass, methodAnnotationClass, this::mapClassToOperation); } - private Stream> mapClassToOperation( + private Stream mapClassToOperation( Class component, Set> annotatedMethods) { ClassAnnotation classAnnotation = AnnotationUtil.findFirstAnnotationOrThrow(classAnnotationClass, component); @@ -44,6 +43,6 @@ private Stream> mapClassToOperation( Operation operation = springAnnotationOperationsService.buildOperation(classAnnotation, component, methods); annotatedMethods.forEach( method -> customizers.forEach(customizer -> customizer.customize(operation, method.method()))); - return Stream.of(Map.entry(operation.getOperationId(), operation)); + return Stream.of(operation); } } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScanner.java index 560324173..7ce1dfb3a 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScanner.java @@ -15,7 +15,6 @@ import java.lang.annotation.Annotation; import java.util.List; -import java.util.Map; import java.util.stream.Stream; @Slf4j @@ -30,17 +29,17 @@ public class SpringAnnotationMethodLevelOperationsScanner customizers; @Override - public Stream> scan(Class clazz) { + public Stream scan(Class clazz) { return AnnotationScannerUtil.findAnnotatedMethods(clazz, methodAnnotationClass) .map(this::mapMethodToOperation); } - private Map.Entry mapMethodToOperation(MethodAndAnnotation method) { + private Operation mapMethodToOperation(MethodAndAnnotation method) { PayloadSchemaObject payloadSchema = payloadMethodParameterService.extractSchema(method.method()); SchemaObject headerSchema = headerClassExtractor.extractHeader(method.method(), payloadSchema); Operation operation = springAnnotationOperationService.buildOperation(method, payloadSchema, headerSchema); customizers.forEach(customizer -> customizer.customize(operation, method.method())); - return Map.entry(operation.getOperationId(), operation); + return operation; } } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsServiceIntegrationTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsServiceIntegrationTest.java index 3ee428455..2d0f3769e 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsServiceIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/operations/DefaultOperationsServiceIntegrationTest.java @@ -46,12 +46,13 @@ void getOperations() { static class SimpleOperationScanner implements OperationsScanner { @Override public Map scan() { - return Map.of( - "foo", - Operation.builder() - .channel(ChannelReference.fromChannel("foo")) - .action(OperationAction.RECEIVE) - .build()); + Operation operation = Operation.builder() + .operationId("foo") + .channel(ChannelReference.fromChannel("foo")) + .action(OperationAction.RECEIVE) + .build(); + + return Map.of(operation.getOperationId(), operation); } } @@ -61,26 +62,28 @@ static class SameTopic { @Component static class SendOperationScanner implements OperationsScanner { static final Operation sentOperation = Operation.builder() + .operationId("send") .channel(ChannelReference.fromChannel(topicName)) .action(OperationAction.SEND) .build(); @Override public Map scan() { - return Map.of("send", sentOperation); + return Map.of(sentOperation.getOperationId(), sentOperation); } } @Component static class ReceiveOperationScanner implements OperationsScanner { static final Operation receiveOperation = Operation.builder() + .operationId("receive") .channel(ChannelReference.fromChannel(topicName)) .action(OperationAction.RECEIVE) .build(); @Override public Map scan() { - return Map.of("receive", receiveOperation); + return Map.of(receiveOperation.getOperationId(), receiveOperation); } } } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java index 5330da4dd..8edd993bf 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java @@ -20,14 +20,14 @@ class OperationMergerTest { @Test void shouldNotMergeDifferentoperationIds() { // given - String operationId1 = "operation1"; - String operationId2 = "operation2"; - Operation publisherOperation = Operation.builder().build(); - Operation subscriberOperation = Operation.builder().build(); + Operation publisherOperation = + Operation.builder().operationId("operation1").build(); + Operation subscriberOperation = + Operation.builder().operationId("operation2").build(); // when - Map mergedOperations = OperationMerger.mergeOperations(Arrays.asList( - Map.entry(operationId1, publisherOperation), Map.entry(operationId2, subscriberOperation))); + Map mergedOperations = + OperationMerger.mergeOperations(Arrays.asList(publisherOperation, subscriberOperation)); // then assertThat(mergedOperations).hasSize(2); @@ -49,9 +49,8 @@ void shouldMergeEqualOperationIdsIntoOneOperation() { .build(); // when - Map mergedOperations = OperationMerger.mergeOperations(Arrays.asList( - Map.entry(publishOperation.getOperationId(), publishOperation), - Map.entry(subscribeOperation.getOperationId(), subscribeOperation))); + Map mergedOperations = + OperationMerger.mergeOperations(Arrays.asList(publishOperation, subscribeOperation)); // then assertThat(mergedOperations).hasSize(1); @@ -71,9 +70,8 @@ void shouldUseFirstOperationFound() { .build(); // when - Map mergedOperations = OperationMerger.mergeOperations(Arrays.asList( - Map.entry(senderOperation.getOperationId(), senderOperation), - Map.entry(receiverOperation.getOperationId(), receiverOperation))); + Map mergedOperations = + OperationMerger.mergeOperations(Arrays.asList(senderOperation, receiverOperation)); // then assertThat(mergedOperations).hasSize(1).hasEntrySatisfying(operationId, it -> { @@ -122,10 +120,8 @@ void shouldMergeDifferentMessageForSameOperation() { .build(); // when - Map mergedOperations = OperationMerger.mergeOperations(List.of( - Map.entry(senderOperation1.getOperationId(), senderOperation1), - Map.entry(senderOperation2.getOperationId(), senderOperation2), - Map.entry(senderOperation3.getOperationId(), senderOperation3))); + Map mergedOperations = + OperationMerger.mergeOperations(List.of(senderOperation1, senderOperation2, senderOperation3)); // then expectedMessage only includes message1 and message2. // Message3 is not included as it is identical in terms of payload type (Message#name) to message 2 @@ -174,17 +170,17 @@ void shouldUseOtherMessageIfFirstMessageIsMissingForOperations() { .build(); Operation publishOperation1 = Operation.builder() .action(OperationAction.SEND) - .title("publisher1") + .operationId("publisher1") .build(); Operation publishOperation2 = Operation.builder() .action(OperationAction.SEND) - .title("publisher2") + .operationId("publisher1") .messages(List.of(MessageReference.toChannelMessage(channelId, message2))) .build(); // when - Map mergedOperations = OperationMerger.mergeOperations( - Arrays.asList(Map.entry("publisher1", publishOperation1), Map.entry("publisher1", publishOperation2))); + Map mergedOperations = + OperationMerger.mergeOperations(Arrays.asList(publishOperation1, publishOperation2)); // then expectedMessage message2 var expectedMessage = MessageReference.toChannelMessage(channelId, message2); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapterTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapterTest.java index 7ffbdf4b6..87bc0b0e7 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapterTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapterTest.java @@ -35,35 +35,32 @@ void noClassFoundTest() { void processClassTest() { // given when(classScanner.scan()).thenReturn(Set.of(String.class)); - Map.Entry operation1 = - Map.entry("operation1", Operation.builder().build()); - Map.Entry operation2 = - Map.entry("operation2", Operation.builder().build()); + Operation operation1 = Operation.builder().operationId("operation1").build(); + Operation operation2 = Operation.builder().operationId("operation2").build(); when(classProcessor.scan(any())).thenReturn(Stream.of(operation1, operation2)); // when Map operations = operationsInClassScannerAdapter.scan(); // then - assertThat(operations).containsExactly(operation2, operation1); + assertThat(operations).containsExactlyEntriesOf(Map.of("operation1", operation1, "operation2", operation2)); } @Test void sameOperationsAreMergedTest() { // given when(classScanner.scan()).thenReturn(Set.of(String.class)); - Map.Entry operation1 = - Map.entry("operation1", Operation.builder().build()); - Map.Entry operation2 = - Map.entry("operation1", Operation.builder().build()); + Operation operation1 = + Operation.builder().operationId("operation1").description("op1").build(); + Operation operation2 = + Operation.builder().operationId("operation1").description("op2").build(); when(classProcessor.scan(any())).thenReturn(Stream.of(operation1, operation2)); // when Map operations = operationsInClassScannerAdapter.scan(); // then - assertThat(operations) - .containsExactly(Map.entry("operation1", Operation.builder().build())); + assertThat(operations).hasSize(1); } @Test diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScannerTest.java index bd76110fd..4d874a406 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationClassLevelOperationsScannerTest.java @@ -12,6 +12,7 @@ import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -59,7 +60,7 @@ void scan() { // when Map actualOperations = operationsScanner .scan(ClassWithListenerAnnotation.class) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .collect(Collectors.toMap(Operation::getOperationId, Function.identity())); // then assertThat(actualOperations).hasSize(1); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScannerTest.java index 1b5194d54..3c9f2d6bd 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationMethodLevelOperationsScannerTest.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -58,7 +59,7 @@ void scan_componentOperationHasListenerMethod() { // when Map actualOperations = operationsScanner .scan(ClassWithListenerAnnotation.class) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + .collect(Collectors.toMap(Operation::getOperationId, Function.identity())); // then assertThat(actualOperations).containsExactly(Map.entry("operationId", operation)); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScannerTest.java index b9783d405..cbe84e244 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationClassLevelOperationsScannerTest.java @@ -8,7 +8,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -37,11 +36,11 @@ void scan() { .thenReturn(operation); // when - List> operations = + List operations = scanner.scan(ClassWithTestListenerAnnotation.class).toList(); // then - assertThat(operations).containsExactly(Map.entry("operationId", operation)); + assertThat(operations).containsExactly(operation); } @Test diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScannerTest.java index 7fe423fa3..d663dbff1 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/SpringAnnotationMethodLevelOperationsScannerTest.java @@ -10,7 +10,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.List; -import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -41,11 +40,11 @@ void scan_componentHasTestListenerMethods() { .thenReturn(operation); // when - List> operations = + List operations = scanner.scan(ClassWithTestListenerAnnotation.class).toList(); // then - assertThat(operations).containsExactly(Map.entry("operationId", operation)); + assertThat(operations).containsExactly(operation); } @Test diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/operations/CloudStreamFunctionOperationsScanner.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/operations/CloudStreamFunctionOperationsScanner.java index 9e6279fde..9a6b5e0b2 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/operations/CloudStreamFunctionOperationsScanner.java +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/operations/CloudStreamFunctionOperationsScanner.java @@ -56,11 +56,11 @@ public Map scan() { elements.addAll(componentClassScanner.scan()); elements.addAll(beanMethodsScanner.getBeanMethods()); - List> operations = elements.stream() + List operations = elements.stream() .map(functionalChannelBeanBuilder::build) .flatMap(Set::stream) .filter(this::isChannelBean) - .map(this::toOperationEntry) + .map(this::buildOperation) .toList(); return OperationMerger.mergeOperations(operations); @@ -70,12 +70,6 @@ private boolean isChannelBean(FunctionalChannelBeanData beanData) { return cloudStreamBindingsProperties.getBindings().containsKey(beanData.cloudStreamBinding()); } - private Map.Entry toOperationEntry(FunctionalChannelBeanData beanData) { - Operation operation = buildOperation(beanData); - - return Map.entry(operation.getOperationId(), operation); - } - private Operation buildOperation(FunctionalChannelBeanData beanData) { String channelName = cloudStreamBindingsProperties .getBindings()