From 264b98c818af148f9b1b0575574baabc615bbade Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sun, 25 Jul 2021 15:59:38 +0200 Subject: [PATCH 1/8] Remove duplicate dependency --- sdk-springboot/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sdk-springboot/pom.xml b/sdk-springboot/pom.xml index a5ce8c158f..a27e8b9b67 100644 --- a/sdk-springboot/pom.xml +++ b/sdk-springboot/pom.xml @@ -89,12 +89,6 @@ 5.2.10.RELEASE compile - - org.springframework - spring-web - 5.2.10.RELEASE - compile - org.springframework spring-context From b88683a0b44f0d1d4bee7f919d278d676ccbddd6 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sun, 25 Jul 2021 16:00:23 +0200 Subject: [PATCH 2/8] Transform into managed dependencies --- sdk-springboot/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdk-springboot/pom.xml b/sdk-springboot/pom.xml index a27e8b9b67..ed134a49b6 100644 --- a/sdk-springboot/pom.xml +++ b/sdk-springboot/pom.xml @@ -74,25 +74,21 @@ org.junit.jupiter junit-jupiter-api - 5.5.2 test org.springframework spring-beans - 5.2.10.RELEASE compile org.springframework spring-web - 5.2.10.RELEASE compile org.springframework spring-context - 5.2.10.RELEASE compile From d7393edc59aab72480a2a2af928043c3673a7c83 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sun, 25 Jul 2021 20:14:16 +0200 Subject: [PATCH 3/8] Remove old JUnit version from dependencies --- sdk-springboot/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdk-springboot/pom.xml b/sdk-springboot/pom.xml index ed134a49b6..12189b0f09 100644 --- a/sdk-springboot/pom.xml +++ b/sdk-springboot/pom.xml @@ -55,11 +55,6 @@ dapr-sdk-actors ${project.version} - - junit - junit - test - org.mockito mockito-core From b45e125ca900dc81adbd60af20af202e47c92901 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sun, 25 Jul 2021 20:38:40 +0200 Subject: [PATCH 4/8] Add tests for DaprBeanPostProcessor --- sdk-springboot/pom.xml | 15 +++++ .../springboot/DaprBeanPostProcessorIT.java | 66 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java diff --git a/sdk-springboot/pom.xml b/sdk-springboot/pom.xml index 12189b0f09..490c9f7180 100644 --- a/sdk-springboot/pom.xml +++ b/sdk-springboot/pom.xml @@ -71,6 +71,11 @@ junit-jupiter-api test + + org.assertj + assertj-core + test + org.springframework spring-beans @@ -91,6 +96,16 @@ spring-boot-autoconfigure compile + + org.springframework + spring-test + test + + + javax.servlet + javax.servlet-api + test + org.springframework.boot spring-boot-configuration-processor diff --git a/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java b/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java new file mode 100644 index 0000000000..79a1144965 --- /dev/null +++ b/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java @@ -0,0 +1,66 @@ +package io.dapr.springboot; + +import io.dapr.Topic; +import org.assertj.core.api.WithAssertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@ContextConfiguration( + classes = { DaprAutoConfiguration.class } +) +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +public class DaprBeanPostProcessorIT implements WithAssertions { + private final DaprRuntime daprRuntime = DaprRuntime.getInstance(); + + @Test + void shouldBindTopicWithPostMappingByPath() { + // Arrange + + // Act + DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); + + // Assert + assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { + assertThat(subscribedTopic.getRoute()).isEqualTo("/path-1"); + assertThat(subscribedTopic.getPubsubName()).isEqualTo("pubsubName"); + assertThat(subscribedTopic.getTopic()).isEqualTo("topic-1"); + assertThat(subscribedTopic.getMetadata()).isEmpty(); + }); + } + + @Test + void shouldBindTopicWithMetadata() { + // Arrange + + // Act + DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); + + // Assert + assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { + assertThat(subscribedTopic.getRoute()).isEqualTo("/path-2"); + assertThat(subscribedTopic.getMetadata()).containsEntry("priority", "high"); + }); + } +} + +@RestController +class PubsubController { + @PostMapping(path = "/path-1") + @Topic(pubsubName = "pubsubName", name = "topic-1") + public ResponseEntity method1() { + return ResponseEntity.ok().build(); + } + + @PostMapping(path = "/path-2") + @Topic(pubsubName = "pubsubName", name = "topic-2", metadata = "{ \"priority\": \"high\" }") + public ResponseEntity method2() { + return ResponseEntity.ok().build(); + } +} From 683394e82ac49628e82163b4217007d86c138b49 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Sun, 25 Jul 2021 20:47:45 +0200 Subject: [PATCH 5/8] Also register PostMappings that use value --- .../springboot/DaprBeanPostProcessor.java | 4 +++- .../springboot/DaprBeanPostProcessorIT.java | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java b/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java index 9cb0c56c02..53040b050f 100644 --- a/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java +++ b/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java @@ -21,7 +21,7 @@ import java.util.Map; /** - * Handles Dapr annotations in Springboot Controllers. + * Handles Dapr annotations in Spring Controllers. */ @Component public class DaprBeanPostProcessor implements BeanPostProcessor { @@ -77,6 +77,8 @@ private static void subscribeToTopics(Class clazz, EmbeddedValueResolver embedde if (mapping != null && mapping.path() != null && mapping.path().length >= 1) { route = mapping.path()[0]; + } else if (mapping != null && mapping.value() != null && mapping.value().length >= 1) { + route = mapping.value()[0]; } String topicName = embeddedValueResolver.resolveStringValue(topic.name()); diff --git a/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java b/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java index 79a1144965..896e938473 100644 --- a/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java +++ b/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java @@ -34,6 +34,21 @@ void shouldBindTopicWithPostMappingByPath() { assertThat(subscribedTopic.getMetadata()).isEmpty(); }); } + @Test + void shouldBindTopicWithPostMappingByValue() { + // Arrange + + // Act + DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); + + // Assert + assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { + assertThat(subscribedTopic.getRoute()).isEqualTo("/path-3"); + assertThat(subscribedTopic.getPubsubName()).isEqualTo("pubsubName"); + assertThat(subscribedTopic.getTopic()).isEqualTo("topic-3"); + assertThat(subscribedTopic.getMetadata()).isEmpty(); + }); + } @Test void shouldBindTopicWithMetadata() { @@ -63,4 +78,10 @@ public ResponseEntity method1() { public ResponseEntity method2() { return ResponseEntity.ok().build(); } + + @PostMapping("/path-3") + @Topic(pubsubName = "pubsubName", name = "topic-3") + public ResponseEntity method3() { + return ResponseEntity.ok().build(); + } } From 90e213f06ec84bff72c0e4e0389efd9104408ab6 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 28 Jul 2021 21:15:11 +0200 Subject: [PATCH 6/8] Modify existing pub/sub test to no use @PostMapping(path="...") --- .../test/java/io/dapr/it/pubsub/http/SubscriberController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-tests/src/test/java/io/dapr/it/pubsub/http/SubscriberController.java b/sdk-tests/src/test/java/io/dapr/it/pubsub/http/SubscriberController.java index eb387a8bf7..1a9df3451e 100644 --- a/sdk-tests/src/test/java/io/dapr/it/pubsub/http/SubscriberController.java +++ b/sdk-tests/src/test/java/io/dapr/it/pubsub/http/SubscriberController.java @@ -48,7 +48,7 @@ public List getMessagesReceivedTTLTopic() { } @Topic(name = "testingtopic", pubsubName = "messagebus") - @PostMapping(path = "/route1") + @PostMapping("/route1") public Mono handleMessage(@RequestBody(required = false) CloudEvent envelope) { return Mono.fromRunnable(() -> { try { From 75ca4ee3d628c61160dab08ba0c3dd7452661dd7 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 28 Jul 2021 21:19:24 +0200 Subject: [PATCH 7/8] Remove added dependencies on AssertJ, Spring Test and Servlet API --- sdk-springboot/pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sdk-springboot/pom.xml b/sdk-springboot/pom.xml index 490c9f7180..12189b0f09 100644 --- a/sdk-springboot/pom.xml +++ b/sdk-springboot/pom.xml @@ -71,11 +71,6 @@ junit-jupiter-api test - - org.assertj - assertj-core - test - org.springframework spring-beans @@ -96,16 +91,6 @@ spring-boot-autoconfigure compile - - org.springframework - spring-test - test - - - javax.servlet - javax.servlet-api - test - org.springframework.boot spring-boot-configuration-processor From 16282572ead43c4156e869310d4a7c5f691402d4 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Wed, 28 Jul 2021 21:19:59 +0200 Subject: [PATCH 8/8] Remove test in favour of the sdk-tests one --- .../springboot/DaprBeanPostProcessorIT.java | 87 ------------------- 1 file changed, 87 deletions(-) delete mode 100644 sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java diff --git a/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java b/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java deleted file mode 100644 index 896e938473..0000000000 --- a/sdk-springboot/src/test/java/io/dapr/springboot/DaprBeanPostProcessorIT.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.dapr.springboot; - -import io.dapr.Topic; -import org.assertj.core.api.WithAssertions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@ContextConfiguration( - classes = { DaprAutoConfiguration.class } -) -@ExtendWith(SpringExtension.class) -@WebAppConfiguration -public class DaprBeanPostProcessorIT implements WithAssertions { - private final DaprRuntime daprRuntime = DaprRuntime.getInstance(); - - @Test - void shouldBindTopicWithPostMappingByPath() { - // Arrange - - // Act - DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); - - // Assert - assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { - assertThat(subscribedTopic.getRoute()).isEqualTo("/path-1"); - assertThat(subscribedTopic.getPubsubName()).isEqualTo("pubsubName"); - assertThat(subscribedTopic.getTopic()).isEqualTo("topic-1"); - assertThat(subscribedTopic.getMetadata()).isEmpty(); - }); - } - @Test - void shouldBindTopicWithPostMappingByValue() { - // Arrange - - // Act - DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); - - // Assert - assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { - assertThat(subscribedTopic.getRoute()).isEqualTo("/path-3"); - assertThat(subscribedTopic.getPubsubName()).isEqualTo("pubsubName"); - assertThat(subscribedTopic.getTopic()).isEqualTo("topic-3"); - assertThat(subscribedTopic.getMetadata()).isEmpty(); - }); - } - - @Test - void shouldBindTopicWithMetadata() { - // Arrange - - // Act - DaprTopicSubscription[] subscribedTopics = daprRuntime.listSubscribedTopics(); - - // Assert - assertThat(subscribedTopics).anySatisfy(subscribedTopic -> { - assertThat(subscribedTopic.getRoute()).isEqualTo("/path-2"); - assertThat(subscribedTopic.getMetadata()).containsEntry("priority", "high"); - }); - } -} - -@RestController -class PubsubController { - @PostMapping(path = "/path-1") - @Topic(pubsubName = "pubsubName", name = "topic-1") - public ResponseEntity method1() { - return ResponseEntity.ok().build(); - } - - @PostMapping(path = "/path-2") - @Topic(pubsubName = "pubsubName", name = "topic-2", metadata = "{ \"priority\": \"high\" }") - public ResponseEntity method2() { - return ResponseEntity.ok().build(); - } - - @PostMapping("/path-3") - @Topic(pubsubName = "pubsubName", name = "topic-3") - public ResponseEntity method3() { - return ResponseEntity.ok().build(); - } -}