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;
17  
18  import static org.junit.Assert.*;
19  
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.activation.DataHandler;
24  
25  import org.junit.Before;
26  import org.junit.Test;
27  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
28  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.*;
29  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationType;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
31  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
32  import org.openehealth.ipf.commons.ihe.xds.core.requests.ProvideAndRegisterDocumentSet;
33  import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FactoryCreator;
34  
35  /**
36   * Tests for {@link ProvideAndRegisterDocumentSetTransformer}.
37   * @author Jens Riemschneider
38   */
39  public abstract class ProvideAndRegisterDocumentSetTransformerTestBase implements FactoryCreator {
40      private ProvideAndRegisterDocumentSetTransformer transformer;
41      private ProvideAndRegisterDocumentSet request;
42      private DataHandler dataHandler;    
43      
44      @Before
45      public void setUp() throws Exception {        
46          EbXMLFactory factory = createFactory();
47          transformer = new ProvideAndRegisterDocumentSetTransformer(factory);        
48  
49          request = SampleData.createProvideAndRegisterDocumentSet();
50          dataHandler = request.getDocuments().get(0).getContent(DataHandler.class);
51      }
52  
53      @Test
54      public void testToEbXML() {
55          EbXMLProvideAndRegisterDocumentSetRequest ebXML = transformer.toEbXML(request);
56          assertNotNull(ebXML);
57          assertEquals(1, ebXML.getExtrinsicObjects().size());
58          assertEquals(2, ebXML.getRegistryPackages().size());
59  
60          List<EbXMLAssociation> associations = ebXML.getAssociations();
61          assertEquals(3, associations.size());
62          assertEquals(AssociationType.HAS_MEMBER, associations.get(0).getAssociationType());
63          assertEquals("submissionSet01", associations.get(0).getSource());
64          assertEquals("document01", associations.get(0).getTarget());
65          
66          assertEquals(AssociationType.HAS_MEMBER, associations.get(1).getAssociationType());
67          assertEquals("submissionSet01", associations.get(1).getSource());
68          assertEquals("folder01", associations.get(1).getTarget());
69          
70          assertEquals(AssociationType.HAS_MEMBER, associations.get(2).getAssociationType());
71          assertEquals("folder01", associations.get(2).getSource());
72          assertEquals("document01", associations.get(2).getTarget());
73          
74          List<EbXMLExtrinsicObject> docEntries = ebXML.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND);
75          assertEquals(1, docEntries.size());
76          assertEquals("document01", docEntries.get(0).getId());
77          assertEquals("Document 01", docEntries.get(0).getName().getValue());
78          
79          List<EbXMLRegistryPackage> folders = ebXML.getRegistryPackages(Vocabulary.FOLDER_CLASS_NODE);
80          assertEquals(1, folders.size());
81          assertEquals("Folder 01", folders.get(0).getName().getValue());
82          
83          List<EbXMLRegistryPackage> submissionSets = ebXML.getRegistryPackages(Vocabulary.SUBMISSION_SET_CLASS_NODE);
84          assertEquals(1, submissionSets.size());
85          assertEquals("Submission Set 01", submissionSets.get(0).getName().getValue());
86  
87          List<EbXMLSlot> slots = ebXML.getSlots(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID);
88          assertEquals(1, slots.size());
89          List<String> slotValues = ebXML.getSlotValues(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID);
90          assertEquals(1, slotValues.size());
91          assertEquals("urn:oid:1.2.3.4.5.6.2333.23", slotValues.get(0));
92  
93          Map<String, DataHandler> documents = ebXML.getDocuments();
94          assertEquals(1, documents.size());
95          assertSame(dataHandler, documents.get("document01"));
96      }
97      
98      @Test
99      public void testToEbXMLNull() {
100         assertNull(transformer.toEbXML(null));
101     }
102     
103     @Test
104     public void testToEbXMLEmpty() {
105         EbXMLProvideAndRegisterDocumentSetRequest result = transformer.toEbXML(new ProvideAndRegisterDocumentSet());
106         assertNotNull(result);
107         assertEquals(0, result.getAssociations().size());
108         assertEquals(0, result.getExtrinsicObjects().size());
109         assertEquals(0, result.getRegistryPackages().size());
110         assertEquals(0, result.getDocuments().size());
111     }
112     
113     @Test
114     public void testFromEbXML() {
115         EbXMLProvideAndRegisterDocumentSetRequest ebXML = transformer.toEbXML(request);
116         ProvideAndRegisterDocumentSet result = transformer.fromEbXML(ebXML);
117         
118         assertEquals(request.toString(), result.toString());
119     }
120     
121     @Test
122     public void testFromEbXMLNull() {
123         assertNull(transformer.toEbXML(null));
124     }
125     
126     @Test
127     public void testFromEbXMLEmpty() {
128         EbXMLProvideAndRegisterDocumentSetRequest ebXML = transformer.toEbXML(new ProvideAndRegisterDocumentSet());
129         assertEquals(new ProvideAndRegisterDocumentSet(), transformer.fromEbXML(ebXML));
130     }
131 }