Search in sources :

Example 16 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userUploadsSourceCode.

@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsSourceCode.class)
public void restDoc_userUploadsSourceCode() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildUploadSourceCodeUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserUploadsSourceCode.class;
    ScheduleSecHubJob job = new ScheduleSecHubJob() {

        public UUID getUUID() {
            return randomUUID;
        }
    };
    job.setExecutionResult(ExecutionResult.OK);
    job.setStarted(LocalDateTime.now().minusMinutes(15));
    job.setEnded(LocalDateTime.now());
    job.setExecutionState(ExecutionState.INITIALIZING);
    job.setOwner("CREATOR1");
    job.setTrafficLight(TrafficLight.GREEN);
    ScheduleJobStatus status = new ScheduleJobStatus(job);
    when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
    InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/zipfile_contains_only_test1.txt.zip");
    MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
    /* execute + test @formatter:off */
    this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sourcecode shall be uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
    requestParts(partWithName("file").description("The sourcecode as zipfile to upload"))));
/* @formatter:on */
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) InputStream(java.io.InputStream) ScheduleJobStatus(com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseUserUploadsSourceCode(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserUploadsSourceCode) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 17 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerBinariesUploadServiceTest method beforeEach.

@BeforeEach
void beforeEach() {
    randomUuid = UUID.randomUUID();
    checksumService = mock(ChecksumSHA256Service.class);
    storageService = mock(StorageService.class);
    assertService = mock(ScheduleAssertService.class);
    storage = mock(JobStorage.class);
    httpRequest = mock(HttpServletRequest.class);
    configuration = mock(SchedulerBinariesUploadConfiguration.class);
    ScheduleSecHubJob job = new ScheduleSecHubJob();
    when(assertService.assertJob(PROJECT1, randomUuid)).thenReturn(job);
    when(storageService.getJobStorage(PROJECT1, randomUuid)).thenReturn(storage);
    /* attach at service to test */
    serviceToTest = new SchedulerBinariesUploadService();
    serviceToTest.checksumSHA256Service = checksumService;
    serviceToTest.storageService = storageService;
    serviceToTest.assertService = assertService;
    serviceToTest.configuration = configuration;
    serviceToTest.logSanitizer = mock(LogSanitizer.class);
    serviceToTest.assertion = mock(UserInputAssertion.class);
    serviceToTest.auditLogService = mock(AuditLogService.class);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ChecksumSHA256Service(com.mercedesbenz.sechub.sharedkernel.util.ChecksumSHA256Service) AuditLogService(com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService) LogSanitizer(com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer) UserInputAssertion(com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) StorageService(com.mercedesbenz.sechub.storage.core.StorageService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerSourcecodeUploadServiceTest 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);
    archiveSupportProvider = mock(ArchiveSupportProvider.class);
    mockedArchiveSupport = mock(ArchiveSupport.class);
    when(archiveSupportProvider.getArchiveSupport()).thenReturn(mockedArchiveSupport);
    configuration = mock(SchedulerSourcecodeUploadConfiguration.class);
    /* attach at service to test */
    serviceToTest = new SchedulerSourcecodeUploadService();
    serviceToTest.checksumSHA256Service = mockedChecksumService;
    serviceToTest.storageService = mockedStorageService;
    serviceToTest.assertService = mockedAssertService;
    serviceToTest.archiveSupportProvider = archiveSupportProvider;
    serviceToTest.configuration = configuration;
    serviceToTest.logSanitizer = mock(LogSanitizer.class);
    serviceToTest.assertion = mock(UserInputAssertion.class);
    serviceToTest.auditLogService = mock(AuditLogService.class);
}
Also used : ChecksumSHA256Service(com.mercedesbenz.sechub.sharedkernel.util.ChecksumSHA256Service) AuditLogService(com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService) ArchiveSupportProvider(com.mercedesbenz.sechub.sharedkernel.util.ArchiveSupportProvider) LogSanitizer(com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer) StorageService(com.mercedesbenz.sechub.storage.core.StorageService) MultipartFile(org.springframework.web.multipart.MultipartFile) UserInputAssertion(com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) ArchiveSupport(com.mercedesbenz.sechub.commons.archive.ArchiveSupport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerStartHandlerTest method schedulerHasBeenStarted.

@Test
public void schedulerHasBeenStarted() throws Exception {
    /* prepare */
    List<ScheduleSecHubJob> jobsRunningButStartedBefore = new ArrayList<>();
    ScheduleSecHubJob job1 = mock(ScheduleSecHubJob.class);
    UUID uuid1 = UUID.randomUUID();
    when(job1.getUUID()).thenReturn(uuid1);
    jobsRunningButStartedBefore.add(job1);
    when(repository.findAllRunningJobsStartedBefore(any())).thenReturn(jobsRunningButStartedBefore);
    /* execute */
    handlerToTest.schedulerHasBeenStarted().run();
    /* test */
    ArgumentCaptor<DomainMessage> argument = ArgumentCaptor.forClass(DomainMessage.class);
    verify(eventBus).sendAsynchron(argument.capture());
    DomainMessage domainMessage = argument.getValue();
    assertEquals(BASE_URL1, domainMessage.get(MessageDataKeys.ENVIRONMENT_BASE_URL));
    ClusterMemberMessage status = domainMessage.get(MessageDataKeys.ENVIRONMENT_CLUSTER_MEMBER_STATUS);
    assertNotNull(status);
    assertEquals(HOSTNAME_1, status.getHostName());
}
Also used : ArrayList(java.util.ArrayList) ClusterMemberMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ClusterMemberMessage) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UUID(java.util.UUID) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 20 with ScheduleSecHubJob

use of com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob in project sechub by mercedes-benz.

the class SchedulerStartHandlerTest method buildZombieInformation_zombiesFound_infomrmation_with_job_UUID_is_contained.

@Test
public void buildZombieInformation_zombiesFound_infomrmation_with_job_UUID_is_contained() {
    /* prepare */
    List<ScheduleSecHubJob> jobsRunningButStartedBefore = new ArrayList<>();
    ScheduleSecHubJob job1 = mock(ScheduleSecHubJob.class);
    ScheduleSecHubJob job2 = mock(ScheduleSecHubJob.class);
    UUID uuid1 = UUID.randomUUID();
    UUID uuid2 = UUID.randomUUID();
    when(job1.getUUID()).thenReturn(uuid1);
    when(job2.getUUID()).thenReturn(uuid2);
    jobsRunningButStartedBefore.add(job1);
    jobsRunningButStartedBefore.add(job2);
    /* execute */
    String result = handlerToTest.buildZombieInformation(jobsRunningButStartedBefore);
    /* test */
    assertTrue(result.contains("ATTENTION: Potential zombie jobs found"));
    assertTrue(result.contains(uuid1.toString()));
    assertTrue(result.contains(uuid2.toString()));
}
Also used : ArrayList(java.util.ArrayList) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UUID(java.util.UUID) 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