1 package de.spring.example.persistence.repository;
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.notNullValue;
5 import static org.junit.Assert.assertThat;
7 import javax.inject.Inject;
9 import org.junit.ClassRule;
10 import org.junit.Ignore;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.springframework.test.context.ContextConfiguration;
14 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
15 import org.springframework.transaction.annotation.Transactional;
17 import com.palantir.docker.compose.DockerComposeRule;
18 import com.palantir.docker.compose.connection.waiting.HealthChecks;
20 import de.spring.example.persistence.domain.AdDescription;
22 @RunWith(SpringJUnit4ClassRunner.class)
23 @ContextConfiguration( {"classpath*:spring-configuration/*.xml",
24 "classpath*:spring-configuration-docker-test/*.xml"} )
27 // IT DOES NOT WORK FOR THESE REASONS:
28 // 1. Spring context is loaded before the DockerComposeRule
29 // 2. DockerComposeRule can work with random ports, the problem is:
30 // the Spring Context was loaded before DockerComposeRule and dataSource
31 // requires some port for connection to data base.
33 // These issues can be fixed using org.junit.Suite and running
34 // DockerComposeRule in the Suite instead of in every Test.
35 // But if I want to run just one test that solution does not work because
36 // DockerComposeRule will be declared in the Suite instead of in the Test.
37 // We will have to run our tests always from the Suite not being able to run
38 // just one Test from the IDE :(
40 public class AdDescriptionRepositoryDockerComposeRuleShould {
43 AdDescriptionRepository adDescriptionRepository;
46 public static final DockerComposeRule DOCKER = DockerComposeRule.builder()
47 .file("src/integTest/resources/docker/docker-compose.yml")
48 .waitingForService("mysql", HealthChecks.toHaveAllPortsOpen())
49 .saveLogsTo("build/dockerLogs")
53 find_ad_descriptions_by_ad() {
54 Iterable<AdDescription> adDescriptions = adDescriptionRepository.findAll();
56 for (AdDescription adDescription : adDescriptions) {
57 assertThat(adDescription, is(notNullValue()));