From 3bdcd51fe0a4d367bd95c927a03a8396ccf52f01 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Fri, 12 Jan 2024 14:35:37 +0100 Subject: [PATCH] feat(core): add Optional to extractable classes (#525) --- .../properties/SpringwolfConfigProperties.java | 2 ++ .../channels/payload/PayloadClassExtractorTest.java | 12 ++++++------ .../SpringwolfConfigPropertiesIntegrationTest.java | 8 +++++--- 3 files changed, 13 insertions(+), 9 deletions(-) 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 f34073c01..74f8c8a51 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 @@ -223,6 +223,8 @@ public static class Payload { "org.apache.kafka.streams.kstream.KStream", 1, "java.util.List", + 0, + "java.util.Optional", 0); public void setExtractableClasses(Map extractableClasses) { diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/payload/PayloadClassExtractorTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/payload/PayloadClassExtractorTest.java index c00579c0b..6b41e953f 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/payload/PayloadClassExtractorTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/asyncapi/scanners/channels/payload/PayloadClassExtractorTest.java @@ -8,8 +8,8 @@ import org.springframework.messaging.support.GenericMessage; import java.lang.reflect.Method; +import java.util.Collection; import java.util.List; -import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -62,16 +62,16 @@ void getPayloadTypeWithMessageOfInterfaces() throws NoSuchMethodException { Class result = extractor.extractFrom(m); - assertEquals(Optional.class, result); + assertEquals(Collection.class, result); } @Test void getPayloadTypeWithInterface() throws NoSuchMethodException { - Method m = TestClass.class.getDeclaredMethod("consumeWithGenericClass", Optional.class); + Method m = TestClass.class.getDeclaredMethod("consumeWithGenericClass", Collection.class); Class result = extractor.extractFrom(m); - assertEquals(Optional.class, result); + assertEquals(Collection.class, result); } @Test @@ -118,9 +118,9 @@ public void consumeWithoutPayloadAnnotation(String value, Integer value2) {} public void consumeWithString(String value) {} - public void consumeWithGenericClass(Optional value) {} + public void consumeWithGenericClass(Collection value) {} - public void consumeWithMessageOfGenericClasses(Message> value) {} + public void consumeWithMessageOfGenericClasses(Message> value) {} public void consumeWithMessageOfStringExtends(Message value) {} diff --git a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfConfigPropertiesIntegrationTest.java b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfConfigPropertiesIntegrationTest.java index 3a67ca99a..f32cbb6cc 100644 --- a/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfConfigPropertiesIntegrationTest.java +++ b/springwolf-core/src/test/java/io/github/stavshamir/springwolf/configuration/SpringwolfConfigPropertiesIntegrationTest.java @@ -89,7 +89,7 @@ void payloadTest() { Map actual = properties.getPayload().getExtractableClasses(); // default values - assertThat(actual).hasSize(5); + assertThat(actual).hasSize(6); assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1); assertThat(actual).containsEntry("org.springframework.messaging.Message", 0); assertThat(actual).containsEntry("java.util.function.Consumer", 0); @@ -122,7 +122,7 @@ void payloadCustomizedTest() { Map actual = properties.getPayload().getExtractableClasses(); // default values - assertThat(actual).hasSize(6); + assertThat(actual).hasSize(7); assertThat(actual).containsEntry("my.custom.class", 1); // default values assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1); @@ -130,6 +130,7 @@ void payloadCustomizedTest() { assertThat(actual).containsEntry("java.util.function.Consumer", 0); assertThat(actual).containsEntry("java.util.function.Supplier", 0); assertThat(actual).containsEntry("java.util.List", 0); + assertThat(actual).containsEntry("java.util.Optional", 0); } } @@ -156,12 +157,13 @@ static class PayloadDisabledIntegrationTest { void payloadDisabledTest() { Map actual = properties.getPayload().getExtractableClasses(); - assertThat(actual).hasSize(4); + assertThat(actual).hasSize(5); // default values assertThat(actual).containsEntry("org.apache.kafka.streams.kstream.KStream", 1); assertThat(actual).containsEntry("org.springframework.messaging.Message", 0); assertThat(actual).containsEntry("java.util.function.Consumer", 0); assertThat(actual).containsEntry("java.util.function.Supplier", 0); + assertThat(actual).containsEntry("java.util.Optional", 0); } } }