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.assertEquals;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.*;
23  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationType;
24  import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
25  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
26  import org.openehealth.ipf.commons.ihe.xds.core.requests.RegisterDocumentSet;
27  import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FactoryCreator;
28  
29  import java.util.List;
30  
31  /**
32   * Tests for {@link RegisterDocumentSetTransformer}.
33   * @author Jens Riemschneider
34   */
35  public abstract class RegisterDocumentSetTransformerTestBase implements FactoryCreator {
36      private RegisterDocumentSetTransformer transformer;
37      private RegisterDocumentSet request;
38  
39      @Before
40      public void setUp() {
41          EbXMLFactory factory = createFactory();
42          transformer = new RegisterDocumentSetTransformer(factory);        
43  
44          request = SampleData.createRegisterDocumentSet();
45      }
46  
47      @Test
48      public void testToEbXML() {
49          EbXMLSubmitObjectsRequest ebXML = transformer.toEbXML(request);
50          assertEquals(1, ebXML.getExtrinsicObjects().size());
51          assertEquals(2, ebXML.getRegistryPackages().size());
52          assertEquals(1, ebXML.getSlots().size());
53  
54          List<EbXMLAssociation> associations = ebXML.getAssociations();
55          assertEquals(3, associations.size());
56          assertEquals(AssociationType.HAS_MEMBER, associations.get(0).getAssociationType());
57          assertEquals("submissionSet01", associations.get(0).getSource());
58          assertEquals("document01", associations.get(0).getTarget());
59          
60          assertEquals(AssociationType.HAS_MEMBER, associations.get(1).getAssociationType());
61          assertEquals("submissionSet01", associations.get(1).getSource());
62          assertEquals("folder01", associations.get(1).getTarget());
63          
64          assertEquals(AssociationType.HAS_MEMBER, associations.get(2).getAssociationType());
65          assertEquals("folder01", associations.get(2).getSource());
66          assertEquals("document01", associations.get(2).getTarget());
67          
68          List<EbXMLExtrinsicObject> docEntries = ebXML.getExtrinsicObjects(DocumentEntryType.STABLE_OR_ON_DEMAND);
69          assertEquals(1, docEntries.size());
70          assertEquals("document01", docEntries.get(0).getId());
71          assertEquals("Document 01", docEntries.get(0).getName().getValue());
72          
73          List<EbXMLRegistryPackage> folders = ebXML.getRegistryPackages(Vocabulary.FOLDER_CLASS_NODE);
74          assertEquals(1, folders.size());
75          assertEquals("Folder 01", folders.get(0).getName().getValue());
76          
77          List<EbXMLRegistryPackage> submissionSets = ebXML.getRegistryPackages(Vocabulary.SUBMISSION_SET_CLASS_NODE);
78          assertEquals(1, submissionSets.size());
79          assertEquals("Submission Set 01", submissionSets.get(0).getName().getValue());
80  
81          assertEquals("urn:oid:1.2.3.4.5.6.2333.23", ebXML.getSingleSlotValue(Vocabulary.SLOT_NAME_HOME_COMMUNITY_ID));
82      }
83      
84      @Test
85      public void testToEbXMLEmpty() {
86          EbXMLSubmitObjectsRequest ebXML = transformer.toEbXML(new RegisterDocumentSet());
87          
88          assertEquals(0, ebXML.getAssociations().size());
89          assertEquals(0, ebXML.getExtrinsicObjects().size());
90          assertEquals(0, ebXML.getRegistryPackages().size());
91          assertEquals(0, ebXML.getSlots().size());
92      }
93  
94      @Test
95      public void testFromEbXML() {
96          EbXMLSubmitObjectsRequest ebXML = transformer.toEbXML(request);
97          RegisterDocumentSet result = transformer.fromEbXML(ebXML);
98          assertEquals(request, result);
99      }
100     
101     @Test
102     public void testFromEbXMLEmpty() {
103         EbXMLSubmitObjectsRequest ebXML = transformer.toEbXML(new RegisterDocumentSet());
104         RegisterDocumentSet result = transformer.fromEbXML(ebXML);
105         assertEquals(new RegisterDocumentSet(), result);      
106     }
107 }