diff --git a/README.adoc b/README.adoc index 1ebeb78a..54594eaa 100644 --- a/README.adoc +++ b/README.adoc @@ -98,6 +98,8 @@ Provides the API to access Apache Pulsar using a Reactive client. === spring-pulsar-sample-apps Provides sample applications to illustrate Spring for Apache Pulsar functionality as well as provide ability for quick manual verification during development. +=== spring-pulsar-test +Provides utilities to help with testing Spring for Apache Pulsar applications. == License Spring for Apache Pulsar is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. diff --git a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/testing-applications.adoc b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/testing-applications.adoc index f4544525..bfad224d 100644 --- a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/testing-applications.adoc +++ b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/testing-applications.adoc @@ -44,3 +44,39 @@ List> messages = PulsarConsumerTestUtil.consumeMessages(consumer .until(ConsumedMessagesConditions.atLeastOneMessageMatches("boom")) .get(); ---- + +== PulsarTestContainerSupport + +The `org.springframework.pulsar.test.support.PulsarTestContainerSupport` interface provides a static Pulsar Testcontainer. +When using Junit Jupiter, the container is automatically started once per test class via `@BeforeAll` annotation. + +The following example shows how you can use the container support in a `@SpringBootTest` in conjunction with the previously mentioned `PulsarConsumerTestUtil`. + +[source,java,indent=0,subs="verbatim"] +---- +@SpringBootTest +class MyApplicationTests implements PulsarTestContainerSupport { + + @DynamicPropertySource + static void pulsarProperties(DynamicPropertyRegistry registry) { + registry.add("spring.pulsar.client.service-url", PULSAR_CONTAINER::getPulsarBrokerUrl); + registry.add("spring.pulsar.admin.service-url", PULSAR_CONTAINER::getHttpServiceUrl); + } + + @Test + void sendAndReceiveWorksAsExpected( + @Autowired PulsarTemplate template, + @Autowired PulsarConsumerFactory consumerFactory) { + var topic = "some-topic"; + var msg = "foo-5150"; + template.send(topic, msg); + var matchedUsers = PulsarConsumerTestUtil.consumeMessages(consumerFactory) + .fromTopic(topic) + .withSchema(Schema.STRING) + .awaitAtMost(Duration.ofSeconds(2)) + .until(ConsumedMessagesConditions.atLeastOneMessageMatches(msg)) + .get(); + assertThat(matchedUsers).hasSize(1); + } +} +---- diff --git a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc index 60013ea6..58fb7f6d 100644 --- a/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc +++ b/spring-pulsar-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc @@ -21,3 +21,7 @@ The APIs provided by the framework no longer throw the checked `PulsarClientExce WARNING: If you were previously catching or rethrowing `PulsarClientException` just to appease the compiler and were not actually handling the exception, you can simply remove your `catch` or `throws` clause. If you were actually handling the exception then you will need to replace `PulsarClientException` with `PulsarException` in your catch clause. + +=== Testing support +The `spring-pulsar-test` module is now available to help test your Spring for Apache Pulsar applications. +See xref:./reference/testing-applications.adoc#testing-applications[Testing Applications] for more details. diff --git a/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/aot/package-info.java b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/aot/package-info.java new file mode 100644 index 00000000..5d310b10 --- /dev/null +++ b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/aot/package-info.java @@ -0,0 +1,9 @@ +/** + * Package containing Reactive AOT runtime hints used by the framework. + */ +@NonNullApi +@NonNullFields +package org.springframework.pulsar.reactive.aot; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; diff --git a/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/support/package-info.java b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/support/package-info.java new file mode 100644 index 00000000..0748c03e --- /dev/null +++ b/spring-pulsar-reactive/src/main/java/org/springframework/pulsar/reactive/support/package-info.java @@ -0,0 +1,9 @@ +/** + * Package containing support classes for processing Pulsar messages. + */ +@NonNullApi +@NonNullFields +package org.springframework.pulsar.reactive.support; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; diff --git a/spring-pulsar-test/spring-pulsar-test.gradle b/spring-pulsar-test/spring-pulsar-test.gradle index adb65e18..5cf27a17 100644 --- a/spring-pulsar-test/spring-pulsar-test.gradle +++ b/spring-pulsar-test/spring-pulsar-test.gradle @@ -1,8 +1,8 @@ plugins { - id 'org.springframework.pulsar.spring-unpublished-module' + id 'org.springframework.pulsar.spring-module' } -description = 'Spring Pulsar Test Module' +description = 'Spring Pulsar Test Utilities Module' dependencies { implementation 'org.junit.jupiter:junit-jupiter-api' diff --git a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarTestContainerSupport.java b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarTestContainerSupport.java index 9b945942..9900a1df 100644 --- a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarTestContainerSupport.java +++ b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/PulsarTestContainerSupport.java @@ -31,6 +31,10 @@ public interface PulsarTestContainerSupport { PulsarContainer PULSAR_CONTAINER = new PulsarContainer(getPulsarImage()); + static DockerImageName getPulsarImage() { + return DockerImageName.parse("apachepulsar/pulsar:latest"); + } + @BeforeAll static void startContainer() { PULSAR_CONTAINER.start(); @@ -40,10 +44,6 @@ public interface PulsarTestContainerSupport { return PULSAR_CONTAINER.getPulsarBrokerUrl(); } - static DockerImageName getPulsarImage() { - return DockerImageName.parse("apachepulsar/pulsar:3.2.0"); - } - static String getHttpServiceUrl() { return PULSAR_CONTAINER.getHttpServiceUrl(); } diff --git a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/package-info.java b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/package-info.java new file mode 100644 index 00000000..4840de16 --- /dev/null +++ b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/model/package-info.java @@ -0,0 +1,10 @@ +/** + * Package containing model classes to ease testing Spring for Apache Pulsar applications. + * @since 1.1.0 + */ +@NonNullApi +@NonNullFields +package org.springframework.pulsar.test.support.model; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; diff --git a/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/package-info.java b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/package-info.java new file mode 100644 index 00000000..173fd9e1 --- /dev/null +++ b/spring-pulsar-test/src/main/java/org/springframework/pulsar/test/support/package-info.java @@ -0,0 +1,11 @@ +/** + * Package containing convenience utilities for testing Spring for Apache Pulsar + * applications. + * @since 1.1.0 + */ +@NonNullApi +@NonNullFields +package org.springframework.pulsar.test.support; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; diff --git a/spring-pulsar/src/main/java/org/springframework/pulsar/aot/package-info.java b/spring-pulsar/src/main/java/org/springframework/pulsar/aot/package-info.java new file mode 100644 index 00000000..501964a5 --- /dev/null +++ b/spring-pulsar/src/main/java/org/springframework/pulsar/aot/package-info.java @@ -0,0 +1,9 @@ +/** + * Package containing AOT runtime hints used by the framework. + */ +@NonNullApi +@NonNullFields +package org.springframework.pulsar.aot; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields;