This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppIT.java
65 lines (52 loc) · 2.29 KB
/
AppIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package schulte.markus.dockercomposerulesparkdemo;
import com.palantir.docker.compose.DockerComposeRule;
import com.palantir.docker.compose.connection.DockerMachine;
import java.io.IOException;
import org.apache.http.client.fluent.Request;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
public class AppIT {
private static final String DOCKER_COMPOSE_YML_FILE = "src/test/resources/docker-compose.yml";
private static final int SPARK_DEFAULT_PORT = 4567;
private static final String SPARK_HELLO_WORLD_SERVICE_NAME = "spark-hello-world-service";
private static final String SPARK_HELLO_WORLD_SERVICE_VERSION_ENV_VAR_NAME
= "SPARK_HELLO_WORLD_SERVICE_VERSION";
@Rule
public final DockerComposeRule docker;
{
// As docker-image, use the one for this git-commit-id (which was created while "mvn package")
final var optionalGitCommitId = GitHelper.getCommitId();
Assume.assumeTrue("Git commit id has to be available", optionalGitCommitId.isPresent());
final var dockerMachine = DockerMachine.localMachine()
.withAdditionalEnvironmentVariable(AppIT.SPARK_HELLO_WORLD_SERVICE_VERSION_ENV_VAR_NAME,
optionalGitCommitId.get())
.build();
this.docker = DockerComposeRule.builder()
.file(AppIT.DOCKER_COMPOSE_YML_FILE)
.machine(dockerMachine)
.build();
}
@Test
public void test() throws IOException {
final var sparkHelloWorldServiceUrl = this.getSparkHelloWorldServiceUrl();
final var content = Request.Get(sparkHelloWorldServiceUrl + App.PATH)
.execute()
.returnContent();
Assert.assertEquals(App.HELLO_WORLD_HTML_CONTENT, content.asString());
}
/**
* @return URL of started spark-hello-world-service (for this git-commit-id).
* "http://127.0.0.1:32775", for example.
*/
private String getSparkHelloWorldServiceUrl() {
// Get ip and port of started spark-hello-world-service
final var serviceDockerPort = this.docker.containers()
.container(AppIT.SPARK_HELLO_WORLD_SERVICE_NAME)
.port(AppIT.SPARK_DEFAULT_PORT);
// Create url (http://...), which is the one for the just started spark-hello-world-service in it's docker-container
return String
.format("http://%s:%d", serviceDockerPort.getIp(), serviceDockerPort.getExternalPort());
}
}