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.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.Address;
23 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Hl7v2Based;
24
25
26
27
28
29 public class AddressTransformerTest {
30 @Test
31 public void testToHL7() {
32 Address address = new Address();
33 address.setStreetAddress("Laliluna Str. 2&3");
34 address.setCity("Sonn^hofen");
35 address.setCountry("ECU");
36 address.setCountyParishCode("STRAHL|EMANN");
37 address.setOtherDesignation("Licht&Lampen");
38 address.setStateOrProvince("Lamp|ing");
39 address.setZipOrPostalCode("123&WARM");
40 assertEquals(
41 "Laliluna Str. 2\\T\\3^Licht\\T\\Lampen^Sonn\\S\\hofen^Lamp\\F\\ing^123\\T\\WARM^ECU^^^STRAHL\\F\\EMANN",
42 Hl7v2Based.render(address));
43 }
44
45 @Test
46 public void testToHL7Empty() {
47 assertNull(Hl7v2Based.render(new Address()));
48 }
49
50 @Test
51 public void testToHL7WithNullParam() {
52 assertNull(Hl7v2Based.render(null));
53 }
54
55
56 @Test
57 public void testFromHL7() {
58 Address address = Hl7v2Based.parse(
59 "Laliluna Str. 2\\T\\3^Licht\\T\\Lampen^Sonn\\S\\hofen^Lamp\\F\\ing^123\\T\\WARM^ECU^^^STRAHL\\F\\EMANN",
60 Address.class);
61 assertEquals("Laliluna Str. 2&3", address.getStreetAddress());
62 assertEquals("Sonn^hofen", address.getCity());
63 assertEquals("ECU", address.getCountry());
64 assertEquals("STRAHL|EMANN", address.getCountyParishCode());
65 assertEquals("Licht&Lampen", address.getOtherDesignation());
66 assertEquals("Lamp|ing", address.getStateOrProvince());
67 assertEquals("123&WARM", address.getZipOrPostalCode());
68 }
69
70 @Test
71 public void testFromHL7UsingSAD() {
72 Address address = Hl7v2Based.parse(
73 "Laliluna Str. 2\\T\\3&whatever^Licht\\T\\Lampen^Sonn\\S\\hofen^Lamp\\F\\ing^123\\T\\WARM^ECU^^^STRAHL\\F\\EMANN",
74 Address.class);
75 assertEquals("Laliluna Str. 2&3", address.getStreetAddress());
76 assertEquals("Sonn^hofen", address.getCity());
77 assertEquals("ECU", address.getCountry());
78 assertEquals("STRAHL|EMANN", address.getCountyParishCode());
79 assertEquals("Licht&Lampen", address.getOtherDesignation());
80 assertEquals("Lamp|ing", address.getStateOrProvince());
81 assertEquals("123&WARM", address.getZipOrPostalCode());
82 }
83
84 @Test
85 public void testFromHL7Nothing() {
86 assertNull(Hl7v2Based.parse("", Address.class));
87 }
88
89 @Test
90 public void testFromHL7WithNullParam() {
91 assertNull(Hl7v2Based.parse(null, Address.class));
92 }
93 }