context Tree {
constraint LabelsStartWithT {
check : self.label.startsWith("t")
message : "Label starts with t"
}
critique LabelsEndInN {
check : self.label.endsWith("n")
message : "Label ends with n"
}
}
operation validateTree(tree, label) {
tree.label = label;
runTarget("validate-tree");
return EVL!EvlUnsatisfiedConstraint.all;
}
@test
operation valid() {
var tree = new Tree!Tree;
var errors = validateTree(tree, "t1n");
assertEquals(0, errors.size);
}
@test
operation error() {
var tree = new Tree!Tree;
var errors = validateTree(tree, "1n");
assertEquals(1, errors.size);
var error = errors.first;
assertEquals(tree, error.instance);
assertEquals(false, error.constraint.isCritique);
assertEquals("LabelsStartWithT", error.constraint.name);
}
@test
operation warning() {
var tree = new Tree!Tree;
var errors = validateTree(tree, "t1");
assertEquals(1, errors.size);
var error = errors.first;
assertEquals(tree, error.instance);
assertEquals(true, error.constraint.isCritique);
assertEquals("LabelsEndInN", error.constraint.name);
}
<project default="evl-exportAsModel">
<target name="evl-exportAsModel">
<epsilon.eunit src="tree-export-as-model.eunit">
<modelTasks>
<epsilon.emf.loadModel name="Tree" metamodelfile="tree.ecore" read="false" store="false" />
</modelTasks>
</epsilon.eunit>
</target>
<target name="validate-tree">
<epsilon.evl src="tree-constraints.evl" failOnErrors="false" failOnWarnings="false" exportAsModel="EVL">
<model ref="Tree" />
</epsilon.evl>
</target>
</project>
Check out the code from the SVN:
Once you have checked out/imported the code, to run the example you need to go through the following steps:
In this example we show how a model validation script written in EVL can be tested with EUnit, using the exportAsModel attribute of the EVL workflow task.
.emf files are Ecore metamodels expressed using the Emfatic textual syntax.
More examples are available in the examples folder of the SVN repository.