Eclipse/JUnit test works, Maven test fails... [message #423582] |
Thu, 02 October 2008 15:08 |
ronald Mising name Messages: 52 Registered: July 2009 |
Member |
|
|
This is a multi-part message in MIME format.
--------------030808050101010809060908
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi all,
I have a little unit test (see attachment) that produces this output in a file resource:
<?xml version="1.0" encoding="ASCII"?>
<xpdl2:Activities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xpdl1="http://www.wfmc.org/2002/XPDL1.0"
xmlns:xpdl2="http://www.wfmc.org/2008/XPDL2.1"
xmlns:xsd="http://www.eclipse.org/xsd/2002/XSD"
xsi:schemaLocation="http://www.wfmc.org/2008/XPDL2.1 http://www.wfmc.org/standards/bpmnxpdl_31.xsd"/>
When I run the test in th eclipse/junit environment, the test works fine.
When I run a "mvn clean test", the exact same test fails with
java.lang.NullPointerException
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
See also previous post named "NullPointerException in XMLSaveImpl.saveDataTypeMany".
I've completely reloaded and regenerated the code from scratch, and I think the problem is that
in order to be able to refer to an XML schema (org.eclipse.xsd.XSDSchema), there's one element
that contains these methods in the interface. They are *not* annotated with the @model tag,
as they're not part of the model but only a utility reference to an XSDSchema in another resource.
XSDSchema getXSDSchema();
void setXSDSchema(XSDSchema xsdSchema);
Because of this (?), and after reloading the genmodel, the genmodel contains additional references to
XMLType (referencing platform:/plugin/org.eclipse.emf.ecore/model/xmltype.ecore) and Ecore (referencing
platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore).
Question is, do I have to initialize these when I run maven tests in order to prevent the NullPointerException because somewhere an EPackage is
appearantly not registered?
TIA
Ronaldo
--------------030808050101010809060908
Content-Type: text/plain;
name="CopyOfTestXpdl2Example.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="CopyOfTestXpdl2Example.java"
package com.xpdl21.model.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Collections;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.xsd.XSDPackage;
import org.eclipse.xsd.util.XSDResourceFactoryImpl;
import org.junit.Test;
import org.wfmc.xpdl10.xpdl1.Xpdl1Package;
import org.wfmc.xpdl21.xpdl2.ActivitiesType;
import org.wfmc.xpdl21.xpdl2.DocumentRoot;
import org.wfmc.xpdl21.xpdl2.Xpdl2Factory;
import org.wfmc.xpdl21.xpdl2.Xpdl2Package;
import org.wfmc.xpdl21.xpdl2.util.Xpdl2ResourceFactoryImpl;
public class CopyOfTestXpdl2Example extends AbstractXPDLTest {
private static final Logger logger = Logger.getLogger(CopyOfTestXpdl2Example.class);
@Test
public void testSimpleSave() throws Exception {
String sourceFile = "/testSimpleSave.xpdl";
deleteFile("sourceFile");
URI uri = getFileURI(sourceFile);
Xpdl2Package.eINSTANCE.eClass();
Xpdl1Package.eINSTANCE.eClass();
XSDPackage.eINSTANCE.eClass();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put(
"xsd", new XSDResourceFactoryImpl());
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new Xpdl2ResourceFactoryImpl());
resourceSet.getPackageRegistry().put(Xpdl2Package.eNS_URI, Xpdl2Package.eINSTANCE);
resourceSet.getPackageRegistry().put(Xpdl1Package.eNS_URI, Xpdl1Package.eINSTANCE);
resourceSet.getPackageRegistry().put(XSDPackage.eNS_URI, XSDPackage.eINSTANCE);
Resource resource = resourceSet.createResource(uri);
DocumentRoot documentRoot = Xpdl2Factory.eINSTANCE.createDocumentRoot();
documentRoot.getXMLNSPrefixMap().put(Xpdl1Package.eNS_PREFIX , Xpdl1Package.eNS_URI);
documentRoot.getXMLNSPrefixMap().put(Xpdl2Package.eNS_PREFIX , Xpdl2Package.eNS_URI);
documentRoot.getXMLNSPrefixMap().put(XSDPackage.eNS_PREFIX, XSDPackage.eNS_URI);
documentRoot.getXSISchemaLocation().put(Xpdl2Package.eNS_URI , "http://www.wfmc.org/standards/bpmnxpdl_31.xsd");
ActivitiesType root = Xpdl2Factory.eINSTANCE.createActivitiesType();
documentRoot.setActivities(root);
resource.getContents().add(documentRoot);
resource.save(Collections.EMPTY_MAP);
}
} //Xpdl2Example
--------------030808050101010809060908--
|
|
|
Re: Eclipse/JUnit test works, Maven test fails... [message #423590 is a reply to message #423582] |
Thu, 02 October 2008 16:00 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Ronaldo,
Maybe doing XMLTypePackage.eINSTANCE.eClass() will help.
If you do this same logic in the generated XyzExample.java for this
model, does that work okay.
If you care to send me a zip of the exported projects that I could use
to reproduce this locally, that's likely to be faster than trying to
come up with theories...
Ronaldo wrote:
> Hi all,
>
> I have a little unit test (see attachment) that produces this output
> in a file resource:
>
> <?xml version="1.0" encoding="ASCII"?>
> <xpdl2:Activities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xpdl1="http://www.wfmc.org/2002/XPDL1.0"
> xmlns:xpdl2="http://www.wfmc.org/2008/XPDL2.1"
> xmlns:xsd="http://www.eclipse.org/xsd/2002/XSD"
> xsi:schemaLocation="http://www.wfmc.org/2008/XPDL2.1
> http://www.wfmc.org/standards/bpmnxpdl_31.xsd"/>
>
> When I run the test in th eclipse/junit environment, the test works fine.
> When I run a "mvn clean test", the exact same test fails with
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeMany( XMLSaveImpl.java:1742)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1485)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:678)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:588)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:256)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>
>
> See also previous post named "NullPointerException in
> XMLSaveImpl.saveDataTypeMany".
>
> I've completely reloaded and regenerated the code from scratch, and I
> think the problem is that
> in order to be able to refer to an XML schema
> (org.eclipse.xsd.XSDSchema), there's one element
> that contains these methods in the interface. They are *not* annotated
> with the @model tag,
> as they're not part of the model but only a utility reference to an
> XSDSchema in another resource.
>
> XSDSchema getXSDSchema();
> void setXSDSchema(XSDSchema xsdSchema);
>
> Because of this (?), and after reloading the genmodel, the genmodel
> contains additional references to
> XMLType (referencing
> platform:/plugin/org.eclipse.emf.ecore/model/xmltype.ecore) and Ecore
> (referencing platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore).
>
> Question is, do I have to initialize these when I run maven tests in
> order to prevent the NullPointerException because somewhere an
> EPackage is appearantly not registered?
>
> TIA
> Ronaldo
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.03281 seconds