Add annotation to skip test classes which require docker if it is not found on the host
This commit is contained in:
parent
17d74648de
commit
edbc789a93
|
@ -19,6 +19,7 @@ import ca.uhn.fhir.rest.param.TokenAndListParam;
|
|||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||
import ca.uhn.fhir.test.utilities.docker.RequiresDocker;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.DateTimeType;
|
||||
|
@ -50,6 +51,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@RequiresDocker
|
||||
@ContextConfiguration(classes = {TestR4ConfigWithElasticsearchClient.class})
|
||||
public class BaseR4SearchLastN extends BaseJpaTest {
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import ca.uhn.fhir.test.utilities.docker.RequiresDocker;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
|
@ -59,6 +60,7 @@ import ca.uhn.fhir.validation.FhirValidator;
|
|||
import ca.uhn.fhir.validation.ValidationResult;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@RequiresDocker
|
||||
@ContextConfiguration(classes = {TestR4ConfigWithElasticSearch.class})
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
|
||||
public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
|
||||
|
|
|
@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry;
|
|||
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
|
||||
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
|
||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||
import ca.uhn.fhir.test.utilities.docker.RequiresDocker;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.CodeSystem;
|
||||
|
@ -45,6 +46,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@RequiresDocker
|
||||
@ContextConfiguration(classes = {TestR4ConfigWithElasticSearch.class})
|
||||
public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest {
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson;
|
|||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
import ca.uhn.fhir.test.utilities.docker.RequiresDocker;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
|
@ -47,6 +48,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@RequiresDocker
|
||||
@ContextConfiguration(classes = {TestR4ConfigWithElasticsearchClient.class})
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class PersistObservationIndexedSearchParamLastNR4IT {
|
||||
|
|
|
@ -18,6 +18,7 @@ import ca.uhn.fhir.rest.param.TokenAndListParam;
|
|||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParamModifier;
|
||||
import ca.uhn.fhir.test.utilities.docker.RequiresDocker;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -27,6 +28,7 @@ import org.junit.jupiter.api.BeforeAll;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
@ -57,7 +59,8 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ExtendWith({SpringExtension.class})
|
||||
@RequiresDocker
|
||||
@Testcontainers
|
||||
public class LastNElasticsearchSvcMultipleObservationsIT {
|
||||
|
||||
|
@ -70,9 +73,12 @@ public class LastNElasticsearchSvcMultipleObservationsIT {
|
|||
|
||||
private final FhirContext myFhirContext = FhirContext.forCached(FhirVersionEnum.R4);
|
||||
|
||||
|
||||
@Container
|
||||
public static ElasticsearchContainer elasticsearchContainer = TestElasticsearchContainerHelper.getEmbeddedElasticSearch();
|
||||
|
||||
|
||||
|
||||
private ElasticsearchSvcImpl elasticsearchSvc;
|
||||
|
||||
@BeforeEach
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package ca.uhn.fhir.jpa.search.lastn.config;
|
||||
|
||||
import com.github.dockerjava.api.exception.InternalServerErrorException;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
import java.time.Duration;
|
||||
|
@ -13,6 +18,7 @@ public class TestElasticsearchContainerHelper {
|
|||
public static final String ELASTICSEARCH_IMAGE = "docker.elastic.co/elasticsearch/elasticsearch:" + ELASTICSEARCH_VERSION;
|
||||
|
||||
public static ElasticsearchContainer getEmbeddedElasticSearch() {
|
||||
|
||||
return new ElasticsearchContainer(ELASTICSEARCH_IMAGE)
|
||||
.withStartupTimeout(Duration.of(300, SECONDS));
|
||||
}
|
||||
|
|
|
@ -68,5 +68,5 @@
|
|||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -95,8 +95,13 @@
|
|||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package ca.uhn.fhir.test.utilities.docker;
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.testcontainers.elasticsearch.ElasticsearchContainer;
|
||||
|
||||
|
||||
/**
|
||||
* Execution condition which will skip test classes that require docker if it is not present on the host machine
|
||||
*/
|
||||
public class DockerRequiredCondition implements ExecutionCondition {
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext theExtensionContext) {
|
||||
try {
|
||||
new ElasticsearchContainer();
|
||||
return ConditionEvaluationResult.enabled("Docker is installed so we can run these tests!");
|
||||
} catch (Exception e) {
|
||||
return ConditionEvaluationResult.disabled("It appears as though docker is not installed on the host machine!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package ca.uhn.fhir.test.utilities.docker;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ExtendWith(DockerRequiredCondition.class)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface RequiresDocker {
|
||||
}
|
Loading…
Reference in New Issue