Search in sources :

Example 1 with ScheduleSecHubJob

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);
}
Also used : ChecksumSHA256Service(com.mercedesbenz.sechub.sharedkernel.util.ChecksumSHA256Service) MultipartFile(org.springframework.web.multipart.MultipartFile) AuditLogService(com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService) LogSanitizer(com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer) UserInputAssertion(com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) ZipSupport(com.mercedesbenz.sechub.sharedkernel.util.ZipSupport) StorageService(com.mercedesbenz.sechub.storage.core.StorageService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ScheduleSecHubJob

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");
    }
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 3 with ScheduleSecHubJob

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());
}
Also used : UUID(java.util.UUID) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 4 with ScheduleSecHubJob

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);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) UUID(java.util.UUID) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) Job(org.springframework.batch.core.Job) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) Test(org.junit.Test)

Example 5 with ScheduleSecHubJob

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);
}
Also used : ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) Test(org.junit.Test)

Aggregations

ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)30 Test (org.junit.Test)12 UUID (java.util.UUID)6 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 ScheduleJobStatus (com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus)4 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)4 NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)3 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)3 AuditLogService (com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService)3 LogSanitizer (com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer)3 ChecksumSHA256Service (com.mercedesbenz.sechub.sharedkernel.util.ChecksumSHA256Service)3 UserInputAssertion (com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 StorageService (com.mercedesbenz.sechub.storage.core.StorageService)3 InputStream (java.io.InputStream)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 UseCaseSchedulerStartsJob (com.mercedesbenz.sechub.sharedkernel.usecases.job.UseCaseSchedulerStartsJob)2 UseCaseUserApprovesJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)2