Skip to content

Commit

Permalink
Upgrade to Spring Boot 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasadreddy committed Dec 1, 2023
1 parent fb9dd2c commit 32afe2b
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 139 deletions.
4 changes: 2 additions & 2 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java=17.0.4-tem
gradle=8.1.1
java=17.0.8-tem
gradle=8.5
maven=3.8.6
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.2'
id 'io.spring.dependency-management' version '1.1.2'
id 'com.diffplug.spotless' version "6.18.0"
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'com.diffplug.spotless' version "6.23.0"
}

group = 'com.testcontainers'
Expand All @@ -20,8 +20,8 @@ repositories {
}

ext {
set('testcontainers.version', "1.18.3")
set('awspringVersion', "3.0.1")
set('testcontainers.version', "1.19.3")
set('awspringVersion', "3.0.3")
}

dependencies {
Expand Down Expand Up @@ -56,7 +56,13 @@ spotless {
java {
importOrder()
removeUnusedImports()
palantirJavaFormat("2.30.0")
prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0'])
.config([
'parser': 'java',
'tabWidth': 2,
'printWidth': 80,
'plugins': ['prettier-plugin-java']
])
formatAnnotations()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you are using *Gradle* as your build tool, you should have the dependencies c

[source,groovy,indent=0]
----
include::{codebase}/build.gradle[lines="22..42"]
include::{codebase}/build.gradle[lines="22..44"]
----

For the complete code, please refer to the GitHub repository
Expand Down Expand Up @@ -138,7 +138,7 @@ configure the Spring Cloud AWS properties as follows:

[source,java]
----
include::{codebase}/src/test/java/com/testcontainers/demo/MessageListenerTest.java[lines="22..45,76"]
include::{codebase}/src/test/java/com/testcontainers/demo/MessageListenerTest.java[lines="22..58,98"]
----

We have used Testcontainers JUnit 5 Extension annotations *@Testcontainers* and *@Container*
Expand All @@ -152,7 +152,7 @@ method to create the necessary resources (S3 buckets or SQS queues etc) by using

[source,java,indent=0]
----
include::{codebase}/src/test/java/com/testcontainers/demo/MessageListenerTest.java[lines="47..51"]
include::{codebase}/src/test/java/com/testcontainers/demo/MessageListenerTest.java[lines="60..70"]
----

We have used *localStack.execInContainer()* API to run commands inside the container and used *awslocal* CLI tool,
Expand Down
23 changes: 16 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.2</version>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.testcontainers</groupId>
Expand All @@ -17,8 +17,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<testcontainers.version>1.18.3</testcontainers.version>
<awspring.version>3.0.1</awspring.version>
<testcontainers.version>1.19.3</testcontainers.version>
<awspring.version>3.0.3</awspring.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -87,14 +87,23 @@
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.36.0</version>
<version>2.41.0</version>
<configuration>
<java>
<importOrder />
<removeUnusedImports />
<palantirJavaFormat>
<version>2.30.0</version>
</palantirJavaFormat>
<prettier>
<devDependencies>
<prettier>3.0.3</prettier>
<prettier-plugin-java>2.3.0</prettier-plugin-java>
</devDependencies>
<config>
<parser>java</parser>
<tabWidth>2</tabWidth>
<printWidth>80</printWidth>
<plugins>prettier-plugin-java</plugins>
</config>
</prettier>
<formatAnnotations />
</java>
</configuration>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/testcontainers/demo/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@ConfigurationPropertiesScan
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
43 changes: 23 additions & 20 deletions src/main/java/com/testcontainers/demo/MessageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@

@RestController
public class MessageController {
private final MessageSender messageSender;
private final StorageService storageService;
private final ApplicationProperties properties;

MessageController(MessageSender messageSender, StorageService storageService, ApplicationProperties properties) {
this.messageSender = messageSender;
this.storageService = storageService;
this.properties = properties;
}
private final MessageSender messageSender;
private final StorageService storageService;
private final ApplicationProperties properties;

@PostMapping("/api/messages")
public Map<String, String> create(@RequestBody Message message) {
messageSender.publish(properties.queue(), message);
return Map.of("uuid", message.uuid().toString());
}
MessageController(
MessageSender messageSender,
StorageService storageService,
ApplicationProperties properties
) {
this.messageSender = messageSender;
this.storageService = storageService;
this.properties = properties;
}

@GetMapping("/api/messages/{uuid}")
public Map<String, String> get(@PathVariable String uuid) throws IOException {
String content = storageService.downloadAsString(properties.bucket(), uuid);
return Map.of(
"uuid", uuid,
"content", content);
}
@PostMapping("/api/messages")
public Map<String, String> create(@RequestBody Message message) {
messageSender.publish(properties.queue(), message);
return Map.of("uuid", message.uuid().toString());
}

@GetMapping("/api/messages/{uuid}")
public Map<String, String> get(@PathVariable String uuid) throws IOException {
String content = storageService.downloadAsString(properties.bucket(), uuid);
return Map.of("uuid", uuid, "content", content);
}
}
32 changes: 19 additions & 13 deletions src/main/java/com/testcontainers/demo/MessageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@

@Service
public class MessageListener {
private final StorageService storageService;
private final ApplicationProperties properties;

public MessageListener(StorageService storageService, ApplicationProperties properties) {
this.storageService = storageService;
this.properties = properties;
}
private final StorageService storageService;
private final ApplicationProperties properties;

@SqsListener(queueNames = {"${app.queue}"})
public void handle(Message message) {
String bucketName = this.properties.bucket();
String key = message.uuid().toString();
ByteArrayInputStream is = new ByteArrayInputStream(message.content().getBytes(StandardCharsets.UTF_8));
this.storageService.upload(bucketName, key, is);
}
public MessageListener(
StorageService storageService,
ApplicationProperties properties
) {
this.storageService = storageService;
this.properties = properties;
}

@SqsListener(queueNames = { "${app.queue}" })
public void handle(Message message) {
String bucketName = this.properties.bucket();
String key = message.uuid().toString();
ByteArrayInputStream is = new ByteArrayInputStream(
message.content().getBytes(StandardCharsets.UTF_8)
);
this.storageService.upload(bucketName, key, is);
}
}
15 changes: 8 additions & 7 deletions src/main/java/com/testcontainers/demo/MessageSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

@Service
public class MessageSender {
private final SqsTemplate sqsTemplate;

public MessageSender(SqsTemplate sqsTemplate) {
this.sqsTemplate = sqsTemplate;
}
private final SqsTemplate sqsTemplate;

public void publish(String queueName, Message message) {
sqsTemplate.send(to -> to.queue(queueName).payload(message));
}
public MessageSender(SqsTemplate sqsTemplate) {
this.sqsTemplate = sqsTemplate;
}

public void publish(String queueName, Message message) {
sqsTemplate.send(to -> to.queue(queueName).payload(message));
}
}
31 changes: 17 additions & 14 deletions src/main/java/com/testcontainers/demo/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@

@Service
public class StorageService {
private final S3Template s3Template;

public StorageService(S3Template s3Template) {
this.s3Template = s3Template;
}
private final S3Template s3Template;

public void upload(String bucketName, String key, InputStream stream) {
this.s3Template.upload(bucketName, key, stream);
}
public StorageService(S3Template s3Template) {
this.s3Template = s3Template;
}

public InputStream download(String bucketName, String key) throws IOException {
return this.s3Template.download(bucketName, key).getInputStream();
}
public void upload(String bucketName, String key, InputStream stream) {
this.s3Template.upload(bucketName, key, stream);
}

public InputStream download(String bucketName, String key)
throws IOException {
return this.s3Template.download(bucketName, key).getInputStream();
}

public String downloadAsString(String bucketName, String key) throws IOException {
try (InputStream is = this.download(bucketName, key)) {
return new String(is.readAllBytes());
}
public String downloadAsString(String bucketName, String key)
throws IOException {
try (InputStream is = this.download(bucketName, key)) {
return new String(is.readAllBytes());
}
}
}
Loading

0 comments on commit 32afe2b

Please sign in to comment.