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.Test;
22  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Organization;
25  
26  /**
27   * Tests for transformation between HL7 v2 and {@link Organization}.
28   * @author Jens Riemschneider
29   */
30  public class OrganizationTransformerTest {
31      @Test
32      public void testToHL7() {
33          AssigningAuthority assigningAuthority = new AssigningAuthority();
34          assigningAuthority.setUniversalId("1.2&.3.4");
35          assigningAuthority.setUniversalIdType("he&llo_WU&RZ");
36  
37          Organization organization = new Organization();
38          organization.setOrganizationName("Untere&Klinik");
39          organization.setIdNumber("a|number");
40          organization.setAssigningAuthority(assigningAuthority);
41          
42          assertEquals("Untere\\T\\Klinik^^^^^&1.2\\T\\.3.4&he\\T\\llo_WU\\T\\RZ^^^^a\\F\\number",
43                  Hl7v2Based.render(organization));
44      }
45  
46      @Test
47      public void testToHL7Empty() {
48          assertNull(Hl7v2Based.render(new Organization()));
49      }
50  
51  
52      @Test
53      public void testFromHL7() {
54          Organization organization = Hl7v2Based.parse(
55                  "Untere\\T\\Klinik^^^^^he\\T\\llo&1.2\\T\\.3.4&WU\\T\\RZ^^^^a\\F\\number",
56                  Organization.class);
57  
58          assertEquals("Untere&Klinik", organization.getOrganizationName());
59          assertEquals("a|number", organization.getIdNumber());
60          assertEquals("1.2&.3.4", organization.getAssigningAuthority().getUniversalId());
61          assertEquals("WU&RZ", organization.getAssigningAuthority().getUniversalIdType());
62      }
63  
64      @Test
65      public void testFromHL7WithNullParam() {
66          assertNull(Hl7v2Based.parse(null, Organization.class));
67      }    
68  
69      @Test
70      public void testFromHL7WithEmptyParam() {
71          assertNull(Hl7v2Based.parse("", Organization.class));
72      }    
73  }