View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.transform.requests.ebxml30;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRetrieveImagingDocumentSetRequest;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
24  import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
25  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveImagingDocumentSet;
26  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.RetrieveImagingDocumentSetRequestTransformer;
27  
28  import java.util.List;
29  
30  import static org.junit.Assert.*;
31  
32  /**
33   * Tests for {@link RetrieveImagingDocumentSetRequestTransformer}.
34   * @author Clay Sebourn
35   */
36  public class RetrieveImagingDocumentSetRequestTransformerTest
37  {
38      private RetrieveImagingDocumentSetRequestTransformer transformer;
39      private RetrieveImagingDocumentSet request;
40      
41      @Before
42      public void setUp() {
43          EbXMLFactory factory = new EbXMLFactory30();
44          transformer = new RetrieveImagingDocumentSetRequestTransformer(factory);
45          
46          request = SampleData.createRetrieveImagingDocumentSet();
47      }
48  
49      @Test
50      public void testToEbXML() {
51          EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
52          assertNotNull(ebXML);
53          
54          assertEquals(2, ebXML.getRetrieveStudies().size());
55          assertEquals("urn:oid:1.1.1", ebXML.getRetrieveStudies().get(0).getStudyInstanceUID());
56  
57          assertEquals(2, ebXML.getRetrieveStudies().get(0).getRetrieveSerieses().size());
58          assertEquals("urn:oid:1.2.1", ebXML.getRetrieveStudies().get(0).getRetrieveSerieses().get(0).getSeriesInstanceUID());
59  
60          List<DocumentReference> documents = ebXML.getRetrieveStudies().get(0).getRetrieveSerieses().get(0).getDocuments();
61          assertEquals(2, documents.size());
62  
63          DocumentReference doc = documents.get(0);
64          assertEquals("doc1", doc.getDocumentUniqueId());
65          assertEquals("urn:oid:1.2.3", doc.getHomeCommunityId());
66          assertEquals("repo1", doc.getRepositoryUniqueId());
67   
68          doc = documents.get(1);
69          assertEquals("doc2", doc.getDocumentUniqueId());
70          assertEquals("urn:oid:1.2.4", doc.getHomeCommunityId());
71          assertEquals("repo2", doc.getRepositoryUniqueId());
72  
73          List<String> transferSyntaxUIds = ebXML.getTransferSyntaxUIDList();
74          assertEquals("1.2.840.10008.1.2.4.64", true, transferSyntaxUIds.contains("1.2.840.10008.1.2.4.64"));
75          assertEquals("1.2.840.10008.1.2.4.70", true, transferSyntaxUIds.contains("1.2.840.10008.1.2.4.70"));
76       }
77      
78       @Test
79       public void testToEbXMLNull() {
80           assertNull(transformer.toEbXML(null));
81       }
82  
83       @Test
84       public void testToEbXMLEmpty() {
85           EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(new RetrieveImagingDocumentSet());
86           assertNotNull(ebXML);
87           assertEquals(0, ebXML.getRetrieveStudies().size());
88       }
89  
90       @Test
91       public void testFromEbXML() {
92           EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
93           RetrieveImagingDocumentSet result = transformer.fromEbXML(ebXML);
94           assertEquals(request, result);
95       }
96       
97       @Test
98       public void testFromEbXMLNull() {
99           assertNull(transformer.toEbXML(null));
100      }
101 
102      @Test
103      public void testFromEbXMLEmpty() {
104          EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(new RetrieveImagingDocumentSet());
105          RetrieveImagingDocumentSet result = transformer.fromEbXML(ebXML);
106          assertEquals(new RetrieveImagingDocumentSet(), result);
107      }
108 }