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 2016/01/24 12:50:34 UTC

[2/9] camel git commit: Added unit test

Added unit test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0bb82e11
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0bb82e11
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0bb82e11

Branch: refs/heads/master
Commit: 0bb82e11b40e794163d56e2b97ea21adf9b69f1f
Parents: 9391f00
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Jan 24 12:16:31 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Jan 24 12:16:31 2016 +0100

----------------------------------------------------------------------
 .../component/hl7/HL7MLLPNettyRouteToTest.java  | 133 +++++++++++++++++++
 .../src/test/resources/log4j.properties         |  21 +--
 2 files changed, 144 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0bb82e11/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPNettyRouteToTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPNettyRouteToTest.java b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPNettyRouteToTest.java
new file mode 100644
index 0000000..642fdee
--- /dev/null
+++ b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7MLLPNettyRouteToTest.java
@@ -0,0 +1,133 @@
+/**
+ * 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.component.hl7;
+
+import ca.uhn.hl7v2.model.Message;
+import ca.uhn.hl7v2.model.v24.message.ADR_A19;
+import ca.uhn.hl7v2.model.v24.segment.MSA;
+import ca.uhn.hl7v2.model.v24.segment.MSH;
+import ca.uhn.hl7v2.model.v24.segment.QRD;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+/**
+ * Unit test for the HL7MLLPNetty Codec.
+ */
+public class HL7MLLPNettyRouteToTest extends HL7TestSupport {
+
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+
+        // START SNIPPET: e1
+        HL7MLLPNettyDecoderFactory decoder = new HL7MLLPNettyDecoderFactory();
+        decoder.setCharset("iso-8859-1");
+        decoder.setConvertLFtoCR(true);
+        jndi.bind("hl7decoder", decoder);
+
+        HL7MLLPNettyEncoderFactory encoder = new HL7MLLPNettyEncoderFactory();
+        decoder.setCharset("iso-8859-1");
+        decoder.setConvertLFtoCR(true);
+        jndi.bind("hl7encoder", encoder);
+        // END SNIPPET: e1
+
+        return jndi;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
+                    .process(new Processor() {
+                        @Override
+                        public void process(Exchange exchange) throws Exception {
+                            String body = exchange.getIn().getBody(String.class);
+                            System.out.println(body);
+                            log.info(body);
+                        }
+                    })
+                    .log("I was here ${body}")
+                    .to("mock:result");
+
+
+                from("netty4:tcp://127.0.0.1:" + getPort() + "?sync=true&decoder=#hl7decoder&encoder=#hl7encoder")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws Exception {
+                            Message input = exchange.getIn().getBody(Message.class);
+
+                            assertEquals("2.4", input.getVersion());
+                            QRD qrd = (QRD)input.get("QRD");
+                            assertEquals("0101701234", qrd.getWhoSubjectFilter(0).getIDNumber().getValue());
+
+                            Message response = createHL7AsMessage();
+                            exchange.getOut().setBody(response);
+                        }
+                    });
+            }
+        };
+    }
+
+    @Test
+    public void testSendHL7Message() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        // START SNIPPET: e2
+        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 = template.requestBody("direct:start", in.toString(), String.class);
+        // END SNIPPET: e2
+
+        String[] lines = out.split("\r");
+        assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADR^A19^ADR_A19|456|P|2.4", lines[0]);
+        assertEquals("MSA|AA|123", lines[1]);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    // START SNIPPET: e3
+    private static Message createHL7AsMessage() throws Exception {
+        ADR_A19 adr = new ADR_A19();
+        adr.initQuickstart("ADR", "A19", "P");
+
+        // Populate the MSH Segment
+        MSH mshSegment = adr.getMSH();
+        mshSegment.getDateTimeOfMessage().getTimeOfAnEvent().setValue("200701011539");
+        mshSegment.getSendingApplication().getNamespaceID().setValue("MYSENDER");
+        mshSegment.getMessageControlID().setValue("456");
+
+        // Populate the PID Segment
+        MSA msa = adr.getMSA();
+        msa.getAcknowledgementCode().setValue("AA");
+        msa.getMessageControlID().setValue("123");
+
+        QRD qrd = adr.getQRD();
+        qrd.getQueryDateTime().getTimeOfAnEvent().setValue("20080805120000");
+
+        return adr;
+    }
+    // END SNIPPET: e3
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0bb82e11/components/camel-hl7/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-hl7/src/test/resources/log4j.properties b/components/camel-hl7/src/test/resources/log4j.properties
index 5d0c9a9..e7a6576 100644
--- a/components/camel-hl7/src/test/resources/log4j.properties
+++ b/components/camel-hl7/src/test/resources/log4j.properties
@@ -1,4 +1,4 @@
-## ---------------------------------------------------------------------------
+## ------------------------------------------------------------------------
 ## 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.
@@ -13,23 +13,24 @@
 ## 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.
-## ---------------------------------------------------------------------------
+## ------------------------------------------------------------------------
 
 #
-# The logging properties used during tests..
+# The logging properties used for testing.
 #
-log4j.rootLogger=INFO, file
+log4j.rootLogger=INFO, out
+
+# uncomment the following to enable camel debugging
+#log4j.logger.org.apache.camel.component.hl7=DEBUG
 
 # CONSOLE appender not used by default
-log4j.appender.console=org.apache.log4j.ConsoleAppender
-log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
 
 # File appender
 log4j.appender.file=org.apache.log4j.FileAppender
 log4j.appender.file.layout=org.apache.log4j.PatternLayout
 log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
 log4j.appender.file.file=target/camel-hl7-test.log
-
-# debug loging for Camel
-log4j.logger.org.apache.camel.component.hl7=DEBUG