Search in sources :

Example 1 with ExitThrowable

use of com.checkmarx.flow.exception.ExitThrowable in project cx-flow by checkmarx-ltd.

the class ThresholdsSteps method validateExitCode.

@Then("cxflow should exit with the correct {}")
public void validateExitCode(int expectedExitCode) {
    Throwable exception = testContext.getCxFlowExecutionException();
    Assert.assertNotNull("Expected an exception to be thrown.", exception);
    Assert.assertEquals(InvocationTargetException.class, exception.getClass());
    Throwable targetException = ((InvocationTargetException) exception).getTargetException();
    Assert.assertTrue(targetException instanceof ExitThrowable);
    int actualExitCode = ((ExitThrowable) targetException).getExitCode();
    Assert.assertEquals("The expected exist code did not match", expectedExitCode, actualExitCode);
}
Also used : ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Then(io.cucumber.java.en.Then)

Example 2 with ExitThrowable

use of com.checkmarx.flow.exception.ExitThrowable in project cx-flow by checkmarx-ltd.

the class ScaThresholdsSteps method validateExitCode.

@Then("cxflow SCA should exit with the correct {}")
public void validateExitCode(int expectedExitCode) {
    Throwable exception = testContext.getCxFlowExecutionException();
    Assert.assertNotNull("Expected an exception to be thrown.", exception);
    Assert.assertEquals(InvocationTargetException.class, exception.getClass());
    Throwable targetException = ((InvocationTargetException) exception).getTargetException();
    Assert.assertTrue(targetException instanceof ExitThrowable);
    int actualExitCode = ((ExitThrowable) targetException).getExitCode();
    Assert.assertEquals("The expected exist code did not match", expectedExitCode, actualExitCode);
}
Also used : ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Then(io.cucumber.java.en.Then)

Example 3 with ExitThrowable

use of com.checkmarx.flow.exception.ExitThrowable in project cx-flow by checkmarx-ltd.

the class AstCliSteps method validateExitCode.

@Then("run should exit with exit code {}")
public void validateExitCode(int expectedExitCode) {
    Assert.assertNotNull("Expected an exception to be thrown.", cxFlowExecutionException);
    Assert.assertEquals(InvocationTargetException.class, cxFlowExecutionException.getClass());
    Throwable targetException = ((InvocationTargetException) cxFlowExecutionException).getTargetException();
    Assert.assertTrue(targetException instanceof ExitThrowable);
    int actualExitCode = ((ExitThrowable) targetException).getExitCode();
    Assert.assertEquals("The expected exit code did not match", expectedExitCode, actualExitCode);
}
Also used : ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Then(io.cucumber.java.en.Then)

Example 4 with ExitThrowable

use of com.checkmarx.flow.exception.ExitThrowable in project cx-flow by checkmarx-ltd.

the class CxFlowRunner method run.

@Override
public void run(ApplicationArguments args) throws InvocationTargetException {
    if (!args.getOptionNames().isEmpty()) {
        try {
            if (args.containsOption("web")) {
                log.debug("Running web mode");
            } else {
                log.debug("Running cmd mode. Parameters: {}", String.join(" ", args.getSourceArgs()));
                commandLineRunner(args);
            }
        } catch (ExitThrowable ee) {
            log.info("Finished with exit code: {}", ee.getExitCode());
            if (args.containsOption(THROW_INSTEAD_OF_EXIT_OPTION)) {
                throw new InvocationTargetException(ee);
            }
            System.exit(ee.getExitCode());
        } finally {
            if (executors != null && (args.containsOption("scan") || args.containsOption(PARSE_OPTION) || args.containsOption(BATCH_OPTION))) {
                executors.forEach(ThreadPoolTaskExecutor::shutdown);
            }
        }
    }
}
Also used : ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ExitThrowable

use of com.checkmarx.flow.exception.ExitThrowable in project cx-flow by checkmarx-ltd.

the class RunningCxFlowSteps method cxflowExitsWithStatusCodeStatusCode.

@Then("CxFlow exits with exit code {}")
public void cxflowExitsWithStatusCodeStatusCode(int expectedExitCode) {
    Throwable exception = testContext.getCxFlowExecutionException();
    Assert.assertNotNull("Expected an exception to be thrown.", exception);
    Assert.assertEquals(InvocationTargetException.class, exception.getClass());
    Throwable targetException = ((InvocationTargetException) exception).getTargetException();
    Assert.assertTrue(targetException instanceof ExitThrowable);
    int actualExitCode = ((ExitThrowable) targetException).getExitCode();
    Assert.assertEquals(expectedExitCode, actualExitCode);
}
Also used : ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) ExitThrowable(com.checkmarx.flow.exception.ExitThrowable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Then(io.cucumber.java.en.Then)

Aggregations

ExitThrowable (com.checkmarx.flow.exception.ExitThrowable)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 Then (io.cucumber.java.en.Then)6 ScanRequest (com.checkmarx.flow.dto.ScanRequest)1 When (io.cucumber.java.en.When)1 File (java.io.File)1 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)1