Search in sources :

Example 6 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class BulkDataAccessAPIUnusualDataTests method testPatientExportWithNoAttestation.

@Test
void testPatientExportWithNoAttestation() throws Exception {
    // Valid contract number for sponsor, but no attestation
    String token = testUtil.setupContractWithNoAttestation(List.of(SPONSOR_ROLE));
    Optional<Contract> contractOptional = contractRepository.findContractByContractNumber(VALID_CONTRACT_NUMBER);
    Contract contract = contractOptional.get();
    this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + "/Group/" + contract.getContractNumber() + "/$export").contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(403));
    List<LoggableEvent> apiRequestEvents = loggerEventRepository.load(ApiRequestEvent.class);
    ApiRequestEvent requestEvent = (ApiRequestEvent) apiRequestEvents.get(0);
    List<LoggableEvent> apiResponseEvents = loggerEventRepository.load(ApiResponseEvent.class);
    ApiResponseEvent responseEvent = (ApiResponseEvent) apiResponseEvents.get(0);
    assertEquals(requestEvent.getRequestId(), responseEvent.getRequestId());
    List<LoggableEvent> errorEvents = loggerEventRepository.load(ErrorEvent.class);
    ErrorEvent errorEvent = (ErrorEvent) errorEvents.get(0);
    assertEquals(ErrorEvent.ErrorType.UNAUTHORIZED_CONTRACT, errorEvent.getErrorType());
    assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(JobStatusChangeEvent.class), loggerEventRepository.load(FileEvent.class)));
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) Contract(gov.cms.ab2d.common.model.Contract) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class AdminAPIMaintenanceModeTests method testSwitchMaintenanceModeOnAndOff.

@Test
public void testSwitchMaintenanceModeOnAndOff() throws Exception {
    List<PropertiesDTO> propertiesDTOs = new ArrayList<>();
    PropertiesDTO maintenanceModeDTO = new PropertiesDTO();
    maintenanceModeDTO.setKey(MAINTENANCE_MODE);
    maintenanceModeDTO.setValue("true");
    propertiesDTOs.add(maintenanceModeDTO);
    ObjectMapper mapper = new ObjectMapper();
    this.mockMvc.perform(put(API_PREFIX_V1 + ADMIN_PREFIX + PROPERTIES_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(propertiesDTOs)).header("Authorization", "Bearer " + token)).andExpect(status().is(200));
    this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
    List<LoggableEvent> apiReqEvents = loggerEventRepository.load(ApiRequestEvent.class);
    assertEquals(2, apiReqEvents.size());
    List<LoggableEvent> apiResEvents = loggerEventRepository.load(ApiResponseEvent.class);
    assertEquals(1, apiResEvents.size());
    ApiResponseEvent responseEvent = (ApiResponseEvent) apiResEvents.get(0);
    assertEquals(HttpStatus.SERVICE_UNAVAILABLE.value(), responseEvent.getResponseCode());
    List<LoggableEvent> reloadEvents = loggerEventRepository.load(ReloadEvent.class);
    assertEquals(1, reloadEvents.size());
    ReloadEvent reloadEvent = (ReloadEvent) reloadEvents.get(0);
    assertEquals(ReloadEvent.FileType.PROPERTIES, reloadEvent.getFileType());
    assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class), loggerEventRepository.load(JobStatusChangeEvent.class)));
    propertiesDTOs.clear();
    maintenanceModeDTO.setValue("false");
    propertiesDTOs.add(maintenanceModeDTO);
    this.mockMvc.perform(put(API_PREFIX_V1 + ADMIN_PREFIX + PROPERTIES_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(propertiesDTOs)).header("Authorization", "Bearer " + token)).andExpect(status().is(200));
    this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(202));
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) ArrayList(java.util.ArrayList) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class JobProcessorIntegrationTest method processJob.

@Test
@DisplayName("When a job is in submitted status, it can be processed")
void processJob() {
    var processedJob = cut.process(job.getJobUuid());
    List<LoggableEvent> jobStatusChange = loggerEventRepository.load(JobStatusChangeEvent.class);
    assertEquals(1, jobStatusChange.size());
    JobStatusChangeEvent jobEvent = (JobStatusChangeEvent) jobStatusChange.get(0);
    assertEquals(JobStatus.SUCCESSFUL.name(), jobEvent.getNewStatus());
    assertEquals(JobStatus.IN_PROGRESS.name(), jobEvent.getOldStatus());
    assertEquals(JobStatus.SUCCESSFUL, processedJob.getStatus());
    assertEquals(COMPLETED_PERCENT, processedJob.getStatusMessage());
    assertNotNull(processedJob.getExpiresAt());
    assertNotNull(processedJob.getCompletedAt());
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) JobStatusChangeEvent(gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class JobProcessorIntegrationTest method when_beneHasNoEobs_notCounted.

@Test
@DisplayName("When bene has no eobs then do not count bene toward statistic")
void when_beneHasNoEobs_notCounted() {
    reset(mockBfdClient);
    OngoingStubbing<IBaseBundle> stubbing = when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any()));
    stubbing = andThenAnswerEobs(stubbing, 0, 95);
    stubbing.thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle());
    var processedJob = cut.process(job.getJobUuid());
    assertEquals(JobStatus.SUCCESSFUL, processedJob.getStatus());
    assertEquals(COMPLETED_PERCENT, processedJob.getStatusMessage());
    assertNotNull(processedJob.getExpiresAt());
    assertNotNull(processedJob.getCompletedAt());
    List<LoggableEvent> beneSearchEvents = loggerEventRepository.load(ContractSearchEvent.class);
    assertEquals(1, beneSearchEvents.size());
    ContractSearchEvent event = (ContractSearchEvent) beneSearchEvents.get(0);
    assertEquals(JOB_UUID, event.getJobId());
    assertEquals(100, event.getBenesExpected());
    assertEquals(100, event.getBenesSearched());
    assertEquals(CONTRACT_NAME, event.getContractNumber());
    assertEquals(95, event.getBenesWithEobs());
    final List<JobOutput> jobOutputs = processedJob.getJobOutputs();
    assertFalse(jobOutputs.isEmpty());
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) JobOutput(gov.cms.ab2d.common.model.JobOutput) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with LoggableEvent

use of gov.cms.ab2d.eventlogger.LoggableEvent in project ab2d by CMSgov.

the class JobPreProcessorIntegrationTest method whenJobIsInSubmittedStatus_ThenJobShouldBePutInProgress.

@Test
@DisplayName("When a job is in submitted status, it can be put into progress upon starting processing")
void whenJobIsInSubmittedStatus_ThenJobShouldBePutInProgress() throws InterruptedException {
    when(coverageDriver.isCoverageAvailable(any(Job.class), any(ContractDTO.class))).thenReturn(true);
    var processedJob = cut.preprocess(job.getJobUuid());
    assertEquals(JobStatus.IN_PROGRESS, processedJob.getStatus());
    List<LoggableEvent> jobStatusChange = loggerEventRepository.load(JobStatusChangeEvent.class);
    assertEquals(1, jobStatusChange.size());
    JobStatusChangeEvent event = (JobStatusChangeEvent) jobStatusChange.get(0);
    assertEquals("SUBMITTED", event.getOldStatus());
    assertEquals("IN_PROGRESS", event.getNewStatus());
    assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ApiRequestEvent.class), loggerEventRepository.load(ApiResponseEvent.class), loggerEventRepository.load(ReloadEvent.class), loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class)));
    loggerEventRepository.delete();
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) JobStatusChangeEvent(gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)36 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)33 Test (org.junit.jupiter.api.Test)22 OffsetDateTime (java.time.OffsetDateTime)11 DisplayName (org.junit.jupiter.api.DisplayName)11 File (java.io.File)8 Path (java.nio.file.Path)7 ApiResponseEvent (gov.cms.ab2d.eventlogger.events.ApiResponseEvent)5 FileEvent (gov.cms.ab2d.eventlogger.events.FileEvent)5 JobStatusChangeEvent (gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent)5 ApiRequestEvent (gov.cms.ab2d.eventlogger.events.ApiRequestEvent)4 ArrayList (java.util.ArrayList)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 SpringIntegrationTest (org.springframework.integration.test.context.SpringIntegrationTest)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)3 Job (gov.cms.ab2d.common.model.Job)3 PdpClient (gov.cms.ab2d.common.model.PdpClient)3 ContractSearchEvent (gov.cms.ab2d.eventlogger.events.ContractSearchEvent)3 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)3