You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/08/25 13:36:56 UTC

[camel-quarkus] branch main updated: Add ability to test HL7 extension with multiple HAPI implementations

This is an automated email from the ASF dual-hosted git repository.

ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/main by this push:
     new 1fa3f1e  Add ability to test HL7 extension with multiple HAPI implementations
1fa3f1e is described below

commit 1fa3f1e958072b81aeb3dea121f8166a8b0ca286
Author: James Netherton <ja...@gmail.com>
AuthorDate: Wed Aug 25 11:30:28 2021 +0100

    Add ability to test HL7 extension with multiple HAPI implementations
    
    Fixes #2744
---
 integration-tests/hl7/pom.xml                      | 43 ++++++++++++++++++++++
 .../quarkus/component/hl7/it/Hl7Resource.java      | 13 +++++++
 .../camel/quarkus/component/hl7/it/Hl7Test.java    | 21 +++++++++++
 3 files changed, 77 insertions(+)

diff --git a/integration-tests/hl7/pom.xml b/integration-tests/hl7/pom.xml
index 8578794..bcc08b2 100644
--- a/integration-tests/hl7/pom.xml
+++ b/integration-tests/hl7/pom.xml
@@ -188,6 +188,49 @@
                 </plugins>
             </build>
         </profile>
+
+        <!--
+            To enable testing with additional HAPI model versions supported by Camel
+            Disabled by default due to the impact on native build times
+        -->
+        <profile>
+            <id>hapi.all</id>
+            <activation>
+                <property>
+                    <name>hapi.all</name>
+                </property>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v21</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v23</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v231</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v24</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v25</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v251</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>ca.uhn.hapi</groupId>
+                    <artifactId>hapi-structures-v26</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
     </profiles>
 
 </project>
diff --git a/integration-tests/hl7/src/main/java/org/apache/camel/quarkus/component/hl7/it/Hl7Resource.java b/integration-tests/hl7/src/main/java/org/apache/camel/quarkus/component/hl7/it/Hl7Resource.java
index 6672e27..b6c0f8f 100644
--- a/integration-tests/hl7/src/main/java/org/apache/camel/quarkus/component/hl7/it/Hl7Resource.java
+++ b/integration-tests/hl7/src/main/java/org/apache/camel/quarkus/component/hl7/it/Hl7Resource.java
@@ -27,11 +27,13 @@ import javax.json.JsonObjectBuilder;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
+import ca.uhn.hl7v2.model.AbstractMessage;
 import ca.uhn.hl7v2.model.v22.datatype.AD;
 import ca.uhn.hl7v2.model.v22.datatype.CK;
 import ca.uhn.hl7v2.model.v22.datatype.PN;
@@ -150,6 +152,17 @@ public class Hl7Resource {
         return producerTemplate.requestBody("direct:ack", message, String.class);
     }
 
+    @Path("/convert/{version}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String convertStringToAdt(@PathParam("version") String version, String message) throws ClassNotFoundException {
+        String adtClassName = "ca.uhn.hl7v2.model." + version.toLowerCase() + ".message.ADT_A01";
+        Class<?> adtClass = Class.forName(adtClassName);
+        AbstractMessage result = (AbstractMessage) context.getTypeConverter().convertTo(adtClass, message);
+        return result.getMessage().getVersion();
+    }
+
     private JsonObject adtToJsonObject(ADT_A01 result) {
         JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
 
diff --git a/integration-tests/hl7/src/test/java/org/apache/camel/quarkus/component/hl7/it/Hl7Test.java b/integration-tests/hl7/src/test/java/org/apache/camel/quarkus/component/hl7/it/Hl7Test.java
index 60ec127..a69fdcd 100644
--- a/integration-tests/hl7/src/test/java/org/apache/camel/quarkus/component/hl7/it/Hl7Test.java
+++ b/integration-tests/hl7/src/test/java/org/apache/camel/quarkus/component/hl7/it/Hl7Test.java
@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets;
 
 import ca.uhn.hl7v2.DefaultHapiContext;
 import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.Version;
 import ca.uhn.hl7v2.model.Message;
 import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
 import ca.uhn.hl7v2.parser.GenericParser;
@@ -34,6 +35,8 @@ import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import org.apache.commons.io.IOUtils;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.endsWith;
@@ -208,6 +211,24 @@ class Hl7Test {
                 .body(containsString("MSA|CA"));
     }
 
+    @ParameterizedTest
+    @MethodSource("hapiVersions")
+    public void hl7TypeConverter(String version) {
+        RestAssured.given()
+                .body(PID_MESSAGE)
+                .post("/hl7/convert/" + version)
+                .then()
+                .statusCode(200)
+                .body(is(Version.valueOf(version).getVersion()));
+    }
+
+    public static String[] hapiVersions() {
+        return Version.availableVersions()
+                .stream()
+                .map(Version::toString)
+                .toArray(String[]::new);
+    }
+
     private static final String readPidFile() {
         try {
             String pidContent = IOUtils.toString(Hl7Test.class.getResourceAsStream("/hl7-2.2-pid.txt"), StandardCharsets.UTF_8);