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.responses.ebxml30;
17
18 import static org.junit.Assert.*;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
23 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRetrieveDocumentSetResponse;
24 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
25 import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
26 import org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocument;
27 import org.openehealth.ipf.commons.ihe.xds.core.responses.RetrievedDocumentSet;
28 import org.openehealth.ipf.commons.ihe.xds.core.transform.responses.RetrieveDocumentSetResponseTransformer;
29
30 import javax.activation.DataHandler;
31
32
33
34
35
36 public class RetrieveDocumentSetResponseTransformerTest {
37 private RetrieveDocumentSetResponseTransformer transformer;
38 private RetrievedDocumentSet response;
39 private DataHandler dataHandler1;
40 private DataHandler dataHandler2;
41
42 @Before
43 public void setUp() throws Exception {
44 EbXMLFactory factory = new EbXMLFactory30();
45 transformer = new RetrieveDocumentSetResponseTransformer(factory);
46
47 response = SampleData.createRetrievedDocumentSet();
48 dataHandler1 = response.getDocuments().get(0).getDataHandler();
49 dataHandler2 = response.getDocuments().get(1).getDataHandler();
50 }
51
52 @Test
53 public void testToEbXML() {
54 EbXMLRetrieveDocumentSetResponse ebXML = transformer.toEbXML(response);
55 assertNotNull(ebXML);
56
57 assertEquals(2, ebXML.getDocuments().size());
58
59 RetrievedDocument doc = ebXML.getDocuments().get(0);
60 DocumentReference requestData = doc.getRequestData();
61 assertEquals("doc1", requestData.getDocumentUniqueId());
62 assertEquals("urn:oid:1.2.3", requestData.getHomeCommunityId());
63 assertEquals("repo1", requestData.getRepositoryUniqueId());
64 assertEquals("application/test1", doc.getMimeType());
65 assertSame(dataHandler1, doc.getDataHandler());
66
67 doc = ebXML.getDocuments().get(1);
68 requestData = doc.getRequestData();
69 assertEquals("doc2", requestData.getDocumentUniqueId());
70 assertEquals("urn:oid:1.2.4", requestData.getHomeCommunityId());
71 assertEquals("repo2", requestData.getRepositoryUniqueId());
72 assertEquals("repo2-new", doc.getNewRepositoryUniqueId());
73 assertEquals("doc2-new", doc.getNewDocumentUniqueId());
74 assertEquals("application/test2", doc.getMimeType());
75 assertSame(dataHandler2, doc.getDataHandler());
76 }
77
78 @Test
79 public void testToEbXMLNull() {
80 assertNull(transformer.toEbXML(null));
81 }
82
83 @Test
84 public void testToEbXMLEmpty() {
85 EbXMLRetrieveDocumentSetResponse ebXML = transformer.toEbXML(new RetrievedDocumentSet());
86 assertNotNull(ebXML);
87 assertEquals(0, ebXML.getDocuments().size());
88 }
89
90
91
92 @Test
93 public void testFromEbXML() {
94 EbXMLRetrieveDocumentSetResponse ebXML = transformer.toEbXML(response);
95 RetrievedDocumentSet result = transformer.fromEbXML(ebXML);
96 assertEquals(response, result);
97 }
98
99 @Test
100 public void testFromEbXMLNull() {
101 assertNull(transformer.toEbXML(null));
102 }
103
104 @Test
105 public void testFromEbXMLEmpty() {
106 EbXMLRetrieveDocumentSetResponse ebXML = transformer.toEbXML(new RetrievedDocumentSet());
107 RetrievedDocumentSet result = transformer.fromEbXML(ebXML);
108 assertEquals(new RetrievedDocumentSet(), result);
109 }
110 }