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.assertEquals;
19  import static org.junit.Assert.assertNull;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
24  
25  /**
26   * Tests for transformations between HL7 v2 and {@link Person}.
27   * @author Jens Riemschneider
28   */
29  public class PersonTransformerTest {
30      private Person person;
31  
32      @Before
33      public void setUp() {
34          AssigningAuthority assigningAuthority = new AssigningAuthority("1.2&.3.4", "he&llo_WU&RZ");
35          Identifiable id = new Identifiable("u^fz", assigningAuthority);
36          Name name = new XcnName("Seu&fzer", "Em&il", "Ant|on", "der&7.", "D&r.", null);
37          person = new Person(id, name);
38      }
39      
40      @Test
41      public void testToHL7() {
42          assertEquals("u\\S\\fz^Seu\\T\\fzer^Em\\T\\il^Ant\\F\\on^der\\T\\7.^D\\T\\r.^^^&1.2\\T\\.3.4&he\\T\\llo_WU\\T\\RZ",
43                  Hl7v2Based.render(person));
44      }
45  
46      @Test
47      public void testToHL7NoName() {
48          person.setName(null);
49          assertEquals("u\\S\\fz^^^^^^^^&1.2\\T\\.3.4&he\\T\\llo_WU\\T\\RZ",
50                  Hl7v2Based.render(person));
51      }
52  
53      @Test
54      public void testToHL7NoID() {
55          person.setId(null);
56          assertEquals("^Seu\\T\\fzer^Em\\T\\il^Ant\\F\\on^der\\T\\7.^D\\T\\r.", Hl7v2Based.render(person));
57      }
58  
59      @Test
60      public void testToHL7Empty() {
61          assertNull(Hl7v2Based.render(new Person()));
62      }
63      
64      @Test
65      public void testToHL7WithNullParam() {
66          assertNull(Hl7v2Based.render(null));
67      }
68      
69  
70      @Test
71      public void testFromHL7() {
72          Person result = Hl7v2Based.parse(
73                  "u\\S\\fz^Seu\\T\\fzer^Em\\T\\il^Ant\\F\\on^der\\T\\7.^D\\T\\r.^^^&1.2\\T\\.3.4&he\\T\\llo_WU\\T\\RZ",
74                  Person.class);
75  
76          assertEquals(person, result);
77      }
78  
79      @Test
80      public void testFromHL7NoIDNumber() {
81          Person result = Hl7v2Based.parse("^Seu\\T\\fzer^Em\\T\\il^Ant\\F\\on^der\\T\\7.^D\\T\\r.", Person.class);
82  
83          person.setId(null);
84          assertEquals(person, result);
85      }
86      
87      @Test
88      public void testFromHL7NoName() {
89          Person result = Hl7v2Based.parse("u\\S\\fz^^^^^^^^&1.2\\T\\.3.4&he\\T\\llo_WU\\T\\RZ", Person.class);
90  
91          person.setName(null);
92          assertEquals(person, result);
93      }
94      
95      @Test
96      public void testFromHL7Empty() {
97          assertNull(Hl7v2Based.parse("", Person.class));
98      }
99  
100     @Test
101     public void testFromHL7WithNullParam() {
102         assertNull(Hl7v2Based.parse(null, Person.class));
103     }    
104 }