Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unit Test for DSL with dependent DSL(Unit Test for DSL with dependent DSL)
Unit Test for DSL with dependent DSL [message #1244284] Wed, 12 February 2014 05:45 Go to next message
Sebastian Neumann is currently offline Sebastian NeumannFriend
Messages: 9
Registered: December 2010
Junior Member
Hi,

I am also trying to write unit tests including a dependent DSL. The grammar looks like this.

grammar abc.Dsl with org.eclipse.xtext.common.Terminals

generate dsl "http://abc/MainDsl"

import "http://abc/SubDsl" as subdsl


In the Unit test you inject the Model (in this case the MainDsl-Model) with:

@InjectWith(typeof(MainDslInjectorProvider))
@RunWith(typeof(XtextRunner))
class AssertFieldParserTest {
  @Inject extension ParseHelper<MainDslModel>
  ...


The problem is that this only allows me to parse the MainDsl, but not the SubDsl. How can this be achieved? I found a hint in a blog http://christiandietrich.wordpress.com/2012/05/08/unittesting-xtend-generators but the modified ParseHelper does not work for me; it still only parses one model, and not both. And I cannot inject a second ParseHelper. Does anyone have a solution to this? Eventually I need to verify my code generation and that I can only achieve having access to both models.

Cheers,
Sebastian

Re: Unit Test for DSL with dependent DSL [message #1244331 is a reply to message #1244284] Wed, 12 February 2014 07:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
Can please someone share code I can use and fix. It takes to much
time to do everything myself to reproduce the problem

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1245003 is a reply to message #1244331] Thu, 13 February 2014 06:36 Go to previous messageGo to next message
Sebastian Neumann is currently offline Sebastian NeumannFriend
Messages: 9
Registered: December 2010
Junior Member
Hi Christian,

I quickly set up the two DSLs. The MainDsl imports the SubDSL. For the ease of use both just define one element. I also added a test module using the DSLs.

Eventually the sub files will look like this:

Sub - hyperlink newPage {"//*abc" : XPATH}
Main - click newPage (where newPage is the element defined in the sub)

Now I want to write a unit test where I parse both language models, and when I assert the 'click' element, I want to have access to the hyperlink associated via the 'newPage" reference.

I hope that illustrates my problem. Pls let me know if you need further information; I appreciate your support!

Cheers,
Sebastian

[Updated on: Thu, 13 February 2014 06:37]

Report message to a moderator

Re: Unit Test for DSL with dependent DSL [message #1245017 is a reply to message #1245003] Thu, 13 February 2014 07:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
Hmm this works strainght forward...

@InjectWith(typeof(ExtMainDslInjectorProvider))
@RunWith(typeof(XtextRunner))
class ClickHyperlinkTest {
	
	@Inject extension ExtendedParseHelper<Model>
	@Inject Provider <ResourceSet> rsp

	/**
	 * Have to hack the test a bit in order to have access to both DSL (.define and .test)
	 */
	@Test
	def void parseForms() {
		val rs = rsp.get
		'''
		hyperlink  newPage {"//*abc" : XPATH}
		'''.parse(URI.createURI("test.sub"), rs)
		val domainModel = '''
			click newPage
		'''.parse(rs)
		
		assertEquals(ElementType.XPATH, domainModel.fields.get(0).link.findBy.type)
				
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1245075 is a reply to message #1245017] Thu, 13 February 2014 09:03 Go to previous messageGo to next message
Sebastian Neumann is currently offline Sebastian NeumannFriend
Messages: 9
Registered: December 2010
Junior Member
Hi,

Thanks, that works like a charme. I see now how you use the Provider and the Resource, and pass it to the ParseHelper. That makes sense!

Cheers,
Sebastian

[Updated on: Thu, 13 February 2014 09:22]

Report message to a moderator

Re: Unit Test for DSL with dependent DSL [message #1405461 is a reply to message #1245075] Thu, 07 August 2014 12:09 Go to previous messageGo to next message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi,

Is there any way to read this content from file instead of hardcoding in code :
hyperlink  newPage {"//*abc" : XPATH}
This content should be read from file so that we can pass contents to parse() method.
I tried using parse(InputStream in, URI uriToUse, Map options,ResourceSet resourceSet) but not sure what to pass as options.

Please suggest.

Cheers

Kunal
Re: Unit Test for DSL with dependent DSL [message #1405503 is a reply to message #1405461] Thu, 07 August 2014 13:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
Hi,

depends on what you actually want to do.

- create a resource set
- load a bunch of resources
- work with them.

this should be streight forward (of course then you cannot use parsehelper)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1416000 is a reply to message #1405503] Thu, 04 September 2014 06:02 Go to previous messageGo to next message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi,
For the above case of Running Junit for Dependent DSL's, If I try to run the Junit Test Case from command Line , I am getting below exception:
Guice configuration errors:
1) No implementation for javax.inject.Provider<org.eclipse.emf.ecore.resource.ResourceSet> was bound.
     [java]   while locating javax.inject.Provider<org.eclipse.emf.ecore.resource.ResourceSet>
     [java]     for field at com.mydsl.TestMyDsl.resourceSet(TestMyDsl.java:48)
     [java]   while locating com.mydsl.TestMyDsl


Any Clue, what would be the reason why Guice is not able to locate dependent dsl.

Cheers
Kunal
Re: Unit Test for DSL with dependent DSL [message #1416019 is a reply to message #1416000] Thu, 04 September 2014 06:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
Hi,

have no idea on that sry. use e.g. maven tycho works fine for me.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1416095 is a reply to message #1416019] Thu, 04 September 2014 09:59 Go to previous messageGo to next message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi Christian,
I have used ant build script and inside that I am using Junit target to run xtext junit test cases.

Cheers
Kunal
Re: Unit Test for DSL with dependent DSL [message #1416143 is a reply to message #1416095] Thu, 04 September 2014 12:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
maybe it has something todo with how you run the tests, maybe the injector provider is not working correct then or some caches are not cleaned up.
do you have only one test or multiple?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1419091 is a reply to message #1416143] Mon, 08 September 2014 04:50 Go to previous messageGo to next message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi Christian,
I run multiple test.

Cheers
Kunal
Re: Unit Test for DSL with dependent DSL [message #1419126 is a reply to message #1419091] Mon, 08 September 2014 06:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13271
Registered: July 2009
Senior Member
Can you share an example that i can simply take and run/debug

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Unit Test for DSL with dependent DSL [message #1419272 is a reply to message #1419126] Mon, 08 September 2014 11:02 Go to previous message
Kunal Khaware is currently offline Kunal KhawareFriend
Messages: 41
Registered: December 2013
Location: Hyderabad,India
Member

Hi Christian,
Thanks for the reply, I figured out the issue in my code it was all due to below line :
@Inject
private Provider<ResourceSet> resourceSet;


It was unable to find the implementation class to inject the Provider class.

I modified the above declaration and used below code
try {
    	resourceSet = new Provider<ResourceSet>() {
			
			@Override
			public ResourceSet get() {
				
				ResourceSet resourceSet = new ResourceSetImpl(); 
				return resourceSet;
			}
		};


Thanks a lot for Reply.

Cheers

Kunal
Previous Topic:My DSL plugin install fails
Next Topic:New Xcore build available?
Goto Forum:
  


Current Time: Thu Dec 12 02:41:47 GMT 2019

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

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

Back to the top