Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Complete example Custom Validator Test?
Complete example Custom Validator Test? [message #758749] Thu, 24 November 2011 08:20 Go to next message
Eclipse UserFriend
Trying to write some custom validations test first. I looked at example code in the docs - which is useful but doesn't include imports or really show how to create sample models to test against. I tried the sample projects but none seems to include tests for custom validation. I'm not familiar with the ecore API which doesn't help.

Would appreciate if someone could point me to a complete example of a test file. So far I have the basics in place I think (imports, setup):

package org.domainmodels.Ooa.unittest;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.domainmodels.OoaInjectorProvider;
import org.domainmodels.OoaStandaloneSetup;
import org.domainmodels.validation.OoaJavaValidator;

import org.eclipse.xtext.junit4.InjectWith;
import org.eclipselabs.xtext.utils.unittesting.XtextRunner2;
import org.eclipse.xtext.junit.AbstractXtextTests;
import org.eclipse.xtext.junit.validation.ValidatorTester;

@RunWith(XtextRunner2.class)
@InjectWith(OoaInjectorProvider.class)
public class TestOoaCustomValidation extends AbstractXtextTests {

	private ValidatorTester<OoaJavaValidator> tester;

	  @Override
	  public void setUp() {
		  try {
		    with(OoaStandaloneSetup.class);
		    OoaJavaValidator validator = get(OoaJavaValidator.class);
		    tester = new ValidatorTester<OoaJavaValidator>(validator, getInjector());
		  } catch(Exception e) {
			  System.out.println(e);
		  }
	  }
	  
	@Test
	public void testClassMustHaveAtLeastOneIdentifier(){
		
		fail();
	}

}


Thanks.

[Updated on: Thu, 24 November 2011 08:21] by Moderator

Re: Complete example Custom Validator Test? [message #758761 is a reply to message #758749] Thu, 24 November 2011 08:47 Go to previous messageGo to next message
Eclipse UserFriend
MyDslJavaValidator validator = get(MyDslJavaValidator.class);
ValidatorTester<MyDslJavaValidator> tester = new ValidatorTester<MyDslJavaValidator>(validator, getInjector());
tester.validate(undertest);
tester.diagnose().assertOK();

alternatively you can call tester.validator().checkGreetingStartsWithCapital(undertest);

[Updated on: Thu, 24 November 2011 08:48] by Moderator

Re: Complete example Custom Validator Test? [message #758763 is a reply to message #758761] Thu, 24 November 2011 08:59 Go to previous messageGo to next message
Eclipse UserFriend
Or alternatively, you can use org.eclipse.emf.ecore.util.Diagnostician which also takes care of composited validators.
Re: Complete example Custom Validator Test? [message #758833 is a reply to message #758763] Thu, 24 November 2011 11:35 Go to previous message
Eclipse UserFriend
Christian, Meinte,

Thanks for the quick response.

My question was more specifically around creating an ecore model in memory to test. However I found another example in the docs and got the rest from there.
Previous Topic:Property Generator.pathRtProject used in two views of the model
Next Topic:URI serialization
Goto Forum:
  


Current Time: Wed Jul 23 16:21:51 EDT 2025

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

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

Back to the top