From b77a8eec16ae1ed07f5f68c246a2fc06afb1117b Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sat, 21 Jan 2017 18:33:51 +0100 Subject: [PATCH] Renaming integration tests for making them work with SonarQube --- ...positoryDockerComposeRuleIntegrationShould.java | 61 ++++++++++++++++++++ ...scriptionRepositoryDockerComposeRuleShould.java | 61 -------------------- .../AdDescriptionRepositoryIntegrationShould.java | 35 +++++++++++ .../repository/AdDescriptionRepositoryShould.java | 35 ----------- .../repository/AdRespositoryIntegrationShould.java | 67 ++++++++++++++++++++++ .../repository/AdRespositoryShould.java | 67 ---------------------- 6 files changed, 163 insertions(+), 163 deletions(-) create mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleIntegrationShould.java delete mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleShould.java create mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryIntegrationShould.java delete 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/java/de/spring/example/persistence/repository/AdRespositoryIntegrationShould.java delete mode 100644 SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryShould.java diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleIntegrationShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleIntegrationShould.java new file mode 100644 index 0000000..8da4faa --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleIntegrationShould.java @@ -0,0 +1,61 @@ +package de.spring.example.persistence.repository; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +import javax.inject.Inject; + +import org.junit.ClassRule; +import org.junit.Ignore; +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 + +// IT DOES NOT WORK FOR THESE REASONS: +// 1. Spring context is loaded before the DockerComposeRule +// 2. DockerComposeRule can work with random ports, the problem is: +// the Spring Context was loaded before DockerComposeRule and dataSource +// requires some port for connection to data base. + +// These issues can be fixed using org.junit.Suite and running +// DockerComposeRule in the Suite instead of in every Test. +// But if I want to run just one test that solution does not work because +// DockerComposeRule will be declared in the Suite instead of in the Test. +// We will have to run our tests always from the Suite not being able to run +// just one Test from the IDE :( +@Ignore +public class AdDescriptionRepositoryDockerComposeRuleIntegrationShould { + + @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(); + + for (AdDescription adDescription : adDescriptions) { + assertThat(adDescription, is(notNullValue())); + } + } + +} diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleShould.java deleted file mode 100644 index bc53430..0000000 --- a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryDockerComposeRuleShould.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.spring.example.persistence.repository; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import javax.inject.Inject; - -import org.junit.ClassRule; -import org.junit.Ignore; -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 - -// IT DOES NOT WORK FOR THESE REASONS: -// 1. Spring context is loaded before the DockerComposeRule -// 2. DockerComposeRule can work with random ports, the problem is: -// the Spring Context was loaded before DockerComposeRule and dataSource -// requires some port for connection to data base. - -// These issues can be fixed using org.junit.Suite and running -// DockerComposeRule in the Suite instead of in every Test. -// But if I want to run just one test that solution does not work because -// DockerComposeRule will be declared in the Suite instead of in the Test. -// We will have to run our tests always from the Suite not being able to run -// just one Test from the IDE :( -@Ignore -public class AdDescriptionRepositoryDockerComposeRuleShould { - - @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(); - - for (AdDescription adDescription : adDescriptions) { - assertThat(adDescription, is(notNullValue())); - } - } - -} diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryIntegrationShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryIntegrationShould.java new file mode 100644 index 0000000..685aaa5 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryIntegrationShould.java @@ -0,0 +1,35 @@ +package de.spring.example.persistence.repository; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +import javax.inject.Inject; + +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 de.spring.example.persistence.domain.AdDescription; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( {"classpath*:spring-configuration/*.xml", + "classpath*:spring-configuration-docker-test/*.xml"} ) +@Transactional +public class AdDescriptionRepositoryIntegrationShould { + + @Inject + AdDescriptionRepository adDescriptionRepository; + + @Test public void + find_ad_descriptions_by_ad() { + Iterable adDescriptions = adDescriptionRepository.findAll(); + + for (AdDescription adDescription : adDescriptions) { + assertThat(adDescription, is(notNullValue())); + } + } + +} 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 deleted file mode 100644 index 081704f..0000000 --- a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdDescriptionRepositoryShould.java +++ /dev/null @@ -1,35 +0,0 @@ -package de.spring.example.persistence.repository; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import javax.inject.Inject; - -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 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; - - @Test public void - find_ad_descriptions_by_ad() { - Iterable adDescriptions = adDescriptionRepository.findAll(); - - for (AdDescription adDescription : adDescriptions) { - assertThat(adDescription, is(notNullValue())); - } - } - -} diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryIntegrationShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryIntegrationShould.java new file mode 100644 index 0000000..6b168a4 --- /dev/null +++ b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryIntegrationShould.java @@ -0,0 +1,67 @@ +package de.spring.example.persistence.repository; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.time.OffsetDateTime; + +import javax.inject.Inject; + +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 de.spring.example.persistence.domain.Ad; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration( {"classpath*:spring-configuration/*.xml", + "classpath*:spring-configuration-h2-test/*.xml"} ) +@Transactional +public class AdRespositoryIntegrationShould { + // Ad + public static final Long COMPANY_ID = 2L; + public static final Long COMPANY_CATEG_ID = 3L; + public static final String AD_MOBILE_IMAGE = "slippers.jpg"; + public static final OffsetDateTime CREATED_AT = OffsetDateTime.now().minusDays(1); + public static final OffsetDateTime UPDATED_AT = OffsetDateTime.now(); + + @Inject + AdRepository adRepository; + + @Test public void + find_one_ad_by_id() { + Ad ad = createAd(); + Ad createdAd = adRepository.save(ad); + + Ad storedAd = adRepository.findOne(createdAd.getId()); + + assertThat(createdAd, is(storedAd)); + } + + @Test public void + find_one_ad_by_id_using_native_query() { + Ad ad = createAd(); + Ad createdAd = adRepository.save(ad); + + Ad storedAd = adRepository.findByIdNativeQuery(createdAd.getId()); + + assertThat(createdAd, is(storedAd)); + } + + @Test public void + find_one_ad_by_id_using_named_query() { + Ad ad = createAd(); + Ad createdAd = adRepository.save(ad); + + Ad storedAd = adRepository.findByIdQuery(createdAd.getId()); + + assertThat(createdAd, is(storedAd)); + } + + private static final Ad createAd() { + return new Ad(null, null, COMPANY_ID, COMPANY_CATEG_ID, AD_MOBILE_IMAGE, + CREATED_AT, UPDATED_AT); + } +} diff --git a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryShould.java b/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryShould.java deleted file mode 100644 index 40ad661..0000000 --- a/SpringJava/Gradle/spring-jpa-persistence/src/integTest/java/de/spring/example/persistence/repository/AdRespositoryShould.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.spring.example.persistence.repository; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.time.OffsetDateTime; - -import javax.inject.Inject; - -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 de.spring.example.persistence.domain.Ad; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( {"classpath*:spring-configuration/*.xml", - "classpath*:spring-configuration-h2-test/*.xml"} ) -@Transactional -public class AdRespositoryShould { - // Ad - public static final Long COMPANY_ID = 2L; - public static final Long COMPANY_CATEG_ID = 3L; - public static final String AD_MOBILE_IMAGE = "slippers.jpg"; - public static final OffsetDateTime CREATED_AT = OffsetDateTime.now().minusDays(1); - public static final OffsetDateTime UPDATED_AT = OffsetDateTime.now(); - - @Inject - AdRepository adRepository; - - @Test public void - find_one_ad_by_id() { - Ad ad = createAd(); - Ad createdAd = adRepository.save(ad); - - Ad storedAd = adRepository.findOne(createdAd.getId()); - - assertThat(createdAd, is(storedAd)); - } - - @Test public void - find_one_ad_by_id_using_native_query() { - Ad ad = createAd(); - Ad createdAd = adRepository.save(ad); - - Ad storedAd = adRepository.findByIdNativeQuery(createdAd.getId()); - - assertThat(createdAd, is(storedAd)); - } - - @Test public void - find_one_ad_by_id_using_named_query() { - Ad ad = createAd(); - Ad createdAd = adRepository.save(ad); - - Ad storedAd = adRepository.findByIdQuery(createdAd.getId()); - - assertThat(createdAd, is(storedAd)); - } - - private static final Ad createAd() { - return new Ad(null, null, COMPANY_ID, COMPANY_CATEG_ID, AD_MOBILE_IMAGE, - CREATED_AT, UPDATED_AT); - } -} -- 2.1.4