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.responses;
17  
18  import static org.junit.Assert.*;
19  
20  import java.util.List;
21  
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
25  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAssociation;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLExtrinsicObject;
27  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
28  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLQueryResponse;
29  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryPackage;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationType;
31  import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
32  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
33  import org.openehealth.ipf.commons.ihe.xds.core.responses.QueryResponse;
34  import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FactoryCreator;
35  
36  /**
37   * Tests for {@link QueryResponseTransformer}.
38   * @author Jens Riemschneider
39   */
40  public abstract class QueryResponseTransformerTestBase implements FactoryCreator {
41      private QueryResponseTransformer transformer;
42      private QueryResponse responseLeafClass;    
43      private QueryResponse responseObjRef;    
44      
45      @Before
46      public void setUp() {        
47          EbXMLFactory factory = createFactory();
48          transformer = new QueryResponseTransformer(factory);        
49  
50          responseLeafClass = SampleData.createQueryResponseWithLeafClass();
51          responseObjRef = SampleData.createQueryResponseWithObjRef();
52      }
53  
54      @Test
55      public void testToEbXMLLeafClass() {
56          EbXMLQueryResponse ebXML = transformer.toEbXML(responseLeafClass);
57          assertNotNull(ebXML);
58          assertEquals(1, ebXML.getExtrinsicObjects().size());
59          assertEquals(2, ebXML.getRegistryPackages().size());
60  
61          List<EbXMLAssociation> associations = ebXML.getAssociations();
62          assertEquals(3, associations.size());
63          assertEquals(AssociationType.HAS_MEMBER, associations.get(0).getAssociationType());
64          assertEquals("submissionSet01", associations.get(0).getSource());
65          assertEquals("document01", associations.get(0).getTarget());
66          
67          assertEquals(AssociationType.HAS_MEMBER, associations.get(1).getAssociationType());
68          assertEquals("submissionSet01", associations.get(1).getSource());
69          assertEquals("folder01", associations.get(1).getTarget());
70          
71          assertEquals(AssociationType.HAS_MEMBER, associations.get(2).getAssociationType());
72          assertEquals("folder01", associations.get(2).getSource());
73          assertEquals("document01", associations.get(2).getTarget());
74          
75          List<EbXMLExtrinsicObject> docEntries = ebXML.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND);
76          assertEquals(1, docEntries.size());
77          assertEquals("document01", docEntries.get(0).getId());
78          assertEquals("Document 01", docEntries.get(0).getName().getValue());
79          
80          List<EbXMLRegistryPackage> folders = ebXML.getRegistryPackages(Vocabulary.FOLDER_CLASS_NODE);
81          assertEquals(1, folders.size());
82          assertEquals("Folder 01", folders.get(0).getName().getValue());
83          
84          List<EbXMLRegistryPackage> submissionSets = ebXML.getRegistryPackages(Vocabulary.SUBMISSION_SET_CLASS_NODE);
85          assertEquals(1, submissionSets.size());
86          assertEquals("Submission Set 01", submissionSets.get(0).getName().getValue());
87      }
88      
89      @Test
90      public void testToEbXMLObjRef() {
91          EbXMLQueryResponse ebXML = transformer.toEbXML(responseObjRef);
92          assertNotNull(ebXML);
93          assertEquals(2, ebXML.getReferences().size());
94          assertEquals("ref1", ebXML.getReferences().get(0).getId());
95          assertEquals("ref2", ebXML.getReferences().get(1).getId());        
96      }
97      
98      @Test
99      public void testToEbXMLNull() {
100         assertNull(transformer.toEbXML(null));
101     }
102     
103     @Test
104     public void testToEbXMLEmpty() {
105         EbXMLQueryResponse result = transformer.toEbXML(new QueryResponse());
106         assertNotNull(result);
107         assertEquals(0, result.getAssociations().size());
108         assertEquals(0, result.getExtrinsicObjects().size());
109         assertEquals(0, result.getRegistryPackages().size());
110     }
111     
112 
113     
114     
115     @Test
116     public void testFromEbXMLLeafClass() {
117         EbXMLQueryResponse ebXML = transformer.toEbXML(responseLeafClass);
118         QueryResponse result = transformer.fromEbXML(ebXML);
119         
120         assertEquals(responseLeafClass, result);
121     }
122     
123     @Test
124     public void testFromEbXMLObjRef() {
125         EbXMLQueryResponse ebXML = transformer.toEbXML(responseObjRef);
126         QueryResponse result = transformer.fromEbXML(ebXML);
127         
128         assertEquals(responseObjRef, result);
129     }
130     
131     @Test
132     public void testFromEbXMLNull() {
133         assertNull(transformer.toEbXML(null));
134     }
135     
136     @Test
137     public void testFromEbXMLEmpty() {
138         EbXMLQueryResponse ebXML = transformer.toEbXML(new QueryResponse());
139         assertEquals(new QueryResponse(), transformer.fromEbXML(ebXML));
140     }
141 }