Search in sources :

Example 1 with SecHubExecutionException

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

the class CheckmarxProductExecutorMockTest method when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time.

@Test
public void when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time() throws Exception {
    /* prepare */
    SecHubExecutionContext context = createExecutionContextForPseudoCodeScan();
    ProductExecutorCallback callback = mock(ProductExecutorCallback.class);
    ProductExecutorConfigSetup setup = createCheckmarxSetupWithAllMandotoryPartsSet();
    ProductExecutorConfig executorConfig = new ProductExecutorConfig(ProductIdentifier.CHECKMARX, 1, setup);
    ProductExecutorContext executorContext = mock(ProductExecutorContext.class);
    when(executorContext.getCallback()).thenReturn(callback);
    when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
    ProductResult currentResult = new ProductResult(JOB_UUID, PROJECT_EXAMPLE, executorConfig, "pseudo-result");
    when(executorContext.getCurrentProductResult()).thenReturn(currentResult);
    /* @formatter:off */
    when(checkmarxAdapter.start(any(), any())).thenThrow(// first fails
    new AdapterException(new AdapterLogId("1", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenThrow(// second fails
    new AdapterException(new AdapterLogId("2", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenReturn(// third: would be access but should not happen! resilience shall here only work one time!
    "result2");
    /* @formatter:on */
    SecHubExecutionException expected = null;
    /* execute */
    try {
        executorToTest.execute(context, executorContext);
    } catch (SecHubExecutionException e) {
        expected = e;
    }
    /* test */
    assertNotNull("No SecHubExecutionException happened, but must!", expected);
    // the adapter must be called twice - first errr, than one retry, third error
    verify(checkmarxAdapter, times(2)).start(any(), any());
    // means no retry again
    Throwable cause = expected.getCause();
    String message = cause.getMessage();
    assertTrue(message.contains("Changes exceeded the threshold limit"));
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ProductExecutorCallback(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback) AdapterLogId(com.mercedesbenz.sechub.adapter.AdapterLogId) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Test(org.junit.Test)

Example 2 with SecHubExecutionException

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

the class SecHubExecutionExceptionTest method throwAsSecHubExecutionException_rethrows_adapter_exception_when_exception_is_adapter_exception.

@Test
public void throwAsSecHubExecutionException_rethrows_adapter_exception_when_exception_is_adapter_exception() throws Exception {
    /* prepare */
    SecHubExecutionException cause = new SecHubExecutionException("originMessage");
    /* test */
    expected.expect(SecHubExecutionException.class);
    expected.expectMessage("originMessage");
    /* execute */
    throwAsSecHubExecutionException("otherMessage", cause);
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) Test(org.junit.Test)

Example 3 with SecHubExecutionException

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

the class AbstractProductExecutor method startExecution.

private List<ProductResult> startExecution(ProductExecutorData data) throws SecHubExecutionException {
    LOG.debug("Executing {}", data.traceLogId);
    try {
        List<ProductResult> targetResults = new ArrayList<>();
        if (data.networkTargetInfoList == null) {
            /* no special network target handling necessary - so just start one time */
            executeByAdapterAndSetTime(data, targetResults);
        } else {
            /* network target handling necessary */
            if (data.networkTargetInfoList.isEmpty()) {
                LOG.warn("{} Was not able to execute because not even one target registry info found!", data.traceLogId);
            } else {
                for (NetworkTargetInfo info : data.networkTargetInfoList) {
                    /* change current registry info */
                    data.currentNetworkTargetInfo = info;
                    executeByAdapterAndSetTime(data, targetResults);
                }
            }
        }
        return targetResults;
    } catch (SecHubExecutionException e) {
        throw e;
    } catch (Exception e) {
        /*
             * every other exception is wrapped to a SecHub execution exception which is
             * handled
             */
        throw new SecHubExecutionException(getIdentifier() + " execution failed." + data.traceLogId, e);
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ArrayList(java.util.ArrayList) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Example 4 with SecHubExecutionException

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

the class ScanServiceTest method scanservice_does_cleanup_storage_of_job__when_HAS_failed.

/**
 * Here we test that on failure the storage is ALSO cleaned. Why? Because in
 * future there should be the possiblity for a retry mechanism, but currently
 * there is none. When this is implemented we must change the test so it will
 * check there is NO cleaning. But having no retry mechanism implemented, we
 * expect the cleanup process done even when failing.
 *
 * @throws Exception
 */
@Test
public void scanservice_does_cleanup_storage_of_job__when_HAS_failed() throws Exception {
    /* prepare */
    DomainMessage request = prepareValidRequest();
    doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any());
    /* execute */
    DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request);
    /* test */
    assertTrue(result.hasFailed());
    verify(jobStorage).deleteAll();
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 5 with SecHubExecutionException

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

the class ScanServiceTest method scanservice_does_NOT_execute_reportservice_when_webscan_throws_sechubexception.

@Test
public void scanservice_does_NOT_execute_reportservice_when_webscan_throws_sechubexception() throws Exception {
    /* prepare */
    DomainMessage request = prepareValidRequest();
    doThrow(new SecHubExecutionException("ups...", new RuntimeException())).when(webScanProductExecutionService).executeProductsAndStoreResults(any());
    /* execute */
    DomainMessageSynchronousResult result = serviceToTest.receiveSynchronMessage(request);
    /* test */
    assertTrue(result.hasFailed());
    verify(webScanProductExecutionService).executeProductsAndStoreResults(any());
    verify(reportService, never()).createReport(any());
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Aggregations

SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)14 Test (org.junit.Test)6 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)3 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)3 UUID (java.util.UUID)3 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)2 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)2 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)2 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)2 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)2 IOException (java.io.IOException)2 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)1 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)1 TrafficLight (com.mercedesbenz.sechub.commons.model.TrafficLight)1 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)1 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)1 TargetRegistry (com.mercedesbenz.sechub.domain.scan.TargetRegistry)1 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)1