Skip to content

Commit

Permalink
migrated to Spring Boot 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xpinjection committed Sep 15, 2023
1 parent cb5249d commit 4aa86ea
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 11 deletions.
14 changes: 14 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3'

services:
library-db:
image: postgres:11
container_name: postgresql
environment:
POSTGRES_DB: library
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- "5432:5432"
labels:
org.springframework.boot.ignore: true
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.10</version>
<version>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -76,8 +76,8 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
<artifactId>spring-boot-docker-compose</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -136,6 +136,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
Expand Down Expand Up @@ -171,7 +176,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.18.3</version>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ server:
enabled: true

spring:
docker:
compose:
lifecycle-management: none
enabled: false
sql:
init:
mode: never
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;

public class LocalLibraryApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(LibraryApplication.class)
.initializers(new StandaloneApplicationContextInitializer())
.sources(RuntimeDependenciesConfiguration.class)
//.initializers(new StandaloneApplicationContextInitializer())
.applicationStartup(new BufferingApplicationStartup(2048))
//.applicationStartup(new FlightRecorderApplicationStartup())
.profiles("dev")
.run(args);
}

@TestConfiguration
@ImportTestcontainers(RuntimeDependencies.class)
public static class RuntimeDependenciesConfiguration {
}
}
12 changes: 12 additions & 0 deletions src/test/java/com/xpinjection/library/RuntimeDependencies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.xpinjection.library;

import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.containers.PostgreSQLContainer;

public interface RuntimeDependencies {
@ServiceConnection
PostgreSQLContainer<?> POSTGRE_SQL = new PostgreSQLContainer<>("postgres:11")
.withDatabaseName("library")
.withUsername("test")
.withPassword("test");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.database.rider.spring.api.DBRider;
import com.github.viclovsky.swagger.coverage.FileSystemOutputWriter;
import com.github.viclovsky.swagger.coverage.SwaggerCoverageV3RestAssured;
import com.xpinjection.library.RuntimeDependencies;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -11,15 +12,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.test.context.ActiveProfiles;

import java.nio.file.Path;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
//@ContextConfiguration(initializers = StandaloneApplicationContextInitializer.class)
@DBRider
@Slf4j
@ActiveProfiles("test")
@ImportTestcontainers(RuntimeDependencies.class)
public abstract class AbstractApiTest {
private static final ApiReports REPORTS = ApiReports.builder()
.coveragePath(Path.of("target", "api-coverage"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.github.database.rider.core.api.dataset.DataSetFormat;
import com.github.database.rider.core.api.exporter.ExportDataSet;
import com.github.database.rider.spring.api.DBRider;
import com.xpinjection.library.RuntimeDependencies;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ActiveProfiles;

Expand All @@ -20,6 +22,7 @@
@DataJpaTest
@DBRider
@ActiveProfiles("test")
@ImportTestcontainers(RuntimeDependencies.class)
public abstract class AbstractDaoTest<D> {
private static long ID = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.github.database.rider.core.api.dataset.DataSet;
import com.github.database.rider.core.api.dataset.SeedStrategy;
import com.xpinjection.library.RuntimeDependencies;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
Expand All @@ -30,6 +32,7 @@
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("test")
@ImportTestcontainers(RuntimeDependencies.class)
public class BookUITest {
@Autowired
private WebApplicationContext context;
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ spring:
enabled: false
freemarker:
cache: false
datasource:
url: jdbc:tc:postgresql:11:///library?TC_REUSABLE=true
username: test
password: test
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
jpa:
show-sql: true
test:
Expand Down

0 comments on commit 4aa86ea

Please sign in to comment.