1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.adapters.general.adapterpolicyenginetransformejb.adapterpolicyenginetransform;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformPatientIdAQRToCppXACMLRequestType;
|
---|
8 | import gov.hhs.fha.nhinc.common.nhinccommonadapter.TransformPatientIdAQRToCppXACMLResponseType;
|
---|
9 | import java.io.FileReader;
|
---|
10 | import java.io.StringReader;
|
---|
11 | import javax.xml.bind.JAXBContext;
|
---|
12 | import javax.xml.bind.Unmarshaller;
|
---|
13 | import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse;
|
---|
14 | import org.junit.After;
|
---|
15 | import org.junit.AfterClass;
|
---|
16 | import org.junit.Before;
|
---|
17 | import org.junit.BeforeClass;
|
---|
18 | import org.junit.Test;
|
---|
19 | import static org.junit.Assert.*;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | *
|
---|
23 | * @author westbergl
|
---|
24 | */
|
---|
25 | public class AdapterPolicyEngineTransformTest
|
---|
26 | {
|
---|
27 |
|
---|
28 | public AdapterPolicyEngineTransformTest()
|
---|
29 | {
|
---|
30 | }
|
---|
31 |
|
---|
32 | @BeforeClass
|
---|
33 | public static void setUpClass() throws Exception
|
---|
34 | {
|
---|
35 | }
|
---|
36 |
|
---|
37 | @AfterClass
|
---|
38 | public static void tearDownClass() throws Exception
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Before
|
---|
43 | public void setUp()
|
---|
44 | {
|
---|
45 | }
|
---|
46 |
|
---|
47 | @After
|
---|
48 | public void tearDown()
|
---|
49 | {
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * This method reads the entire contents of a text file and returns the contents in
|
---|
54 | * a string variable.
|
---|
55 | *
|
---|
56 | * @param sFileName The path and location of the text file.
|
---|
57 | * @return The contents that was read in.
|
---|
58 | */
|
---|
59 | public String readTextFile(String sFileName)
|
---|
60 | {
|
---|
61 | String sText = "";
|
---|
62 | FileReader frTextFile = null;
|
---|
63 |
|
---|
64 | try
|
---|
65 | {
|
---|
66 | frTextFile = new FileReader(sFileName);
|
---|
67 | char caBuf[] = new char[1024];
|
---|
68 | int iLen = 0;
|
---|
69 | StringBuffer sbText = new StringBuffer();
|
---|
70 | while ((iLen = frTextFile.read(caBuf, 0, 1024)) != -1)
|
---|
71 | {
|
---|
72 | sbText.append(caBuf, 0, iLen);
|
---|
73 | }
|
---|
74 |
|
---|
75 | sText = sbText.toString();
|
---|
76 | }
|
---|
77 | catch (Exception e)
|
---|
78 | {
|
---|
79 | String sErrorMessage = "Failed to read text file: " + sFileName + ". Error: " + e.getMessage();
|
---|
80 | fail(sErrorMessage);
|
---|
81 | }
|
---|
82 | finally
|
---|
83 | {
|
---|
84 | if (frTextFile != null)
|
---|
85 | {
|
---|
86 | try
|
---|
87 | {
|
---|
88 | frTextFile.close();
|
---|
89 | }
|
---|
90 | catch (Exception e)
|
---|
91 | {
|
---|
92 |
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | return sText;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * This method unmarshalls the XML into an AdhocQueryResponse object.
|
---|
102 | *
|
---|
103 | * @param sAdhocQueryResponseXML The XML of the AdhocQueryResponse object to be unmarshalled.
|
---|
104 | * @return The AdhocQueryResponse object.
|
---|
105 | */
|
---|
106 | public AdhocQueryResponse unmarshalAdhocQueryResponse(String sAdhocQueryResponseXML)
|
---|
107 | {
|
---|
108 | AdhocQueryResponse oAdhocQueryResponse = null;
|
---|
109 |
|
---|
110 | if (sAdhocQueryResponseXML != null)
|
---|
111 | {
|
---|
112 | try
|
---|
113 | {
|
---|
114 | JAXBContext jc = JAXBContext.newInstance("oasis.names.tc.ebxml_regrep.xsd.query._3");
|
---|
115 | Unmarshaller unmarshaller = jc.createUnmarshaller();
|
---|
116 | StringReader srAdhocQueryResponseXML = new StringReader(sAdhocQueryResponseXML);
|
---|
117 | oAdhocQueryResponse = (AdhocQueryResponse)unmarshaller.unmarshal(srAdhocQueryResponseXML);
|
---|
118 | }
|
---|
119 | catch (Exception e)
|
---|
120 | {
|
---|
121 | fail("Failed to unmarshal the AdhocQueryResponse document.");
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | return oAdhocQueryResponse;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Test of transformXACMLRequestToCppAQR method, of class AdapterPolicyEngineTransform.
|
---|
131 | */
|
---|
132 | @Test
|
---|
133 | public void testTransformXACMLRequestToCppAQR()
|
---|
134 | {
|
---|
135 | // System.out.println("transformXACMLRequestToCppAQR");
|
---|
136 | // TransformXACMLRequestToCppAQRRequestType transformXACMLRequestToCppAQRRequest = new TransformXACMLRequestToCppAQRRequestType();
|
---|
137 | // AdapterPolicyEngineTransform instance = new AdapterPolicyEngineTransform();
|
---|
138 | // TransformXACMLRequestToCppAQRResponseType expResult = null;
|
---|
139 | // TransformXACMLRequestToCppAQRResponseType result = instance.transformXACMLRequestToCppAQR(transformXACMLRequestToCppAQRRequest);
|
---|
140 | // assertEquals(expResult, result);
|
---|
141 | // // TODO review the generated test code and remove the default call to fail.
|
---|
142 | // fail("The test case is a prototype.");
|
---|
143 | }
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Test of transformAQRToCppRDSR method, of class AdapterPolicyEngineTransform.
|
---|
147 | */
|
---|
148 | @Test
|
---|
149 | public void testTransformAQRToCppRDSR()
|
---|
150 | {
|
---|
151 | // System.out.println("transformAQRToCppRDSR");
|
---|
152 | // TransformAQRToCppRDSRRequestType transformAQRToCppRDSRRequest = null;
|
---|
153 | // AdapterPolicyEngineTransform instance = new AdapterPolicyEngineTransform();
|
---|
154 | // TransformAQRToCppRDSRResponseType expResult = null;
|
---|
155 | // TransformAQRToCppRDSRResponseType result = instance.transformAQRToCppRDSR(transformAQRToCppRDSRRequest);
|
---|
156 | // assertEquals(expResult, result);
|
---|
157 | // // TODO review the generated test code and remove the default call to fail.
|
---|
158 | // fail("The test case is a prototype.");
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Test of checkPatientOptIn method, of class AdapterPolicyEngineTransform.
|
---|
163 | */
|
---|
164 | @Test
|
---|
165 | public void testCheckPatientOptIn()
|
---|
166 | {
|
---|
167 | // System.out.println("checkPatientOptIn");
|
---|
168 | // CheckPatientOptInRequestType checkPatientOptInRequest = null;
|
---|
169 | // AdapterPolicyEngineTransform instance = new AdapterPolicyEngineTransform();
|
---|
170 | // CheckPatientOptInResponseType expResult = null;
|
---|
171 | // CheckPatientOptInResponseType result = instance.checkPatientOptIn(checkPatientOptInRequest);
|
---|
172 | // assertEquals(expResult, result);
|
---|
173 | // // TODO review the generated test code and remove the default call to fail.
|
---|
174 | // fail("The test case is a prototype.");
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Test of transformXACMLRequestToAQRForPatientId method, of class AdapterPolicyEngineTransform.
|
---|
179 | */
|
---|
180 | @Test
|
---|
181 | public void testTransformXACMLRequestToAQRForPatientId()
|
---|
182 | {
|
---|
183 | // System.out.println("transformXACMLRequestToAQRForPatientId");
|
---|
184 | // TransformXACMLRequestToAQRForPatientIdRequestType transformXACMLRequestToAQRForPatientIdRequest = null;
|
---|
185 | // AdapterPolicyEngineTransform instance = new AdapterPolicyEngineTransform();
|
---|
186 | // TransformXACMLRequestToAQRForPatientIdResponseType expResult = null;
|
---|
187 | // TransformXACMLRequestToAQRForPatientIdResponseType result = instance.transformXACMLRequestToAQRForPatientId(transformXACMLRequestToAQRForPatientIdRequest);
|
---|
188 | // assertEquals(expResult, result);
|
---|
189 | // // TODO review the generated test code and remove the default call to fail.
|
---|
190 | // fail("The test case is a prototype.");
|
---|
191 | }
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Test of transformPatientIdAQRToCppXACML method, of class AdapterPolicyEngineTransform.
|
---|
195 | */
|
---|
196 | @Test
|
---|
197 | public void testTransformPatientIdAQRToCppXACML()
|
---|
198 | {
|
---|
199 | System.out.println("transformPatientIdAQRToCppXACML");
|
---|
200 |
|
---|
201 | // Get the example text.
|
---|
202 | //----------------------
|
---|
203 | String sXML = readTextFile("SampleAdhocQueryResponse.xml");
|
---|
204 | AdhocQueryResponse oAQR = unmarshalAdhocQueryResponse(sXML);
|
---|
205 |
|
---|
206 | TransformPatientIdAQRToCppXACMLRequestType oInput = new TransformPatientIdAQRToCppXACMLRequestType();
|
---|
207 | oInput.setAdhocQueryResponse(oAQR);
|
---|
208 |
|
---|
209 |
|
---|
210 | AdapterPolicyEngineTransform instance = new AdapterPolicyEngineTransform();
|
---|
211 | TransformPatientIdAQRToCppXACMLResponseType oResponse = instance.transformPatientIdAQRToCppXACML(oInput);
|
---|
212 |
|
---|
213 | }
|
---|
214 | }
|
---|