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.*;
19
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
26 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
28 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
29 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Code;
30 import org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString;
31 import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
32
33
34
35
36
37 public abstract class CodeTransformerTestBase implements FactoryCreator {
38 private CodeTransformer transformer;
39 private Code code;
40 private EbXMLObjectLibrary objectLibrary;
41
42 @Before
43 public final void baseSetUp() {
44 EbXMLFactory factory = createFactory();
45 transformer = new CodeTransformer(factory);
46 objectLibrary = factory.createObjectLibrary();
47
48 LocalizedString displayName = new LocalizedString();
49 displayName.setCharset("charset");
50 displayName.setLang("lang");
51 displayName.setValue("value");
52
53 code = new Code();
54 code.setCode("code");
55 code.setDisplayName(displayName);
56 code.setSchemeName("schemeName");
57 }
58
59 @Test
60 public void testToEbXML() {
61 EbXMLClassification ebXML = transformer.toEbXML(code, objectLibrary);
62
63 assertNotNull(ebXML);
64 assertEquals("code", ebXML.getNodeRepresentation());
65
66 List<EbXMLSlot> slots = ebXML.getSlots();
67 assertEquals(1, slots.size());
68
69 EbXMLSlot slot = slots.get(0);
70 assertEquals(Vocabulary.SLOT_NAME_CODING_SCHEME, slot.getName());
71 assertEquals(Collections.singletonList("schemeName"), slot.getValueList());
72
73 List<LocalizedString> localizedStrings = ebXML.getNameAsInternationalString().getLocalizedStrings();
74 assertEquals(1, localizedStrings.size());
75
76 LocalizedString localized = localizedStrings.get(0);
77 assertEquals("charset", localized.getCharset());
78 assertEquals("lang", localized.getLang());
79 assertEquals("value", localized.getValue());
80 }
81
82 @Test
83 public void testToEbXMLNull() {
84 assertNull(transformer.toEbXML(null, objectLibrary));
85 }
86
87 @Test
88 public void testToEbXMLEmpty() {
89 EbXMLClassification ebXML = transformer.toEbXML(new Code(), objectLibrary);
90 assertNotNull(ebXML);
91
92 assertNull(ebXML.getNodeRepresentation());
93 assertNull(ebXML.getName());
94 assertEquals(0, ebXML.getSlots().size());
95 }
96
97
98 @Test
99 public void testFromEbXML() {
100 EbXMLClassification ebXML = transformer.toEbXML(code, objectLibrary);
101 assertEquals(code, transformer.fromEbXML(ebXML));
102 }
103
104 @Test
105 public void testFromEbXMLNull() {
106 assertNull(transformer.fromEbXML(null));
107 }
108
109 @Test
110 public void testFromEbXmlEmpty() {
111 EbXMLClassification ebXML = transformer.toEbXML(new Code(), objectLibrary);
112 assertEquals(new Code(), transformer.fromEbXML(ebXML));
113 }
114 }