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.GetFoldersQuery;
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.GetFoldersQueryTransformer;
29  
30  /**
31   * Tests for {@link GetFoldersQueryTransformer}.
32   * @author Jens Riemschneider
33   */
34  public class GetFoldersQueryTransformerTest {
35      private GetFoldersQueryTransformer transformer;
36      private GetFoldersQuery query;
37      private EbXMLAdhocQueryRequest ebXML;
38      
39      @Before
40      public void setUp() {
41          transformer = new GetFoldersQueryTransformer();
42          query = new GetFoldersQuery();
43  
44          query.setUuids(Arrays.asList("uuid1", "uuid2"));
45          query.setUniqueIds(Arrays.asList("uniqueId1", "uniqueId2"));
46          query.setHomeCommunityId("home");
47  
48          ebXML = new EbXMLFactory30().createAdhocQueryRequest();
49      }
50      
51      @Test
52      public void testToEbXML() {
53          transformer.toEbXML(query, ebXML);
54          assertEquals(QueryType.GET_FOLDERS.getId(), ebXML.getId());
55          
56          assertEquals(Arrays.asList("('uuid1')", "('uuid2')"),
57                  ebXML.getSlotValues(QueryParameter.FOLDER_UUID.getSlotName()));
58          
59          assertEquals(Arrays.asList("('uniqueId1')", "('uniqueId2')"),
60                  ebXML.getSlotValues(QueryParameter.FOLDER_UNIQUE_ID.getSlotName()));
61  
62          assertEquals("home", ebXML.getHome());
63          assertEquals(2, ebXML.getSlots().size());
64      }
65      
66      @Test
67      public void testToEbXMLNull() {
68          transformer.toEbXML(null, ebXML);
69          assertEquals(0, ebXML.getSlots().size());
70      }
71      
72      @Test
73      public void testToEbXMLEmpty() {
74          transformer.toEbXML(new GetFoldersQuery(), ebXML);
75          assertEquals(0, ebXML.getSlots().size());
76      }
77  
78      
79      
80      @Test
81      public void testFromEbXML() {
82          transformer.toEbXML(query, ebXML);
83          GetFoldersQuery result = new GetFoldersQuery();
84          transformer.fromEbXML(result, ebXML);
85          
86          assertEquals(query, result);
87      }
88      
89      @Test
90      public void testFromEbXMLNull() {
91          GetFoldersQuery result = new GetFoldersQuery();
92          transformer.fromEbXML(result, null);        
93          assertEquals(new GetFoldersQuery(), result);
94      }
95          
96      @Test
97      public void testFromEbXMLEmpty() {
98          GetFoldersQuery result = new GetFoldersQuery();
99          transformer.fromEbXML(result, ebXML);        
100         assertEquals(new GetFoldersQuery(), result);
101     }
102 }