Example: Test a model validation script with EUnit

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:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.eunit.examples.evl project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.eunit.examples.evl project
  2. right click the .launch file in the org.eclipse.epsilon.eunit.examples.evl project
  3. select Run as... and click the first item in the menu that pops up

What's this?

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.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

More examples are available in the examples folder of the SVN repository.