You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/20 13:45:34 UTC

svn commit: r998896 - in /camel/trunk/tests/camel-itest-osgi: ./ src/test/java/org/apache/camel/itest/osgi/hl7/ src/test/resources/org/apache/camel/itest/osgi/hl7/

Author: davsclaus
Date: Mon Sep 20 11:45:34 2010
New Revision: 998896

URL: http://svn.apache.org/viewvc?rev=998896&view=rev
Log:
CAMEL-3126: Added more osgi tests.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7DataFormatTest.java
      - copied, changed from r998823, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7MLLPCodecTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/CamelContext.xml
      - copied, changed from r998888, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml
Modified:
    camel/trunk/tests/camel-itest-osgi/pom.xml

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=998896&r1=998895&r2=998896&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Mon Sep 20 11:45:34 2010
@@ -36,6 +36,11 @@
       <id>biz.aQute</id>
       <url>http://www.aqute.biz/repo</url>
     </repository>
+    <repository>
+      <id>hapi</id>
+      <name>HAPI Maven Repository</name>
+      <url>http://hl7api.sourceforge.net/m2/</url>
+    </repository>
   </repositories>
 
   <dependencies>
@@ -111,6 +116,17 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-hl7</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>ca.uhn.hapi</groupId>
+      <artifactId>hapi-structures-v24</artifactId>
+      <version>1.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-shiro</artifactId>
       <scope>test</scope>
     </dependency>

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7DataFormatTest.java (from r998823, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7DataFormatTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7DataFormatTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java&r1=998823&r2=998896&rev=998896&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/freemarker/FreemarkerTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7DataFormatTest.java Mon Sep 20 11:45:34 2010
@@ -14,13 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.freemarker;
+package org.apache.camel.itest.osgi.hl7;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
+import ca.uhn.hl7v2.HL7Exception;
+import ca.uhn.hl7v2.model.DataTypeException;
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,49 +36,92 @@ import static org.ops4j.pax.exam.contain
 import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
 
 @RunWith(JUnit4TestRunner.class)
-public class FreemarkerTest extends OSGiIntegrationTestSupport {
-    
+public class HL7DataFormatTest extends OSGiIntegrationTestSupport {
+
     @Test
-    public void testReceivesResponse() throws Exception {        
-        assertRespondsWith("foo", "<hello>foo</hello>");
-        assertRespondsWith("bar", "<hello>bar</hello>");
+    public void testUnmarshalFailed() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(0);
+
+        String body = createHL7AsString();
+        try {
+            template.sendBody("direct:unmarshalFailed", body);
+            fail("Should have thrown exception");
+        } catch (CamelExecutionException e) {
+            assertIsInstanceOf(HL7Exception.class, e.getCause());
+            assertIsInstanceOf(DataTypeException.class, e.getCause());
+            assertTrue("Should be a validation error message", e.getCause().getMessage().startsWith("Failed validation rule"));
+        }
+
+        assertMockEndpointsSatisfied();
     }
 
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException {
-        Exchange response = template.request("direct:a", new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
-            }
-        });
-        assertOutMessageBodyEquals(response, expectedBody);
+    @Test
+    public void testUnmarshalOk() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(1);
+
+        String body = createHL7AsString();
+        template.sendBody("direct:unmarshalOk", body);
+
+        assertMockEndpointsSatisfied();
     }
 
-    protected RouteBuilder createRouteBuilder() {
+    protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
-            public void configure() {
-                from("direct:a").to("freemarker:org/apache/camel/itest/osgi/freemarker/example.ftl");
+            public void configure() throws Exception {
+                from("direct:unmarshalFailed").unmarshal().hl7().to("mock:unmarshal");
+
+                from("direct:unmarshalOk").unmarshal().hl7(false).to("mock:unmarshal");
             }
         };
     }
-    
+
+    private static String createHL7AsString() {
+        String line1 = "MSH|^~\\&|REQUESTING|ICE|INHOUSE|RTH00|20080808093202||ORM^O01|0808080932027444985|P|2.4|||AL|NE|||";
+        String line2 = "PID|1||ICE999999^^^ICE^ICE||Testpatient^Testy^^^Mr||19740401|M|||123 Barrel Drive^^^^SW18 4RT|||||2||||||||||||||";
+        String line3 = "NTE|1||Free text for entering clinical details|";
+        String line4 = "PV1|1||^^^^^^^^Admin Location|||||||||||||||NHS|";
+        String line5 = "ORC|NW|213||175|REQ||||20080808093202|ahsl^^Administrator||G999999^TestDoctor^GPtests^^^^^^NAT|^^^^^^^^Admin Location | 819600|200808080932||RTH00||ahsl^^Administrator||";
+        String line6 = "OBR|1|213||CCOR^Serum Cortisol ^ JRH06|||200808080932||0.100||||||^|G999999^TestDoctor^GPtests^^^^^^NAT|819600|ADM162||||||820|||^^^^^R||||||||";
+        String line7 = "OBR|2|213||GCU^Serum Copper ^ JRH06 |||200808080932||0.100||||||^|G999999^TestDoctor^GPtests^^^^^^NAT|819600|ADM162||||||820|||^^^^^R||||||||";
+        String line8 = "OBR|3|213||THYG^Serum Thyroglobulin ^JRH06|||200808080932||0.100||||||^|G999999^TestDoctor^GPtests^^^^^^NAT|819600|ADM162||||||820|||^^^^^R||||||||";
+
+        StringBuilder body = new StringBuilder();
+        body.append(line1);
+        body.append("\n");
+        body.append(line2);
+        body.append("\n");
+        body.append(line3);
+        body.append("\n");
+        body.append(line4);
+        body.append("\n");
+        body.append(line5);
+        body.append("\n");
+        body.append(line6);
+        body.append("\n");
+        body.append(line7);
+        body.append("\n");
+        body.append(line8);
+        return body.toString();
+    }
+
     @Configuration
     public static Option[] configure() {
         Option[] options = options(
-            // install the spring dm profile            
-            profile("spring.dm").version("1.2.0"),    
+            // install the spring dm profile
+            profile("spring.dm").version("1.2.0"),
             // this is how you set the default log level when using pax logging (logProfile)
             org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
-            
-            // using the features to install the camel components             
-            scanFeatures(getCamelKarafFeatureUrl(),                         
-                          "camel-core", "camel-spring", "camel-test", "camel-freemarker"),
-            
+
+            // using the features to install the camel components
+            scanFeatures(getCamelKarafFeatureUrl(),
+                          "camel-core", "camel-spring", "camel-test", "camel-hl7"),
+
             workingDirectory("target/paxrunner/"),
 
             felix(), equinox());
-        
+
         return options;
     }
 }
\ No newline at end of file

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7MLLPCodecTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7MLLPCodecTest.java?rev=998896&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7MLLPCodecTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/hl7/HL7MLLPCodecTest.java Mon Sep 20 11:45:34 2010
@@ -0,0 +1,88 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.itest.osgi.hl7;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
+
+@RunWith(JUnit4TestRunner.class)
+public class HL7MLLPCodecTest extends OSGiIntegrationSpringTestSupport implements Processor {
+
+    @Override
+    protected OsgiBundleXmlApplicationContext createApplicationContext() {
+        return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/hl7/CamelContext.xml"});
+    }
+
+    @Test
+    public void testSendHL7Message() throws Exception {
+        String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4";
+        String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";
+
+        StringBuilder in = new StringBuilder();
+        in.append(line1);
+        in.append("\n");
+        in.append(line2);
+
+        String out = (String)template.requestBody("mina:tcp://127.0.0.1:8888?sync=true&codec=#hl7codec", in.toString());
+
+        String[] lines = out.split("\r");
+        assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123", lines[0]);
+        assertEquals("MSA|AA|123", lines[1]);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        String out = "MSH|^~\\&|MYSENDER||||200701011539||ADR^A19||||123\rMSA|AA|123\n"; 
+        exchange.getOut().setBody(out);
+    }
+
+    @Configuration
+    public static Option[] configure() {
+        Option[] options = options(
+            // install the spring dm profile
+            profile("spring.dm").version("1.2.0"),
+            // this is how you set the default log level when using pax logging (logProfile)
+            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
+            // using the features to install the camel components
+            scanFeatures(getCamelKarafFeatureUrl(),
+                          "camel-core", "camel-spring", "camel-test", "camel-mina", "camel-hl7"),
+
+            // add hl7 osgi bundle
+            mavenBundle().groupId("http://hl7api.sourceforge.net/m2/!ca.uhn.hapi").artifactId("hapi-osgi-base").version("1.0.1"),
+
+            workingDirectory("target/paxrunner/"),
+
+            felix(), equinox());
+
+        return options;
+    }
+}
\ No newline at end of file

Copied: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/CamelContext.xml (from r998888, camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/CamelContext.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/CamelContext.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml&r1=998888&r2=998896&rev=998896&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/jms/CamelContext.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/hl7/CamelContext.xml Mon Sep 20 11:45:34 2010
@@ -23,19 +23,18 @@
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
+    <bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
+        <property name="charset" value="iso-8859-1"/>
+    </bean>
+
+    <bean id="responseBean" class="org.apache.camel.itest.osgi.hl7.HL7MLLPCodecTest"/>
+
     <camelContext xmlns="http://camel.apache.org/schema/spring">
         <camel:route>
-            <camel:from uri="activemq:queue:foo"/>
+            <camel:from uri="mina:tcp://127.0.0.1:8888?sync=true&amp;codec=#hl7codec"/>
+            <camel:process ref="responseBean"/>
             <camel:to uri="mock:result"/>
         </camel:route>
     </camelContext>
 
-    <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
-        <property name="connectionFactory">
-            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
-                <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
-            </bean>
-        </property>
-    </bean>
-
 </beans>