Skip to content

Commit

Permalink
fix: Fixed unstable JobsService test (#52)
Browse files Browse the repository at this point in the history
Refs: #51
  • Loading branch information
nirikash authored Jul 1, 2024
1 parent 266f527 commit 3fb7fdc
Showing 1 changed file with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ void shouldStartJobAndGetStatus() {
JobState jobState = pdfConverterJobsService.getJobState(jobId);
assertThat(jobState.isCompletedExceptionally()).isFalse();
assertThat(jobState.isCancelled()).isFalse();
Optional<byte[]> jobResult = pdfConverterJobsService.getJobResult(jobId);
assertThat(jobResult).isNotEmpty();
assertThat(new String(jobResult.get())).isEqualTo("test pdf");

assertThatThrownBy(() -> pdfConverterJobsService.getJobState(jobId))
.isInstanceOf(NoSuchElementException.class)
.hasMessageContaining(jobId);
verify(securityService).logout(subject);
}

Expand All @@ -94,32 +101,11 @@ void shouldReturnFailInExceptionalCase() {
verify(securityService).logout(subject);
}

@Test
void shouldReturnResultAndCleanJob() {
prepareSecurityServiceSubject(subject);
when(requestAttributes.getAttribute(LogoutFilter.ASYNC_SKIP_LOGOUT, RequestAttributes.SCOPE_REQUEST)).thenReturn(Boolean.TRUE);
ExportParams exportParams = ExportParams.builder().build();
when(pdfConverter.convertToPdf(exportParams, null)).thenReturn("test pdf".getBytes());

String jobId = pdfConverterJobsService.startJob(exportParams, 60);

assertThat(jobId).isNotBlank();
waitToFinishJob(jobId);
Optional<byte[]> jobResult = pdfConverterJobsService.getJobResult(jobId);
assertThat(jobResult).isNotEmpty();
assertThat(new String(jobResult.get())).isEqualTo("test pdf");

assertThatThrownBy(() -> pdfConverterJobsService.getJobState(jobId))
.isInstanceOf(NoSuchElementException.class)
.hasMessageContaining(jobId);
verify(securityService).logout(subject);
}

@Test
void shouldGetAllJobsStatuses() {
prepareSecurityServiceSubject(subject);
ExportParams exportParams = ExportParams.builder().build();
when(pdfConverter.convertToPdf(exportParams, null)).thenReturn("test pdf".getBytes());
lenient().when(pdfConverter.convertToPdf(exportParams, null)).thenReturn("test pdf".getBytes());

String jobId1 = pdfConverterJobsService.startJob(exportParams, 60);
String jobId2 = pdfConverterJobsService.startJob(exportParams, 60);
Expand Down

0 comments on commit 3fb7fdc

Please sign in to comment.