Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » (no subject)
(no subject) [message #687058] Thu, 26 May 2011 09:19 Go to next message
John Smith is currently offline John SmithFriend
Messages: 137
Registered: July 2009
Senior Member
I want to execute some code as JUnit Test, and not as JUnit Plug-in
Test. But my code uses plugin:/ URIs for EMF resources. Has anybody
experiences with this, what the best way is to adapt it to java-only
execution? We dont need this functionality not only for JUnit test but
also their should be a commandline facility for the core functionality
later.
(no subject) [message #687062 is a reply to message #687058] Thu, 26 May 2011 12:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30452
Registered: July 2009
Senior Member
What's a plugin: URI? Do you mean platform:/plugin? You could
generated an XyzPlugin class as use it's getBaseURL as the basis for
loading things from it from its URI.

exquisitus wrote:
> I want to execute some code as JUnit Test, and not as JUnit Plug-in
> Test. But my code uses plugin:/ URIs for EMF resources. Has anybody
> experiences with this, what the best way is to adapt it to java-only
> execution? We dont need this functionality not only for JUnit test but
> also their should be a commandline facility for the core functionality
> later.
(no subject) [message #687070 is a reply to message #687058] Thu, 26 May 2011 17:52 Go to previous message
Eclipse UserFriend
Originally posted by:

Below I've pasted code from a JUnit test I have. The idea is to create
an URI mapping from the real URI, with whatever protocol you use, to a
folder URI where the models and model instances are.

Hallvard

URI testUri =
URI.createURI(String.valueOf(getClass().getResource(testData)));


Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
new XMLResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
new EcoreResourceFactoryImpl());

ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XMLResource.OPTION_SCHEMA_LOCATION,
Boolean.TRUE);

// make tests independent of location, by using a logical uri
URI testFolderUri = createParentFolderUri(testUri);
resourceSet.getURIConverter().getURIMap().put(TESTS_URI, testFolderUri);

private URI createParentFolderUri(URI uri) {
String lastSegment = uri.lastSegment();
return (lastSegment == null || lastSegment.length() == 0 ? uri :
uri.trimSegments(1).appendSegment(""));
}


On 26.05.11 11.19, exquisitus wrote:
> I want to execute some code as JUnit Test, and not as JUnit Plug-in
> Test. But my code uses plugin:/ URIs for EMF resources. Has anybody
> experiences with this, what the best way is to adapt it to java-only
> execution? We dont need this functionality not only for JUnit test but
> also their should be a commandline facility for the core functionality
> later.
(no subject) [message #687269 is a reply to message #687058] Thu, 26 May 2011 12:13 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30452
Registered: July 2009
Senior Member
What's a plugin: URI? Do you mean platform:/plugin? You could
generated an XyzPlugin class as use it's getBaseURL as the basis for
loading things from it from its URI.

exquisitus wrote:
> I want to execute some code as JUnit Test, and not as JUnit Plug-in
> Test. But my code uses plugin:/ URIs for EMF resources. Has anybody
> experiences with this, what the best way is to adapt it to java-only
> execution? We dont need this functionality not only for JUnit test but
> also their should be a commandline facility for the core functionality
> later.
(no subject) [message #687279 is a reply to message #687058] Thu, 26 May 2011 17:52 Go to previous message
Eclipse UserFriend
Originally posted by:

Below I've pasted code from a JUnit test I have. The idea is to create
an URI mapping from the real URI, with whatever protocol you use, to a
folder URI where the models and model instances are.

Hallvard

URI testUri =
URI.createURI(String.valueOf(getClass().getResource(testData)));


Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml",
new XMLResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xmi",
new XMIResourceFactoryImpl());

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore",
new EcoreResourceFactoryImpl());

ResourceSetImpl resourceSet = new ResourceSetImpl();
resourceSet.getLoadOptions().put(XMLResource.OPTION_SCHEMA_LOCATION,
Boolean.TRUE);

// make tests independent of location, by using a logical uri
URI testFolderUri = createParentFolderUri(testUri);
resourceSet.getURIConverter().getURIMap().put(TESTS_URI, testFolderUri);

private URI createParentFolderUri(URI uri) {
String lastSegment = uri.lastSegment();
return (lastSegment == null || lastSegment.length() == 0 ? uri :
uri.trimSegments(1).appendSegment(""));
}


On 26.05.11 11.19, exquisitus wrote:
> I want to execute some code as JUnit Test, and not as JUnit Plug-in
> Test. But my code uses plugin:/ URIs for EMF resources. Has anybody
> experiences with this, what the best way is to adapt it to java-only
> execution? We dont need this functionality not only for JUnit test but
> also their should be a commandline facility for the core functionality
> later.
Previous Topic:(no subject)
Next Topic:(no subject)
Goto Forum:
  


Current Time: Thu Sep 19 21:00:37 GMT 2019

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

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

Back to the top