use of com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback in project sechub by mercedes-benz.
the class CheckmarxProductExecutorMockTest method when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done.
@Test
public void when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done() 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")).thenReturn(// second: access
"result2");
/* @formatter:on */
/* execute */
executorToTest.execute(context, executorContext);
/* test */
// the adapter must be called twice
verify(checkmarxAdapter, times(2)).start(any(), any());
}
use of com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback 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"));
}
Aggregations