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  
20  import java.util.Arrays;
21  import java.util.List;
22  
23  import ca.uhn.hl7v2.model.v25.datatype.XCN;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
27  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
28  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
29  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.*;
31  
32  /**
33   * Tests for {@link AuthorTransformer}.
34   * @author Jens Riemschneider
35   */
36  public abstract class AuthorTransformerTestBase implements FactoryCreator {
37      private AuthorTransformer transformer;
38      private EbXMLObjectLibrary objectLibrary;
39      private Author author;
40      
41      @Before
42      public final void baseSetUp() {
43          EbXMLFactory factory = createFactory();
44          transformer = new AuthorTransformer(factory);
45          objectLibrary = factory.createObjectLibrary();
46          
47          Name<XCN> name = new XcnName();
48          name.setFamilyName("Adams");
49  
50          AssigningAuthority assigningAuthority = new AssigningAuthority();
51          assigningAuthority.setUniversalId("1.2.840.113619.6.197");
52          assigningAuthority.setUniversalIdType(Vocabulary.UNIVERSAL_ID_TYPE_OID);
53  
54          Identifiable id = new Identifiable();
55          id.setId("123");
56          id.setAssigningAuthority(assigningAuthority);        
57  
58          Person authorPerson = new Person();
59          authorPerson.setName(name);
60          authorPerson.setId(id);
61  
62          author = new Author();
63          author.setAuthorPerson(authorPerson);
64          
65          author.getAuthorInstitution().add(new Organization("inst1"));
66          author.getAuthorInstitution().add(new Organization("inst2"));
67          
68          author.getAuthorRole().add(new Identifiable("role1", new AssigningAuthority("2.3.1", "ISO")));
69          author.getAuthorRole().add(new Identifiable("role2", null));
70          
71          author.getAuthorSpecialty().add(new Identifiable("spec1", new AssigningAuthority("2.3.3", "ISO")));
72          author.getAuthorSpecialty().add(new Identifiable("spec2", null));
73  
74          author.getAuthorTelecom().add(new Telecom(null, null, 7771L, null));
75          author.getAuthorTelecom().add(new Telecom(null, null, 7772L, null));
76      }
77      
78      @Test
79      public void testToEbXML() {
80          EbXMLClassification ebXML = transformer.toEbXML(author, objectLibrary);        
81          assertNotNull(ebXML);
82          assertNull(ebXML.getClassificationScheme());        
83          assertEquals("", ebXML.getNodeRepresentation());
84          
85          List<EbXMLSlot> slots = ebXML.getSlots();
86          assertEquals(5, slots.size());
87          
88          assertEquals(Vocabulary.SLOT_NAME_AUTHOR_PERSON, slots.get(0).getName());
89          assertEquals("123^Adams^^^^^^^&1.2.840.113619.6.197&ISO", slots.get(0).getValueList().get(0));
90          
91          assertEquals(Vocabulary.SLOT_NAME_AUTHOR_INSTITUTION, slots.get(1).getName());
92          assertEquals(Arrays.asList("inst1", "inst2"), slots.get(1).getValueList());
93  
94          assertEquals(Vocabulary.SLOT_NAME_AUTHOR_ROLE, slots.get(2).getName());
95          assertEquals(Arrays.asList("role1^^^&2.3.1&ISO", "role2"), slots.get(2).getValueList());
96  
97          assertEquals(Vocabulary.SLOT_NAME_AUTHOR_SPECIALTY, slots.get(3).getName());
98          assertEquals(Arrays.asList("spec1^^^&2.3.3&ISO", "spec2"), slots.get(3).getValueList());
99  
100         assertEquals(Vocabulary.SLOT_NAME_AUTHOR_TELECOM, slots.get(4).getName());
101         assertEquals(Arrays.asList("^PRN^PH^^^^7771", "^PRN^PH^^^^7772"), slots.get(4).getValueList());
102     }
103     
104     @Test
105     public void testToEbXMLWithNull() {
106         assertNull(transformer.toEbXML(null, objectLibrary));
107     }
108     
109     @Test
110     public void testToEbXMLWithEmptyAuthor() {
111         EbXMLClassification ebXML = transformer.toEbXML(new Author(), objectLibrary);
112         assertNotNull(ebXML);
113         assertNull(ebXML.getClassificationScheme());        
114         assertEquals("", ebXML.getNodeRepresentation());
115         
116         assertEquals(0, ebXML.getSlots().size());
117     }
118     
119     
120     
121     @Test
122     public void testFromEbXML() {
123         EbXMLClassification classification = transformer.toEbXML(author, objectLibrary);
124         assertEquals(author, transformer.fromEbXML(classification));
125     }
126     
127     @Test
128     public void testFromEbXMLNull() {
129         assertNull(transformer.fromEbXML(null));
130     }
131     
132     @Test
133     public void testFromEbXMLEmpty() {
134         EbXMLClassification ebXML = transformer.toEbXML(new Author(), objectLibrary);
135         assertEquals(new Author(), transformer.fromEbXML(ebXML));
136     }
137 }