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