File tree Expand file tree Collapse file tree 5 files changed +63
-0
lines changed
test/java/com/github/thorlauridsen Expand file tree Collapse file tree 5 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,17 @@ and http://localhost:8081/ to view the Swagger documentation for each service.
151151- [ Liquibase] ( https://github.com/liquibase/liquibase ) - Used to manage database schema changelogs
152152- [ WireMock] ( https://github.com/wiremock/wiremock ) - For mocking HTTP services in tests
153153- [ Lombok] ( https://github.com/projectlombok/lombok ) - Used to reduce boilerplate code
154+ - [ Testcontainers] ( https://github.com/testcontainers ) - Creates a temporary PostgreSQL database for tests
155+
156+ ## Testing
157+ You can run the tests for this project using the following command:
158+ ```
159+ ./gradlew test
160+ ```
161+ Please note that this project uses
162+ [ Testcontainers] ( https://github.com/testcontainers )
163+ to create a temporary PostgreSQL database for tests. This requires
164+ a local Docker instance to be running when executing the tests.
154165
155166## Gradle best practices for Kotlin
156167[ docs.gradle.org] ( https://docs.gradle.org/current/userguide/performance.html ) - [ kotlinlang.org] ( https://kotlinlang.org/docs/gradle-best-practices.html )
Original file line number Diff line number Diff line change 1+ spring :
2+ datasource :
3+ url : jdbc:postgresql://localhost:5432/sample-db
4+ username : postgres
5+ password : postgres
6+ liquibase :
7+ enabled : true
Original file line number Diff line number Diff line change 1111import org .springframework .beans .factory .annotation .Autowired ;
1212import org .springframework .boot .resttestclient .autoconfigure .AutoConfigureRestTestClient ;
1313import org .springframework .boot .test .context .SpringBootTest ;
14+ import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
1415import org .springframework .core .ParameterizedTypeReference ;
1516import org .springframework .http .MediaType ;
17+ import org .springframework .test .context .ActiveProfiles ;
1618import org .springframework .test .web .servlet .client .RestTestClient ;
19+ import org .testcontainers .containers .PostgreSQLContainer ;
20+ import org .testcontainers .junit .jupiter .Container ;
21+ import org .testcontainers .junit .jupiter .Testcontainers ;
1722import tools .jackson .databind .json .JsonMapper ;
1823
1924import static com .github .thorlauridsen .controller .BaseEndpoint .FLIGHT_BASE_ENDPOINT ;
2025import static org .junit .jupiter .api .Assertions .assertEquals ;
2126import static org .junit .jupiter .api .Assertions .assertNotNull ;
2227
28+ /**
29+ * Test class for testing the FlightController.
30+ * A local Docker instance is required to run the tests as Testcontainers is used.
31+ */
32+ @ ActiveProfiles ("postgres" )
2333@ AutoConfigureRestTestClient
2434@ SpringBootTest
35+ @ Testcontainers
2536@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
2637class FlightControllerTest {
2738
39+ @ Container
40+ @ ServiceConnection
41+ static PostgreSQLContainer <?> postgres = new PostgreSQLContainer <>("postgres:18" );
42+
2843 @ Autowired
2944 private RestTestClient restTestClient ;
3045
Original file line number Diff line number Diff line change 1111import org .springframework .beans .factory .annotation .Autowired ;
1212import org .springframework .boot .resttestclient .autoconfigure .AutoConfigureRestTestClient ;
1313import org .springframework .boot .test .context .SpringBootTest ;
14+ import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
1415import org .springframework .core .ParameterizedTypeReference ;
1516import org .springframework .http .MediaType ;
17+ import org .springframework .test .context .ActiveProfiles ;
1618import org .springframework .test .web .servlet .client .RestTestClient ;
19+ import org .testcontainers .containers .PostgreSQLContainer ;
20+ import org .testcontainers .junit .jupiter .Container ;
21+ import org .testcontainers .junit .jupiter .Testcontainers ;
1722import tools .jackson .databind .json .JsonMapper ;
1823
1924import static com .github .thorlauridsen .controller .BaseEndpoint .HOTEL_BASE_ENDPOINT ;
2025import static org .junit .jupiter .api .Assertions .assertEquals ;
2126import static org .junit .jupiter .api .Assertions .assertNotNull ;
2227
28+ /**
29+ * Test class for testing the HotelController.
30+ * A local Docker instance is required to run the tests as Testcontainers is used.
31+ */
32+ @ ActiveProfiles ("postgres" )
2333@ AutoConfigureRestTestClient
2434@ SpringBootTest
35+ @ Testcontainers
2536@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
2637class HotelControllerTest {
2738
39+ @ Container
40+ @ ServiceConnection
41+ static PostgreSQLContainer <?> postgres = new PostgreSQLContainer <>("postgres:18" );
42+
2843 @ Autowired
2944 private RestTestClient restTestClient ;
3045
Original file line number Diff line number Diff line change 1111import org .springframework .beans .factory .annotation .Autowired ;
1212import org .springframework .boot .resttestclient .autoconfigure .AutoConfigureRestTestClient ;
1313import org .springframework .boot .test .context .SpringBootTest ;
14+ import org .springframework .boot .testcontainers .service .connection .ServiceConnection ;
1415import org .springframework .core .ParameterizedTypeReference ;
1516import org .springframework .http .MediaType ;
17+ import org .springframework .test .context .ActiveProfiles ;
1618import org .springframework .test .web .servlet .client .RestTestClient ;
19+ import org .testcontainers .containers .PostgreSQLContainer ;
20+ import org .testcontainers .junit .jupiter .Container ;
21+ import org .testcontainers .junit .jupiter .Testcontainers ;
1722import tools .jackson .databind .json .JsonMapper ;
1823
1924import static com .github .thorlauridsen .controller .BaseEndpoint .RENTAL_CAR_BASE_ENDPOINT ;
2025import static org .junit .jupiter .api .Assertions .assertEquals ;
2126import static org .junit .jupiter .api .Assertions .assertNotNull ;
2227
28+ /**
29+ * Test class for testing the RentalCarController.
30+ * A local Docker instance is required to run the tests as Testcontainers is used.
31+ */
32+ @ ActiveProfiles ("postgres" )
2333@ AutoConfigureRestTestClient
2434@ SpringBootTest
35+ @ Testcontainers
2536@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
2637class RentalCarControllerTest {
2738
39+ @ Container
40+ @ ServiceConnection
41+ static PostgreSQLContainer <?> postgres = new PostgreSQLContainer <>("postgres:18" );
42+
2843 @ Autowired
2944 private RestTestClient restTestClient ;
3045
You can’t perform that action at this time.
0 commit comments