Search in sources :

Example 1 with AfterTest

use of org.whole.lang.tests.model.AfterTest in project whole by wholeplatform.

the class AfterTestPart method getModelSpecificChildren.

protected List<IEntity> getModelSpecificChildren() {
    AfterTest entity = getModelEntity();
    List<IEntity> list = new ArrayList<IEntity>(3);
    list.add(entity.getDescription());
    list.add(entity.getName());
    list.add(entity.getBody());
    return list;
}
Also used : IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) AfterTest(org.whole.lang.tests.model.AfterTest)

Example 2 with AfterTest

use of org.whole.lang.tests.model.AfterTest in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(Test entity) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    getBindings().wEnterScope(ts);
    String name = entity.getName().getValue();
    Outcome outcome = TestsEntityFactory.instance.createOutcome(OutcomeEnum.SUCCESS);
    StringLiteral location = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    StringLiteral cause = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    Result result = TestsEntityFactory.instance.createResult(outcome, location, cause);
    try {
        for (BeforeTest beforeTest : BehaviorUtils.<BeforeTest>compileAndLazyEvaluate(createAspectPath("BeforeTest"), entity)) {
            beforeTest.accept(this);
            getResult();
        }
        entity.getBody().accept(this);
        getResult();
        for (AfterTest afterTest : BehaviorUtils.<AfterTest>compileAndLazyEvaluate(createAspectPath("AfterTest"), entity)) {
            afterTest.accept(this);
            getResult();
        }
        printWriter().printf("    %32s(...) OK\n", name);
    } catch (OperationCanceledException e) {
        throw e;
    } catch (TestsException e) {
        outcome.wSetValue(OutcomeEnum.FAILURE);
        location.setValue(EntityUtils.getLocation(e.getSubjectStatement()));
        cause.setValue(e.getMessage());
        reportFailure(name, e);
    } catch (RuntimeException e) {
        outcome.wSetValue(OutcomeEnum.ERROR);
        IEntity sourceEntity = null;
        if (e instanceof IWholeRuntimeException) {
            sourceEntity = ((IWholeRuntimeException) e).getSourceEntity();
            if (EntityUtils.getCompoundRoot(sourceEntity) != EntityUtils.getCompoundRoot(entity))
                // FIXME replace with outer aspect or statement
                sourceEntity = null;
        }
        if (sourceEntity == null)
            sourceEntity = entity;
        location.setValue(EntityUtils.getLocation(sourceEntity));
        cause.setValue(e.getMessage());
        reportError(name, e);
    } finally {
        ts.rollback();
        getBindings().wExitScope();
    }
    if (EntityUtils.isResolver(entity.getExpectedResult()))
        entity.setExpectedResult(EntityUtils.clone(result));
    if (!Matcher.match(result, entity.getActualResult()))
        entity.setActualResult(result);
    setResult(result);
}
Also used : IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) ITransactionScope(org.whole.lang.bindings.ITransactionScope) StringLiteral(org.whole.lang.tests.model.StringLiteral) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) IEntity(org.whole.lang.model.IEntity) Outcome(org.whole.lang.tests.model.Outcome) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) Result(org.whole.lang.tests.model.Result)

Aggregations

IEntity (org.whole.lang.model.IEntity)2 AfterTest (org.whole.lang.tests.model.AfterTest)2 ArrayList (java.util.ArrayList)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 BeforeTest (org.whole.lang.tests.model.BeforeTest)1 Outcome (org.whole.lang.tests.model.Outcome)1 Result (org.whole.lang.tests.model.Result)1 StringLiteral (org.whole.lang.tests.model.StringLiteral)1