View Javadoc
1   /*
2    * Copyright 2009 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.xds.core.transform.hl7;
17  
18  import static org.junit.Assert.*;
19  
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
23  
24  /**
25   * Tests for transformation between HL7 v2 and {@link AssigningAuthority}.
26   * @author Jens Riemschneider
27   */
28  public class AssigningAuthorityTransformerTest {
29  
30      @Test
31      public void testToHL7() {
32          AssigningAuthority assigningAuthority = new AssigningAuthority();
33          assigningAuthority.setUniversalId("nam&ID_ui^ID");
34          assigningAuthority.setUniversalIdType("type|ID");
35          assertEquals("&nam\\T\\ID_ui\\S\\ID&type\\F\\ID", Hl7v2Based.render(assigningAuthority));
36      }
37      
38      @Test
39      public void testToHL7OptionalParams() {
40          AssigningAuthority assigningAuthority = new AssigningAuthority();
41          assigningAuthority.setUniversalIdType("type|ID");
42          assertEquals("&&type\\F\\ID", Hl7v2Based.render(assigningAuthority));
43      }
44      
45      @Test
46      public void testToHL7NoParams() {
47          assertNull(Hl7v2Based.render(new AssigningAuthority()));
48      }
49  
50      @Test
51      public void testToHL7Null() {
52          assertNull(Hl7v2Based.render(null));
53      }
54      
55  
56      @Test
57      public void testFromHL7() {
58          AssigningAuthority assigningAuthority =
59                  Hl7v2Based.parse("nam\\T\\ID&ui\\S\\ID&type\\F\\ID", AssigningAuthority.class);
60          assertEquals("ui^ID", assigningAuthority.getUniversalId());
61          assertEquals("type|ID", assigningAuthority.getUniversalIdType());
62      }
63      
64      @Test
65      public void testFromHL7NoParams() {
66          assertNull(Hl7v2Based.parse("", AssigningAuthority.class));
67      }
68  
69      @Test
70      public void testFromHL7OptionalParams() {
71          AssigningAuthority assigningAuthority = Hl7v2Based.parse("nam\\T\\ID&&type\\F\\ID", AssigningAuthority.class);
72          assertNull(assigningAuthority.getUniversalId());
73          assertEquals("type|ID", assigningAuthority.getUniversalIdType());
74      }
75      
76      @Test
77      public void testFromHL7Null() {
78          assertNull(Hl7v2Based.parse(null, AssigningAuthority.class));
79      }
80  
81      @Test
82      public void testFromHL7Nothing() {
83          assertNull(Hl7v2Based.parse("", AssigningAuthority.class));
84      }
85  }