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 org.junit.Before;
22  import org.junit.Test;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
24  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
25  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetSubmissionSetsQuery;
26  import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
27  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
28  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.GetSubmissionSetsQueryTransformer;
29  
30  /**
31   * Tests for {@link GetSubmissionSetsQueryTransformer}.
32   * @author Jens Riemschneider
33   */
34  public class GetSubmissionSetsQueryTransformerTest {
35      private GetSubmissionSetsQueryTransformer transformer;
36      private GetSubmissionSetsQuery query;
37      private EbXMLAdhocQueryRequest ebXML;
38      
39      @Before
40      public void setUp() {
41          transformer = new GetSubmissionSetsQueryTransformer();
42          query = new GetSubmissionSetsQuery();
43  
44          query.setUuids(Arrays.asList("uuid1", "uuid2"));
45          query.setHomeCommunityId("home");
46  
47          ebXML = new EbXMLFactory30().createAdhocQueryRequest();
48      }
49      
50      @Test
51      public void testToEbXML() {
52          transformer.toEbXML(query, ebXML);
53          assertEquals(QueryType.GET_SUBMISSION_SETS.getId(), ebXML.getId());
54          
55          assertEquals(Arrays.asList("('uuid1')", "('uuid2')"),
56                  ebXML.getSlotValues(QueryParameter.UUID.getSlotName()));
57          
58          assertEquals("home", ebXML.getHome());
59          assertEquals(1, ebXML.getSlots().size());
60      }
61      
62      @Test
63      public void testToEbXMLNull() {
64          transformer.toEbXML(null, ebXML);
65          assertEquals(0, ebXML.getSlots().size());
66      }
67      
68      @Test
69      public void testToEbXMLEmpty() {
70          transformer.toEbXML(new GetSubmissionSetsQuery(), ebXML);
71          assertEquals(0, ebXML.getSlots().size());
72      }
73  
74      
75      
76      @Test
77      public void testFromEbXML() {
78          transformer.toEbXML(query, ebXML);
79          GetSubmissionSetsQuery result = new GetSubmissionSetsQuery();
80          transformer.fromEbXML(result, ebXML);
81          
82          assertEquals(query, result);
83      }
84      
85      @Test
86      public void testFromEbXMLNull() {
87          GetSubmissionSetsQuery result = new GetSubmissionSetsQuery();
88          transformer.fromEbXML(result, null);        
89          assertEquals(new GetSubmissionSetsQuery(), result);
90      }
91          
92      @Test
93      public void testFromEbXMLEmpty() {
94          GetSubmissionSetsQuery result = new GetSubmissionSetsQuery();
95          transformer.fromEbXML(result, ebXML);        
96          assertEquals(new GetSubmissionSetsQuery(), result);
97      }
98  }