Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » unit test language with JavaVMTypes(Unit test fails when using JavaVMTypes in the language)
unit test language with JavaVMTypes [message #754885] Fri, 04 November 2011 19:11 Go to next message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
Hello guys,

I am developing a grammar for a language based on Java.
I'm able to use the JavaVMTypes and can successfully run the editor with references to Java types. However when I run my language jUnit test, I get the following error:

org.eclipse.xtext.parser.ParseException: java.lang.IllegalStateException: Unresolved proxy 
h ttp://www.eclipse.org/xtext/common/JavaVMTypes#//JvmParameterizedTypeReference. Make sure the EPackage has been registered.
	at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:105)
	at .......




My setup configuration looks as follows:

    bean = StandaloneSetup {
        scanClassPath = true
        platformUri = "${runtimeProject}/.."
		registerGenModelFile = "platform:/resource/org.eclipse.xtext.xbase/model/Xbase.genmodel"
		registerGenModelFile = "platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.genmodel"
    }


Is there a special configuration required to allow JavaVMTypes to be visible to the jUnit tests? My generated editor however works correctly.

Thanks in advanced.
Re: unit test language with JavaVMTypes [message #754886 is a reply to message #754885] Fri, 04 November 2011 19:12 Go to previous messageGo to next message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
I am importing the JavaVMTypes as follows:
grammar org.xtext.java.AspectJ with org.eclipse.xtext.common.Terminals

generate aspectJ "h ttp://www.xtext.org/java/AspectJ"

import "h ttp://www.eclipse.org/emf/2002/Ecore" as ecore
import "h ttp://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
....

Re: unit test language with JavaVMTypes [message #754897 is a reply to message #754886] Fri, 04 November 2011 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your test class look like? this works for me

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class TheTest {
	
	@Inject
	private ParseHelper<Model> parseHelper;
	
	@Test
	public void test() throws Exception {
		Model model = parseHelper.parse("map string to java.lang.String");
		for (Mapping mapping : model.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


as well as this

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new 
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.getResource(URI.createURI("src/test.mydsl"), true);
		r.load(null);
		Model m = (Model) r.getContents().get(0);
		for (Mapping mapping : m.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


with

grammar org.xtext.example.mydsl.MyDsl with 
org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes

Model:
	mappings+=Mapping*;
	
Mapping:
	'map' name=ID 'to' ref=[jvmTypes::JvmType|FQN];
	
FQN: ID ("." ID)*;


using Xtext 2.1.0 and a project created with the wizard.

~Christian


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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754898 is a reply to message #754886] Fri, 04 November 2011 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your test class look like? this works for me

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class TheTest {
	
	@Inject
	private ParseHelper<Model> parseHelper;
	
	@Test
	public void test() throws Exception {
		Model model = parseHelper.parse("map string to java.lang.String");
		for (Mapping mapping : model.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


as well as this

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new 
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.getResource(URI.createURI("src/test.mydsl"), true);
		r.load(null);
		Model m = (Model) r.getContents().get(0);
		for (Mapping mapping : m.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


with

grammar org.xtext.example.mydsl.MyDsl with 
org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes

Model:
	mappings+=Mapping*;
	
Mapping:
	'map' name=ID 'to' ref=[jvmTypes::JvmType|FQN];
	
FQN: ID ("." ID)*;


using Xtext 2.1.0 and a project created with the wizard.

~Christian


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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754899 is a reply to message #754886] Fri, 04 November 2011 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your test class look like? this works for me

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class TheTest {
	
	@Inject
	private ParseHelper<Model> parseHelper;
	
	@Test
	public void test() throws Exception {
		Model model = parseHelper.parse("map string to java.lang.String");
		for (Mapping mapping : model.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


as well as this

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new 
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.getResource(URI.createURI("src/test.mydsl"), true);
		r.load(null);
		Model m = (Model) r.getContents().get(0);
		for (Mapping mapping : m.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


with

grammar org.xtext.example.mydsl.MyDsl with 
org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes

Model:
	mappings+=Mapping*;
	
Mapping:
	'map' name=ID 'to' ref=[jvmTypes::JvmType|FQN];
	
FQN: ID ("." ID)*;


using Xtext 2.1.0 and a project created with the wizard.

~Christian


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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754900 is a reply to message #754886] Fri, 04 November 2011 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your test class look like? this works for me

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class TheTest {
	
	@Inject
	private ParseHelper<Model> parseHelper;
	
	@Test
	public void test() throws Exception {
		Model model = parseHelper.parse("map string to java.lang.String");
		for (Mapping mapping : model.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


as well as this

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new 
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.getResource(URI.createURI("src/test.mydsl"), true);
		r.load(null);
		Model m = (Model) r.getContents().get(0);
		for (Mapping mapping : m.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


with

grammar org.xtext.example.mydsl.MyDsl with 
org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes

Model:
	mappings+=Mapping*;
	
Mapping:
	'map' name=ID 'to' ref=[jvmTypes::JvmType|FQN];
	
FQN: ID ("." ID)*;


using Xtext 2.1.0 and a project created with the wizard.

~Christian


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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754901 is a reply to message #754886] Fri, 04 November 2011 20:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

how does your test class look like? this works for me

@RunWith(XtextRunner.class)
@InjectWith(MyDslInjectorProvider.class)
public class TheTest {
	
	@Inject
	private ParseHelper<Model> parseHelper;
	
	@Test
	public void test() throws Exception {
		Model model = parseHelper.parse("map string to java.lang.String");
		for (Mapping mapping : model.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


as well as this

public class Main {
	
	public static void main(String[] args) throws IOException {
		Injector i = new 
MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
		ResourceSet rs = i.getInstance(ResourceSet.class);
		Resource r = rs.getResource(URI.createURI("src/test.mydsl"), true);
		r.load(null);
		Model m = (Model) r.getContents().get(0);
		for (Mapping mapping : m.getMappings()) {
			System.out.println(mapping.getName() + " => " + 
mapping.getRef().getQualifiedName());
		}
	}

}


with

grammar org.xtext.example.mydsl.MyDsl with 
org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes

Model:
	mappings+=Mapping*;
	
Mapping:
	'map' name=ID 'to' ref=[jvmTypes::JvmType|FQN];
	
FQN: ID ("." ID)*;


using Xtext 2.1.0 and a project created with the wizard.

~Christian


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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754902 is a reply to message #754897] Fri, 04 November 2011 20:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hmmm seems as if the forum has a i hate the newsgroups day once more. one post gets six posts Wink

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754917 is a reply to message #754902] Sat, 05 November 2011 00:32 Go to previous messageGo to next message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
Thanks for your reply Christian.

One of my unit tests looks as follows:

@org.junit.runner.RunWith(typeof(XtextRunner))
@InjectWith(typeof(AspectJInjectorProvider))
class MethodTest {
		
	@Inject ParseHelper<CompilationUnit> parser

	@Test
	def void stringMethodTest(){
		var model = parser.parse('''
			public aspect LineItemExposureControlAspect {
				public java.lang.String test() {
					java.lang.String result;
					return result;
				}
			}
		''')

		var aspect = (model.typeDefinitions.get(0) as AspectDeclaration).definition;
		var method = (aspect.body.members.get(0) as JavaMethodDefinition);

		Assert::assertEquals("java.lang.String",method.returnType.reference.type.qualifiedName); 
	}

}


However I noticed that the error only occurs when I run multiple tests immediately after each other.
I have quite a number of test cases and I run them by a simple right click on the test project choosing "Run as" -> "JUnit Test".
The error doesn't occur when I run the test individually.

Do you have any idea what causes this problem?
Re: unit test language with JavaVMTypes [message #754933 is a reply to message #754917] Sat, 05 November 2011 11:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is a bug in Xtext 2.0.0/2.0.1 that is fixed in 2.1.0
http://www.eclipse.org/forums/index.php/t/261509/

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: unit test language with JavaVMTypes [message #754953 is a reply to message #754933] Sat, 05 November 2011 20:09 Go to previous message
Goran   is currently offline Goran Friend
Messages: 45
Registered: November 2011
Member
Thanks Christian. Indeed it's solved in Xtext 2.1.0!
Previous Topic:How to Disallow White Spaces in Qualified Name
Next Topic:Xtext2: iterate through eAllContents
Goto Forum:
  


Current Time: Fri Apr 26 16:02:50 GMT 2024

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

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

Back to the top