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.ebxml.EbXMLAdhocQueryRequest;
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
25  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Code;
26  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
27  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindFoldersForMultiplePatientsQuery;
28  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryList;
29  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
30  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
31  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.FindFoldersForMultiplePatientsQueryTransformer;
32  
33  import java.util.Arrays;
34  import java.util.Collections;
35  import java.util.List;
36  
37  import static org.junit.Assert.assertEquals;
38  
39  /**
40   * Tests for {@link FindFoldersForMultiplePatientsQueryTransformer}.
41   * @author Michael Ottati
42   */
43  public class FindFoldersForMultiplePatientsQueryTransformerTest {
44      private FindFoldersForMultiplePatientsQueryTransformer transformer;
45      private FindFoldersForMultiplePatientsQuery query;
46      private EbXMLAdhocQueryRequest ebXML;
47      
48      @Before
49      public void setUp() {
50          transformer = new FindFoldersForMultiplePatientsQueryTransformer();
51          query = new FindFoldersForMultiplePatientsQuery();
52  
53          query.setPatientIds(Arrays.asList(new Identifiable("id1", new AssigningAuthority("uni1", "uniType1")), new Identifiable("id2", new AssigningAuthority("uni2", "uniType2"))));
54          query.getLastUpdateTime().setFrom("20150102030405");
55          query.getLastUpdateTime().setTo("20150102030406");
56          QueryList<Code> codes = new QueryList<>();
57          codes.getOuterList().add(
58                  Arrays.asList(new Code("code7", null, "scheme7"), new Code("code8", null, "scheme8")));
59          codes.getOuterList().add(
60                  Collections.singletonList(new Code("code9", null, "scheme9")));
61          query.setCodes(codes);
62          query.setStatus(Arrays.asList(AvailabilityStatus.APPROVED, AvailabilityStatus.SUBMITTED));
63          query.setHomeCommunityId("12.21.41");
64  
65          ebXML = new EbXMLFactory30().createAdhocQueryRequest();
66      }
67      
68      @Test
69      public void testToEbXML() {
70          transformer.toEbXML(query, ebXML);
71          assertEquals(QueryType.FIND_FOLDERS_MPQ.getId(), ebXML.getId());
72          assertEquals("12.21.41", ebXML.getHome());
73  
74          assertEquals(Arrays.asList("('id1^^^&uni1&uniType1')","('id2^^^&uni2&uniType2')"),
75                  ebXML.getSlotValues(QueryParameter.FOLDER_PATIENT_ID.getSlotName()));
76          
77          assertEquals(Collections.singletonList("20150102030405"),
78                  ebXML.getSlotValues(QueryParameter.FOLDER_LAST_UPDATE_TIME_FROM.getSlotName()));
79          assertEquals(Collections.singletonList("20150102030406"),
80                  ebXML.getSlotValues(QueryParameter.FOLDER_LAST_UPDATE_TIME_TO.getSlotName()));
81  
82          List<EbXMLSlot> slots = ebXML.getSlots(QueryParameter.FOLDER_CODES.getSlotName());
83          assertEquals(2, slots.size());
84          assertEquals(Arrays.asList("('code7^^scheme7')", "('code8^^scheme8')"), slots.get(0).getValueList());
85          assertEquals(Collections.singletonList("('code9^^scheme9')"), slots.get(1).getValueList());
86          
87          assertEquals(Arrays.asList("('urn:oasis:names:tc:ebxml-regrep:StatusType:Approved')", "('urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted')"),
88                  ebXML.getSlotValues(QueryParameter.FOLDER_STATUS.getSlotName()));
89  
90          assertEquals(6, ebXML.getSlots().size());
91      }
92      
93      @Test
94      public void testToEbXMLNull() {
95          transformer.toEbXML(null, ebXML);
96          assertEquals(0, ebXML.getSlots().size());
97      }
98      
99      @Test
100     public void testToEbXMLEmpty() {
101         transformer.toEbXML(new FindFoldersForMultiplePatientsQuery(), ebXML);
102         assertEquals(0, ebXML.getSlots().size());
103     }
104 
105 
106 
107     @Test
108     public void testFromEbXML() {
109         transformer.toEbXML(query, ebXML);
110         FindFoldersForMultiplePatientsQuery result = new FindFoldersForMultiplePatientsQuery();
111         transformer.fromEbXML(result, ebXML);
112         
113         assertEquals(query, result);
114     }
115     
116     @Test
117     public void testFromEbXMLLineBreakInAValueList() {
118         transformer.toEbXML(query, ebXML);
119         ebXML.getSlots().get(5).getValueList().clear();
120         ebXML.getSlots().get(5).getValueList().add("('urn:oasis:names:tc:ebxml-regrep:StatusType:Approved',\n'urn:oasis:names:tc:ebxml-regrep:StatusType:Submitted')");
121         FindFoldersForMultiplePatientsQuery result = new FindFoldersForMultiplePatientsQuery();
122         transformer.fromEbXML(result, ebXML);
123         
124         assertEquals(query, result);
125     }
126     
127     @Test
128     public void testFromEbXMLNull() {
129         FindFoldersForMultiplePatientsQuery result = new FindFoldersForMultiplePatientsQuery();
130         transformer.fromEbXML(result, null);        
131         assertEquals(new FindFoldersForMultiplePatientsQuery(), result);
132     }
133         
134     @Test
135     public void testFromEbXMLEmpty() {
136         FindFoldersForMultiplePatientsQuery result = new FindFoldersForMultiplePatientsQuery();
137         transformer.fromEbXML(result, ebXML);        
138         assertEquals(new FindFoldersForMultiplePatientsQuery().toString(), result.toString());
139     }
140 }