Interim code for ConsentInterceptorTest

This commit is contained in:
souradeepsaha 2023-06-05 10:04:50 -04:00
parent 3d11a015d7
commit 8d9b60751f
1 changed files with 21 additions and 5 deletions

View File

@ -161,7 +161,6 @@ public class ConsentInterceptorTest {
HttpPut httpPut = new HttpPut("http://localhost:" + myPort + "/Patient/PT-1-0"); HttpPut httpPut = new HttpPut("http://localhost:" + myPort + "/Patient/PT-1-0");
httpPut.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); httpPut.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
httpPut.setHeader("Authorization", "ingestfa_client iaamSmile123");
httpPut.setEntity(new StringEntity("{\"resourceType\": \"Patient\", \"id\": \"PT-1-0\",\"text\": {\"status\": \"generated\",\"div\": \"<div><p>A valid patient resource for testing purposes</p></div>\" },\"gender\": \"male\"}")); httpPut.setEntity(new StringEntity("{\"resourceType\": \"Patient\", \"id\": \"PT-1-0\",\"text\": {\"status\": \"generated\",\"div\": \"<div><p>A valid patient resource for testing purposes</p></div>\" },\"gender\": \"male\"}"));
@ -185,8 +184,6 @@ public class ConsentInterceptorTest {
when(myConsentSvc.canSeeResource(any(), any(), any())).thenReturn(ConsentOutcome.FORBID); when(myConsentSvc.canSeeResource(any(), any(), any())).thenReturn(ConsentOutcome.FORBID);
HttpGet httpGet = new HttpGet("http://localhost:" + myPort + "/Patient/PT-1-0"); HttpGet httpGet = new HttpGet("http://localhost:" + myPort + "/Patient/PT-1-0");
httpGet.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
httpGet.setHeader("Authorization", "ingestfa_client iaamSmile123");
try (CloseableHttpResponse status = myClient.execute(httpGet)) { try (CloseableHttpResponse status = myClient.execute(httpGet)) {
ourLog.info("RESULT {}", status); ourLog.info("RESULT {}", status);
@ -208,8 +205,27 @@ public class ConsentInterceptorTest {
when(myConsentSvc.willSeeResource(any(), any(), any())).thenReturn(ConsentOutcome.FORBID); when(myConsentSvc.willSeeResource(any(), any(), any())).thenReturn(ConsentOutcome.FORBID);
HttpGet httpGet = new HttpGet("http://localhost:" + myPort + "/Patient/PT-1-0"); HttpGet httpGet = new HttpGet("http://localhost:" + myPort + "/Patient/PT-1-0");
httpGet.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
httpGet.setHeader("Authorization", "ingestfa_client iaamSmile123"); try (CloseableHttpResponse status = myClient.execute(httpGet)) {
ourLog.info("RESULT {}", status);
assertEquals(403, status.getStatusLine().getStatusCode());
String responseContent = IOUtils.toString(status.getEntity().getContent(), Charsets.UTF_8);
ourLog.info("Response: {}", responseContent);
}
}
@Test
public void testContentService_whenForbiddingOperationOnServerOutgoingResponse_returnsForbidden() throws IOException {
Patient patientA = new Patient();
patientA.setId("PT-1-0");
patientA.setActive(true);
patientA.addName().setFamily("FAMILY").addGiven("GIVEN");
patientA.addIdentifier().setSystem("SYSTEM").setValue("VALUEA");
ourPatientProvider.store(patientA);
when(myConsentSvc.willSeeResource(any(), any(), any())).thenReturn(ConsentOutcome.FORBID);
HttpGet httpGet = new HttpGet("http://localhost:" + myPort + "/Patient/PT-1-0");
try (CloseableHttpResponse status = myClient.execute(httpGet)) { try (CloseableHttpResponse status = myClient.execute(httpGet)) {
ourLog.info("RESULT {}", status); ourLog.info("RESULT {}", status);