com.consol.citrus.TestCase Java Examples

The following examples show how to use com.consol.citrus.TestCase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 6 votes vote down vote up
public void completeTestAction(TestCase testCase, TestAction testAction) {
    if (skipTestAction(testAction)) {
        return;
    }

    ScenarioExecution te = lookupScenarioExecution(testCase);
    Iterator<ScenarioAction> iterator = te.getScenarioActions().iterator();
    ScenarioAction lastScenarioAction = null;
    while (iterator.hasNext()) {
        lastScenarioAction = iterator.next();
    }

    if (lastScenarioAction == null) {
        throw new CitrusRuntimeException(String.format("No test action found with name %s", testAction.getName()));
    }
    if (!lastScenarioAction.getName().equals(testAction.getName())) {
        throw new CitrusRuntimeException(String.format("Expected to find last test action with name %s but got %s", testAction.getName(), lastScenarioAction.getName()));
    }

    lastScenarioAction.setEndDate(getTimeNow());
}
 
Example #2
Source File: TestCaseService.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
private TestcaseModel getTestcaseModel(TestCase testCase) {
    TestcaseModel testModel = new TestcaseModel();
    testModel.setName(testCase.getName());

    VariablesModel variablesModel = new VariablesModel();
    for (Map.Entry<String, Object> entry : testCase.getVariableDefinitions().entrySet()) {
        VariablesModel.Variable variable = new VariablesModel.Variable();
        variable.setName(entry.getKey());
        variable.setValue(entry.getValue().toString());
        variablesModel.getVariables().add(variable);
    }
    testModel.setVariables(variablesModel);

    TestActionsType actions = new TestActionsType();
    for (com.consol.citrus.TestAction action : testCase.getActions()) {
        actions.getActionsAndSendsAndReceives().add(getActionModel(action));
    }

    testModel.setActions(actions);
    return testModel;
}
 
Example #3
Source File: AllureCitrusTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@Step("Run test case {testDesigner}")
private AllureResults run(final TestDesigner testDesigner) {
    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            CitrusSpringConfig.class, AllureCitrusConfig.class
    );
    final Citrus citrus = Citrus.newInstance(applicationContext);
    final TestContext testContext = citrus.createTestContext();

    final TestActionListeners listeners = applicationContext.getBean(TestActionListeners.class);
    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    final AllureLifecycle lifecycle = applicationContext.getBean(AllureLifecycle.class);
    try {
        Allure.setLifecycle(lifecycle);
        final TestCase testCase = testDesigner.getTestCase();
        testCase.setTestActionListeners(listeners);

        citrus.run(testCase, testContext);
    } catch (Exception ignored) {
    } finally {
        Allure.setLifecycle(defaultLifecycle);
    }

    return applicationContext.getBean(AllureResultsWriterStub.class);
}
 
Example #4
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void stopTestCase(final TestCase testCase,
                          final Status status,
                          final StatusDetails details) {
    final String uuid = removeUuid(testCase);
    final Map<String, Object> definitions = testCase.getVariableDefinitions();
    final List<Parameter> parameters = definitions.entrySet().stream()
            .map(entry -> createParameter(entry.getKey(), entry.getValue()))
            .collect(Collectors.toList());

    getLifecycle().updateTestCase(uuid, result -> {
        result.setParameters(parameters);
        result.setStage(Stage.FINISHED);
        result.setStatus(status);
        result.setStatusDetails(details);
    });
    getLifecycle().stopTestCase(uuid);
    getLifecycle().writeTestCase(uuid);
}
 
Example #5
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private String createUuid(final TestCase testCase) {
    final String uuid = UUID.randomUUID().toString();
    try {
        lock.writeLock().lock();
        testUuids.put(testCase, uuid);
    } finally {
        lock.writeLock().unlock();
    }
    return uuid;
}
 
Example #6
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestActionStart(TestCase testCase, TestAction testAction) {
    if (!ignoreTestAction(testAction)) {
        LOG.debug(testCase.getName() + "(" +
                StringUtils.arrayToCommaDelimitedString(getParameters(testCase)) + ") - " +
                testAction.getName() + ": " +
                (StringUtils.hasText(testAction.getDescription()) ? testAction.getDescription() : ""));
        executionService.createTestAction(testCase, testAction);
    }
}
 
Example #7
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestFailure(TestCase test, Throwable cause) {
    TestResult result = TestResult.failed(test.getName(), test.getTestClass().getSimpleName(), cause, test.getParameters());
    testResults.addResult(result);

    LOG.info(result.toString());
    LOG.info(result.getFailureType());
    executionService.completeScenarioExecutionFailure(test, cause);
}
 
Example #8
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestSuccess(TestCase test) {
    TestResult result = TestResult.success(test.getName(), test.getTestClass().getSimpleName(), test.getParameters());
    testResults.addResult(result);
    LOG.info(result.toString());
    executionService.completeScenarioExecutionSuccess(test);
}
 
Example #9
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
private String[] getParameters(TestCase test) {
    List<String> parameterStrings = new ArrayList<String>();
    for (Map.Entry<String, Object> param : test.getParameters().entrySet()) {
        parameterStrings.add(param.getKey() + "=" + param.getValue());
    }

    return parameterStrings.toArray(new String[parameterStrings.size()]);
}
 
Example #10
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private String removeUuid(final TestCase testCase) {
    try {
        lock.writeLock().lock();
        return testUuids.remove(testCase);
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example #11
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private String getUuid(final TestCase testCase) {
    try {
        lock.readLock().lock();
        return testUuids.get(testCase);
    } finally {
        lock.readLock().unlock();
    }
}
 
Example #12
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void startTestCase(final TestCase testCase) {
    final String uuid = createUuid(testCase);

    final TestResult result = new TestResult()
            .setUuid(uuid)
            .setName(testCase.getName())
            .setStage(Stage.RUNNING);

    result.getLabels().addAll(getProvidedLabels());


    final Optional<? extends Class<?>> testClass = Optional.ofNullable(testCase.getTestClass());
    testClass.map(this::getLabels).ifPresent(result.getLabels()::addAll);
    testClass.map(this::getLinks).ifPresent(result.getLinks()::addAll);

    result.getLabels().addAll(Arrays.asList(
            createHostLabel(),
            createThreadLabel(),
            createFrameworkLabel("citrus"),
            createLanguageLabel("java")
    ));

    testClass.ifPresent(aClass -> {
        final String suiteName = aClass.getCanonicalName();
        result.getLabels().add(createSuiteLabel(suiteName));
    });

    final Optional<String> classDescription = testClass.flatMap(this::getDescription);
    final String description = Stream.of(classDescription)
            .filter(Optional::isPresent)
            .map(Optional::get)
            .collect(Collectors.joining("\n\n"));

    result.setDescription(description);

    getLifecycle().scheduleTestCase(result);
    getLifecycle().startTestCase(uuid);
}
 
Example #13
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
private void completeScenarioExecution(ScenarioExecution.Status status, TestCase testCase, Throwable cause) {
    ScenarioExecution te = lookupScenarioExecution(testCase);
    te.setEndDate(getTimeNow());
    te.setStatus(status);
    if (cause != null) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        cause.printStackTrace(pw);
        te.setErrorMessage(sw.toString());
    }
}
 
Example #14
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
public void createTestAction(TestCase testCase, TestAction testAction) {
    if (skipTestAction(testAction)) {
        return;
    }

    ScenarioExecution te = lookupScenarioExecution(testCase);
    ScenarioAction ta = new ScenarioAction();
    ta.setName(testAction.getName());
    ta.setStartDate(getTimeNow());
    te.addScenarioAction(ta);
}
 
Example #15
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestStart(TestCase test) {
    runningTests.put(StringUtils.arrayToCommaDelimitedString(getParameters(test)), TestResult.success(test.getName(), test.getTestClass().getSimpleName(), test.getParameters()));
}
 
Example #16
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
public void completeScenarioExecutionSuccess(TestCase testCase) {
    completeScenarioExecution(ScenarioExecution.Status.SUCCESS, testCase, null);
}
 
Example #17
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
public void completeScenarioExecutionFailure(TestCase testCase, Throwable cause) {
    completeScenarioExecution(ScenarioExecution.Status.FAILED, testCase, cause);
}
 
Example #18
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestActionSkipped(TestCase testCase, TestAction testAction) {
}
 
Example #19
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
private ScenarioExecution lookupScenarioExecution(TestCase testCase) {
    return scenarioExecutionRepository.findById(lookupScenarioExecutionId(testCase)).orElseThrow(() -> new CitrusRuntimeException(String.format("Failed to look up scenario execution for test %s", testCase.getName())));
}
 
Example #20
Source File: ActivityService.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
private long lookupScenarioExecutionId(TestCase testCase) {
    return Long.parseLong(testCase.getVariableDefinitions().get(ScenarioExecution.EXECUTION_ID).toString());
}
 
Example #21
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestActionFinish(TestCase testCase, TestAction testAction) {
    if (!ignoreTestAction(testAction)) {
        executionService.completeTestAction(testCase, testAction);
    }
}
 
Example #22
Source File: SimulatorStatusListener.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestFinish(TestCase test) {
    runningTests.remove(StringUtils.arrayToCommaDelimitedString(getParameters(test)));
}
 
Example #23
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestStart(final TestCase test) {
    startTestCase(test);
}
 
Example #24
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestActionSkipped(final TestCase testCase, final TestAction testAction) {
    //do nothing
}
 
Example #25
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestActionFinish(final TestCase testCase, final TestAction testAction) {
    getLifecycle().stopStep();
}
 
Example #26
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestActionStart(final TestCase testCase, final TestAction testAction) {
    final String parentUuid = getUuid(testCase);
    final String uuid = UUID.randomUUID().toString();
    getLifecycle().startStep(parentUuid, uuid, new StepResult().setName(testAction.getName()));
}
 
Example #27
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestSkipped(final TestCase test) {
    //do nothing
}
 
Example #28
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestFailure(final TestCase test, final Throwable cause) {
    final Status status = ResultsUtils.getStatus(cause).orElse(Status.BROKEN);
    final StatusDetails details = ResultsUtils.getStatusDetails(cause).orElse(null);
    stopTestCase(test, status, details);
}
 
Example #29
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestSuccess(final TestCase test) {
    stopTestCase(test, Status.PASSED, null);
}
 
Example #30
Source File: AllureCitrus.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Override
public void onTestFinish(final TestCase test) {
    //do nothing
}