From f5fb018899dcc8c3e87a10330f6d72dfdb85af23 Mon Sep 17 00:00:00 2001 From: K Siva Prasad Reddy Date: Mon, 10 Jul 2023 18:20:23 +0530 Subject: [PATCH] Add local development support --- .../com/testcontainers/demo/MessageController.java | 10 ++-------- .../com/testcontainers/demo/MessageListenerTest.java | 2 +- .../java/com/testcontainers/demo/TestApplication.java | 9 +++------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/testcontainers/demo/MessageController.java b/src/main/java/com/testcontainers/demo/MessageController.java index d8d7e87..8f5d436 100644 --- a/src/main/java/com/testcontainers/demo/MessageController.java +++ b/src/main/java/com/testcontainers/demo/MessageController.java @@ -1,8 +1,6 @@ package com.testcontainers.demo; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -24,12 +22,8 @@ public class MessageController { @PostMapping("/api/messages") public Map create(@RequestBody Message message) { - messageSender.publish(properties.bucket(), message); - String key = message.uuid().toString(); - String content = message.content(); - ByteArrayInputStream is = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); - storageService.upload(properties.bucket(), key, is); - return Map.of("uuid", key); + messageSender.publish(properties.queue(), message); + return Map.of("uuid", message.uuid().toString()); } @GetMapping("/api/messages/{uuid}") diff --git a/src/test/java/com/testcontainers/demo/MessageListenerTest.java b/src/test/java/com/testcontainers/demo/MessageListenerTest.java index 1468dee..901f77d 100644 --- a/src/test/java/com/testcontainers/demo/MessageListenerTest.java +++ b/src/test/java/com/testcontainers/demo/MessageListenerTest.java @@ -62,7 +62,7 @@ static void beforeAll() throws IOException, InterruptedException { @Test void shouldHandleMessageSuccessfully() { Message message = new Message(UUID.randomUUID(), "Hello World"); - publisher.publish(QUEUE_NAME, message); + publisher.publish(properties.queue(), message); await().pollInterval(Duration.ofSeconds(2)) .atMost(Duration.ofSeconds(10)) diff --git a/src/test/java/com/testcontainers/demo/TestApplication.java b/src/test/java/com/testcontainers/demo/TestApplication.java index 321b05c..efc5126 100644 --- a/src/test/java/com/testcontainers/demo/TestApplication.java +++ b/src/test/java/com/testcontainers/demo/TestApplication.java @@ -5,20 +5,17 @@ import java.util.UUID; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.context.TestConfiguration; import org.testcontainers.containers.localstack.LocalStackContainer; -import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; -@TestConfiguration(proxyBeanMethods = false) -@Testcontainers public class TestApplication { public static void main(String[] args) { - SpringApplication.from(Application::main).with(TestApplication.class).run(args); + setup(); + SpringApplication.from(Application::main).run(args); } - static { + static void setup() { try { var container = new LocalStackContainer(DockerImageName.parse("localstack/localstack:2.0")); container.start();