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 */
}
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);
}
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);
}
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());
}
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()));
}
Aggregations