-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration tests for SQS Reactive Messaging (#1483)
Co-authored-by: adam.poplawski@tui.co.uk <adam.poplawski@tui.co.uk>
- Loading branch information
1 parent
2bb2738
commit 4bcf46e
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ain/java/io/quarkiverse/it/amazon/sqsmessagingconnector/SqsMessagingConnectorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkiverse.it.amazon.sqsmessagingconnector; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
|
||
import software.amazon.awssdk.services.sqs.SqsClient; | ||
import software.amazon.awssdk.services.sqs.model.SendMessageRequest; | ||
|
||
@ApplicationScoped | ||
public class SqsMessagingConnectorManager { | ||
@Inject | ||
SqsClient sqsClient; | ||
List<String> messages = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("messages") | ||
public void process(String incomingMessage) { | ||
messages.add(incomingMessage); | ||
} | ||
|
||
public void sendMessage(String message, String queueName) { | ||
sqsClient.sendMessage(SendMessageRequest.builder().queueUrl(getQueueUrl(queueName)).messageBody(message).build()); | ||
} | ||
|
||
public List<String> getMessages() { | ||
return messages; | ||
} | ||
|
||
private String getQueueUrl(String queueName) { | ||
return sqsClient.listQueues(r -> r.queueNamePrefix(queueName)).queueUrls().get(0); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...in/java/io/quarkiverse/it/amazon/sqsmessagingconnector/SqsMessagingConnectorResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkiverse.it.amazon.sqsmessagingconnector; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.RestQuery; | ||
|
||
@Path("/sqs-messaging-connector") | ||
public class SqsMessagingConnectorResource { | ||
@Inject | ||
SqsMessagingConnectorManager connectorManager; | ||
|
||
@Path("messages/{queueName}") | ||
@POST | ||
public void sendSyncMessage(String queueName, @RestQuery String message) { | ||
connectorManager.sendMessage(message, queueName); | ||
} | ||
|
||
@Path("messages/{queueName}") | ||
@GET | ||
public List<String> getMessages() { | ||
return connectorManager.getMessages(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ation-tests/src/test/java/io/quarkiverse/it/amazon/AmazonSqsMessagingConnectorITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkiverse.it.amazon; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class AmazonSqsMessagingConnectorITCase extends AmazonSqsMessagingConnectorTest { | ||
} |
55 changes: 55 additions & 0 deletions
55
...gration-tests/src/test/java/io/quarkiverse/it/amazon/AmazonSqsMessagingConnectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkiverse.it.amazon; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.any; | ||
import static org.hamcrest.Matchers.arrayWithSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class AmazonSqsMessagingConnectorTest { | ||
|
||
private final static String QUEUE_NAME = "quarkus-messaging-test-queue"; | ||
private final static List<String> MESSAGES = new ArrayList<>(); | ||
|
||
static { | ||
MESSAGES.add("First Message"); | ||
MESSAGES.add("Second Message"); | ||
MESSAGES.add("Third Message"); | ||
} | ||
|
||
@Test | ||
public void testReceiveMessages() { | ||
//Publish messages | ||
MESSAGES.forEach(msg -> { | ||
given() | ||
.pathParam("queueName", QUEUE_NAME) | ||
.queryParam("message", msg) | ||
.when().post("/test/sqs-messaging-connector/messages/{queueName}") | ||
.then().body(any(String.class)); | ||
}); | ||
|
||
await() | ||
.atMost(Duration.ofSeconds(10L)) | ||
.pollInterval(Duration.ofSeconds(1L)) | ||
.untilAsserted(() -> assertThat(given() | ||
.pathParam("queueName", QUEUE_NAME) | ||
.get("/test/sqs-messaging-connector/messages/{queueName}") | ||
.then() | ||
.assertThat() | ||
.statusCode(is(Response.Status.OK.getStatusCode())) | ||
.extract() | ||
.as(String[].class), arrayWithSize(3))); | ||
} | ||
} |