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.ebxml;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
21  
22  import static org.junit.Assert.*;
23  
24  /**
25   * Tests for {@link RecipientTransformer}.
26   * @author Jens Riemschneider
27   */
28  public class RecipientTransformerTest {
29      private RecipientTransformer transformer;
30      private Recipient recipient;
31      
32      @Before
33      public void setUp() {
34          transformer = new RecipientTransformer();
35  
36          AssigningAuthority assigningAuthority1 = new AssigningAuthority("uni1", "uniType1");
37          Organization organization = new Organization("orgName", "orgId", assigningAuthority1);
38          
39          AssigningAuthority assigningAuthority2 = new AssigningAuthority("uni2", "uniType2");
40          Identifiable id = new Identifiable("personId", assigningAuthority2);        
41          Name name = new XpnName("familyName", "givenName", "second", "suffix", "prefix", "degree");
42          Person person = new Person(id, name);
43          Telecom telecom = new Telecom(41L, 162L, 7773L, null);
44  
45          recipient = new Recipient();
46          recipient.setOrganization(organization);
47          recipient.setPerson(person);
48          recipient.setTelecom(telecom);
49      }
50      
51      @Test
52      public void testToEbXML() {
53          String ebXML = transformer.toEbXML(recipient);
54          assertNotNull(ebXML);
55          
56          assertEquals("orgName^^^^^&uni1&uniType1^^^^orgId|personId^familyName^givenName^second^suffix^prefix^degree^^&uni2&uniType2|^PRN^PH^^41^162^7773",
57                  ebXML);
58      }
59      
60      @Test
61      public void testToEbXMLNoPerson() {
62          recipient.setPerson(null);
63          String ebXML = transformer.toEbXML(recipient);
64          assertNotNull(ebXML);
65          
66          assertEquals("orgName^^^^^&uni1&uniType1^^^^orgId||^PRN^PH^^41^162^7773", ebXML);
67      }
68      
69      @Test
70      public void testToEbXMLNoOrganization() {
71          recipient.setOrganization(null);
72          String ebXML = transformer.toEbXML(recipient);
73          assertNotNull(ebXML);
74          
75          assertEquals("|personId^familyName^givenName^second^suffix^prefix^degree^^&uni2&uniType2|^PRN^PH^^41^162^7773",
76                  ebXML);
77      }
78      
79      @Test
80      public void testToEbXMLNoTelecom() {
81          recipient.setTelecom(null);
82          String ebXML = transformer.toEbXML(recipient);
83          assertNotNull(ebXML);
84  
85          assertEquals("orgName^^^^^&uni1&uniType1^^^^orgId|personId^familyName^givenName^second^suffix^prefix^degree^^&uni2&uniType2",
86                  ebXML);
87      }
88  
89      @Test
90      public void testToEbXMLEmpty() {
91          assertNull(transformer.toEbXML(new Recipient()));
92      }
93      
94      @Test
95      public void testToEbXMLNull() {
96          assertNull(transformer.toEbXML(null));
97      }
98      
99      @Test
100     public void testFromEbXML() {
101         assertEquals(recipient, 
102                 transformer.fromEbXML("orgName^^^^^namespace1&uni1&uniType1^^^^orgId|personId^familyName^givenName^second^suffix^prefix^degree^^namespace2&uni2&uniType2|^PRN^PH^^41^162^7773"));
103     }
104 
105     @Test
106     public void testFromEbXMLNoPerson() {
107         recipient.setPerson(null);
108         assertEquals(recipient, 
109                 transformer.fromEbXML("orgName^^^^^namespace1&uni1&uniType1^^^^orgId||^PRN^PH^^41^162^7773"));
110     }
111     
112     @Test
113     public void testFromEbXMLNoOrganization() {
114         recipient.setOrganization(null);
115         assertEquals(recipient, 
116                 transformer.fromEbXML("|personId^familyName^givenName^second^suffix^prefix^degree^^namespace2&uni2&uniType2|^PRN^PH^^41^162^7773"));
117     }
118     
119     @Test
120     public void testFromEbXMLNoTelecom() {
121         recipient.setTelecom(null);
122         assertEquals(recipient,
123                 transformer.fromEbXML("orgName^^^^^namespace1&uni1&uniType1^^^^orgId|personId^familyName^givenName^second^suffix^prefix^degree^^namespace2&uni2&uniType2"));
124     }
125 
126     @Test
127     public void testFromEbXMLEmpty() {
128         assertNull(transformer.fromEbXML(""));
129     }
130 
131     @Test
132     public void testFromEbXMLNull() {
133         assertNull(transformer.fromEbXML(null));
134     }
135 }