1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
26
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 }