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.List;
21  
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAssociation;
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.metadata.*;
29  
30  /**
31   * Tests for {@link AssociationTransformer}.
32   * @author Jens Riemschneider.
33   */
34  public abstract class AssociationTransformerTestBase implements FactoryCreator {
35      private AssociationTransformer transformer;
36      private EbXMLObjectLibrary objectLibrary;
37      protected Association association;
38      
39      @Before
40      public void baseSetUp() {
41          EbXMLFactory factory = createFactory();
42          transformer = new AssociationTransformer(factory);
43          objectLibrary = factory.createObjectLibrary();
44          objectLibrary.put("id1", new Object());
45          objectLibrary.put("id2", new Object());
46          
47          association = new Association();
48          association.setAssociationType(AssociationType.REPLACE);
49          association.setSourceUuid("id1");
50          association.setTargetUuid("id2");        
51          association.setLabel(AssociationLabel.ORIGINAL);
52          association.setEntryUuid("uuid");
53          association.setDocCode(new Code("code", new LocalizedString("display", "en-US", "UTF-8"), "scheme"));
54      }
55      
56      @Test
57      public void testToEbXML() {
58          EbXMLAssociation ebXML = transformer.toEbXML(association, objectLibrary);
59          assertNotNull(ebXML);
60          
61          assertEquals(AssociationType.REPLACE, ebXML.getAssociationType());
62          assertEquals("id1", ebXML.getSource());
63          assertEquals("id2", ebXML.getTarget());
64          assertEquals("Original", ebXML.getSingleSlotValue(Vocabulary.SLOT_NAME_SUBMISSION_SET_STATUS));
65          assertEquals("uuid", ebXML.getId());
66          
67          List<EbXMLClassification> classifications = ebXML.getClassifications(Vocabulary.ASSOCIATION_DOC_CODE_CLASS_SCHEME);
68          assertEquals(1, classifications.size());
69          EbXMLClassification classification = classifications.get(0);
70          assertEquals("uuid", classification.getClassifiedObject());
71          assertEquals("code", classification.getNodeRepresentation());
72          assertEquals("display", classification.getNameAsInternationalString().getSingleLocalizedString().getValue());
73          assertEquals("scheme", classification.getSingleSlotValue("codingScheme"));
74  
75          checkExtraValues(ebXML);
76      }
77      
78      @Test
79      public void testToEbXMLNull() {
80          assertNull(transformer.toEbXML(null, objectLibrary));
81      }
82  
83      @Test
84      public void testToEbXMLEmpty() {
85          EbXMLAssociation ebXML = transformer.toEbXML(new Association(), objectLibrary);
86          assertNotNull(ebXML);
87          assertNull(ebXML.getAssociationType());
88          assertNull(ebXML.getSource());
89          assertNull(ebXML.getTarget());
90          assertNull(ebXML.getSingleSlotValue(Vocabulary.SLOT_NAME_SUBMISSION_SET_STATUS));
91          assertNull(ebXML.getId());
92          assertEquals(0, ebXML.getClassifications().size());
93      }
94      
95      
96      @Test
97      public void testFromEbXML() {
98          EbXMLAssociation ebXML = transformer.toEbXML(association, objectLibrary);
99          assertEquals(association, transformer.fromEbXML(ebXML));
100     }
101     
102     @Test
103     public void testFromEbXMLNull() {
104         assertNull(transformer.fromEbXML(null));
105     }
106 
107     @Test
108     public void testFromEbXMLEmpty() {
109         EbXMLAssociation ebXML = transformer.toEbXML(new Association(), objectLibrary);
110         assertEquals(new Association(), transformer.fromEbXML(ebXML));
111     }
112 
113     protected abstract void checkExtraValues(EbXMLAssociation ebXML);
114 }