View Javadoc
1   /*
2    * Copyright 2009 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 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.Code;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
31  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetSubmissionSetAndContentsQuery;
32  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryList;
33  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
34  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
35  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.GetDocumentsQueryTransformer;
36  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.GetSubmissionSetAndContentsQueryTransformer;
37  
38  /**
39   * Tests for {@link GetDocumentsQueryTransformer}.
40   * @author Jens Riemschneider
41   */
42  public class GetSubmissionSetAndContentsQueryTransformerTest {
43      private GetSubmissionSetAndContentsQueryTransformer transformer;
44      private GetSubmissionSetAndContentsQuery query;
45      private EbXMLAdhocQueryRequest ebXML;
46      
47      @Before
48      public void setUp() {
49          transformer = new GetSubmissionSetAndContentsQueryTransformer();
50          query = new GetSubmissionSetAndContentsQuery();
51  
52          query.setUuid("uuid1");
53          query.setUniqueId("uniqueId1");
54          query.setHomeCommunityId("home");
55          QueryList<Code> confidentialityCodes = new QueryList<>();
56          confidentialityCodes.getOuterList().add(
57                  Arrays.asList(new Code("code10", null, "scheme10"), new Code("code11", null, "scheme11")));
58          confidentialityCodes.getOuterList().add(
59                  Collections.singletonList(new Code("code12", null, "scheme12")));
60          query.setConfidentialityCodes(confidentialityCodes);
61          query.setFormatCodes(Arrays.asList(new Code("code13", null, "scheme13"), new Code("code14", null, "scheme14")));
62          query.setDocumentEntryTypes(Arrays.asList(DocumentEntryType.STABLE, DocumentEntryType.ON_DEMAND));
63  
64          ebXML = new EbXMLFactory30().createAdhocQueryRequest();
65      }
66      
67      @Test
68      public void testToEbXML() {
69          transformer.toEbXML(query, ebXML);
70          assertEquals(QueryType.GET_SUBMISSION_SET_AND_CONTENTS.getId(), ebXML.getId());
71          
72          assertEquals(Collections.singletonList("'uuid1'"),
73                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_UUID.getSlotName()));
74          
75          assertEquals(Collections.singletonList("'uniqueId1'"),
76                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_UNIQUE_ID.getSlotName()));
77  
78          assertEquals("home", ebXML.getHome());
79  
80          assertEquals(Arrays.asList("('code13^^scheme13')", "('code14^^scheme14')"),
81                  ebXML.getSlotValues(QueryParameter.DOC_ENTRY_FORMAT_CODE.getSlotName()));
82          
83          List<EbXMLSlot> slots = ebXML.getSlots(QueryParameter.DOC_ENTRY_CONFIDENTIALITY_CODE.getSlotName());
84          assertEquals(2, slots.size());
85          assertEquals(Arrays.asList("('code10^^scheme10')", "('code11^^scheme11')"), slots.get(0).getValueList());
86          assertEquals(Collections.singletonList("('code12^^scheme12')"), slots.get(1).getValueList());
87  
88          assertEquals(Arrays.asList("('urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1')", "('urn:uuid:34268e47-fdf5-41a6-ba33-82133c465248')"),
89                  ebXML.getSlotValues(QueryParameter.DOC_ENTRY_TYPE.getSlotName()));
90  
91          assertEquals(6, ebXML.getSlots().size());
92      }
93      
94      @Test
95      public void testToEbXMLNull() {
96          transformer.toEbXML(null, ebXML);
97          assertEquals(0, ebXML.getSlots().size());
98      }
99      
100     @Test
101     public void testToEbXMLEmpty() {
102         transformer.toEbXML(new GetSubmissionSetAndContentsQuery(), ebXML);
103         assertEquals(0, ebXML.getSlots().size());
104     }
105 
106     
107     
108     @Test
109     public void testFromEbXML() {
110         transformer.toEbXML(query, ebXML);
111         GetSubmissionSetAndContentsQuery result = new GetSubmissionSetAndContentsQuery();
112         transformer.fromEbXML(result, ebXML);
113         
114         assertEquals(query, result);
115     }
116     
117     @Test
118     public void testFromEbXMLNull() {
119         GetSubmissionSetAndContentsQuery result = new GetSubmissionSetAndContentsQuery();
120         transformer.fromEbXML(result, null);        
121         assertEquals(new GetSubmissionSetAndContentsQuery(), result);
122     }
123         
124     @Test
125     public void testFromEbXMLEmpty() {
126         GetSubmissionSetAndContentsQuery result = new GetSubmissionSetAndContentsQuery();
127         transformer.fromEbXML(result, ebXML);        
128         assertEquals(new GetSubmissionSetAndContentsQuery(), result);
129     }
130 }