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 2009/07/29 17:04:15 UTC

svn commit: r798934 - /camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java

Author: davsclaus
Date: Wed Jul 29 15:04:15 2009
New Revision: 798934

URL: http://svn.apache.org/viewvc?rev=798934&view=rev
Log:
CAMEL-1863: Added HL7 example that fails validation.

Modified:
    camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java

Modified: camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java?rev=798934&r1=798933&r2=798934&view=diff
==============================================================================
--- camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java (original)
+++ camel/trunk/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java Wed Jul 29 15:04:15 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hl7;
 
 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;
@@ -28,22 +29,23 @@
  */
 public class HL7ValidateTest extends CamelTestSupport {
 
-// TODO: Need HL7 that can fail HL7 validator
-//    @Test
-//    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());
-//        }
-//
-//        assertMockEndpointsSatisfied();
-//    }
+    @Test
+    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();
+    }
 
     @Test
     public void testUnmarshalOk() throws Exception {
@@ -67,13 +69,31 @@
     }
 
     private static String createHL7AsString() {
-        String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||QRY^A19|1234|P|2.4";
-        String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";
+        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||||||||";
 
         StringBuffer body = new StringBuffer();
         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();
     }