Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unittest and importURI(Relativ Path Issue)
Unittest and importURI [message #766704] Fri, 16 December 2011 09:33 Go to next message
Jochen Matuschek is currently offline Jochen MatuschekFriend
Messages: 3
Registered: December 2011
Junior Member
Hi,

i am using importURI in my grammar and my import statement works fine in the Eclipse Editor. I used the ImportUriGlobalScopeProvider. Now I can use a filename relativ to the local file like this:

import "basistypen.ml"


It allows me the reference types in the imported file. So far so great.

But when i try my Code in a Unittest I get validation erros because of the not resolved imports. And the reference to the type in the imported file is not resolved :

ERROR:Couldn't resolve reference to Datentyp 'tFassung2'. (src/de/vfst/MLtest/res/xslgeneriert2.ml line : 14)
ERROR:Imported resource could not be found. (src/de/vfst/MLtest/res/xslgeneriert2.ml line : 1)


The thing is: when i change the path of the import to a path relativ to my testproject folder:

import "de/vfst/ml/basis/basistypen.ml"


it works perfectly but this is - of cause - not useable.

What am i missing? How can I use relative paths in my unittest?
Is my test approach to simple?

I would be very thankful for some help. If more information is needed I am happy to provide it.

Here is the code of the unittest:

@RunWith(XtextRunner.class)
@InjectWith(InjectorProviderCustom.class)
public class MLIntegrationTest1 {

	@Inject 
	private Provider<ResourceSet> resourceSetProvider;
	
	@Inject
	private IResourceValidator validator;

	@Inject
	private IGenerator generator;
	
	@Inject 
	private JavaIoFileSystemAccess fileAccess;

	@Test
	public void ImportTest() {
		ResourceSet set = resourceSetProvider.get();
		URI uri = URI.createURI("src/de/vfst/MLtest/res/xslgeneriert2.ml");
		Resource resource = set.getResource(uri, true);
		
		List<Issue> list = validator.validate(resource, CheckMode.ALL,
				CancelIndicator.NullImpl);
		if (!list.isEmpty()) {
			for (Issue issue : list) {
				System.err.println(issue);
			}
		}

		// configure and start the generator
		fileAccess.setOutputPath("src-gen/");
		generator.doGenerate(resource, fileAccess);
	}	
}
Re: Unittest and importURI [message #766736 is a reply to message #766704] Fri, 16 December 2011 10:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

did you try to add all of your resources to the resourceset before doing the actual test work

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unittest and importURI [message #766749 is a reply to message #766736] Fri, 16 December 2011 11:00 Go to previous messageGo to next message
Jochen Matuschek is currently offline Jochen MatuschekFriend
Messages: 3
Registered: December 2011
Junior Member
Thank for the response.
I already tried something like this before.

		ResourceSet set = resourceSetProvider.get();
		
		URI basisUri = URI.createURI("src/de/vfst/MLtest/res/basistypen.ml");
		Resource basisResource = set.getResource(basisUri, true);
		URI uri = URI.createURI("src/de/vfst/MLtest/res/xslgeneriert2.ml");
		Resource resource = set.getResource(uri, true);


Same outcome.
It seems the basistypen.ml is registered in a map inside the resourceset under the key "src/de/vfst/MLtest/res/basistypen.ml". The import/reference seems to look for the key "basistypen.ml". But I am not sure about this.
Re: Unittest and importURI [message #767894 is a reply to message #766749] Mon, 19 December 2011 06:55 Go to previous messageGo to next message
Jochen Matuschek is currently offline Jochen MatuschekFriend
Messages: 3
Registered: December 2011
Junior Member
I found the reason and a solution for the problem, but I don't like the solution.

In the class ExtensibleURIConverterImpl im method normalize(URI uri) is a statement that uses the "local" path:
...
result = URI.createFileURI(new File(result.trimFragment().toString()).getAbsolutePath());
...


After finding that, I tried to change the current path and than accessing the file.
So instead of
//URI uri = URI.createURI("src/de/vfst/MLtest/res/xslgeneriert2.ml");

I used
System.setProperty("user.dir", System.getProperty("user.dir")+"/src/de/vfst/MLtest/res/");
URI uri = URI.createURI("xslgeneriert2.ml");
Resource resource = set.getResource(uri, true);


Now this works fine for the test, but I doubt it is a good soluting since it is Windows related.

Is there a way to set a basedir?
Re: Unittest and importURI [message #767933 is a reply to message #767894] Mon, 19 December 2011 08:21 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Jochen

This is a general EMF limitation. EMF provides the tools to support
standalone usage, but provides very little help in initializing them.

You may find an analysis of the problem in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=360926#c7.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=361063 is a contribution
inspired by MWE's approach to assist in resolving the problem.

Considerable further progress has been made in the bug/318092 branch for
/org.eclipse.ocl.examples.domain/src/org/eclipse/ocl/examples/domain/utilities/ProjectMap.java
in http://git.eclipse.org/c/mdt/org.eclipse.ocl.git.

Regards

Ed Willink



On 19/12/2011 06:56, Jochen Matuschek wrote:
> I found the reason and a solution for the problem, but I don't like
> the solution.
>
> In the class ExtensibleURIConverterImpl im method normalize(URI uri)
> is a statement that uses the "local" path:
> ..
> result = URI.createFileURI(new
> File(result.trimFragment().toString()).getAbsolutePath());
> ..
>
> After finding that, I tried to change the current path and than
> accessing the file.
> So instead of
> //URI uri = URI.createURI("src/de/vfst/MLtest/res/xslgeneriert2.ml");
> I used
> System.setProperty("user.dir",
> System.getProperty("user.dir")+"/src/de/vfst/MLtest/res/");
> URI uri = URI.createURI("xslgeneriert2.ml");
> Resource resource = set.getResource(uri, true);
>
>
> Now this works fine for the test, but I doubt it is a good soluting
> since it is Windows related.
>
> Is there a way to set a basedir?
Previous Topic:cross reference for import statement?
Next Topic:Duplicate Element Problem
Goto Forum:
  


Current Time: Fri Apr 26 03:05:35 GMT 2024

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

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

Back to the top