use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.
the class AuthenticationTests method testClientNoAuthorization.
@Test
public void testClientNoAuthorization() throws Exception {
PdpClient pdpClient = pdpClientRepository.findByClientId(TEST_PDP_CLIENT);
pdpClient.setRoles(Collections.emptySet());
pdpClientRepository.save(pdpClient);
this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/Patient/$export").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(403));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(1, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(1, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(HttpStatus.FORBIDDEN.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
}
use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.
the class AuthenticationTests method testClientDoesNotExist.
@Test
public void testClientDoesNotExist() throws Exception {
PdpClient pdpClient = pdpClientRepository.findByClientId(TEST_PDP_CLIENT);
pdpClientRepository.delete(pdpClient);
this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/Patient/$export").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(403));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(1, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(1, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(HttpStatus.FORBIDDEN.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
}
use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testGetStatusWhileFinished.
@Test
void testGetStatusWhileFinished() throws Exception {
MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH + "?_type=ExplanationOfBenefit").header("Authorization", "Bearer " + token).contentType(MediaType.APPLICATION_JSON)).andReturn();
String statusUrl = mvcResult.getResponse().getHeader(CONTENT_LOCATION);
assertNotNull(statusUrl);
JobOutput jobOutput = new JobOutput();
jobOutput.setFhirResourceType(EOB);
jobOutput.setFilePath("file.ndjson");
jobOutput.setError(false);
jobOutput.setFileLength(5000L);
jobOutput.setChecksum("file");
jobClientMock.addJobOutputForDownload(jobOutput);
JobOutput errorJobOutput = new JobOutput();
errorJobOutput.setFhirResourceType(OPERATION_OUTCOME);
errorJobOutput.setFilePath("error.ndjson");
errorJobOutput.setFileLength(6000L);
errorJobOutput.setChecksum("error");
errorJobOutput.setError(true);
jobClientMock.addJobOutputForDownload(errorJobOutput);
String jobUuid = jobClientMock.pickAJob();
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
this.mockMvc.perform(get(statusUrl).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(200)).andExpect(buildExpiresMatcher()).andExpect(jsonPath("$.transactionTime", Is.is(new org.hl7.fhir.dstu3.model.DateTimeType(OffsetDateTime.now().toString()).toHumanDisplay()))).andExpect(jsonPath("$.request", Is.is(startJobDTO.getUrl()))).andExpect(jsonPath("$.requiresAccessToken", Is.is(true))).andExpect(jsonPath("$.output[0].type", Is.is(EOB))).andExpect(jsonPath("$.output[0].url", Is.is("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/file.ndjson"))).andExpect(jsonPath("$.output[0].extension[0].url", Is.is(CHECKSUM_STRING))).andExpect(jsonPath("$.output[0].extension[0].valueString", Is.is("sha256:file"))).andExpect(jsonPath("$.output[0].extension[1].url", Is.is(CONTENT_LENGTH_STRING))).andExpect(jsonPath("$.output[0].extension[1].valueDecimal", Is.is(5000))).andExpect(jsonPath("$.error[0].type", Is.is(OPERATION_OUTCOME))).andExpect(jsonPath("$.error[0].url", Is.is("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/file/error.ndjson"))).andExpect(jsonPath("$.error[0].extension[0].url", Is.is(CHECKSUM_STRING))).andExpect(jsonPath("$.error[0].extension[0].valueString", Is.is("sha256:error"))).andExpect(jsonPath("$.error[0].extension[1].url", Is.is(CONTENT_LENGTH_STRING))).andExpect(jsonPath("$.error[0].extension[1].valueDecimal", Is.is(6000)));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(2, apiRequestEvents.size());
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
ApiRequestEvent requestEvent2 = (ApiRequestEvent) apiRequestEvents.get(1);
if (requestEvent.getUrl().contains("export")) {
assertNull(requestEvent.getJobId());
} else {
assertEquals(jobUuid, requestEvent.getJobId());
}
if (requestEvent2.getUrl().contains("export")) {
assertNull(requestEvent2.getJobId());
} else {
assertEquals(jobUuid, requestEvent2.getJobId());
}
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(2, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
ApiResponseEvent responseEvent2 = (ApiResponseEvent) apiResponseEvents.get(1);
assertEquals(jobUuid, responseEvent.getJobId());
assertEquals(jobUuid, responseEvent2.getJobId());
assertEquals(200, responseEvent2.getResponseCode());
assertTrue(requestEvent.getRequestId().equals(responseEvent.getRequestId()) || requestEvent.getRequestId().equalsIgnoreCase(responseEvent2.getRequestId()));
assertTrue(requestEvent2.getRequestId().equals(responseEvent.getRequestId()) || requestEvent2.getRequestId().equalsIgnoreCase(responseEvent2.getRequestId()));
assertEquals(requestEvent2.getRequestId(), responseEvent2.getRequestId());
// Technically the job status change has 1 entry but should have more because
// it went through the entire process, but because it is done manually here
// events weren't created for it.
assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class)));
}
use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testPatientExportDuplicateSubmission.
@Test
void testPatientExportDuplicateSubmission() throws Exception {
createMaxJobs();
MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(429)).andExpect(header().string("Retry-After", "30")).andExpect(header().doesNotExist(X_PROG)).andReturn();
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
assertEquals(MAX_JOBS_PER_CLIENT + 1, apiRequestEvents.size());
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
assertEquals(MAX_JOBS_PER_CLIENT + 1, apiResponseEvents.size());
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(apiResponseEvents.size() - 1);
assertEquals(HttpStatus.TOO_MANY_REQUESTS.value(), responseEvent.getResponseCode());
List<LoggableEvent> errorEvents = loggerEventRepository.load(ErrorEvent.class);
ErrorEvent errorEvent = (ErrorEvent) errorEvents.get(0);
assertEquals(ErrorEvent.ErrorType.TOO_MANY_STATUS_REQUESTS, errorEvent.getErrorType());
List<LoggableEvent> jobEvents = loggerEventRepository.load(JobStatusChangeEvent.class);
assertEquals(MAX_JOBS_PER_CLIENT, jobEvents.size());
jobEvents.forEach(e -> assertEquals(SUBMITTED.name(), ((JobStatusChangeEvent) e).getNewStatus()));
JobStatusChangeEvent jobEvent = (JobStatusChangeEvent) jobEvents.get(0);
assertEquals(SUBMITTED.name(), jobEvent.getNewStatus());
assertNull(jobEvent.getOldStatus());
assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(FileEvent.class)));
assertEquals(MAX_JOBS_PER_CLIENT, Objects.requireNonNull(mvcResult.getResponse().getHeader(CONTENT_LOCATION)).split(",").length);
}
use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.
the class BulkDataAccessAPIIntegrationTests method testBasicPatientExport.
@Test
void testBasicPatientExport() throws Exception {
ResultActions resultActions = this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token));
List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
assertEquals(1, apiRequestEvents.size());
List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
assertEquals(1, apiResponseEvents.size());
assertEquals(HttpStatus.ACCEPTED.value(), responseEvent.getResponseCode());
assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
List<LoggableEvent> jobEvents = loggerEventRepository.load(JobStatusChangeEvent.class);
assertEquals(1, jobEvents.size());
JobStatusChangeEvent jobEvent = (JobStatusChangeEvent) jobEvents.get(0);
assertEquals(SUBMITTED.name(), jobEvent.getNewStatus());
assertNull(jobEvent.getOldStatus());
assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class)));
String jobUuid = jobClientMock.pickAJob();
assertEquals(jobUuid, responseEvent.getJobId());
String statusUrl = "http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + "/Job/" + jobUuid + "/$status";
resultActions.andExpect(status().isAccepted()).andExpect(header().string(CONTENT_LOCATION, statusUrl));
StartJobDTO startJobDTO = jobClientMock.lookupJob(jobUuid);
assertEquals("http://localhost" + API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH, startJobDTO.getUrl());
assertEquals(EOB, startJobDTO.getResourceTypes());
assertEquals(pdpClientRepository.findByClientId(TEST_PDP_CLIENT).getOrganization(), startJobDTO.getOrganization());
}
Aggregations