Skip to content

Commit b179d62

Browse files
committed
Extended README for docker-compose-rule
1 parent c20a97f commit b179d62

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mvn clean install
4040
Only, if you want to check manually, you can do a `docker-compose up -d` and open your Browser with [http:localhost:8080/swagger-ui.html] and fire up a GET-Request to /secretservers with Swagger :)
4141

4242

43-
# Integrationtesting
43+
# Integrationtesting with [docker-compose-rule](https://github.com/palantir/docker-compose-rule)
4444

4545
As client-bob only has access to the DNS aliases `server-alice` and `server-tom`, if it itself is part of the Docker (Compose) network and these aliases are used to access both client certificate secured endpoints, we need another way to run an Integration test inside the Docker network scope.
4646

@@ -68,6 +68,49 @@ docker-compose-rule needs a special Maven repository to be added in `docker-netw
6868
</repositories>
6969
```
7070

71+
And the code you need, to fire up all Docker Compose services / Docker Containers is really simple:
72+
73+
```
74+
package de.jonashackt;
75+
76+
import com.palantir.docker.compose.DockerComposeRule;
77+
import com.palantir.docker.compose.connection.waiting.HealthChecks;
78+
import org.apache.http.HttpStatus;
79+
import org.junit.ClassRule;
80+
import org.junit.Test;
81+
import org.junit.runner.RunWith;
82+
import org.springframework.test.context.ContextConfiguration;
83+
import org.springframework.test.context.junit4.SpringRunner;
84+
85+
import static io.restassured.RestAssured.when;
86+
import static org.hamcrest.Matchers.containsString;
87+
88+
@RunWith(SpringRunner.class)
89+
@ContextConfiguration()
90+
public class ClientTest {
91+
92+
@ClassRule
93+
public static DockerComposeRule docker = DockerComposeRule.builder()
94+
.file("../docker-compose.yml")
95+
.waitingForService("server-alice", HealthChecks.toHaveAllPortsOpen())
96+
.waitingForService("server-tom", HealthChecks.toHaveAllPortsOpen())
97+
.waitingForService("client-bob", HealthChecks.toRespondOverHttp(8080, (port) -> port.inFormat("http://$HOST:$EXTERNAL_PORT/swagger-ui.html")))
98+
.build();
99+
100+
@Test
101+
public void is_client_bob_able_to_call_all_servers_with_client_certs() {
102+
103+
when()
104+
.get("http://localhost:8080/secretservers")
105+
.then()
106+
.statusCode(HttpStatus.SC_OK)
107+
.assertThat()
108+
.body(containsString("Both Servers called - Alice said 'Alice answering!' & Tom replied 'Tom answering!'."));
109+
}
110+
}
111+
112+
```
113+
71114
# TlDR: How to create multiple keys & certificates for multiple servers - and add these into appropriate truststores / keystores
72115

73116

0 commit comments

Comments
 (0)