Skip to content

Commit ddabb56

Browse files
committed
Integration test added for storage service client added
1 parent 2f3e566 commit ddabb56

File tree

8 files changed

+72
-39
lines changed

8 files changed

+72
-39
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
____ ____ _
2+
/ __ \___ ____ _/ / /_____ _____ ________ ______ __(_)_______
3+
/ /_/ / _ \/ __ `/ / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \
4+
/ _, _/ __/ /_/ / / /_/ /_/ / / (__ ) __/ / | |/ / / /__/ __/
5+
/_/ |_|\___/\__,_/_/\__/\____/_/ /____/\___/_/ |___/_/\___/\___/
6+
7+
v.${application.version}

storage-service-client/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
<version>1.3.0</version>
6161
<scope>test</scope>
6262
</dependency>
63+
<dependency>
64+
<groupId>com.lohika.jclub.storage</groupId>
65+
<artifactId>storage-service</artifactId>
66+
<version>0.0.1-SNAPSHOT</version>
67+
<scope>test</scope>
68+
</dependency>
6369
<dependency>
6470
<groupId>org.springframework.boot</groupId>
6571
<artifactId>spring-boot-starter-test</artifactId>

storage-service-client/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

storage-service-client/src/test/java/com/lohika/jclub/storage/StorageServiceClientTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
package com.lohika.jclub.storage;
22

3-
import com.github.dockerjava.api.command.CreateContainerCmd;
4-
53
import org.junit.ClassRule;
6-
import org.junit.Ignore;
74
import org.junit.Test;
85
import org.junit.runner.RunWith;
96
import org.springframework.beans.factory.annotation.Autowired;
107
import org.springframework.boot.test.context.SpringBootTest;
8+
import org.springframework.boot.test.util.EnvironmentTestUtils;
9+
import org.springframework.context.ApplicationContextInitializer;
10+
import org.springframework.context.ConfigurableApplicationContext;
1111
import org.springframework.hateoas.PagedResources;
12+
import org.springframework.test.context.ContextConfiguration;
1213
import org.springframework.test.context.junit4.SpringRunner;
1314
import org.testcontainers.containers.GenericContainer;
14-
import org.testcontainers.containers.wait.Wait;
15+
import org.testcontainers.containers.wait.LogMessageWaitStrategy;
1516

1617
import static org.hamcrest.Matchers.hasItem;
1718
import static org.hamcrest.Matchers.is;
1819
import static org.hamcrest.Matchers.notNullValue;
1920
import static org.hamcrest.Matchers.nullValue;
2021
import static org.junit.Assert.assertThat;
2122

22-
@Ignore
2323
@RunWith(SpringRunner.class)
2424
@SpringBootTest(classes = StorageServiceClientTestApplication.class)
25+
@ContextConfiguration(initializers = StorageServiceClientTest.Initializer.class)
2526
public class StorageServiceClientTest {
2627

2728
@ClassRule
2829
public static GenericContainer storageService = new GenericContainer("storage-service:latest")
2930
.withExposedPorts(8091)
30-
.withCreateContainerCmdModifier(
31-
cmd -> ((CreateContainerCmd) cmd)
32-
.withPublishAllPorts(true)
33-
.withName("storage-service"))
34-
.waitingFor(Wait.forListeningPort());
31+
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s"));
3532

3633
@Autowired
3734
private StorageServiceClient storageServiceClient;
@@ -108,4 +105,15 @@ public void delete() {
108105
Apartment actual = storageServiceClient.get(created.getId());
109106
assertThat(actual, nullValue());
110107
}
108+
109+
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
110+
@Override
111+
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
112+
113+
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
114+
"storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":"
115+
+ storageService.getMappedPort(8091) + "/"
116+
);
117+
}
118+
}
111119
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
spring.application.name=storage-service-client
2-
spring.cloud.loadbalancer.retry
1+
spring.application.name=storage-service-client-testing
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_____ __ _
2+
/ ___// /_____ _________ _____ ____ ________ ______ __(_)_______
3+
\__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \
4+
___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/
5+
/____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/
6+
/____/
7+
v.${application.version}

storage-service/pom.xml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,32 @@
7575
<groupId>org.springframework.boot</groupId>
7676
<artifactId>spring-boot-maven-plugin</artifactId>
7777
</plugin>
78-
<!--<plugin>-->
79-
<!--<groupId>com.spotify</groupId>-->
80-
<!--<artifactId>docker-maven-plugin</artifactId>-->
81-
<!--<version>0.2.3</version>-->
82-
<!--<executions>-->
83-
<!--<execution>-->
84-
<!--<id>build-image</id>-->
85-
<!--<phase>install</phase>-->
86-
<!--<goals>-->
87-
<!--<goal>build</goal>-->
88-
<!--</goals>-->
89-
<!--</execution>-->
90-
<!--</executions>-->
91-
<!--<configuration>-->
92-
<!--<imageName>storage-service</imageName>-->
93-
<!--<baseImage>java</baseImage>-->
94-
<!--<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>-->
95-
<!--<resources>-->
96-
<!--<resource>-->
97-
<!--<targetPath>/</targetPath>-->
98-
<!--<directory>${project.build.directory}</directory>-->
99-
<!--<include>${project.build.finalName}.jar</include>-->
100-
<!--</resource>-->
101-
<!--</resources>-->
102-
<!--</configuration>-->
103-
<!--</plugin>-->
78+
<plugin>
79+
<groupId>com.spotify</groupId>
80+
<artifactId>docker-maven-plugin</artifactId>
81+
<version>0.2.3</version>
82+
<executions>
83+
<execution>
84+
<id>build-image</id>
85+
<phase>install</phase>
86+
<goals>
87+
<goal>build</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
<configuration>
92+
<imageName>storage-service</imageName>
93+
<baseImage>java</baseImage>
94+
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
95+
<resources>
96+
<resource>
97+
<targetPath>/</targetPath>
98+
<directory>${project.build.directory}</directory>
99+
<include>${project.build.finalName}.jar</include>
100+
</resource>
101+
</resources>
102+
</configuration>
103+
</plugin>
104104
</plugins>
105105
</build>
106106

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_____ __ _
2+
/ ___// /_____ _________ _____ ____ ________ ______ __(_)_______
3+
\__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / ___/ _ \/ ___/ | / / / ___/ _ \
4+
___/ / /_/ /_/ / / / /_/ / /_/ / __/ (__ ) __/ / | |/ / / /__/ __/
5+
/____/\__/\____/_/ \__,_/\__, /\___/ /____/\___/_/ |___/_/\___/\___/
6+
/____/
7+
v.${application.version}

0 commit comments

Comments
 (0)