Search in sources :

Example 1 with IWholeRuntimeException

use of org.whole.lang.exceptions.IWholeRuntimeException 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)

Example 2 with IWholeRuntimeException

use of org.whole.lang.exceptions.IWholeRuntimeException in project whole by wholeplatform.

the class TestsInterpreterVisitor method reportError.

protected void reportError(String name, RuntimeException e) {
    StringWriter writer = new StringWriter();
    e.printStackTrace(new PrintWriter(writer));
    printWriter().printf("    %32s(...) ERRORS: %s", name, writer.toString());
    if (e instanceof IWholeRuntimeException) {
        IWholeRuntimeException wre = (IWholeRuntimeException) e;
        if (wre.getSourceEntity() != null)
            printWriter().printf(" [at %s]\n\n", EntityUtils.getLocation(wre.getSourceEntity()));
    }
}
Also used : StringWriter(java.io.StringWriter) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) PrintWriter(java.io.PrintWriter)

Aggregations

IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 IEntity (org.whole.lang.model.IEntity)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 AfterTest (org.whole.lang.tests.model.AfterTest)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