use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerUploadServiceTest method beforeEach.
@BeforeEach
void beforeEach() {
randomUuid = UUID.randomUUID();
mockedChecksumService = mock(ChecksumSHA256Service.class);
mockedStorageService = mock(StorageService.class);
mockedAssertService = mock(ScheduleAssertService.class);
ScheduleSecHubJob job = new ScheduleSecHubJob();
when(mockedAssertService.assertJob(PROJECT1, randomUuid)).thenReturn(job);
storage = mock(JobStorage.class);
when(mockedStorageService.getJobStorage(PROJECT1, randomUuid)).thenReturn(storage);
file = mock(MultipartFile.class);
mockedZipSupport = mock(ZipSupport.class);
/* attach at service to test */
serviceToTest = new SchedulerUploadService();
serviceToTest.checksumSHA256Service = mockedChecksumService;
serviceToTest.storageService = mockedStorageService;
serviceToTest.assertService = mockedAssertService;
serviceToTest.zipSupport = mockedZipSupport;
serviceToTest.logSanitizer = mock(LogSanitizer.class);
serviceToTest.assertion = mock(UserInputAssertion.class);
serviceToTest.auditLogService = mock(AuditLogService.class);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class SchedulerUploadService method assertJobFoundAndStillInitializing.
private void assertJobFoundAndStillInitializing(String projectId, UUID jobUUID) {
ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
ExecutionState state = secHubJob.getExecutionState();
if (!ExecutionState.INITIALIZING.equals(state)) {
// upload only possible when in initializing state
throw new NotAcceptableException("Not in correct state");
}
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class ScheduleJobLauncherServiceTest method executeJob__sends_domain_message_about_JOB_STARTED.
@Test
public void executeJob__sends_domain_message_about_JOB_STARTED() throws Exception {
/* prepare */
UUID jobUUID = UUID.randomUUID();
ScheduleSecHubJob secHubJob = mock(ScheduleSecHubJob.class);
when(secHubJob.getJsonConfiguration()).thenReturn("jsonConfig");
when(secHubJob.getUUID()).thenReturn(jobUUID);
when(jobRepository.findNextJobToExecute()).thenReturn(Optional.of(secHubJob));
/* execute */
serviceToTest.executeJob(secHubJob);
/* test */
ArgumentCaptor<DomainMessage> message = ArgumentCaptor.forClass(DomainMessage.class);
verify(eventBus).sendAsynchron(message.capture());
assertEquals(MessageID.JOB_STARTED, message.getValue().getMessageId());
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class ScheduleJobLauncherServiceTest method executeJob__calls_job_launcher_with_job_uuid_as_parameter.
@Test
public void executeJob__calls_job_launcher_with_job_uuid_as_parameter() throws Exception {
/* prepare */
UUID jobUUID = UUID.randomUUID();
ScheduleSecHubJob secHubJob = mock(ScheduleSecHubJob.class);
when(secHubJob.getJsonConfiguration()).thenReturn("jsonConfig");
when(secHubJob.getUUID()).thenReturn(jobUUID);
when(jobRepository.findNextJobToExecute()).thenReturn(Optional.of(secHubJob));
/* execute */
serviceToTest.executeJob(secHubJob);
/* test */
ArgumentCaptor<JobParameters> captor = ArgumentCaptor.forClass(JobParameters.class);
verify(asyncJobLauncher).run(any(Job.class), captor.capture());
String sechubUUID = captor.getValue().getString(BATCHPARAM_SECHUB_UUID);
assertEquals(MOCKED_PARAM_BUILDER_SECHUB_UUID, sechubUUID);
}
use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.
the class ScheduleJobMarkerServiceTest method markNextJobExecutedByThisPOD__updates_execution_state_to_started.
@Test
public void markNextJobExecutedByThisPOD__updates_execution_state_to_started() throws Exception {
/* prepare */
when(jobRepository.save(secHubJob)).thenReturn(secHubJob);
/* execute */
ScheduleSecHubJob result = serviceToTest.markNextJobToExecuteByThisInstance();
/* test */
verify(secHubJob).setStarted(any());
verify(secHubJob).setExecutionState(eq(ExecutionState.STARTED));
assertEquals(secHubJob, result);
}
Aggregations