Review maven configuration for testcontainers 08/122808/1
authorBruno Sakoto <bruno.sakoto@bell.ca>
Wed, 21 Jul 2021 22:26:07 +0000 (18:26 -0400)
committerBruno Sakoto <bruno.sakoto@bell.ca>
Wed, 21 Jul 2021 22:27:32 +0000 (18:27 -0400)
Maven build was not failing when test containers are not able to run
because of following maven surefire plugin bug:

* https://github.com/junit-team/junit5/issues/2178
* https://issues.apache.org/jira/browse/SUREFIRE-1688

This bug is fixed in surefire 3.0.0-M5. Then, 3.0.0-M4 version coming
from oparent is now overridden in pom plugin management.

This commit also improves spock testcontainers integration by using
the appropriate spock dependency.

Issue-ID: CPS-515
Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
Change-Id: I3ad902e598ece31601115d6484e520b6321ce8dd

pom.xml
src/test/groovy/org/onap/cps/temporal/controller/event/listener/kafka/DataUpdatedEventListenerIntegrationSpec.groovy
src/test/groovy/org/onap/cps/temporal/repository/NetworkDataRepositorySpec.groovy

diff --git a/pom.xml b/pom.xml
index 161c7e5..4f5020a 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <dependency>
+                <groupId>org.testcontainers</groupId>
+                <artifactId>testcontainers-bom</artifactId>
+                <version>1.15.3</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 
         </dependency>
         <dependency>
             <groupId>org.testcontainers</groupId>
-            <artifactId>junit-jupiter</artifactId>
-            <version>1.15.2</version>
+            <artifactId>spock</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.testcontainers</groupId>
             <artifactId>postgresql</artifactId>
-            <version>1.15.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.testcontainers</groupId>
             <artifactId>kafka</artifactId>
-            <version>1.15.3</version>
             <scope>test</scope>
         </dependency>
         <dependency>
 
        <pluginManagement>
             <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <version>3.0.0-M5</version>
+                </plugin>
                 <plugin>
                     <groupId>com.google.cloud.tools</groupId>
                     <artifactId>jib-maven-plugin</artifactId>
index 4c362ad..2ba011f 100644 (file)
@@ -29,6 +29,7 @@ import org.springframework.kafka.core.KafkaTemplate
 import org.springframework.test.context.DynamicPropertyRegistry
 import org.springframework.test.context.DynamicPropertySource
 import org.testcontainers.containers.KafkaContainer
+import org.testcontainers.spock.Testcontainers
 import spock.lang.Shared
 import spock.lang.Specification
 import spock.util.concurrent.PollingConditions
@@ -40,19 +41,18 @@ import java.util.concurrent.TimeUnit
  * This integration test is running database and kafka dependencies as docker containers.
  */
 @SpringBootTest
+@Testcontainers
 @Slf4j
 class DataUpdatedEventListenerIntegrationSpec extends Specification {
 
     @Shared
-    def databaseTestContainer = TimescaleContainer.getInstance()
+    TimescaleContainer databaseTestContainer = TimescaleContainer.getInstance()
 
     static kafkaTestContainer = new KafkaContainer()
     static {
         Runtime.getRuntime().addShutdownHook(new Thread(kafkaTestContainer::stop))
     }
-
     def setupSpec() {
-        databaseTestContainer.start()
         kafkaTestContainer.start()
     }
 
index f66b35e..c23015c 100644 (file)
@@ -23,7 +23,7 @@ import org.onap.cps.temporal.domain.NetworkData
 import org.onap.cps.temporal.repository.containers.TimescaleContainer
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
-import org.testcontainers.junit.jupiter.Testcontainers
+import org.testcontainers.spock.Testcontainers
 import spock.lang.Shared
 import spock.lang.Specification
 
@@ -49,11 +49,7 @@ class NetworkDataRepositorySpec extends Specification {
             .schemaSet(schemaSetName).anchor(anchorName).payload(payload).build()
 
     @Shared
-    def databaseTestContainer = TimescaleContainer.getInstance()
-
-    def setupSpec() {
-        databaseTestContainer.start()
-    }
+    TimescaleContainer databaseTestContainer = TimescaleContainer.getInstance()
 
     def 'Store latest network data in timeseries database.'() {
         when: 'a new Network Data is stored'