use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup in project sechub by mercedes-benz.
the class CheckmarxProductExecutorMockTest method createCheckmarxSetupWithAllMandotoryPartsSet.
private ProductExecutorConfigSetup createCheckmarxSetupWithAllMandotoryPartsSet() {
ProductExecutorConfigSetup setup = mock(ProductExecutorConfigSetup.class);
ProductExecutorConfigSetupCredentials credentials = mock(ProductExecutorConfigSetupCredentials.class);
when(setup.getCredentials()).thenReturn(credentials);
when(credentials.getUser()).thenReturn("user");
when(credentials.getPassword()).thenReturn("pwd");
List<ProductExecutorConfigSetupJobParameter> jobParameters = new ArrayList<>();
MappingData data = new MappingData();
data.getEntries().add(new MappingEntry(".*", "teamId1", ""));
jobParameters.add(new ProductExecutorConfigSetupJobParameter(MappingIdentifier.CHECKMARX_NEWPROJECT_TEAM_ID.getId(), data.toJSON()));
when(setup.getJobParameters()).thenReturn(jobParameters);
return setup;
}
use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup 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.config.ProductExecutorConfigSetup 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.domain.scan.product.config.ProductExecutorConfigSetup in project sechub by mercedes-benz.
the class PDSProductExecutorMinimumConfigValidation method validate.
@Override
protected void validate(ValidationContext<ProductExecutorConfig> context) {
/* check not null... */
validateNotNull(context);
ProductExecutorConfig configToValidate = getObjectToValidate(context);
if (configToValidate == null) {
return;
}
ProductExecutorConfigSetup setup = configToValidate.getSetup();
validateNotNull(context, setup, "setup");
if (setup == null) {
return;
}
List<ProductExecutorConfigSetupJobParameter> jobParameters = setup.getJobParameters();
validateNotNull(context, jobParameters, "jobParameters");
if (jobParameters == null) {
return;
}
validateMandatoryPartsSet(context, jobParameters);
}
use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup in project sechub by mercedes-benz.
the class AbstractProductExecutionServiceTest method before.
@Before
public void before() throws Exception {
serviceToTest = new TestImplAbstractProductExecutionService();
serviceToTest.allAvailableProductExecutors = new ArrayList<>();
SecHubConfiguration configuration = new SecHubConfiguration();
configuration.setProjectId("projectid1");
sechubJobUUID = UUID.randomUUID();
logger = mock(Logger.class);
traceLogID = mock(UUIDTraceLogID.class);
executors = new ArrayList<>();
executor = mock(ProductExecutor.class);
when(executor.getIdentifier()).thenReturn(USED_PRODUCT_IDENTIFIER);
when(executor.getVersion()).thenReturn(USED_PRODUCT_EXECUTOR_VERSION);
executors.add(executor);
context = mock(SecHubExecutionContext.class);
when(context.getSechubJobUUID()).thenReturn(sechubJobUUID);
when(context.getConfiguration()).thenReturn(configuration);
ProductExecutorConfigRepository productExecutorConfigRepository = mock(ProductExecutorConfigRepository.class);
serviceToTest.productExecutorConfigRepository = productExecutorConfigRepository;
config1 = new ProductExecutorConfig(USED_PRODUCT_IDENTIFIER, 0, new ProductExecutorConfigSetup());
when(productExecutorConfigRepository.findExecutableConfigurationsForProject(any(), eq(USED_PRODUCT_IDENTIFIER), eq(USED_PRODUCT_EXECUTOR_VERSION))).thenReturn(Arrays.asList(config1));
productResultRepository = mock(ProductResultRepository.class);
serviceToTest.productResultRepository = productResultRepository;
productExecutorContextFactory = mock(ProductExecutorContextFactory.class);
serviceToTest.productExecutorContextFactory = productExecutorContextFactory;
productExecutorContext = mock(ProductExecutorContext.class);
when(productExecutorContextFactory.create(any(), any(), any(), any())).thenReturn(productExecutorContext);
}
Aggregations