From 01ac78700e2ec13107fbf5efcbcc2091420d14f0 Mon Sep 17 00:00:00 2001 From: Ivan Vasyliev Date: Sun, 26 Apr 2020 17:23:05 +0300 Subject: [PATCH] add autoconfigured testcontainer --- build.gradle | 6 +++++- .../com/example/demo/DemoApplicationTests.groovy | 13 ++++++++++--- src/test/resources/application.properties | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/application.properties diff --git a/build.gradle b/build.gradle index 306fe43..4955b86 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.1.3.RELEASE' + id 'org.springframework.boot' version '2.2.6.RELEASE' id 'groovy' } @@ -28,4 +28,8 @@ dependencies { // for connection pooling runtime "org.apache.tomcat:tomcat-jdbc:8.5.0" runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0" + + // For the testcontainers-spring-boot dependencies: + testCompile 'org.springframework.cloud:spring-cloud-starter:2.2.2.RELEASE' + testCompile 'com.playtika.testcontainers:embedded-postgresql:1.48' } diff --git a/src/test/groovy/com/example/demo/DemoApplicationTests.groovy b/src/test/groovy/com/example/demo/DemoApplicationTests.groovy index fe48ebf..4542fd2 100644 --- a/src/test/groovy/com/example/demo/DemoApplicationTests.groovy +++ b/src/test/groovy/com/example/demo/DemoApplicationTests.groovy @@ -2,6 +2,7 @@ package com.example.demo import org.junit.Test import org.junit.runner.RunWith +import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit4.SpringRunner @@ -9,8 +10,14 @@ import org.springframework.test.context.junit4.SpringRunner @SpringBootTest class DemoApplicationTests { - @Test - void contextLoads() { - } + @Autowired + BookService bookService; + + @Test + void saveAndFindBook() { + bookService.save("TestOne") + + assert bookService.findByTitle("TestOne") !=null + } } diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..4d931fc --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,4 @@ +spring.datasource.url=jdbc:postgresql://${embedded.postgresql.host}:${embedded.postgresql.port}/${embedded.postgresql.schema} +spring.datasource.username=${embedded.postgresql.user} +spring.datasource.password=${embedded.postgresql.password} +hibernate.hbm2ddl.auto=create