From 5a329199a78756899240e911e07abf490ed19c77 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 25 Dec 2016 22:27:15 +0100 Subject: [PATCH] Integration test with docker-compose-rule --- SpringJava/Gradle/spring-jpa-persistence/README | 3 ++ .../Gradle/spring-jpa-persistence/build.gradle | 2 ++ .../repository/AdDescriptionRepositoryShould.java | 41 ++++++++++++++++++++++ .../integTest/resources/docker/docker-compose.yml | 7 ++++ .../datasource-test-configuration.xml | 32 +++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 SpringJava/Gradle/spring-jpa-persistence/README create mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryShould.java create mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/docker/docker-compose.yml create mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/spring-configuration-docker-test/datasource-test-configuration.xml diff --git a/SpringJava/Gradle/spring-jpa-persistence/README b/SpringJava/Gradle/spring-jpa-persistence/README new file mode 100644 index 0000000..fdc0e75 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/README @@ -0,0 +1,3 @@ + +Custom version of docker-compose. Variable required by docker-compose-rule. +export DOCKER_COMPOSE_LOCATION=/mnt/docker/docker-compose diff --git a/SpringJava/Gradle/spring-jpa-persistence/build.gradle b/SpringJava/Gradle/spring-jpa-persistence/build.gradle index 8bb8363..1c8882c 100644 --- a/SpringJava/Gradle/spring-jpa-persistence/build.gradle +++ b/SpringJava/Gradle/spring-jpa-persistence/build.gradle @@ -25,6 +25,7 @@ sourceCompatibility = 1.8 repositories { mavenCentral() + maven { url 'https://dl.bintray.com/palantir/releases' } } eclipse { @@ -108,6 +109,7 @@ dependencies { testCompile('com.h2database:h2:1.4.193') // or MYSQL with docker :) testCompile('mysql:mysql-connector-java:6.0.5') + testCompile 'com.palantir.docker.compose:docker-compose-rule:0.28.1' } sourceSets { diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryShould.java new file mode 100644 index 0000000..ffaa3ad --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryShould.java @@ -0,0 +1,41 @@ +package de.spring.example.persistence.repository; + +import javax.inject.Inject; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.waiting.HealthChecks; + +import de.spring.example.persistence.domain.AdDescription; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( {"classpath*:spring-configuration/*.xml", + "classpath*:spring-configuration-docker-test/*.xml"} ) +@Transactional +public class AdDescriptionRepositoryShould { + + @Inject + AdDescriptionRepository adDescriptionRepository; + + @ClassRule + public static final DockerComposeRule DOCKER = DockerComposeRule.builder() + .file("src/integTest/resources/docker/docker-compose.yml") + .waitingForService("mysql", HealthChecks.toHaveAllPortsOpen()) + .saveLogsTo("build/dockerLogs") + .build(); + + @Test public void + find_ad_descriptions_by_ad() { + Iterable adDescriptions = adDescriptionRepository.findAll(); + + Iterable lol = adDescriptions; + + } + +} diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/docker/docker-compose.yml b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/docker/docker-compose.yml new file mode 100644 index 0000000..4c815b3 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/docker/docker-compose.yml @@ -0,0 +1,7 @@ +mysql: + image: mysql + ports: + - "3737:3306" + privileged: true + environment: + MYSQL_ROOT_PASSWORD: "root" diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/spring-configuration-docker-test/datasource-test-configuration.xml b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/spring-configuration-docker-test/datasource-test-configuration.xml new file mode 100644 index 0000000..4296799 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/resources/spring-configuration-docker-test/datasource-test-configuration.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + -- 2.1.4