Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Standalone validation with CompleteOCL evaluates nothing(Problem with running CompleteOCL standalone for JUnit tests)
Standalone validation with CompleteOCL evaluates nothing [message #1729593] Fri, 15 April 2016 17:42 Go to next message
Roman Tre is currently offline Roman TreFriend
Messages: 5
Registered: April 2016
Junior Member
Hello,

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,

Roman
Re: Standalone validation with CompleteOCL evaluates nothing [message #1729603 is a reply to message #1729593] Fri, 15 April 2016 19:33 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You've made a standard EMF mistake.

Using EObjects that are not contained in a ResourceSet is frequently
troublesome.

Using EObjects that are not even contained in a Resource is nearly
always troublesome.

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.

org.eclipse.ocl.pivot.uml.UML2AS.initialize(resourceSet);

---

You will find even standalone usage much easier to develop as 'plugins'
so that the MANIFEST does all the hard work for you.

Regards

Ed Willink


On 15/04/2016 18:42, Roman Tre wrote:
> Hello,
>
> 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,
>
> Roman
Re: Standalone validation with CompleteOCL evaluates nothing [message #1730213 is a reply to message #1729603] Fri, 22 April 2016 11:47 Go to previous messageGo to next message
Roman Tre is currently offline Roman TreFriend
Messages: 5
Registered: April 2016
Junior Member
Hi Ed,

first of all, thanks for your reply!
I created a dynamic instance of my sample BookModel and loaded the created .xmi-file into a ResourceSet (see http://www.vogella.com/tutorials/EclipseEMFPersistence/article.html#javacode_load).
Using the now created Resource object as an input for my validator as described in "Parsing OCL Documents" did the trick.

Is there a way to create a Resource for an "in-memory" EObject - for example created with:
Book book01 = BookModelFactory.eINSTANCE.createBook();

so I don't have to load it from a XMI-file?


Regards,

Roman
Re: Standalone validation with CompleteOCL evaluates nothing [message #1730220 is a reply to message #1730213] Fri, 22 April 2016 12:10 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Absolutely, Everything in EMF works on Resources. You are free to create
them programmatically rather than by loading. Indeed it can be much
easier since you avoid all the excitement of URI resolution. If you find
that the API for something is inadequate, then exapand the code a bit
and submit a Bugzilla.

Regards

Ed Willink


On 22/04/2016 12:47, Roman Tre wrote:
> Hi Ed,
>
> first of all, thanks for your reply!
> I created a dynamic instance of my sample BookModel and loaded the
> created .xmi-file into a ResourceSet (see
> http://www.vogella.com/tutorials/EclipseEMFPersistence/article.html#javacode_load).
> Using the now created Resource object as an input for my validator as
> described in "Parsing OCL Documents" did the trick.
>
> Is there a way to create a Resource for an "in-memory" EObject - for
> example created with:
> Book book01 = BookModelFactory.eINSTANCE.createBook();
> so I don't have to load it from a XMI-file?
>
>
> Regards,
>
> Roman
Previous Topic:OCL git repository
Next Topic:Native validation with custom OCL files
Goto Forum:
  


Current Time: Fri Apr 19 18:12:38 GMT 2024

Powered by FUDForum. Page generated in 0.05449 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top