-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestConfig.java
More file actions
71 lines (61 loc) · 2.58 KB
/
Copy pathTestConfig.java
File metadata and controls
71 lines (61 loc) · 2.58 KB
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
66
67
68
69
70
71
package org.snomed.release.note;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.snomed.release.note.config.Config;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.elasticsearch.ElasticsearchContainer;
import org.testcontainers.junit.jupiter.Container;
@SpringBootApplication
@TestConfiguration
public class TestConfig extends Config {
private static final String ELASTIC_SEARCH_SERVER_VERSION = "8.11.1";
// set it to true to use local instance instead of test container
static final boolean useLocalElasticsearch = false;
private static final Logger LOGGER = LoggerFactory.getLogger(TestConfig.class);
@Container
private static final ElasticsearchContainer elasticsearchContainer;
static {
if (useLocalElasticsearch) {
elasticsearchContainer = null;
} else {
if (!DockerClientFactory.instance().isDockerAvailable()) {
LOGGER.error("No docker client available to run integration tests.");
LOGGER.info("Integration tests use the TestContainers framework.(https://www.testcontainers.org)");
LOGGER.info("TestContainers framework requires docker to be installed.(https://www.testcontainers.org/supported_docker_environment)");
LOGGER.info("You can download docker via (https://docs.docker.com/get-docker)");
System.exit(-1);
}
elasticsearchContainer = new TestElasticsearchContainer();
elasticsearchContainer.start();
}
}
public static class TestElasticsearchContainer extends ElasticsearchContainer {
public TestElasticsearchContainer() {
super("docker.elastic.co/elasticsearch/elasticsearch:" + ELASTIC_SEARCH_SERVER_VERSION);
// these are mapped ports used by the test container the actual ports used might be different
this.addFixedExposedPort(9235, 9235);
this.addFixedExposedPort(9330, 9330);
this.addEnv("xpack.security.enabled", "false");
this.addEnv("cluster.name", "integration-test-cluster");
}
}
static ElasticsearchContainer getElasticsearchContainerInstance() {
return elasticsearchContainer;
}
@Override
public @NotNull ClientConfiguration clientConfiguration() {
if (!useLocalElasticsearch) {
assert elasticsearchContainer != null;
return ClientConfiguration.builder()
.connectedTo(elasticsearchContainer.getHttpHostAddress())
.build();
}
return ClientConfiguration.builder()
.connectedToLocalhost()
.build();
}
}