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.requests.ebxml30;
17
18 import static org.junit.Assert.*;
19
20 import java.util.Arrays;
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
27 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
28 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
29 import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
30 import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetAllQuery;
31 import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryList;
32 import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
33 import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
34 import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.GetAllQueryTransformer;
35
36
37
38
39
40 public class GetAllQueryTransformerTest {
41 private GetAllQueryTransformer transformer;
42 private GetAllQuery query;
43 private EbXMLAdhocQueryRequest ebXML;
44
45 @Before
46 public void setUp() {
47 transformer = new GetAllQueryTransformer();
48 query = new GetAllQuery();
49
50 query.setPatientId(new Identifiable("id1", new AssigningAuthority("uni1", "uniType1")));
51 QueryList<Code> confidentialityCodes = new QueryList<>();
52 confidentialityCodes.getOuterList().add(
53 Arrays.asList(new Code("code10", null, "scheme10"), new Code("code11", null, "scheme11")));
54 confidentialityCodes.getOuterList().add(
55 Collections.singletonList(new Code("code12", null, "scheme12")));
56 query.setConfidentialityCodes(confidentialityCodes);
57 query.setFormatCodes(Arrays.asList(new Code("code13", null, "scheme13"), new Code("code14", null, "scheme14")));
58 query.setStatusDocuments(Arrays.asList(AvailabilityStatus.APPROVED, AvailabilityStatus.SUBMITTED));
59 query.setStatusFolders(Collections.singletonList(AvailabilityStatus.DEPRECATED));
60 query.setStatusSubmissionSets(Collections.singletonList(AvailabilityStatus.SUBMITTED));
61 query.setHomeCommunityId("12.21.41");
62 query.setDocumentEntryTypes(Collections.singletonList(DocumentEntryType.STABLE));
63
64 ebXML = new EbXMLFactory30().createAdhocQueryRequest();
65 }
66
67 @Test
68 public void testToEbXML() {
69 transformer.toEbXML(query, ebXML);
70 assertEquals(QueryType.GET_ALL.getId(), ebXML.getId());
71 assertEquals("12.21.41", ebXML.getHome());
72
73 assertEquals(Collections.singletonList("'id1^^^&uni1&uniType1'"),
74 ebXML.getSlotValues(QueryParameter.PATIENT_ID.getSlotName()));
75
76 List<EbXMLSlot> slots = ebXML.getSlots(QueryParameter.DOC_ENTRY_CONFIDENTIALITY_CODE.getSlotName());
77 assertEquals(2, slots.size());
78 assertEquals(Arrays.asList("('code10^^scheme10')", "('code11^^scheme11')"), slots.get(0).getValueList());
79 assertEquals(Collections.singletonList("('code12^^scheme12')"), slots.get(1).getValueList());
80
81 assertEquals(Arrays.asList("('code13^^scheme13')", "('code14^^scheme14')"),
82 ebXML.getSlotValues(QueryParameter.DOC_ENTRY_FORMAT_CODE.getSlotName()));
83
84 assertEquals(Arrays.asList("('urn:oasis:names:tc:ebxml-regrep:StatusType:Approved')", "('urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted')"),
85 ebXML.getSlotValues(QueryParameter.DOC_ENTRY_STATUS.getSlotName()));
86
87 assertEquals(Collections.singletonList("('urn:oasis:names:tc:ebxml-regrep:StatusType:Deprecated')"),
88 ebXML.getSlotValues(QueryParameter.FOLDER_STATUS.getSlotName()));
89
90 assertEquals(Collections.singletonList("('urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted')"),
91 ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_STATUS.getSlotName()));
92
93 assertEquals(Collections.singletonList("('urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1')"),
94 ebXML.getSlotValues(QueryParameter.DOC_ENTRY_TYPE.getSlotName()));
95
96 assertEquals(8, ebXML.getSlots().size());
97 }
98
99 @Test
100 public void testToEbXMLNull() {
101 transformer.toEbXML(null, ebXML);
102 assertEquals(0, ebXML.getSlots().size());
103 }
104
105 @Test
106 public void testToEbXMLEmpty() {
107 transformer.toEbXML(new GetAllQuery(), ebXML);
108 assertEquals(0, ebXML.getSlots().size());
109 }
110
111
112
113 @Test
114 public void testFromEbXML() {
115 transformer.toEbXML(query, ebXML);
116 GetAllQuery result = new GetAllQuery();
117 transformer.fromEbXML(result, ebXML);
118
119 assertEquals(query, result);
120 }
121
122 @Test
123 public void testFromEbXMLNull() {
124 GetAllQuery result = new GetAllQuery();
125 transformer.fromEbXML(result, null);
126 assertEquals(new GetAllQuery(), result);
127 }
128
129 @Test
130 public void testFromEbXMLEmpty() {
131 GetAllQuery result = new GetAllQuery();
132 transformer.fromEbXML(result, ebXML);
133 assertEquals(new GetAllQuery(), result);
134 }
135 }