Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validation of several models (with dependencies between them)
Validation of several models (with dependencies between them) [message #659496] Mon, 14 March 2011 10:35 Go to next message
Rubén Porras Campo is currently offline Rubén Porras CampoFriend
Messages: 67
Registered: July 2009
Member
Hi

I would like to test how a Xtext generator behaves with different sources, using Integration Testing of different models.

I wrote the following code, which works fine as long as I only want to test one model file (datatypes.btc).

If want to test a second model, that needs definitions of the first one, it does not work. No surprise, I already expected that... I suspect I need to use a ResourceSet, so that both files are checked together, but how?

Has anyone done it successfully?

package foo.bttg.test;

import java.io.FileInputStream;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.junit.AbstractXtextTests;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.Issue;

import foo.bttg.meta_model.btc.BTCStandaloneSetup;

public class ExpensiveChecks extends AbstractXtextTests {

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    with(new BTCStandaloneSetup());
  }

  private List<Issue> validate(EObject model) {
    XtextResource res = ((XtextResource) model.eResource());

    List<Issue> list = res.getResourceServiceProvider().getResourceValidator()
        .validate(res, CheckMode.ALL, new CancelIndicator.NullImpl());
    return list;
  }

  public void testAssignability() throws Exception {
    FileInputStream datatypes = new FileInputStream(
        "C:\\eclipse_workspaces\\helios\\foo.bttg.model\\src\\btc\\datatypes.btc");

    FileInputStream book = new FileInputStream(
        "C:\\eclipse_workspaces\\helios\\foo.bttg.model\\src\\btt\\book.btt");

    XtextResource btc = getResource(datatypes, URI.createURI("datatypes.btc"));
//    XtextResource btt = getResource(book, URI.createURI("book.btt"));

    List<Issue> list = validate(getModel(btc));
    assertEquals(list.toString(), 0, list.size());

  //  list = validate(getModel(btt));
  //  assertEquals(list.toString(), 0, list.size());
  }
}



Thanks.
Re: Validation of several models (with dependencies between them) [message #659505 is a reply to message #659496] Mon, 14 March 2011 11:07 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
After getting the first resource, get its resource set and load the
second in it, approx

Resource btt = btc.getResourceSet().createResource(
URI.createURI("book.btt"));
btt.load(book, null);



Am 14.03.11 11:36, schrieb Ruben:
> Hi
>
> I would like to test how a Xtext generator behaves with different
> sources, using Integration Testing of different models.
>
> I wrote the following code, which works fine as long as I only want to
> test one model file (datatypes.btc).
>
> If want to test a second model, that needs definitions of the first one,
> it does not work. No surprise, I already expected that... I suspect I
> need to use a ResourceSet, so that both files are checked together, but
> how?
>
> Has anyone done it successfully?
>
>
> package foo.bttg.test;
>
> import java.io.FileInputStream;
> import java.util.List;
>
> import org.eclipse.emf.common.util.URI;
> import org.eclipse.emf.ecore.EObject;
> import org.eclipse.xtext.junit.AbstractXtextTests;
> import org.eclipse.xtext.resource.XtextResource;
> import org.eclipse.xtext.util.CancelIndicator;
> import org.eclipse.xtext.validation.CheckMode;
> import org.eclipse.xtext.validation.Issue;
>
> import foo.bttg.meta_model.btc.BTCStandaloneSetup;
>
> public class ExpensiveChecks extends AbstractXtextTests {
>
> @Override
> protected void setUp() throws Exception {
> super.setUp();
> with(new BTCStandaloneSetup());
> }
>
> private List<Issue> validate(EObject model) {
> XtextResource res = ((XtextResource) model.eResource());
>
> List<Issue> list = res.getResourceServiceProvider().getResourceValidator()
> .validate(res, CheckMode.ALL, new CancelIndicator.NullImpl());
> return list;
> }
>
> public void testAssignability() throws Exception {
> FileInputStream datatypes = new FileInputStream(
> " C:\\eclipse_workspaces\\helios\\foo.bttg.model\\src\\btc\\da tatypes.btc ");
>
> FileInputStream book = new FileInputStream(
> " C:\\eclipse_workspaces\\helios\\foo.bttg.model\\src\\btt\\bo ok.btt ");
>
> XtextResource btc = getResource(datatypes, URI.createURI("datatypes.btc"));
> // XtextResource btt = getResource(book, URI.createURI("book.btt"));
>
> List<Issue> list = validate(getModel(btc));
> assertEquals(list.toString(), 0, list.size());
>
> // list = validate(getModel(btt));
> // assertEquals(list.toString(), 0, list.size());
> }
> }
>
>
>
> Thanks.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Validation of several models (with dependencies between them) [message #659544 is a reply to message #659496] Mon, 14 March 2011 14:18 Go to previous messageGo to next message
Rubén Porras Campo is currently offline Rubén Porras CampoFriend
Messages: 67
Registered: July 2009
Member
Hi Jan,

and how I get an XtextResource from a normal Resource so that I can call the validator?

thanks.
Re: Validation of several models (with dependencies between them) [message #659587 is a reply to message #659544] Mon, 14 March 2011 17:01 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You are using our test framework (AbstractXtextTests.getResource())
which loads resources in an by default XtextResourceSet. A simple cast
of the ResourceSet will do.

Am 14.03.11 15:18, schrieb Ruben:
> Hi Jan,
>
> and how I get an XtextResource from a normal Resource so that I can call
> the validator?
>
> thanks.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Changing the DSL file extension
Next Topic:How to use Xtend create extensions with JavaBeansMetaModel
Goto Forum:
  


Current Time: Tue Apr 16 11:43:30 GMT 2024

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

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

Back to the top