Test with a cross-reference model [message #1806274] |
Tue, 07 May 2019 06:02  |
Eclipse User |
|
|
|
Hello,
I am making unit tests in my DSL named Karbura. Karbura imports another model from another a DSL named MyDSL. Below is the test I am making. To resolve the model of MyDSL I use the function beneath. When I launch an eclipse instance to test this everything works fine and it resolve "portA" in the test below. However, in my test I place the object1.mydsl at the same directory than my test but it could not resolve it. I got this error for resolving :
The ERROR :
URI : object1.mydsl
URI Resolve : __synthetic0.cy
0 [main] ERROR base.resource.BatchLinkableResource - resolution of uriFragment '|3' failed.
java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base
The TEST :
@Test
def void TestMyDSLImport() {
val result = parseHelper.parse('''
object object1 import "object1.mydsl"
object1.portA // It is a port from object1.mydsl
''')
result.assertNoErrors
Assert.assertNotNull(result)
Assert.assertTrue(result.eResource.errors.isEmpty)
}
The Resolving function :
public static MyDSLModel getMyDSLObject(Object object) {
URI new_uri = URI.createFileURI(object.getImportPath());
MyDSLStandaloneSetup.doSetup();
System.out.println("URI : " + new_uri);
System.out.println("URI Resolve : " + object.eResource().getURI());
if (new_uri.isRelative()) {
new_uri = new_uri.resolve(object.eResource().getURI());
}
Resource r = object.eResource().getResourceSet().getResource(new_uri, true);
if (r != null && r.getContents().size() > 0 && r.getContents().get(0) instanceof MyDSLModel) {
return (MyDSLModel) r.getContents().get(0);
} else {
try {
throw new Exception("No valid model found for resource " + object.getImportPath());
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
How can I achieve this test ?
Thanks
[Updated on: Wed, 08 May 2019 03:18] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08858 seconds