Skip to content

Commit

Permalink
Add local development support
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasadreddy committed Jul 10, 2023
1 parent 1cf05fc commit f5fb018
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/main/java/com/testcontainers/demo/MessageController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,12 +22,8 @@ public class MessageController {

@PostMapping("/api/messages")
public Map<String, String> 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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/com/testcontainers/demo/TestApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f5fb018

Please sign in to comment.