1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.transform.responses;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertNull;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
23 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLFactory;
24 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryError;
25 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryResponse;
26 import org.openehealth.ipf.commons.ihe.xds.core.responses.*;
27 import org.openehealth.ipf.commons.ihe.xds.core.transform.ebxml.FactoryCreator;
28
29 import java.util.List;
30
31
32
33
34
35 public abstract class ResponseTransformerTestBase implements FactoryCreator {
36 private ResponseTransformer transformer;
37 private Response response;
38
39 @Before
40 public void baseSetUp() {
41 EbXMLFactory factory = createFactory();
42 transformer = new ResponseTransformer(factory);
43
44 response = SampleData.createResponse();
45 }
46
47 @Test
48 public void testToEbXMLRegistryResponse() {
49 EbXMLRegistryResponse ebXML = transformer.toEbXML(response);
50
51 assertEquals(Status.FAILURE, ebXML.getStatus());
52 List<EbXMLRegistryError> errors = ebXML.getErrors();
53 assertEquals(3, errors.size());
54
55 EbXMLRegistryError error = errors.get(0);
56 assertEquals("context1", error.getCodeContext());
57 assertEquals(ErrorCode.PATIENT_ID_DOES_NOT_MATCH.getOpcode(), error.getErrorCode());
58 assertEquals(Severity.ERROR, error.getSeverity());
59 assertEquals("location1", error.getLocation());
60
61 error = errors.get(1);
62 assertEquals("context2", error.getCodeContext());
63 assertEquals(ErrorCode.SQL_ERROR.getOpcode(), error.getErrorCode());
64 assertEquals(Severity.WARNING, error.getSeverity());
65 assertEquals(null, error.getLocation());
66
67 error = errors.get(2);
68 assertEquals("context3", error.getCodeContext());
69 assertEquals("MyCustomErrorCode", error.getErrorCode());
70 assertEquals(Severity.ERROR, error.getSeverity());
71 assertEquals("location3", error.getLocation());
72 }
73
74 @Test
75 public void testToEbXMLRegistryResponseEmpty() {
76 EbXMLRegistryResponse ebXML = transformer.toEbXML(new Response());
77 assertNull(ebXML.getStatus());
78 assertEquals(0, ebXML.getErrors().size());
79 }
80
81
82 @Test
83 public void testFromEbXML() {
84 EbXMLRegistryResponse ebXML = transformer.toEbXML(response);
85 Response result = transformer.fromEbXML(ebXML);
86 assertEquals(response, result);
87 }
88
89 @Test
90 public void testFromEbXMLEmpty() {
91 EbXMLRegistryResponse ebXML = transformer.toEbXML(new Response());
92 Response result = transformer.fromEbXML(ebXML);
93 assertEquals(new Response(), result);
94 }
95 }