View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.hl7v2ws.pcd01;
17  
18  import org.junit.Test;
19  
20  import ca.uhn.hl7v2.HL7Exception;
21  
22  /**
23   * @author Kingsley Nwaigbo
24   * 
25   */
26  public class QA_Pcd01MSHValidatorTest extends AbstractPCD01ValidatorTest {
27  
28      @Test
29      public void testMaximalMessage() throws HL7Exception {
30          validate(maximumMessage);
31      }
32  
33      // ################ MSH Segment tests ###############################
34      @Test(expected = HL7Exception.class)
35      public void testMissingMSH3() throws HL7Exception {
36          validate(maxMsgReplace("AcmeInc^ACDE48234567ABCD^EUI-64", ""));
37      }
38  
39      @Test(expected = HL7Exception.class)
40      public void testMissingMSH7() throws HL7Exception  {
41          validate(maxMsgReplace("20090713090030+0500", ""));
42      }
43  
44      @Test(expected = HL7Exception.class)
45      public void testMissingMSH9() throws HL7Exception  {
46          validate(maxMsgReplace("ORU^R01^ORU_R01", ""));
47      }
48  
49      @Test(expected = HL7Exception.class)
50      public void testMissingMSH9dot1() throws HL7Exception  {
51          validate(maxMsgReplace("ORU^R01^ORU_R01", "^R01^ORU_R01"));
52      }
53  
54      @Test(expected = HL7Exception.class)
55      public void testMissingMSH9dot1_9dot3() throws HL7Exception  {
56          validate(maxMsgReplace("ORU^R01^ORU_R01", "^R01"));
57      }
58  
59      @Test(expected = Exception.class)
60      public void testMissingMSH9dot2_9dot3() throws HL7Exception  {
61          validate(maxMsgReplace("ORU^R01^ORU_R01", "ORU"));
62      }
63  
64      @Test(expected = HL7Exception.class)
65      public void testMissingMSH10() throws HL7Exception  {
66          validate(maxMsgReplace("MSGID1234", ""));
67      }
68  
69      @Test(expected = HL7Exception.class)
70      public void testMissingMSH11() throws HL7Exception  {
71          validate(maxMsgReplace("P", ""));
72      }
73  
74      @Test(expected = HL7Exception.class)
75      public void testWrongMSH11() throws HL7Exception  {
76          validate(maxMsgReplace("P", "X"));
77      }
78  
79      @Test(expected = HL7Exception.class)
80      public void testMissingMSH12() throws HL7Exception  {
81          validate(maxMsgReplace("2.6", ""));
82      }
83  
84      @Test(expected = HL7Exception.class)
85      public void testMissingMSH21() throws HL7Exception  {
86          validate(maxMsgReplace("IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO",
87                                 ""));
88      }
89  
90      @Test(expected = HL7Exception.class)
91      public void testMissingMSH21dot1() throws HL7Exception {
92          validate(maxMsgReplace("IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO",
93                                 "^HL7^2.16.840.1.113883.9.n.m^HL7"));
94      }
95  
96      @Test(expected = HL7Exception.class)
97      public void testMissingMSH21dot2_3_4() throws HL7Exception  {
98          validate(maxMsgReplace("IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO",
99                                 "IHE PCD ORU-R01 2006"));
100     }
101 
102     @Test(expected = HL7Exception.class)
103     public void testMissingMSH21dot2_3() throws HL7Exception {
104         validate(maxMsgReplace("IHE PCD ORU-R01 2006^HL7^1.3.6.1.4.1.19376.1.6.1.1.1^ISO",
105                                "IHE PCD ORU-R01 2006^^^HL7"));
106     }
107 
108 }