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.ebxml;
17  
18  import static org.junit.Assert.*;
19  import static org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.EbrsTestUtils.*;
20  
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
24  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
25  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryPackage;
27  import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
28  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Folder;
29  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
30  
31  /**
32   * Tests for {@link FolderTransformer}.
33   * @author Jens Riemschneider
34   */
35  public abstract class FolderTransformerTestBase implements FactoryCreator {
36      private FolderTransformer transformer;
37      private Folder folder;
38      private EbXMLObjectLibrary objectLibrary;
39      private boolean homeAware = true;
40  
41      /**
42       * @param homeAware
43       *          <code>true</code> to enable comparison of the homeCommunityId.
44       */
45      protected void setHomeAware(boolean homeAware) {
46          this.homeAware = homeAware;
47      }
48      
49      @Before
50      public final void baseSetUp() {
51          EbXMLFactory factory = createFactory();
52          transformer = new FolderTransformer(factory);
53          objectLibrary = factory.createObjectLibrary();
54          
55          folder = new Folder();
56          folder.setAvailabilityStatus(AvailabilityStatus.APPROVED);
57          folder.setComments(createLocal(10));
58          folder.setEntryUuid("uuid");
59          folder.setLastUpdateTime("20150102030405");
60          folder.setPatientId(createIdentifiable(3));
61          folder.setTitle(createLocal(11));
62          folder.setUniqueId("uniqueId");
63          folder.getCodeList().add(createCode(6));
64          folder.getCodeList().add(createCode(7));
65          folder.setLimitedMetadata(true);
66  
67          if (homeAware) {
68              folder.setHomeCommunityId("123.456");
69          }
70      }
71  
72      @Test
73      public void testToEbXML() {
74          EbXMLRegistryPackage ebXML = transformer.toEbXML(folder, objectLibrary);        
75          assertNotNull(ebXML);
76          
77          assertEquals(AvailabilityStatus.APPROVED, ebXML.getStatus());
78          assertEquals("uuid", ebXML.getId());
79          assertNull(ebXML.getObjectType());
80          if (homeAware) {
81              assertEquals("123.456", ebXML.getHome());
82          }
83          
84          assertEquals(createLocal(10), ebXML.getDescription());        
85          assertEquals(createLocal(11), ebXML.getName());
86          
87          assertSlot(Vocabulary.SLOT_NAME_LAST_UPDATE_TIME, ebXML.getSlots(), "20150102030405");
88  
89          EbXMLClassification classification = 
90              assertClassification(Vocabulary.FOLDER_CODE_LIST_CLASS_SCHEME, ebXML, 0, "code 6", 6);
91          assertSlot(Vocabulary.SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 6");
92  
93          classification = assertClassification(Vocabulary.FOLDER_CODE_LIST_CLASS_SCHEME, ebXML, 1, "code 7", 7);
94          assertSlot(Vocabulary.SLOT_NAME_CODING_SCHEME, classification.getSlots(), "scheme 7");
95          
96          assertExternalIdentifier(Vocabulary.FOLDER_PATIENT_ID_EXTERNAL_ID, ebXML, 
97                  "id 3^^^&uni 3&uniType 3", Vocabulary.FOLDER_LOCALIZED_STRING_PATIENT_ID);
98  
99          assertExternalIdentifier(Vocabulary.FOLDER_UNIQUE_ID_EXTERNAL_ID, ebXML, 
100                 "uniqueId", Vocabulary.FOLDER_LOCALIZED_STRING_UNIQUE_ID);
101 
102         assertClassification(Vocabulary.FOLDER_LIMITED_METADATA_CLASS_SCHEME, ebXML, 0, null, 0);
103 
104         assertEquals(3, ebXML.getClassifications().size());
105         assertEquals(1, ebXML.getSlots().size());
106         assertEquals(2, ebXML.getExternalIdentifiers().size());
107     }
108 
109     @Test
110     public void testToEbXMLNull() {
111         assertNull(transformer.toEbXML(null, objectLibrary));
112     }
113    
114     @Test
115     public void testToEbXMLEmpty() {
116         EbXMLRegistryPackage ebXML = transformer.toEbXML(new Folder(), objectLibrary);        
117         assertNotNull(ebXML);
118         
119         assertNull(ebXML.getStatus());
120         assertNull(ebXML.getId());
121         
122         assertNull(ebXML.getDescription());        
123         assertNull(ebXML.getName());
124         
125         assertEquals(0, ebXML.getSlots().size());
126         assertEquals(0, ebXML.getClassifications().size());
127         assertEquals(0, ebXML.getExternalIdentifiers().size());
128     }
129     
130     @Test
131     public void testFromEbXML() {
132         EbXMLRegistryPackage ebXML = transformer.toEbXML(folder, objectLibrary);
133         Folder result = transformer.fromEbXML(ebXML);
134         
135         assertNotNull(result);
136         assertEquals(folder, result);
137     }
138     
139     @Test
140     public void testFromEbXMLNull() {
141         assertNull(transformer.fromEbXML(null));
142     }
143     
144     @Test
145     public void testFromEbXMLEmpty() {
146         EbXMLRegistryPackage ebXML = transformer.toEbXML(new Folder(), objectLibrary);
147         Folder result = transformer.fromEbXML(ebXML);
148         assertEquals(new Folder(), result);
149     }
150 }