View Javadoc
1   /*
2    * Copyright 2013 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 org.junit.Before;
19  import org.junit.Test;
20  import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.*;
22  import org.openehealth.ipf.commons.ihe.xds.core.requests.RemoveMetadata;
23  
24  import static org.junit.Assert.*;
25  
26  /**
27   * Tests for {@link RemoveMetadataRequestTransformer}.
28   * @author Boris Stanojevic
29   */
30  public class RemoveMetadataTransformerTest {
31      private RemoveMetadataRequestTransformer transformer;
32      private RemoveMetadata request;
33  
34      
35      @Before
36      public void setUp() throws Exception {        
37          transformer = new RemoveMetadataRequestTransformer();
38          request = SampleData.createRemoveMetadata();
39      }
40  
41      @Test
42      public void testToEbXML() {
43          EbXMLRemoveMetadataRequest ebXML = transformer.toEbXML(request);
44          assertNotNull(ebXML);
45          assertEquals(2, ebXML.getReferences().size());
46          assertEquals("1.2.3", ebXML.getReferences().get(0).getHome());
47          assertEquals("5.6.7", ebXML.getReferences().get(1).getHome());
48          assertNull(ebXML.getHome());
49          assertNull(ebXML.getId());
50      }
51  
52      @Test
53      public void testToEbXMLNull() {
54          assertNull(transformer.toEbXML(null));
55      }
56      
57      @Test
58      public void testToEbXMLEmpty() {
59          EbXMLRemoveMetadataRequest result = transformer.toEbXML(new RemoveMetadata());
60          assertNotNull(result);
61          assertNotNull(result.getReferences());
62          assertEquals(0, result.getReferences().size());
63      }
64      
65      @Test
66      public void testFromEbXML() {
67          EbXMLRemoveMetadataRequest ebXML = transformer.toEbXML(request);
68          RemoveMetadata result = transformer.fromEbXML(ebXML);
69          
70          assertEquals(request.toString(), result.toString());
71      }
72      
73      @Test
74      public void testFromEbXMLNull() {
75          assertNull(transformer.toEbXML(null));
76      }
77      
78      @Test
79      public void testFromEbXMLEmpty() {
80          EbXMLRemoveMetadataRequest ebXML = transformer.toEbXML(new RemoveMetadata());
81          assertEquals(new RemoveMetadata(), transformer.fromEbXML(ebXML));
82      }
83  }