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 static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertSame;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.List;
23
24 import ca.uhn.hl7v2.model.v25.datatype.XPN;
25 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
26 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLExternalIdentifier;
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLInternationalString;
28 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryObject;
29 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
30 import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
31
32
33
34
35
36 public abstract class EbrsTestUtils {
37 private EbrsTestUtils() {
38 throw new UnsupportedOperationException("Utility class");
39 }
40
41
42
43
44
45
46
47
48
49
50
51
52 public static void assertExternalIdentifier(
53 String scheme,
54 EbXMLRegistryObject regEntry,
55 String expectedValue,
56 String expectedName) {
57
58 int found = 0;
59 for (EbXMLExternalIdentifier identifier : regEntry.getExternalIdentifiers()) {
60 if (identifier.getIdentificationScheme().equals(scheme)) {
61 ++found;
62 assertEquals(expectedValue, identifier.getValue());
63 assertEquals(expectedName, toLocal(identifier.getName()).getValue());
64 }
65 }
66
67 assertEquals(1, found);
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public static EbXMLClassification assertClassification(String scheme, EbXMLRegistryObject regEntry, int occurrence, String expectedNodeRepresentation, int expectedLocalizedIdxName) {
88 List<EbXMLClassification> filtered = regEntry.getClassifications(scheme);
89 assertTrue("Not enough classification matching the scheme: " + scheme, filtered.size() > occurrence);
90
91 EbXMLClassification classification = filtered.get(occurrence);
92 assertSame(regEntry.getId(), classification.getClassifiedObject());
93 assertEquals(expectedNodeRepresentation, classification.getNodeRepresentation());
94 if (expectedLocalizedIdxName > 0) {
95 assertEquals(
96 createLocal(expectedLocalizedIdxName),
97 toLocal(classification.getNameAsInternationalString()));
98 }
99
100 return classification;
101 }
102
103
104
105
106
107
108
109
110
111
112 public static void assertSlot(String slotName, List<EbXMLSlot> slots, String... expectedSlotValues) {
113 int found = 0;
114 for (EbXMLSlot slot : slots) {
115 if (slot.getName().equals(slotName)) {
116 List<String> values = slot.getValueList();
117 for (String expectedValue : expectedSlotValues) {
118 assertTrue("Not found: " + expectedValue + ", was: " + values, values.contains(expectedValue));
119 }
120 assertEquals(values.size(), expectedSlotValues.length);
121 ++found;
122 }
123 }
124
125 assertEquals(1, found);
126 }
127
128
129
130
131
132
133
134
135 public static LocalizedString toLocal(EbXMLInternationalString international) {
136 assertEquals(1, international.getLocalizedStrings().size());
137 return international.getSingleLocalizedString();
138 }
139
140
141
142
143
144
145
146
147 public static Person createPerson(int idx) {
148 Person person = new Person();
149 person.setId(createIdentifiable(idx));
150 person.setName(createName(idx));
151 return person;
152 }
153
154
155
156
157
158
159
160
161 public static Organization createOrganization(int idx) {
162 Organization organization = new Organization();
163 organization.setAssigningAuthority(createAssigningAuthority(idx));
164 organization.setIdNumber("id " + idx);
165 organization.setOrganizationName("orgName " + idx);
166 return organization;
167 }
168
169
170
171
172
173
174
175
176 public static Name<XPN> createName(int idx) {
177 return new XpnName("familyName " + idx, "givenName " + idx, "prefix " + idx, "second " + idx, "suffix " + idx, "degree " + idx);
178 }
179
180
181
182
183
184
185
186
187 public static Identifiable createIdentifiable(int idx) {
188 return new Identifiable("id " + idx, createAssigningAuthority(idx));
189 }
190
191
192
193
194
195
196
197
198 public static AssigningAuthority createAssigningAuthority(int idx) {
199 return new AssigningAuthority("uni " + idx, "uniType " + idx);
200 }
201
202
203
204
205
206
207
208
209 public static Code createCode(int idx) {
210 return new Code("code " + idx, createLocal(idx), "scheme " + idx);
211 }
212
213
214
215
216
217
218
219
220 public static LocalizedString createLocal(int idx) {
221 return new LocalizedString("value " + idx, "lang " + idx, "charset " + idx);
222 }
223 }