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  
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
27  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority;
28  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
29  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Code;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
31  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindSubmissionSetsQuery;
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.FindSubmissionSetsQueryTransformer;
35  
36  /**
37   * Tests for {@link FindSubmissionSetsQueryTransformer}.
38   * @author Jens Riemschneider
39   */
40  public class FindSubmissionSetsQueryTransformerTest {
41      private FindSubmissionSetsQueryTransformer transformer;
42      private FindSubmissionSetsQuery query;
43      private EbXMLAdhocQueryRequest ebXML;
44      
45      @Before
46      public void setUp() {
47          transformer = new FindSubmissionSetsQueryTransformer();
48          query = new FindSubmissionSetsQuery();
49          
50          query.setPatientId(new Identifiable("id1", new AssigningAuthority("uni1", "uniType1")));
51          query.setContentTypeCodes(Arrays.asList(new Code("code1", null, "system1"), new Code("code2", null, "system2")));
52          query.getSubmissionTime().setFrom("20150102030405");
53          query.getSubmissionTime().setTo("20150102030406");
54          query.setAuthorPerson("per'son1");
55          query.setStatus(Arrays.asList(AvailabilityStatus.APPROVED, AvailabilityStatus.SUBMITTED));
56          query.setHomeCommunityId("12.21.41");
57  
58          ebXML = new EbXMLFactory30().createAdhocQueryRequest();
59      }
60      
61      @Test
62      public void testToEbXML() {
63          transformer.toEbXML(query, ebXML);
64          assertEquals(QueryType.FIND_SUBMISSION_SETS.getId(), ebXML.getId());
65          assertEquals("12.21.41", ebXML.getHome());
66  
67          assertEquals(Collections.singletonList("'id1^^^&uni1&uniType1'"),
68                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_PATIENT_ID.getSlotName()));
69          
70          assertEquals(Arrays.asList("('code1^^system1')", "('code2^^system2')"),
71                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_CONTENT_TYPE_CODE.getSlotName()));
72  
73          assertEquals(Collections.singletonList("20150102030405"),
74                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_SUBMISSION_TIME_FROM.getSlotName()));
75          assertEquals(Collections.singletonList("20150102030406"),
76                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_SUBMISSION_TIME_TO.getSlotName()));
77  
78          assertEquals(Collections.singletonList("'per''son1'"),
79                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_AUTHOR_PERSON.getSlotName()));
80  
81          assertEquals(Arrays.asList("('urn:oasis:names:tc:ebxml-regrep:StatusType:Approved')", "('urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted')"),
82                  ebXML.getSlotValues(QueryParameter.SUBMISSION_SET_STATUS.getSlotName()));
83          
84          assertEquals(6, ebXML.getSlots().size());
85      }
86      
87      @Test
88      public void testToEbXMLNull() {
89          transformer.toEbXML(null, ebXML);
90          assertEquals(0, ebXML.getSlots().size());
91      }
92      
93      @Test
94      public void testToEbXMLEmpty() {
95          transformer.toEbXML(new FindSubmissionSetsQuery(), ebXML);
96          assertEquals(0, ebXML.getSlots().size());
97      }
98  
99      
100     
101     @Test
102     public void testFromEbXML() {
103         transformer.toEbXML(query, ebXML);
104         FindSubmissionSetsQuery result = new FindSubmissionSetsQuery();
105         transformer.fromEbXML(result, ebXML);
106         
107         assertEquals(query, result);
108     }
109     
110     @Test
111     public void testFromEbXMLNull() {
112         FindSubmissionSetsQuery result = new FindSubmissionSetsQuery();
113         transformer.fromEbXML(result, null);        
114         assertEquals(new FindSubmissionSetsQuery(), result);
115     }
116         
117     @Test
118     public void testFromEbXMLEmpty() {
119         FindSubmissionSetsQuery result = new FindSubmissionSetsQuery();
120         transformer.fromEbXML(result, ebXML);        
121         assertEquals(new FindSubmissionSetsQuery(), result);
122     }
123 }