|Re: Standalone validation with CompleteOCL evaluates nothing [message #1729603 is a reply to message #1729593]
||Fri, 15 April 2016 19:33
| Ed Willink
Registered: July 2009
You've made a standard EMF mistake.
Using EObjects that are not contained in a ResourceSet is frequently
Using EObjects that are not even contained in a Resource is nearly
For Complete OCL Validation a ResourceSet is necessary since that is
where a cached ValidationAdapter is kept to workaround the lack of a
delegating validation registry. I had a look at throwing an
IllegalStateException where initialization fails, but unfortunately
Complete OCL adds value to variety of model applications that may not
comply with Complete OCL's expectations. Attempting to diagnose bad
Complete OCL config in a foreign application could cause wierd breakages.
You don't need UMLStandaloneSetup when you are not using UML, and you
certainly don't want something from an ocl.build plugin which is not in
the OCL distribution..
See the Pivot Standalone Configuration section of the OCL documentation.
You will find even standalone usage much easier to develop as 'plugins'
so that the MANIFEST does all the hard work for you.
On 15/04/2016 18:42, Roman Tre wrote:
> I'm trying to run a standalone validation of an EObject with a CompleteOCL file that holds all the validation constraints to be able to perform JUnit tests without having to start an additional eclipse runtime (because this is too time-consuming if you want to do Test-Driven-Development).
> I used the current Eclipse Mars documentation for "Pivot Standalone Configuration" (http://help.eclipse.org/mars/topic/org.eclipse.ocl.doc/help/PivotStandalone.html) and "Parsing OCL Documents" (http://help.eclipse.org/mars/topic/org.eclipse.ocl.doc/help/PivotParsingDocuments.html) to create a little sample project, that I attached to this topic.
> My sample project contains a CompleteOCL file called bookvalidation.ocl with an invariant that throws an expected error every time it is executed - it can be tested by creating a dynamic instance of my bookModel and executing the bookvalidation.ocl on it.
> But when I want to use the Diagnostician class to run my validation file it seems nothing is evaluated and diagnostics.getSeverity() is Diagnostic.OK every time:
> // Get all resources on the classpath
> OCL ocl = OCL.newInstance(OCL.CLASS_PATH);
> // Register an extended EValidator for the Complete OCL document constraints
> CompleteOCLEObjectValidator myValidator = new CompleteOCLEObjectValidator(
> BookModelPackage.eINSTANCE, completeOclUri, ocl.getEnvironmentFactory());
> EValidator.Registry.INSTANCE.put(BookModelPackage.eINSTANCE, myValidator);
> // Validate the object
> Diagnostician diagnostician = Diagnostician.INSTANCE;
> Diagnostic diagnostics = diagnostician.validate(objToValidate);
> Where did I go wrong? Is this a bug?
> Thanks in advance,
Powered by FUDForum
. Page generated in 0.01980 seconds