Search in sources :

Example 1 with ProgressMonitor

use of com.mercedesbenz.sechub.sharedkernel.ProgressMonitor in project sechub by mercedes-benz.

the class ScanServiceTest method before.

@Before
public void before() throws Exception {
    storageService = mock(StorageService.class);
    jobStorage = mock(JobStorage.class);
    scanProjectConfigService = mock(ScanProjectConfigService.class);
    scanJobRegistry = mock(ScanJobListener.class);
    monitorFactory = mock(ScanProgressMonitorFactory.class);
    ProgressMonitor monitor = mock(ProgressMonitor.class);
    when(monitor.getId()).thenReturn("monitor-test-id");
    when(storageService.getJobStorage(any(), any())).thenReturn(jobStorage);
    when(monitorFactory.createProgressMonitor(any())).thenReturn(monitor);
    webScanProductExecutionService = mock(WebScanProductExecutionService.class);
    codeScanProductExecutionService = mock(CodeScanProductExecutionService.class);
    infrastructureScanProductExecutionService = mock(InfrastructureScanProductExecutionService.class);
    scanLogService = mock(ProjectScanLogService.class);
    reportService = mock(CreateScanReportService.class);
    report = mock(ScanReport.class);
    when(report.getTrafficLightAsString()).thenReturn(TRAFFIC_LIGHT);
    when(reportService.createReport(any())).thenReturn(report);
    serviceToTest = new ScanService();
    serviceToTest.webScanProductExecutionService = webScanProductExecutionService;
    serviceToTest.infraScanProductExecutionService = infrastructureScanProductExecutionService;
    serviceToTest.codeScanProductExecutionService = codeScanProductExecutionService;
    serviceToTest.reportService = reportService;
    serviceToTest.storageService = storageService;
    serviceToTest.scanLogService = scanLogService;
    serviceToTest.scanProjectConfigService = scanProjectConfigService;
    serviceToTest.scanJobListener = scanJobRegistry;
    serviceToTest.monitorFactory = monitorFactory;
}
Also used : ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) CodeScanProductExecutionService(com.mercedesbenz.sechub.domain.scan.product.CodeScanProductExecutionService) StorageService(com.mercedesbenz.sechub.storage.core.StorageService) ProgressMonitor(com.mercedesbenz.sechub.sharedkernel.ProgressMonitor) ProjectScanLogService(com.mercedesbenz.sechub.domain.scan.log.ProjectScanLogService) ScanProjectConfigService(com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfigService) InfrastructureScanProductExecutionService(com.mercedesbenz.sechub.domain.scan.product.InfrastructureScanProductExecutionService) WebScanProductExecutionService(com.mercedesbenz.sechub.domain.scan.product.WebScanProductExecutionService) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) CreateScanReportService(com.mercedesbenz.sechub.domain.scan.report.CreateScanReportService) Before(org.junit.Before)

Example 2 with ProgressMonitor

use of com.mercedesbenz.sechub.sharedkernel.ProgressMonitor in project sechub by mercedes-benz.

the class ScanService method executeScan.

protected void executeScan(SecHubExecutionContext context, DomainMessage request) throws SecHubExecutionException {
    DomainDataTraceLogID sechubJobUUID = traceLogID(request);
    LOG.info("start scan for {}", sechubJobUUID);
    UUID logUUID = scanLogService.logScanStarted(context);
    try {
        BatchJobMessage jobIdMessage = request.get(MessageDataKeys.BATCH_JOB_ID);
        if (jobIdMessage == null) {
            throw new IllegalStateException("no batch job id set for sechub job:" + sechubJobUUID);
        }
        long batchJobId = jobIdMessage.getBatchJobId();
        ProgressMonitor progressMonitor = monitorFactory.createProgressMonitor(batchJobId);
        /* delegate execution : */
        ScanJobExecutor executor = new ScanJobExecutor(this, context, progressMonitor, millisecondsToWaitBeforeCancelCheck);
        executor.execute();
        scanLogService.logScanEnded(logUUID);
    } catch (Exception e) {
        if (context.isAbandonded()) {
            scanLogService.logScanAbandoned(logUUID);
        } else {
            scanLogService.logScanFailed(logUUID);
        }
        /* rethrow when already an execution exception */
        if (e instanceof SecHubExecutionException) {
            SecHubExecutionException exceptionToRethrow = (SecHubExecutionException) e;
            throw exceptionToRethrow;
        }
        /* wrap it */
        throw new SecHubExecutionException("Execute scan failed", e);
    }
}
Also used : ProgressMonitor(com.mercedesbenz.sechub.sharedkernel.ProgressMonitor) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) BatchJobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage) DomainDataTraceLogID(com.mercedesbenz.sechub.sharedkernel.messaging.DomainDataTraceLogID) UUID(java.util.UUID) JSONConverterException(com.mercedesbenz.sechub.commons.model.JSONConverterException) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) IOException(java.io.IOException) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Aggregations

ProgressMonitor (com.mercedesbenz.sechub.sharedkernel.ProgressMonitor)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 ProjectScanLogService (com.mercedesbenz.sechub.domain.scan.log.ProjectScanLogService)1 CodeScanProductExecutionService (com.mercedesbenz.sechub.domain.scan.product.CodeScanProductExecutionService)1 InfrastructureScanProductExecutionService (com.mercedesbenz.sechub.domain.scan.product.InfrastructureScanProductExecutionService)1 WebScanProductExecutionService (com.mercedesbenz.sechub.domain.scan.product.WebScanProductExecutionService)1 ScanProjectConfigService (com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfigService)1 CreateScanReportService (com.mercedesbenz.sechub.domain.scan.report.CreateScanReportService)1 ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)1 DomainDataTraceLogID (com.mercedesbenz.sechub.sharedkernel.messaging.DomainDataTraceLogID)1 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)1 StorageService (com.mercedesbenz.sechub.storage.core.StorageService)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1 Before (org.junit.Before)1