This is an automated email from the ASF dual-hosted git repository. jpoth pushed a commit to branch fhir in repository https://gitbox.apache.org/repos/asf/camel-spring-boot-examples.git
commit ce63a075d77e208f24fe411352df2d1dc693592f Author: John Poth <poth.j...@gmail.com> AuthorDate: Wed Jun 26 17:16:06 2024 +0200 fhir: move to test-infra --- fhir/pom.xml | 9 ++- fhir/src/main/java/sample/camel/MyCamelRouter.java | 2 +- fhir/src/main/resources/application.properties | 4 +- .../java/sample/camel/MyCamelApplicationTest.java | 67 +++++++++------------- 4 files changed, 36 insertions(+), 46 deletions(-) diff --git a/fhir/pom.xml b/fhir/pom.xml index 9045973..4fbf3ca 100644 --- a/fhir/pom.xml +++ b/fhir/pom.xml @@ -111,10 +111,13 @@ <artifactId>junit-vintage-engine</artifactId> <scope>test</scope> </dependency> + <!-- test infra --> <dependency> - <groupId>org.testcontainers</groupId> - <artifactId>testcontainers</artifactId> - <version>${testcontainers-version}</version> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-infra-fhir</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> </dependency> </dependencies> diff --git a/fhir/src/main/java/sample/camel/MyCamelRouter.java b/fhir/src/main/java/sample/camel/MyCamelRouter.java index 4d0efbd..35af825 100644 --- a/fhir/src/main/java/sample/camel/MyCamelRouter.java +++ b/fhir/src/main/java/sample/camel/MyCamelRouter.java @@ -22,7 +22,7 @@ import ca.uhn.hl7v2.model.v24.segment.PID; import org.apache.camel.LoggingLevel; import org.apache.camel.builder.RouteBuilder; import org.apache.http.ProtocolException; -import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.r4.model.Patient; import org.springframework.stereotype.Component; /** diff --git a/fhir/src/main/resources/application.properties b/fhir/src/main/resources/application.properties index e008cad..e318c57 100644 --- a/fhir/src/main/resources/application.properties +++ b/fhir/src/main/resources/application.properties @@ -15,9 +15,9 @@ ## limitations under the License. ## --------------------------------------------------------------------------- -serverUrl=http://localhost:8081/hapi-fhir-jpaserver/fhir +serverUrl=http://localhost:8081/fhir -fhirVersion=DSTU3 +fhirVersion=R4 input=target/work/fhir/input diff --git a/fhir/src/test/java/sample/camel/MyCamelApplicationTest.java b/fhir/src/test/java/sample/camel/MyCamelApplicationTest.java index 0eeafca..ae63fde 100644 --- a/fhir/src/test/java/sample/camel/MyCamelApplicationTest.java +++ b/fhir/src/test/java/sample/camel/MyCamelApplicationTest.java @@ -16,41 +16,32 @@ */ package sample.camel; +import java.io.File; +import java.util.concurrent.TimeUnit; + import org.apache.camel.CamelContext; import org.apache.camel.ProducerTemplate; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.spring.boot.CamelContextConfiguration; +import org.apache.camel.test.infra.fhir.services.FhirService; +import org.apache.camel.test.infra.fhir.services.FhirServiceFactory; import org.apache.camel.test.spring.junit5.CamelSpringBootTest; import org.apache.commons.io.FileUtils; - +import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; - -import org.hl7.fhir.dstu3.model.Patient; +import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -import com.github.dockerjava.api.command.CreateContainerCmd; -import com.github.dockerjava.api.model.ExposedPort; -import com.github.dockerjava.api.model.PortBinding; -import com.github.dockerjava.api.model.Ports; - -import java.io.File; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; +import org.springframework.context.annotation.Bean; @CamelSpringBootTest -@SpringBootTest(classes = MyCamelApplication.class, +@SpringBootTest(classes = {MyCamelApplication.class, MyCamelApplicationTest.class}, properties = "input = target/work/fhir/testinput") public class MyCamelApplicationTest { - private static final int CONTAINER_PORT = 8080; - private static final int EXPOSED_PORT = 8081; - private static final String CONTAINER_IMAGE = "hapiproject/hapi:v4.2.0"; - - private static GenericContainer container; + @RegisterExtension + public static FhirService service = FhirServiceFactory.createSingletonService(); @Autowired private CamelContext camelContext; @@ -58,25 +49,6 @@ public class MyCamelApplicationTest { @Autowired private ProducerTemplate producerTemplate; - @BeforeAll - public static void startServer() throws Exception { - Consumer<CreateContainerCmd> cmd = e -> { - e.withPortBindings(new PortBinding(Ports.Binding.bindPort(EXPOSED_PORT), - new ExposedPort(CONTAINER_PORT))); - }; - - container = new GenericContainer(CONTAINER_IMAGE) - .withNetworkAliases("fhir") - .withExposedPorts(CONTAINER_PORT) - .withCreateContainerCmdModifier(cmd) - .withEnv("HAPI_FHIR_VERSION", "DSTU3") - .withEnv("HAPI_REUSE_CACHED_SEARCH_RESULTS_MILLIS", "-1") - .waitingFor(Wait.forListeningPort()) - .waitingFor(Wait.forHttp("/hapi-fhir-jpaserver/fhir/metadata")); - ; - container.start(); - } - @Test public void shouldPushConvertedHl7toFhir() throws Exception { MockEndpoint mock = camelContext.getEndpoint("mock:result", MockEndpoint.class); @@ -89,4 +61,19 @@ public class MyCamelApplicationTest { mock.assertIsSatisfied(); Assertions.assertEquals("Freeman", mock.getExchanges().get(0).getIn().getBody(Patient.class).getName().get(0).getFamily()); } + + @Bean + CamelContextConfiguration contextConfiguration() { + return new CamelContextConfiguration() { + @Override + public void beforeApplicationStart(CamelContext context) { + context.getPropertiesComponent().addInitialProperty("serverUrl", service.getServiceBaseURL()); + } + + @Override + public void afterApplicationStart(CamelContext camelContext) { + + } + }; + } }