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.Collections;
21  import java.util.List;
22  
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLClassification;
26  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
27  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLObjectLibrary;
28  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLSlot;
29  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Code;
30  import org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString;
31  import org.openehealth.ipf.commons.ihe.xds.core.metadata.Vocabulary;
32  
33  /**
34   * Tests for {@link CodeTransformer}. 
35   * @author Jens Riemschneider
36   */
37  public abstract class CodeTransformerTestBase implements FactoryCreator {
38      private CodeTransformer transformer;
39      private Code code;
40      private EbXMLObjectLibrary objectLibrary;
41      
42      @Before
43      public final void baseSetUp() {
44          EbXMLFactory factory = createFactory();
45          transformer = new CodeTransformer(factory);
46          objectLibrary = factory.createObjectLibrary(); 
47          
48          LocalizedString displayName = new LocalizedString();
49          displayName.setCharset("charset");
50          displayName.setLang("lang");
51          displayName.setValue("value");
52  
53          code = new Code();
54          code.setCode("code");
55          code.setDisplayName(displayName);
56          code.setSchemeName("schemeName");
57      }
58      
59      @Test
60      public void testToEbXML() {
61          EbXMLClassification ebXML = transformer.toEbXML(code, objectLibrary);
62          
63          assertNotNull(ebXML);
64          assertEquals("code", ebXML.getNodeRepresentation());
65          
66          List<EbXMLSlot> slots = ebXML.getSlots();
67          assertEquals(1, slots.size());
68          
69          EbXMLSlot slot = slots.get(0);
70          assertEquals(Vocabulary.SLOT_NAME_CODING_SCHEME, slot.getName());        
71          assertEquals(Collections.singletonList("schemeName"), slot.getValueList());
72          
73          List<LocalizedString> localizedStrings = ebXML.getNameAsInternationalString().getLocalizedStrings();
74          assertEquals(1, localizedStrings.size());
75          
76          LocalizedString localized = localizedStrings.get(0);
77          assertEquals("charset", localized.getCharset());
78          assertEquals("lang", localized.getLang());
79          assertEquals("value", localized.getValue());
80      }
81      
82      @Test
83      public void testToEbXMLNull() {
84          assertNull(transformer.toEbXML(null, objectLibrary));
85      }
86  
87      @Test
88      public void testToEbXMLEmpty() {
89          EbXMLClassification ebXML = transformer.toEbXML(new Code(), objectLibrary);
90          assertNotNull(ebXML);
91          
92          assertNull(ebXML.getNodeRepresentation());
93          assertNull(ebXML.getName());
94          assertEquals(0, ebXML.getSlots().size());
95      }
96      
97      
98      @Test
99      public void testFromEbXML() {
100         EbXMLClassification ebXML = transformer.toEbXML(code, objectLibrary);
101         assertEquals(code, transformer.fromEbXML(ebXML));
102     }
103     
104     @Test
105     public void testFromEbXMLNull() {
106         assertNull(transformer.fromEbXML(null));
107     }
108     
109     @Test
110     public void testFromEbXmlEmpty() {
111         EbXMLClassification ebXML = transformer.toEbXML(new Code(), objectLibrary);
112         assertEquals(new Code(), transformer.fromEbXML(ebXML));
113     }
114 }