diff --git a/sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java b/sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java index f6150809d..99a018bf9 100644 --- a/sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java @@ -62,9 +62,10 @@ public class DaprContainerIT { @Container private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd") - .withAppName("dapr-app") - .withAppPort(8081) - .withAppChannelAddress("host.testcontainers.internal"); + .withAppName("dapr-app") + .withAppPort(8081) + .withAppHealthCheckPath("/actuator/health") + .withAppChannelAddress("host.testcontainers.internal"); /** * Sets the Dapr properties for the test. @@ -80,17 +81,17 @@ private void configStub() { .willReturn(aResponse().withBody("[]").withStatus(200))); stubFor(any(urlMatching("/dapr/subscribe")) - .willReturn(aResponse().withBody("[]").withStatus(200))); + .willReturn(aResponse().withBody("[]").withStatus(200))); stubFor(get(urlMatching("/dapr/config")) - .willReturn(aResponse().withBody("[]").withStatus(200))); + .willReturn(aResponse().withBody("[]").withStatus(200))); stubFor(any(urlMatching("/([a-z1-9]*)")) - .willReturn(aResponse().withBody("[]").withStatus(200))); + .willReturn(aResponse().withBody("[]").withStatus(200))); // create a stub stubFor(post(urlEqualTo("/events")) - .willReturn(aResponse().withBody("event received!").withStatus(200))); + .willReturn(aResponse().withBody("event received!").withStatus(200))); configureFor("localhost", 8081); } @@ -98,13 +99,13 @@ private void configStub() { @Test public void testDaprContainerDefaults() { assertEquals(2, - DAPR_CONTAINER.getComponents().size(), - "The pubsub and kvstore component should be configured by default" + DAPR_CONTAINER.getComponents().size(), + "The pubsub and kvstore component should be configured by default" ); assertEquals( - 1, - DAPR_CONTAINER.getSubscriptions().size(), - "A subscription should be configured by default if none is provided" + 1, + DAPR_CONTAINER.getSubscriptions().size(), + "A subscription should be configured by default if none is provided" ); } @@ -131,10 +132,10 @@ public void testPlacement() throws Exception { Thread.sleep(1000); OkHttpClient okHttpClient = new OkHttpClient.Builder() - .build(); + .build(); Request request = new Request.Builder() - .url(DAPR_CONTAINER.getHttpEndpoint() + "/v1.0/metadata") - .build(); + .url(DAPR_CONTAINER.getHttpEndpoint() + "/v1.0/metadata") + .build(); try (Response response = okHttpClient.newCall(request).execute()) { if (response.isSuccessful() && response.body() != null) { @@ -160,7 +161,7 @@ public void testPubSub() throws Exception { private DaprClientBuilder createDaprClientBuilder() { return new DaprClientBuilder() - .withPropertyOverride(Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint()) - .withPropertyOverride(Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()); + .withPropertyOverride(Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint()) + .withPropertyOverride(Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()); } } diff --git a/spring-boot-examples/consumer-app/pom.xml b/spring-boot-examples/consumer-app/pom.xml index 63df3df40..9f2b44b62 100644 --- a/spring-boot-examples/consumer-app/pom.xml +++ b/spring-boot-examples/consumer-app/pom.xml @@ -1,99 +1,99 @@ - 4.0.0 - - io.dapr - spring-boot-examples - 0.14.0-SNAPSHOT - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + io.dapr + spring-boot-examples + 0.14.0-SNAPSHOT + - consumer-app - consumer-app - Spring Boot, Testcontainers and Dapr Integration Examples :: Consumer App + consumer-app + consumer-app + Spring Boot, Testcontainers and Dapr Integration Examples :: Consumer App - - 3.2.6 - + + 3.2.6 + - - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - + + + + org.springframework.boot + spring-boot-dependencies + ${springboot.version} + pom + import + + + - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-actuator - - - io.dapr.spring - dapr-spring-boot-starter - ${dapr-java-sdk.alpha-version} - + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + io.dapr.spring + dapr-spring-boot-starter + ${dapr-java-sdk.alpha-version} + - - io.dapr.spring - dapr-spring-boot-starter - ${dapr.sdk.alpha.version} - + + io.dapr.spring + dapr-spring-boot-starter + ${dapr.sdk.alpha.version} + - - io.dapr.spring - dapr-spring-boot-starter-test - ${dapr.sdk.alpha.version} - test - - - - org.testcontainers - junit-jupiter - test - - - org.testcontainers - postgresql - 1.20.0 - test - - - org.testcontainers - rabbitmq - 1.20.0 - test - - - org.testcontainers - kafka - 1.20.0 - test - + + io.dapr.spring + dapr-spring-boot-starter-test + ${dapr.sdk.alpha.version} + test + - - io.rest-assured - rest-assured - test - - + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + postgresql + 1.20.0 + test + + + org.testcontainers + rabbitmq + 1.20.0 + test + + + org.testcontainers + kafka + 1.20.0 + test + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + io.rest-assured + rest-assured + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/spring-boot-examples/consumer-app/src/main/resources/application.properties b/spring-boot-examples/consumer-app/src/main/resources/application.properties index fa29657d1..b01c2106d 100644 --- a/spring-boot-examples/consumer-app/src/main/resources/application.properties +++ b/spring-boot-examples/consumer-app/src/main/resources/application.properties @@ -1,2 +1,4 @@ +dapr.pubsub.name=pubsub spring.application.name=consumer-app server.port=8081 + diff --git a/spring-boot-examples/consumer-app/src/test/java/io/dapr/springboot/examples/consumer/TestConsumerApplication.java b/spring-boot-examples/consumer-app/src/test/java/io/dapr/springboot/examples/consumer/TestConsumerApplication.java index 741de61bf..d37150746 100644 --- a/spring-boot-examples/consumer-app/src/test/java/io/dapr/springboot/examples/consumer/TestConsumerApplication.java +++ b/spring-boot-examples/consumer-app/src/test/java/io/dapr/springboot/examples/consumer/TestConsumerApplication.java @@ -21,11 +21,10 @@ public class TestConsumerApplication { public static void main(String[] args) { - org.testcontainers.Testcontainers.exposeHostPorts(8081); - SpringApplication - .from(ConsumerApplication::main) + SpringApplication.from(ConsumerApplication::main) .with(DaprTestContainersConfig.class) .run(args); + org.testcontainers.Testcontainers.exposeHostPorts(8081); } diff --git a/spring-boot-examples/consumer-app/src/test/resources/application.properties b/spring-boot-examples/consumer-app/src/test/resources/application.properties index 212a88a83..d6cb8d293 100644 --- a/spring-boot-examples/consumer-app/src/test/resources/application.properties +++ b/spring-boot-examples/consumer-app/src/test/resources/application.properties @@ -1,2 +1,2 @@ dapr.pubsub.name=pubsub -server.port=8081 \ No newline at end of file +server.port=8081 diff --git a/spring-boot-examples/kubernetes/consumer-app.yaml b/spring-boot-examples/kubernetes/consumer-app.yaml index 9135ba971..ab9041783 100644 --- a/spring-boot-examples/kubernetes/consumer-app.yaml +++ b/spring-boot-examples/kubernetes/consumer-app.yaml @@ -42,4 +42,4 @@ spec: imagePullPolicy: Always ports: - containerPort: 8081 - name: consumer-app \ No newline at end of file + name: consumer-app diff --git a/spring-boot-examples/kubernetes/kvbinding.yaml b/spring-boot-examples/kubernetes/kvbinding.yaml index 8032aadae..de8784c33 100644 --- a/spring-boot-examples/kubernetes/kvbinding.yaml +++ b/spring-boot-examples/kubernetes/kvbinding.yaml @@ -10,4 +10,4 @@ spec: value: host=postgresql.default.svc.cluster.local user=postgres password=password port=5432 connect_timeout=10 database=dapr scopes: - - producer-app \ No newline at end of file + - producer-app diff --git a/spring-boot-examples/kubernetes/kvstore.yaml b/spring-boot-examples/kubernetes/kvstore.yaml index af9fc7a01..11083b326 100644 --- a/spring-boot-examples/kubernetes/kvstore.yaml +++ b/spring-boot-examples/kubernetes/kvstore.yaml @@ -14,4 +14,4 @@ spec: value: host=postgresql.default.svc.cluster.local user=postgres password=password port=5432 connect_timeout=10 database=dapr scopes: - - producer-app \ No newline at end of file + - producer-app diff --git a/spring-boot-examples/kubernetes/producer-app.yaml b/spring-boot-examples/kubernetes/producer-app.yaml index 87d9f376a..19b1f18ff 100644 --- a/spring-boot-examples/kubernetes/producer-app.yaml +++ b/spring-boot-examples/kubernetes/producer-app.yaml @@ -42,4 +42,4 @@ spec: imagePullPolicy: Always ports: - containerPort: 8080 - name: producer-app \ No newline at end of file + name: producer-app diff --git a/spring-boot-examples/kubernetes/pubsub.yaml b/spring-boot-examples/kubernetes/pubsub.yaml index d23fa1e06..577b61d6a 100644 --- a/spring-boot-examples/kubernetes/pubsub.yaml +++ b/spring-boot-examples/kubernetes/pubsub.yaml @@ -11,4 +11,4 @@ spec: - name: user value: guest - name: password - value: guest \ No newline at end of file + value: guest diff --git a/spring-boot-examples/producer-app/pom.xml b/spring-boot-examples/producer-app/pom.xml index fc4c1a28b..51614b9ce 100644 --- a/spring-boot-examples/producer-app/pom.xml +++ b/spring-boot-examples/producer-app/pom.xml @@ -1,86 +1,86 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - - io.dapr - spring-boot-examples - 0.14.0-SNAPSHOT - + + io.dapr + spring-boot-examples + 0.14.0-SNAPSHOT + - producer-app - producer-app - Spring Boot, Testcontainers and Dapr Integration Examples :: Producer App + producer-app + producer-app + Spring Boot, Testcontainers and Dapr Integration Examples :: Producer App - - 3.2.6 - + + 3.2.6 + - - - - org.springframework.boot - spring-boot-dependencies - ${springboot.version} - pom - import - - - + + + + org.springframework.boot + spring-boot-dependencies + ${springboot.version} + pom + import + + + - + - - org.springframework.boot - spring-boot-starter-actuator - + + org.springframework.boot + spring-boot-starter-actuator + - - org.springframework.boot - spring-boot-starter-web - - - io.dapr.spring - dapr-spring-boot-starter - ${dapr.sdk.alpha.version} - - - io.dapr.spring - dapr-spring-boot-starter-test - ${dapr.sdk.alpha.version} - test - - - org.testcontainers - junit-jupiter - test - - - org.testcontainers - postgresql - 1.20.0 - test - - - org.testcontainers - rabbitmq - 1.20.0 - test - - - io.rest-assured - rest-assured - test - - + + org.springframework.boot + spring-boot-starter-web + + + io.dapr.spring + dapr-spring-boot-starter + ${dapr.sdk.alpha.version} + + + io.dapr.spring + dapr-spring-boot-starter-test + ${dapr.sdk.alpha.version} + test + + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + postgresql + 1.20.0 + test + + + org.testcontainers + rabbitmq + 1.20.0 + test + + + io.rest-assured + rest-assured + test + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/spring-boot-examples/producer-app/src/test/java/io/dapr/springboot/examples/producer/ProducerAppTests.java b/spring-boot-examples/producer-app/src/test/java/io/dapr/springboot/examples/producer/ProducerAppTests.java index 619b234d7..dd2ac7b01 100644 --- a/spring-boot-examples/producer-app/src/test/java/io/dapr/springboot/examples/producer/ProducerAppTests.java +++ b/spring-boot-examples/producer-app/src/test/java/io/dapr/springboot/examples/producer/ProducerAppTests.java @@ -23,126 +23,126 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringBootTest(classes= {TestProducerApplication.class, DaprTestContainersConfig.class, - DaprAutoConfiguration.class, CustomerWorkflow.class, CustomerFollowupActivity.class, - RegisterCustomerActivity.class, CustomerStore.class}, - webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +@SpringBootTest(classes = {TestProducerApplication.class, DaprTestContainersConfig.class, + DaprAutoConfiguration.class, CustomerWorkflow.class, CustomerFollowupActivity.class, + RegisterCustomerActivity.class, CustomerStore.class}, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) class ProducerAppTests { - private static final String SUBSCRIPTION_MESSAGE_PATTERN = ".*app is subscribed to the following topics.*"; - - @Autowired - private TestSubscriberRestController controller; - - @Autowired - private CustomerStore customerStore; - - @Autowired - private DaprClient daprClient; - - - @Autowired - private DaprContainer daprContainer; - - - @BeforeEach - void setUp() { - RestAssured.baseURI = "http://localhost:" + 8080; - org.testcontainers.Testcontainers.exposeHostPorts(8080); - // Ensure the subscriptions are registered - Wait.forLogMessage(SUBSCRIPTION_MESSAGE_PATTERN, 1).waitUntilReady(daprContainer); - - } - - - @Test - void testOrdersEndpointAndMessaging() throws InterruptedException, IOException { - - given() - .contentType(ContentType.JSON) - .body("{ \"id\": \"abc-123\",\"item\": \"the mars volta LP\",\"amount\": 1}") - .when() - .post("/orders") - .then() - .statusCode(200); - - await() - .atMost(Duration.ofSeconds(15)) - .until(controller.getAllEvents()::size, equalTo(1)); - - given() - .contentType(ContentType.JSON) - .when() - .get("/orders") - .then() - .statusCode(200).body("size()", is(1)); - - given() - .contentType(ContentType.JSON) - .when() - .queryParam("item", "the mars volta LP") - .get("/orders/byItem/") - .then() - .statusCode(200).body("size()", is(1)); - - given() - .contentType(ContentType.JSON) - .when() - .queryParam("item", "other") - .get("/orders/byItem/") - .then() - .statusCode(200).body("size()", is(0)); - - given() - .contentType(ContentType.JSON) - .when() - .queryParam("amount", 1) - .get("/orders/byAmount/") - .then() - .statusCode(200).body("size()", is(1)); - - given() - .contentType(ContentType.JSON) - .when() - .queryParam("amount", 2) - .get("/orders/byAmount/") - .then() - .statusCode(200).body("size()", is(0)); - - } - - @Test - void testCustomersWorkflows() throws InterruptedException, IOException { - - given() - .contentType(ContentType.JSON) - .body("{\"customerName\": \"salaboy\"}") - .when() - .post("/customers") - .then() - .statusCode(200); - - - await() - .atMost(Duration.ofSeconds(15)) - .until(customerStore.getCustomers()::size, equalTo(1)); - Customer customer = customerStore.getCustomer("salaboy"); - assertEquals(true, customer.isInCustomerDB()); - String workflowId = customer.getWorkflowId(); - given() - .contentType(ContentType.JSON) - .body("{ \"workflowId\": \""+workflowId+"\",\"customerName\": \"salaboy\" }") - .when() - .post("/customers/followup") - .then() - .statusCode(200); - - assertEquals(1, customerStore.getCustomers().size()); - - await() - .atMost(Duration.ofSeconds(10)) - .until(customerStore.getCustomer("salaboy")::isFollowUp, equalTo(true)); - - } + private static final String SUBSCRIPTION_MESSAGE_PATTERN = ".*app is subscribed to the following topics.*"; + + @Autowired + private TestSubscriberRestController controller; + + @Autowired + private CustomerStore customerStore; + + @Autowired + private DaprClient daprClient; + + + @Autowired + private DaprContainer daprContainer; + + + @BeforeEach + void setUp() { + RestAssured.baseURI = "http://localhost:" + 8080; + org.testcontainers.Testcontainers.exposeHostPorts(8080); + // Ensure the subscriptions are registered + Wait.forLogMessage(SUBSCRIPTION_MESSAGE_PATTERN, 1).waitUntilReady(daprContainer); + + } + + + @Test + void testOrdersEndpointAndMessaging() throws InterruptedException, IOException { + + given() + .contentType(ContentType.JSON) + .body("{ \"id\": \"abc-123\",\"item\": \"the mars volta LP\",\"amount\": 1}") + .when() + .post("/orders") + .then() + .statusCode(200); + + await() + .atMost(Duration.ofSeconds(15)) + .until(controller.getAllEvents()::size, equalTo(1)); + + given() + .contentType(ContentType.JSON) + .when() + .get("/orders") + .then() + .statusCode(200).body("size()", is(1)); + + given() + .contentType(ContentType.JSON) + .when() + .queryParam("item", "the mars volta LP") + .get("/orders/byItem/") + .then() + .statusCode(200).body("size()", is(1)); + + given() + .contentType(ContentType.JSON) + .when() + .queryParam("item", "other") + .get("/orders/byItem/") + .then() + .statusCode(200).body("size()", is(0)); + + given() + .contentType(ContentType.JSON) + .when() + .queryParam("amount", 1) + .get("/orders/byAmount/") + .then() + .statusCode(200).body("size()", is(1)); + + given() + .contentType(ContentType.JSON) + .when() + .queryParam("amount", 2) + .get("/orders/byAmount/") + .then() + .statusCode(200).body("size()", is(0)); + + } + + @Test + void testCustomersWorkflows() throws InterruptedException, IOException { + + given() + .contentType(ContentType.JSON) + .body("{\"customerName\": \"salaboy\"}") + .when() + .post("/customers") + .then() + .statusCode(200); + + + await() + .atMost(Duration.ofSeconds(15)) + .until(customerStore.getCustomers()::size, equalTo(1)); + Customer customer = customerStore.getCustomer("salaboy"); + assertEquals(true, customer.isInCustomerDB()); + String workflowId = customer.getWorkflowId(); + given() + .contentType(ContentType.JSON) + .body("{ \"workflowId\": \"" + workflowId + "\",\"customerName\": \"salaboy\" }") + .when() + .post("/customers/followup") + .then() + .statusCode(200); + + assertEquals(1, customerStore.getCustomers().size()); + + await() + .atMost(Duration.ofSeconds(10)) + .until(customerStore.getCustomer("salaboy")::isFollowUp, equalTo(true)); + + } } diff --git a/spring-boot-examples/producer-app/src/test/resources/application.properties b/spring-boot-examples/producer-app/src/test/resources/application.properties index ee98d7f11..2429abb69 100644 --- a/spring-boot-examples/producer-app/src/test/resources/application.properties +++ b/spring-boot-examples/producer-app/src/test/resources/application.properties @@ -1,3 +1,3 @@ dapr.statestore.name=kvstore dapr.statestore.binding=kvbinding -dapr.pubsub.name=pubsub \ No newline at end of file +dapr.pubsub.name=pubsub diff --git a/spring-boot-examples/spotbugs-exclude.xml b/spring-boot-examples/spotbugs-exclude.xml index c2e3c8529..264fc79b0 100644 --- a/spring-boot-examples/spotbugs-exclude.xml +++ b/spring-boot-examples/spotbugs-exclude.xml @@ -3,4 +3,4 @@ - \ No newline at end of file +