Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Validation] IBatchValidator.validate returns "No constraints were evaluated."
[EMF Validation] IBatchValidator.validate returns "No constraints were evaluated." [message #1224671] Fri, 27 December 2013 12:11 Go to next message
Andreas Jakobik is currently offline Andreas Jakobik
Messages: 6
Registered: November 2011
Junior Member
Hi,

I'm using
* EMF Validation Framework (1.4.0.v20100428-2315-479-9oB56N5BBR6LCA6)
* EMF Validation Framework OCL Integration (1.4.0.v20100428-2315-23-7w3121133502768)
as part of IBM RSA v8.5.5.

We run OCL constraints defined in UML Profiles that are applied to UML2 models (.emx files). This works just fine in a runtime eclipse environment or in a deployed scenario.

However, running the exact same code as part of a Junit Plug-in Test (JUnit 4 Test runner) is not having the desired effect; The call to org.eclipse.emf.validation.service.IBatchValidator.validate
just returns an IStatus object that contains the message: "No constraints were evaluated". Why? How can I fix this problem?

Here is the relevant code that runs the validation:

	public void validate(Model model) {
		final Model myModel = model;

		// prepare the validaton code to be run in a seperate thread
		Runnable runnable = new Runnable() {
			public void run() {
				final IStatus status= getValidator().validate(myModel);
				
				// Error handling...
			}
		};

		// run the thread
		Display.getDefault().syncExec(runnable);

		// Error handling...
	}


	private IBatchValidator getValidator() {
		if (validator == null) {
			// Set up a batch validator that will execute both live and batch
			// rules. Don't report when a constraint passes validation.
			// Put any errors found in the Eclipse Problems View

			ModelValidationService.getInstance().addValidationListener(
					validationListener);

			validator = (IBatchValidator) ModelValidationService.getInstance()
					.newValidator(EvaluationMode.BATCH);

			validator.setIncludeLiveConstraints(true);
			validator.setReportSuccesses(false);
			validator.putClientData("markerType", "com.ibm.xtools.modeler.ui.validation.validationProblem");

			// accept all constraints but don't report info based constraint
			// details
			validator.addConstraintFilter(new IConstraintFilter() {
				public boolean accept(IConstraintDescriptor constraint,
						EObject target) {
					return !ConstraintSeverity.INFO.equals(constraint
							.getSeverity());
				}
			});
		}
		return validator;
	}

Thanks a lot!

/Andreas
Re: [EMF Validation] IBatchValidator.validate returns "No constraints were evaluated.&q [message #1224734 is a reply to message #1224671] Fri, 27 December 2013 16:49 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 789
Registered: July 2009
Senior Member
Hi, Andreas,

If this works in a run-time workbench but not in a JUnit plug-in test,
then I expect the problem stems from missing registrations, probably
because your JUnit launch configuration is missing some plug-ins.

You say that the constraints are defined in UML profiles applied to
your models. Are those profiles correctly resolved in your JUnit
tests? Such that the stereotypes are recognized as applied to your
model elements?

If you're using some RSA-specific constraint provider to incorporate
constraints defined in your profiles, then I wouldn't be able to
comment much on what could be going wrong. I could suggest stepping
through (in the debugger) the code that collects the constraints to be
evaluated, in the GetBatchConstraintsOperation class and the things it
depends on, specially the ClientContextManager (missing or imprecise
client-context bindings are a common cause of validations not
happening).

HTH,

Christian


On 2013-12-27 12:11:42 +0000, Andreas Jakobik said:

> Hi,
>
> I'm using
> * EMF Validation Framework (1.4.0.v20100428-2315-479-9oB56N5BBR6LCA6)
> * EMF Validation Framework OCL Integration
> (1.4.0.v20100428-2315-23-7w3121133502768)
> as part of IBM RSA v8.5.5.
> We run OCL constraints defined in UML Profiles that are applied to UML2
> models (.emx files). This works just fine in a runtime eclipse
> environment or in a deployed scenario.
> However, running the exact same code as part of a Junit Plug-in Test
> (JUnit 4 Test runner) is not having the desired effect; The call to
> org.eclipse.emf.validation.service.IBatchValidator.validate just
> returns an IStatus object that contains the message: "No constraints
> were evaluated". Why? How can I fix this problem?
>
> Here is the relevant code that runs the validation:
>
>
> public void validate(Model model) {
> final Model myModel = model;
>
> // prepare the validaton code to be run in a seperate thread
> Runnable runnable = new Runnable() {
> public void run() {
> final IStatus status= getValidator().validate(myModel);
>
> // Error handling...
> }
> };
>
> // run the thread
> Display.getDefault().syncExec(runnable);
>
> // Error handling...
> }
>
>
> private IBatchValidator getValidator() {
> if (validator == null) {
> // Set up a batch validator that will execute both live and batch
> // rules. Don't report when a constraint passes validation.
> // Put any errors found in the Eclipse Problems View
>
> ModelValidationService.getInstance().addValidationListener(
> validationListener);
>
> validator = (IBatchValidator) ModelValidationService.getInstance()
> .newValidator(EvaluationMode.BATCH);
>
> validator.setIncludeLiveConstraints(true);
> validator.setReportSuccesses(false);
> validator.putClientData("markerType",
> "com.ibm.xtools.modeler.ui.validation.validationProblem");
>
> // accept all constraints but don't report info based constraint
> // details
> validator.addConstraintFilter(new IConstraintFilter() {
> public boolean accept(IConstraintDescriptor constraint,
> EObject target) {
> return !ConstraintSeverity.INFO.equals(constraint
> .getSeverity());
> }
> });
> }
> return validator;
> }
>
> Thanks a lot!
>
> /Andreas
Re: [EMF Validation] IBatchValidator.validate returns "No constraints were evaluated.&q [message #1226009 is a reply to message #1224734] Tue, 31 December 2013 12:11 Go to previous message
Andreas Jakobik is currently offline Andreas Jakobik
Messages: 6
Registered: November 2011
Junior Member
Hi Christian,
thanks for your prompt answer. This is as you suggest most likely not an issue with the EMF Validation Framework, but rather something fishy in the RSA environment. I tried to debug, but to no avail.

I compared the run configurations for the runtime workbench (where constraints are evaluated) and the JUnit Plugin Test (where "No constraints were evaluated" message is given), but can't spot any differences. Both configurations run the product "com.ibm.rational.rsa.product.v85.ide" and are launched with "all workspace and enabled target plug-ins".

The Junit test class creates a new project in the junit-workspace and copies the test models there. In fact, when I start a runtime workbench with the junit-workspace as location, the constraints are indeed evaluated correctly! So it must be something related to the way the JUnit Plugin Test is set-up that is not working properly, w.r.t. client context bindings. Possibly an RSA issue?

Anyway, thanks for your help. I will investigate this further and get back if/when it is resolved.

MVH (Med vänlig hälsning),
Andreas

[Updated on: Tue, 31 December 2013 12:12]

Report message to a moderator

Previous Topic:EMF.ECORE2JAVA run ant from java
Next Topic:[Texo] Table Name Prefix ignored if Entity extends an abstract class
Goto Forum:
  


Current Time: Fri Sep 19 20:05:01 GMT 2014

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

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