Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext-utils: Content is not allowed in prolog
xtext-utils: Content is not allowed in prolog [message #772863] Fri, 30 December 2011 20:20 Go to next message
Tim Geisler is currently offline Tim GeislerFriend
Messages: 47
Registered: July 2009
Member
I like to have unit tests using xtext-utils in a multi-lingual world.

I have two languages, language A and language B. Language B is based on language A. That is, from language B you can import (e.g., using the importURI mechanism) files from language A.

I have two simple resources, test.a and test.b with the following contents:

test.a:

defineObjectOfLanguageA x // this should define an object x in language A

test.b:

import "test.a"
useObjectOfLanguageA x // this refers in language B to the object x defined in language A

When defining a unit test using xtext-utils:

import org.eclipse.xtext.junit4.InjectWith;
import org.eclipselabs.xtext.utils.unittesting.XtextRunner2;
import org.eclipselabs.xtext.utils.unittesting.XtextTest;
import org.junit.Test;
import org.junit.runner.RunWith;

import BInjectorProvider;

@RunWith(XtextRunner2.class)
@InjectWith(BInjectorProvider.class)
public class SimpleBTest extends XtextTest {
	@Test
	public void simpleBTest() {
		testFile("test.b", "test.a");
	}
}


I get an exception
java.lang.RuntimeException: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Content is not allowed in prolog.
	at org.eclipselabs.xtext.utils.unittesting.XtextTest.loadModel(XtextTest.java:408)
	at org.eclipselabs.xtext.utils.unittesting.XtextTest.testFile(XtextTest.java:175)
	at com.webxcerpt.cm.nsn.cmlui.tests.SimpleCmlUiTest.simpleCmlUiTest(SimpleCmlUiTest.java:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.eclipse.xtext.junit4.XtextRunner$1.evaluate(XtextRunner.java:55)
	at org.eclipselabs.xtext.utils.unittesting.XtextRunner2$1.evaluate(XtextRunner2.java:36)
	at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Content is not allowed in prolog.
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:201)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:242)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1511)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1290)
	at org.eclipselabs.xtext.utils.unittesting.XtextTest.loadModel(XtextTest.java:406)
	... 30 more
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
	at javax.xml.parsers.SAXParser.parse(Unknown Source)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
	... 34 more


This exception occurs when test.a is loaded.

There is a note in the xtext-utils wiki which mentions this error message. However, I am using Xtext 2.1.1, xtext-utils-0.9.2, and use the XtextRunner2 class.

My guess is that the injection framework is not set up for language A, but only for language B, and then as a fallback an XMI resource is loaded.

Is it possible to use xtext-utils for unit testing in my situation? If so, how?

Another workaround (which I did not try yet) could be to save the resource test.a in XMI format.

Best regards,

Tim
Re: xtext-utils: Content is not allowed in prolog [message #772865 is a reply to message #772863] Fri, 30 December 2011 20:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes simply build a own injectorprovider that utilizes the AStandaloneSetup too.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext-utils: Content is not allowed in prolog [message #772871 is a reply to message #772865] Fri, 30 December 2011 20:44 Go to previous messageGo to next message
Tim Geisler is currently offline Tim GeislerFriend
Messages: 47
Registered: July 2009
Member
Hi Christian,

thanks for the quick reply.

I had to think a little bit on what "utilizes the AStandaloneSetup too" means and got the idea: only the EMF registration is relevant which is done as a side effect of the AStandaloneSetup.

So, the method getInjector of BInjectorProvider now looks like:
	public Injector getInjector() {
		if (injector == null) {
			new AStandaloneSetup().createInjectorAndDoEMFRegistration();
			this.injector = new BStandaloneSetup().createInjectorAndDoEMFRegistration();
		}
		return injector;
	}


@the Xtext-utils committers: perhaps it would be good to include a hint on this technique to the documentation.
Re: xtext-utils: Content is not allowed in prolog [message #772872 is a reply to message #772871] Fri, 30 December 2011 20:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

just a remark. you may have to store the injector and call register as well (in setupRegistry)
to get things clean with the global state memento (which is still a bit buggy btw)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext-utils: Content is not allowed in prolog [message #774163 is a reply to message #772871] Tue, 03 January 2012 11:49 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Tim Geisler wrote on Fri, 30 December 2011 21:44
Hi Christian,

@the Xtext-utils committers: perhaps it would be good to include a hint on this technique to the documentation.


I placed a link to your comment on the wiki page.

Thanks,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: xtext-utils: Content is not allowed in prolog [message #883459 is a reply to message #772863] Fri, 08 June 2012 15:17 Go to previous message
Michael Vorburger is currently offline Michael VorburgerFriend
Messages: 103
Registered: July 2009
Senior Member
Thanks, this thread helped me to standalone unit test of a "mixed" xtext language which has references to another language. PS: Because the original *InjectorProvider is in *model.test/src-gen, it's probably best to create another one in *model.test/src:

public class BWithDependenciesInjectorProvider extends BInjectorProvider {

    protected  Injector aStandaloneSetupInjector;
    
    @Override
    public Injector getInjector() {
        if (aSetupInjector == null)
            aSetupInjector = new AStandaloneSetup().createInjectorAndDoEMFRegistration();
        return super.getInjector();
    }

    @Override
    public void setupRegistry() {
        if (aSetupInjector != null)
            new AStandaloneSetup().register(aStandaloneSetupInjector);
        super.setupRegistry();
    }

}
Previous Topic:Error in Xtext
Next Topic:Custom Qualified Name provider does not work, displays error
Goto Forum:
  


Current Time: Thu Apr 25 12:03:05 GMT 2024

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

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

Back to the top