aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Vojtek2014-07-25 06:14:00 (EDT)
committerTomas Kraus2014-07-25 07:14:47 (EDT)
commit18fd11635e619cca349b95ce8775398f75fa3c92 (patch)
tree1e98757fcc67bf1ccb379218a24f1a5f14127373
parentb274dc1249f73801ee7125b961af58fa533228f1 (diff)
downloadeclipselink.runtime-18fd11635e619cca349b95ce8775398f75fa3c92.zip
eclipselink.runtime-18fd11635e619cca349b95ce8775398f75fa3c92.tar.gz
eclipselink.runtime-18fd11635e619cca349b95ce8775398f75fa3c92.tar.bz2
Bug# 440323 - Fixed the possibility to run JAXB tests from Eclipse.
JAXB tests are defined as test suites in package org.eclipse.persistence.testing.jaxb. Fixed the possibility to run moxy tests from directory moxy/eclipselink.moxy.test. Tests are run as ant -f antbuild.xml test. Signed-off-by: Martin Vojtek <martin.vojtek@oracle.com>
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/json/JSONReader.java189
-rw-r--r--moxy/eclipselink.moxy.test/antbuild.properties4
-rw-r--r--moxy/eclipselink.moxy.test/antbuild.xml19
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBWithJSONTestCases.java98
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/adapter/BinderWithAdapterTestCases.java152
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/hashcode/BinderWithHashCodeTestCases.java24
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/jaxbelement/BinderWithJAXBElementTestCases.java32
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nscollison/NamespaceCollisionTestCases.java32
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyCompositeTestCases.java24
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyTestCases.java66
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java2
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java25
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/DifferentClassLoaderTestCases.java25
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/InnerClassTestCases.java25
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/XmlElementsEnumTestCases.java5
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestCases.java81
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java48
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/AnonymousTypeTestCases.java59
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/inheritance/AnonymousTypeInheritanceTestCases.java22
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/SchemaGenXmlElementRefByteArrayTestCases.java84
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/SchemaGenXMLRootElementTestCases.java178
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/SchemaGenXMLTypeTestCases.java91
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/date/DateTestCases.java32
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/SchemaGenEmployeeTestCases.java82
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/SchemaGenImportTestCases.java174
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/SchemaGenImportURLTestCases.java24
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InheritanceWithTransientTestCases.java (renamed from moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InherianceWithTransientTestCases.java)168
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/SchemaGenInheritanceTestCases.java32
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/unmarshaller/DefaultValueTestCases.java32
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlAnyMixed/XmlAnyMixedTestCases.java4
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlidref/object/XmlIdRefObjectWhitespaceTestCases.java7
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlmarshaller/UnmarshalSchemaValidationTestCases.java37
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/OXTestCase.java51
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/readonly/DirectMappingTestCases.java52
34 files changed, 1037 insertions, 943 deletions
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/json/JSONReader.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/json/JSONReader.java
index 26a7963..c9129ce 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/json/JSONReader.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/json/JSONReader.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
+/*******************************************************************************
* Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -71,16 +71,16 @@ public class JSONReader extends XMLReaderAdapter {
private boolean isInCollection;
public JSONReader(String attrPrefix, NamespaceResolver nr, boolean namespaceAware, boolean includeRoot, Character namespaceSeparator, ErrorHandler errorHandler, String textWrapper){
- this(attrPrefix, nr, namespaceAware, includeRoot, namespaceSeparator, errorHandler, textWrapper, null);
- }
-
+ this(attrPrefix, nr, namespaceAware, includeRoot, namespaceSeparator, errorHandler, textWrapper, null);
+ }
+
@SuppressWarnings("StringEquality")
- public JSONReader(String attrPrefix, NamespaceResolver nr, boolean namespaceAware, boolean includeRoot, Character namespaceSeparator, ErrorHandler errorHandler, String textWrapper, Class unmarshalClass){
- this.attributePrefix = attrPrefix;
- if (attributePrefix == Constants.EMPTY_STRING) {
- attributePrefix = null;
- }
- namespaces = nr;
+ public JSONReader(String attrPrefix, NamespaceResolver nr, boolean namespaceAware, boolean includeRoot, Character namespaceSeparator, ErrorHandler errorHandler, String textWrapper, Class unmarshalClass){
+ this.attributePrefix = attrPrefix;
+ if (attributePrefix == Constants.EMPTY_STRING) {
+ attributePrefix = null;
+ }
+ namespaces = nr;
this.namespaceAware = namespaceAware;
if(namespaceSeparator == null){
this.namespaceSeparator = Constants.DOT;
@@ -90,15 +90,15 @@ public class JSONReader extends XMLReaderAdapter {
this.includeRoot = includeRoot;
this.setErrorHandler(errorHandler);
this.textWrapper = textWrapper;
- this.unmarshalClass = unmarshalClass;
- }
-
+ this.unmarshalClass = unmarshalClass;
+ }
+
private final JSONAttributes attributes = new JSONAttributes();
-
+
@Override
- public void parse(InputSource input) throws IOException, SAXException {
- try {
- CharStream charStream;
+ public void parse(InputSource input) throws IOException, SAXException {
+ try {
+ CharStream charStream;
InputStream inputStream = null;
if(null != input.getByteStream()) {
charStream = new ANTLRInputStream(input.getByteStream());
@@ -109,13 +109,16 @@ public class JSONReader extends XMLReaderAdapter {
URL url = new URL(input.getSystemId());
inputStream = url.openStream();
} catch(MalformedURLException malformedURLException) {
- try {
- inputStream = new FileInputStream(input.getSystemId());
- } catch(FileNotFoundException fileNotFoundException) {
- throw malformedURLException;
- }
- }
- charStream = new ANTLRInputStream(inputStream);
+ try {
+ inputStream = new FileInputStream(input.getSystemId());
+ } catch(FileNotFoundException fileNotFoundException) {
+ inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(input.getSystemId());
+ if (null == inputStream) {
+ throw malformedURLException;
+ }
+ }
+ }
+ charStream = new ANTLRInputStream(inputStream);
}
JSONLexer lexer = new JSONLexer(charStream);
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
@@ -291,13 +294,13 @@ public class JSONReader extends XMLReaderAdapter {
}
NodeValue nv = ((UnmarshalRecord)contentHandler).getAttributeChildNodeValue(uri, localName);
if(attributePrefix == null && nv !=null ){
- break;
- }
- }
+ break;
+ }
+ }
if (valueTree.getType() == JSONLexer.NULL) {
- contentHandler.setNil(true);
- }
-
+ contentHandler.setNil(true);
+ }
+
contentHandler.startElement(uri, localName, localName, attributes.setTree(valueTree, attributePrefix, namespaces, namespaceSeparator, namespaceAware));
parse(valueTree);
contentHandler.endElement(uri, localName, localName);
@@ -434,14 +437,14 @@ public class JSONReader extends XMLReaderAdapter {
for(int x=0, size=tree.getChildCount(); x<size; x++) {
parse((CommonTree) tree.getChild(x));
}
- }
- }
- }
+ }
+ }
+ }
@Override
- public boolean isNullRepresentedByXsiNil(AbstractNullPolicy nullPolicy){
- return true;
- }
+ public boolean isNullRepresentedByXsiNil(AbstractNullPolicy nullPolicy){
+ return true;
+ }
private void startCollection(){
@@ -449,41 +452,41 @@ public class JSONReader extends XMLReaderAdapter {
}
private void endCollection(){
- isInCollection = false;
- }
-
+ isInCollection = false;
+ }
+
@Override
- public boolean isInCollection(){
- return isInCollection;
- }
+ public boolean isInCollection(){
+ return isInCollection;
+ }
private boolean isTextValue(String localName){
XPathNode currentNode = ((UnmarshalRecord)contentHandler).getXPathNode();
if(currentNode == null){
return textWrapper != null && textWrapper.equals(localName);
- }
-
- return((currentNode.getNonAttributeChildrenMap() == null
- || currentNode.getNonAttributeChildrenMap().isEmpty()
- || (currentNode.getNonAttributeChildrenMap().size() == 1 && currentNode.getTextNode() != null))
- && textWrapper != null && textWrapper.equals(localName));
- }
-
+ }
+
+ return((currentNode.getNonAttributeChildrenMap() == null
+ || currentNode.getNonAttributeChildrenMap().isEmpty()
+ || (currentNode.getNonAttributeChildrenMap().size() == 1 && currentNode.getTextNode() != null))
+ && textWrapper != null && textWrapper.equals(localName));
+ }
+
/**
* Formats Java formatted string to a real String instance.
* @param Java escaped string with quotation marks
* @return string instance
*/
static String string(String string) {
-
+
char[] inputStringChars = string.toCharArray();
-
+
int lengthWithoutQuotation = inputStringChars.length-2;
StringBuilder returnStringBuilder = new StringBuilder(lengthWithoutQuotation);
int begin = 1;
int end = lengthWithoutQuotation;
-
+
int position = begin;
while (position <= end) {
@@ -554,17 +557,17 @@ public class JSONReader extends XMLReaderAdapter {
} else {
position++;
}
- }
+ }
// add any remaining characters
if (position > begin) {
returnStringBuilder.append(inputStringChars, begin, position-begin);
- }
+ }
return returnStringBuilder.toString();
- }
-
- /**
+ }
+
+ /**
* INTERNAL:
* @since 2.4
*/
@@ -629,13 +632,13 @@ public class JSONReader extends XMLReaderAdapter {
this.namespaceSeparator = namespaceSeparator;
this.namespaceAware = namespaceAware;
return this;
- }
-
- private void addSimpleAttribute(List attributes, String uri, String attributeLocalName,Tree childValueTree){
+ }
+
+ private void addSimpleAttribute(List attributes, String uri, String attributeLocalName,Tree childValueTree){
switch(childValueTree.getType()) {
- case JSONLexer.STRING: {
- String stringValue = JSONReader.string(childValueTree.getChild(0).getText());
- attributes.add(new Attribute(uri, attributeLocalName, attributeLocalName, stringValue));
+ case JSONLexer.STRING: {
+ String stringValue = JSONReader.string(childValueTree.getChild(0).getText());
+ attributes.add(new Attribute(uri, attributeLocalName, attributeLocalName, stringValue));
break;
}
case JSONLexer.NUMBER: {
@@ -650,16 +653,16 @@ public class JSONReader extends XMLReaderAdapter {
attributes.add(new Attribute(uri, attributeLocalName, attributeLocalName, FALSE));
break;
}
- case JSONLexer.NULL: {
- break;
- }
+ case JSONLexer.NULL: {
+ break;
+ }
}
- }
-
+ }
+
@Override
- public int getIndex(String uri, String localName) {
- if(null == localName) {
- return -1;
+ public int getIndex(String uri, String localName) {
+ if(null == localName) {
+ return -1;
}
int index = 0;
for(Attribute attribute : attributes()) {
@@ -746,14 +749,14 @@ public class JSONReader extends XMLReaderAdapter {
/**
* JSONParser is a generated class and maybe regenerated.
* this is a subclass to throw errors that may occur instead of just logging them.
- */
- private static class ExtendedJSONParser extends JSONParser {
-
- private final InputSource inputSource;
- private final ErrorHandler errorHandler;
-
- public ExtendedJSONParser(TokenStream input, InputSource inputSource, ErrorHandler errorHandler) {
- super(input);
+ */
+ private static class ExtendedJSONParser extends JSONParser {
+
+ private final InputSource inputSource;
+ private final ErrorHandler errorHandler;
+
+ public ExtendedJSONParser(TokenStream input, InputSource inputSource, ErrorHandler errorHandler) {
+ super(input);
this.inputSource = inputSource;
this.errorHandler = errorHandler;
}
@@ -773,14 +776,14 @@ public class JSONReader extends XMLReaderAdapter {
private static class SAXExceptionWrapper extends RuntimeException {
SAXExceptionWrapper(SAXException e){
- super(e);
- }
-
+ super(e);
+ }
+
@Override
- public SAXException getCause() {
- return (SAXException)super.getCause();
- }
-
- }
-
-} \ No newline at end of file
+ public SAXException getCause() {
+ return (SAXException)super.getCause();
+ }
+
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/antbuild.properties b/moxy/eclipselink.moxy.test/antbuild.properties
index 6fce674..014a7d6 100644
--- a/moxy/eclipselink.moxy.test/antbuild.properties
+++ b/moxy/eclipselink.moxy.test/antbuild.properties
@@ -34,6 +34,8 @@ resource.jar=javax.resource_1.6.0.v201204270900.jar
ejb.jar=javax.ejb_3.0.0.v200906010428.jar
jms.jar=javax.jms_1.1.0.v200906010428.jar
transaction.jar=javax.transaction_1.1.0.v201002051055.jar
+asm.jar=org.eclipse.persistence.asm_5.0.1.v201405080102.jar
+antlr.jar=org.eclipse.persistence.antlr_3.2.0.v201302191141.jar
eclipselink.core.depend=${activation.jar},${resource.jar},${ejb.jar},${jms.jar},${stax_api.jar},${transaction.jar},${mail.jar},${javax.validation.jar}
@@ -59,4 +61,4 @@ parser=org.eclipse.persistence.platform.xml.jaxp.JAXPParser
# Note: ./dummy_xml_parser.jar doesn't need to exist
# You can set these properties to run moxy tests with any xml parser other than the default from a JVM
xml.parser.jar.dir=.
-xml.parser.jar=dummy_xml_parser.jar \ No newline at end of file
+xml.parser.jar=dummy_xml_parser.jar
diff --git a/moxy/eclipselink.moxy.test/antbuild.xml b/moxy/eclipselink.moxy.test/antbuild.xml
index 22d3823..59aa36c 100644
--- a/moxy/eclipselink.moxy.test/antbuild.xml
+++ b/moxy/eclipselink.moxy.test/antbuild.xml
@@ -57,6 +57,7 @@
<property name="moxytest.2.common.plugins.dir" value="${moxytest.2.trunk.dir}/plugins"/>
<property name="moxytest.2.moxy.dir" value="${moxytest.2.trunk.dir}/moxy/org.eclipse.persistence.moxy"/>
<property name="moxytest.2.core.dir" value="${moxytest.2.trunk.dir}/foundation/org.eclipse.persistence.core"/>
+ <property name="moxytest.2.dynamic.dir" value="${moxytest.2.trunk.dir}/moxy/org.eclipse.persistence.moxy.dynamicxjc"/>
<property name="moxytest.2.buildsys.dir" value="${moxytest.2.trunk.dir}/buildsystem"/>
<property name="moxytest.plugins.dir" value="../plugins"/>
<!-- Temporary until eclipselink.jar property is globally renamed -->
@@ -109,9 +110,10 @@
<pathelement path="${moxytest.2.common.plugins.dir}/${transaction.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${mail.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${jaxrs.jar}"/>
+ <pathelement path="${moxytest.2.common.plugins.dir}/${asm.jar}"/>
<pathelement path="${oep.nosql.lib}"/>
<pathelement path="${junit.lib}"/>
- <pathelement path="${moxytest.2.moxy.dir}/${classes.dir}"/>
+ <pathelement path="${moxytest.2.moxy.dir}/target/${classes.dir}"/>
<pathelement path="${moxytest.2.core.dir}/${classes.dir}"/>
<pathelement path="${jaxb-xjc.lib}"/>
<pathelement path="${jaxb-impl.lib}"/>
@@ -125,7 +127,11 @@
<pathelement path="${moxytest.2.common.plugins.dir}/${activation.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${mail.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${jaxrs.jar}"/>
- <pathelement path="${moxytest.2.moxy.dir}/${classes.dir}"/>
+ <pathelement path="${moxytest.2.common.plugins.dir}/${antlr.jar}"/>
+ <pathelement path="${moxytest.2.common.plugins.dir}/${asm.jar}"/>
+ <pathelement path="${moxytest.2.moxy.dir}/target/${classes.dir}"/>
+ <pathelement path="${moxytest.2.moxy.dir}/${resource.dir}"/>
+ <pathelement path="${moxytest.2.dynamic.dir}/${classes.dir}"/>
<pathelement path="${classes.dir}"/>
<pathelement path="${resource.dir}"/>
<pathelement path="${moxytest.2.core.dir}/${classes.dir}"/>
@@ -135,11 +141,13 @@
<pathelement path="${jaxb-xjc.lib}"/>
<pathelement path="${jaxb-impl.lib}"/>
<pathelement path="${jaxb-core.lib}"/>
+ <pathelement path="${junit.lib}"/>
<pathelement path="${validation-impl.lib}"/>
<pathelement path="${jboss-logging.lib}"/>
<pathelement path="${javax.el-api.lib}"/>
<pathelement path="${javax.el.lib}"/>
<pathelement path="${classmate.lib}"/>
+ <pathelement path="${javax.validation.lib}"/>
</path>
<path id="oxm.compile.path">
<path refid="xml.parser.path"/>
@@ -152,7 +160,7 @@
<pathelement path="${moxytest.2.common.plugins.dir}/${mail.jar}"/>
<pathelement path="${oep.nosql.lib}"/>
<pathelement path="${junit.lib}"/>
- <pathelement path="${moxytest.2.moxy.dir}/${classes.dir}"/>
+ <pathelement path="${moxytest.2.moxy.dir}/target/${classes.dir}"/>
<pathelement path="${moxytest.2.core.dir}/${classes.dir}"/>
</path>
<path id="oxm.run.path">
@@ -164,11 +172,14 @@
<pathelement path="${moxytest.2.common.plugins.dir}/${stax_api.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${transaction.jar}"/>
<pathelement path="${moxytest.2.common.plugins.dir}/${mail.jar}"/>
- <pathelement path="${moxytest.2.moxy.dir}/${classes.dir}"/>
+ <pathelement path="${moxytest.2.common.plugins.dir}/${asm.jar}"/>
+ <pathelement path="${moxytest.2.common.plugins.dir}/${antlr.jar}"/>
+ <pathelement path="${moxytest.2.moxy.dir}/target/${classes.dir}"/>
<pathelement path="${classes.dir}"/>
<pathelement path="${resource.dir}"/>
<pathelement path="${moxytest.2.core.dir}/${classes.dir}"/>
<pathelement path="${moxytest.2.core.dir}/${resource.dir}"/>
+ <pathelement path="${junit.lib}"/>
</path>
<!-- The following compile/run paths reference eclipselink.jar for non-test classes and resources -->
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBWithJSONTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBWithJSONTestCases.java
index e38bd12..d8426ec 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBWithJSONTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBWithJSONTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -26,29 +26,26 @@ import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonReader;
-import javax.json.JsonStructure;
-import javax.json.JsonWriter;
-import javax.json.stream.JsonGenerator;
-import javax.json.stream.JsonParser;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
+import javax.json.JsonStructure;
+import javax.json.JsonWriter;
+import javax.json.stream.JsonGenerator;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
-import org.eclipse.persistence.internal.jaxb.json.schema.JsonSchemaGenerator;
-import org.eclipse.persistence.jaxb.JAXBContext;
-import org.eclipse.persistence.jaxb.MarshallerProperties;
-import org.eclipse.persistence.jaxb.UnmarshallerProperties;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.persistence.jaxb.JAXBContext;
+import org.eclipse.persistence.jaxb.MarshallerProperties;
+import org.eclipse.persistence.jaxb.UnmarshallerProperties;
import org.eclipse.persistence.oxm.MediaType;
-import org.eclipse.persistence.oxm.json.JsonGeneratorResult;
-import org.eclipse.persistence.oxm.json.JsonObjectBuilderResult;
-import org.eclipse.persistence.oxm.json.JsonStructureSource;
-import org.eclipse.persistence.testing.jaxb.JAXBTestCases.MyStreamSchemaOutputResolver;
-import org.xml.sax.InputSource;
-
-public abstract class JAXBWithJSONTestCases extends JAXBTestCases {
+import org.eclipse.persistence.oxm.json.JsonGeneratorResult;
+import org.eclipse.persistence.oxm.json.JsonObjectBuilderResult;
+import org.eclipse.persistence.oxm.json.JsonStructureSource;
+import org.xml.sax.InputSource;
+
+public abstract class JAXBWithJSONTestCases extends JAXBTestCases {
protected String controlJSONLocation;
private String controlJSONWriteLocation;
@@ -210,21 +207,32 @@ public abstract class JAXBWithJSONTestCases extends JAXBTestCases {
}
public void testJSONUnmarshalFromSource() throws Exception {
- if(isUnmarshalTest()){
- getJSONUnmarshaller().setProperty(UnmarshallerProperties.MEDIA_TYPE, getJSONUnmarshalMediaType());
-
-
- Source source = new StreamSource(controlJSONLocation);
- Object testObject = null;
- if(getUnmarshalClass() != null){
- testObject = getJSONUnmarshaller().unmarshal(source, getUnmarshalClass());
- }else{
- testObject = getJSONUnmarshaller().unmarshal(source);
- }
- jsonToObjectTest(testObject);
- }
- }
-
+ if(isUnmarshalTest()){
+ getJSONUnmarshaller().setProperty(UnmarshallerProperties.MEDIA_TYPE, getJSONUnmarshalMediaType());
+
+ InputStream controlJSONInputStream = null;
+ try {
+ controlJSONInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(controlJSONLocation);
+ Source source = new StreamSource(controlJSONInputStream);
+ Object testObject = null;
+ if (getUnmarshalClass() != null) {
+ testObject = getJSONUnmarshaller().unmarshal(source, getUnmarshalClass());
+ } else {
+ testObject = getJSONUnmarshaller().unmarshal(source);
+ }
+ jsonToObjectTest(testObject);
+ } finally {
+ if (null != controlJSONInputStream) {
+ try {
+ controlJSONInputStream.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
public void testJSONUnmarshalFromJsonStructureSource() throws Exception {
if(isUnmarshalTest()){
getJSONUnmarshaller().setProperty(UnmarshallerProperties.MEDIA_TYPE, getJSONUnmarshalMediaType());
@@ -464,7 +472,7 @@ public abstract class JAXBWithJSONTestCases extends JAXBTestCases {
Writer generated = generatedSchemas.get(i);
log(generated.toString());
String controlString = loadInputStreamToString(controlInputstream);
- compareStrings("generateJSONSchema", generated.toString(), controlString, true);
- }
- }
-} \ No newline at end of file
+ compareStrings("generateJSONSchema", generated.toString(), controlString, true);
+ }
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/adapter/BinderWithAdapterTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/adapter/BinderWithAdapterTestCases.java
index a80d517..dc3805c 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/adapter/BinderWithAdapterTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/adapter/BinderWithAdapterTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -11,51 +11,31 @@
* dmccann - June 4/2009 - 2.0 - Initial implementation
******************************************************************************/
package org.eclipse.persistence.testing.jaxb.binder.adapter;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import javax.xml.bind.Binder;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Result;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathFactory;
-
-import org.eclipse.persistence.jaxb.JAXBContext;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.oxm.XMLConstants;
-import org.eclipse.persistence.testing.jaxb.JAXBXMLComparer;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-import junit.framework.TestCase;
-
-/**
- * Tests JAXBBinder marshal/unmarshal with an XmlJavaTypeAdapter.
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.TreeMap;
+
+import javax.xml.bind.Binder;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathFactory;
+
+import junit.framework.TestCase;
+
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.testing.jaxb.JAXBXMLComparer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Tests JAXBBinder marshal/unmarshal with an XmlJavaTypeAdapter.
*
*/
public class BinderWithAdapterTestCases extends TestCase {
@@ -76,13 +56,13 @@ public class BinderWithAdapterTestCases extends TestCase {
xpath = XPathFactory.newInstance().newXPath();
}
- public void testUnmarshal() {
- try {
- String src = "org/eclipse/persistence/testing/jaxb/binder/adapter/element.xml";
- Document doc = documentBuilderFactory.newDocumentBuilder().parse(new FileInputStream(new File(src)));
-
- JAXBElement<Element> result = binder.unmarshal(doc, Element.class);
-
+ public void testUnmarshal() {
+ try {
+ String src = "org/eclipse/persistence/testing/jaxb/binder/adapter/element.xml";
+ Document doc = documentBuilderFactory.newDocumentBuilder().parse(Thread.currentThread().getContextClassLoader().getResourceAsStream(src));
+
+ JAXBElement<Element> result = binder.unmarshal(doc, Element.class);
+
Element returnedElt = result.getValue();
Element controlElt = getControlObject();
@@ -96,15 +76,27 @@ public class BinderWithAdapterTestCases extends TestCase {
Element elt = new Element();
elt.key = 0;
elt.value = new HashMap<Integer, String>();
- elt.value.put(101, "KTM");
- elt.value.put(69, "CBR");
-
- try {
- String src = "org/eclipse/persistence/testing/jaxb/binder/adapter/element.xml";
- Document controlDoc = documentBuilderFactory.newDocumentBuilder().parse(new FileInputStream(new File(src)));
-
- Document doc = documentBuilderFactory.newDocumentBuilder().newDocument();
- binder.marshal(elt, doc);
+ elt.value.put(101, "KTM");
+ elt.value.put(69, "CBR");
+
+ InputStream srcFileInputStream = null;
+
+ try {
+ String src = "org/eclipse/persistence/testing/jaxb/binder/adapter/element.xml";
+
+ try {
+ srcFileInputStream = new FileInputStream(new File(src));
+ } catch (FileNotFoundException fnfe) {
+ srcFileInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(src);
+ if (null == srcFileInputStream) {
+ throw fnfe;
+ }
+ }
+
+ Document controlDoc = documentBuilderFactory.newDocumentBuilder().parse(srcFileInputStream);
+
+ Document doc = documentBuilderFactory.newDocumentBuilder().newDocument();
+ binder.marshal(elt, doc);
// for debugging - do not remove
/*
@@ -116,12 +108,20 @@ public class BinderWithAdapterTestCases extends TestCase {
*/
JAXBXMLComparer comparer = new JAXBXMLComparer();
- assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDoc, doc));
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
+ assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDoc, doc));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ } finally {
+ if (null != srcFileInputStream) {
+ try {
+ srcFileInputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
/**
* Used for unmarshal test verification
*/
@@ -132,7 +132,7 @@ public class BinderWithAdapterTestCases extends TestCase {
TreeMap<Integer, String> tMap = new TreeMap<Integer, String>();
tMap.put(101, "KTM");
tMap.put(69, "CBR");
- elt.value = tMap;
- return elt;
- }
-} \ No newline at end of file
+ elt.value = tMap;
+ return elt;
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/hashcode/BinderWithHashCodeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/hashcode/BinderWithHashCodeTestCases.java
index 826df76..3708daf 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/hashcode/BinderWithHashCodeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/hashcode/BinderWithHashCodeTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -36,13 +36,13 @@ public class BinderWithHashCodeTestCases extends TestCase {
parser = platform.newXMLParser();
}
- public void testAbsentNode() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/absentnode.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
-
+ public void testAbsentNode() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/absentnode.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
+
Binder binder = ctx.createBinder();
Employee emp = (Employee)binder.unmarshal(parser.parse(new StringReader(xml)));
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/jaxbelement/BinderWithJAXBElementTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/jaxbelement/BinderWithJAXBElementTestCases.java
index 5dad7d2..4baa3a5 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/jaxbelement/BinderWithJAXBElementTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/jaxbelement/BinderWithJAXBElementTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -37,20 +37,20 @@ public class BinderWithJAXBElementTestCases extends TestCase {
parser = platform.newXMLParser();
}
- public void testAbsentNode() throws Exception {
- String xml = "<employee><id>123</id><!-- Comment 1 --><name>Matt</name></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/jaxbelement/employee.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
-
+ public void testAbsentNode() throws Exception {
+ String xml = "<employee><id>123</id><!-- Comment 1 --><name>Matt</name></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/jaxbelement/employee.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
+
Binder binder = ctx.createBinder();
JAXBElement emp = binder.unmarshal(parser.parse(new StringReader(xml)), Employee.class);
((Employee)emp.getValue()).id = 456;
binder.updateXML(emp);
- JAXBXMLComparer comparer = new JAXBXMLComparer();
- assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
- }
-} \ No newline at end of file
+ JAXBXMLComparer comparer = new JAXBXMLComparer();
+ assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nscollison/NamespaceCollisionTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nscollison/NamespaceCollisionTestCases.java
index d6d44cf..d2e9344 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nscollison/NamespaceCollisionTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nscollison/NamespaceCollisionTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -37,13 +37,13 @@ public class NamespaceCollisionTestCases extends TestCase {
parser = platform.newXMLParser();
}
- public void testNamespaceCollision() throws Exception {
- String xml = "<ns0:employee xmlns:ns1=\"mynamespace3\" xmlns:ns2=\"mynamespace2\" xmlns:ns0=\"mynamespace1\"><ns2:address><street>123 Fake Street</street></ns2:address><firstName>Matt</firstName><id>123</id></ns0:employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nscollision/employee.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
-
+ public void testNamespaceCollision() throws Exception {
+ String xml = "<ns0:employee xmlns:ns1=\"mynamespace3\" xmlns:ns2=\"mynamespace2\" xmlns:ns0=\"mynamespace1\"><ns2:address><street>123 Fake Street</street></ns2:address><firstName>Matt</firstName><id>123</id></ns0:employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nscollision/employee.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{Employee.class}, null);
+
Binder binder = ctx.createBinder();
JAXBElement elem = binder.unmarshal(parser.parse(new StringReader(xml)), Employee.class);
@@ -52,7 +52,7 @@ public class NamespaceCollisionTestCases extends TestCase {
binder.updateXML(emp.address);
- JAXBXMLComparer comparer = new JAXBXMLComparer();
- assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
- }
-} \ No newline at end of file
+ JAXBXMLComparer comparer = new JAXBXMLComparer();
+ assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyCompositeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyCompositeTestCases.java
index 9449571..c7bff58 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyCompositeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyCompositeTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -38,13 +38,13 @@ public class BinderWithNullPolicyCompositeTestCases extends TestCase {
parser = platform.newXMLParser();
}
- public void testEmptyNode() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name>Matt</name><!-- Comment 2 --><address><street>123 Fake Street</street><city>Kanata</city></address><phone>123-4567</phone><phone>234-5678</phone></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/emptynodecomposite.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeCompositeA.class}, null);
-
+ public void testEmptyNode() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name>Matt</name><!-- Comment 2 --><address><street>123 Fake Street</street><city>Kanata</city></address><phone>123-4567</phone><phone>234-5678</phone></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/emptynodecomposite.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeCompositeA.class}, null);
+
Binder binder = ctx.createBinder();
EmployeeCompositeA emp = (EmployeeCompositeA)binder.unmarshal(parser.parse(new StringReader(xml)));
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyTestCases.java
index 29774ca..b5a8d30 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/binder/nullpolicy/BinderWithNullPolicyTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -39,13 +39,13 @@ public class BinderWithNullPolicyTestCases extends TestCase{
parser = platform.newXMLParser();
}
- public void testAbsentNode() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/absentnode.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeA.class}, null);
-
+ public void testAbsentNode() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/absentnode.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeA.class}, null);
+
Binder binder = ctx.createBinder();
EmployeeA emp = (EmployeeA)binder.unmarshal(parser.parse(new StringReader(xml)));
@@ -58,13 +58,13 @@ public class BinderWithNullPolicyTestCases extends TestCase{
assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
}
- public void testXsiNilNullMarshal() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/xsinil.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeB.class}, null);
-
+ public void testXsiNilNullMarshal() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/xsinil.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeB.class}, null);
+
Binder binder = ctx.createBinder();
EmployeeB emp = (EmployeeB)binder.unmarshal(parser.parse(new StringReader(xml)));
@@ -77,13 +77,13 @@ public class BinderWithNullPolicyTestCases extends TestCase{
assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
}
- public void testXsiNilUnmarshalMarshalValue() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name xmlns:xsi=\"" + javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI + "\" xsi:nil=\"true\">Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/nilwithvalue.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeB.class}, null);
-
+ public void testXsiNilUnmarshalMarshalValue() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name xmlns:xsi=\"" + javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI + "\" xsi:nil=\"true\">Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/nilwithvalue.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeB.class}, null);
+
Binder binder = ctx.createBinder();
EmployeeB emp = (EmployeeB)binder.unmarshal(parser.parse(new StringReader(xml)));
@@ -96,13 +96,13 @@ public class BinderWithNullPolicyTestCases extends TestCase{
assertTrue("Marshalled document does not match the control document.", comparer.isNodeEqual(controlDocument, ((Node)binder.getXMLNode(emp)).getOwnerDocument()));
}
- public void testEmptyNode() throws Exception {
- String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
- String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/emptynode.xml";
- Document controlDocument = parser.parse(new File(controlSource));
-
- JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeC.class}, null);
-
+ public void testEmptyNode() throws Exception {
+ String xml = "<employee><!-- Comment 1 --><name>Matt</name><age>32</age><!-- Comment 2 --><address>Kanata</address></employee>";
+ String controlSource = "org/eclipse/persistence/testing/jaxb/binder/nullpolicy/emptynode.xml";
+ Document controlDocument = parser.parse(Thread.currentThread().getContextClassLoader().getResource(controlSource));
+
+ JAXBContext ctx = JAXBContextFactory.createContext(new Class[]{EmployeeC.class}, null);
+
Binder binder = ctx.createBinder();
EmployeeC emp = (EmployeeC)binder.unmarshal(parser.parse(new StringReader(xml)));
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java
index eb866bf..59b8479 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java
@@ -36,7 +36,7 @@ import java.util.concurrent.TimeUnit;
*/
public class JAXBCaseInsensitivityPerfTestCase extends junit.framework.TestCase {
- private static final File FILE = new File("org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml");
+ private static final File FILE = new File(Thread.currentThread().getContextClassLoader().getResource("org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml").getPath());
private static final int WARM_UP = 10000;
private static final int LAPS = 100000;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java
index eda968e..771261e 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java
@@ -12,6 +12,14 @@
******************************************************************************/
package org.eclipse.persistence.testing.jaxb.casesensitivity;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
@@ -20,13 +28,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Tests the functionality correctness of the case insensitive unmarshalling feature.
*
@@ -35,7 +36,7 @@ import java.util.Map;
*/
public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
- private static final File FILE = new File("org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml");
+ private static final URL CUSTOMER_FILE_URL = Thread.currentThread().getContextClassLoader().getResource("org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml");
private static final Class[] CAMEL_CASE_CUSTOMER = new Class[]{CustomerImpl.class};
private static final Class[] UPPER_CASE_CUSTOMER = new Class[]{org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl.class};
private static final boolean DEBUG = false;
@@ -65,7 +66,7 @@ public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
/* Case-insensitive part */
private CustomerImpl unmarshalCorrectCaseInsensitive() throws JAXBException {
- CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseInsensitive.unmarshal(FILE);
+ CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseInsensitive.unmarshal(CUSTOMER_FILE_URL);
if (DEBUG) System.out.println(correctCaseCustomer);
return correctCaseCustomer;
@@ -74,7 +75,7 @@ public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
private org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl unmarshalOtherCaseInsensitive() throws JAXBException {
org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl otherCaseCustomer
- = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseInsensitive.unmarshal(FILE);
+ = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseInsensitive.unmarshal(CUSTOMER_FILE_URL);
if (DEBUG) System.out.println(otherCaseCustomer);
return otherCaseCustomer;
@@ -83,7 +84,7 @@ public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
/* Case-sensitive part */
private CustomerImpl unmarshalCorrectCaseSensitive() throws JAXBException {
- CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseSensitive.unmarshal(FILE);
+ CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseSensitive.unmarshal(CUSTOMER_FILE_URL);
if (DEBUG) System.out.println(correctCaseCustomer);
return correctCaseCustomer;
@@ -92,7 +93,7 @@ public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
private org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl unmarshalOtherCaseSensitive() throws JAXBException {
org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl otherCaseCustomer
- = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseSensitive.unmarshal(FILE);
+ = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseSensitive.unmarshal(CUSTOMER_FILE_URL);
if (DEBUG) System.out.println(otherCaseCustomer);
return otherCaseCustomer;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/DifferentClassLoaderTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/DifferentClassLoaderTestCases.java
index 9412947..d2aaa89 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/DifferentClassLoaderTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/DifferentClassLoaderTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -34,14 +34,13 @@ public class DifferentClassLoaderTestCases extends JAXBWithJSONTestCases {
setControlDocument(XML_RESOURCE);
setControlJSON(JSON_RESOURCE);
- Class[] classes = new Class[2];
-
- URL[] urls = new URL[1];
- File f = new File("./org/eclipse/persistence/testing/jaxb/classloader/test.jar");
- urls[0] = f.toURL();
- URLClassLoader classLoaderA = new URLClassLoader(urls);
-
-
+ Class[] classes = new Class[2];
+
+ URL[] urls = new URL[1];
+ urls[0] = Thread.currentThread().getContextClassLoader().getResource("./org/eclipse/persistence/testing/jaxb/classloader/test.jar");
+ URLClassLoader classLoaderA = new URLClassLoader(urls);
+
+
Class classAClass = classLoaderA.loadClass("org.eclipse.persistence.testing.jaxb.classloader.ClassA");
ClassLoader test = classAClass.getClassLoader();
classes[1] = classAClass;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/InnerClassTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/InnerClassTestCases.java
index af44bac..a0b0359 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/InnerClassTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/InnerClassTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -25,14 +25,13 @@ import junit.framework.TestCase;
public class InnerClassTestCases extends TestCase {
public void testCreateContext() throws Exception {
- Class[] classes = new Class[1];
-
- URL[] urls = new URL[1];
- File f = new File("./org/eclipse/persistence/testing/jaxb/classloader/innerClass.jar");
- urls[0] = f.toURL();
- URLClassLoader classLoader = new URLClassLoader(urls);
-
- Class classAClass = classLoader.loadClass("org.eclipse.persistence.testing.jaxb.classloader.ClassWithInnerClass");
+ Class[] classes = new Class[1];
+
+ URL[] urls = new URL[1];
+ urls[0] = Thread.currentThread().getContextClassLoader().getResource("./org/eclipse/persistence/testing/jaxb/classloader/innerClass.jar");
+ URLClassLoader classLoader = new URLClassLoader(urls);
+
+ Class classAClass = classLoader.loadClass("org.eclipse.persistence.testing.jaxb.classloader.ClassWithInnerClass");
classes[0] = classAClass;
JAXBContext ctx = JAXBContextFactory.createContext(classes, null, Thread.currentThread().getContextClassLoader());
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/XmlElementsEnumTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/XmlElementsEnumTestCases.java
index c207554..68b0d3b 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/XmlElementsEnumTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/classloader/XmlElementsEnumTestCases.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -28,8 +28,7 @@ public class XmlElementsEnumTestCases extends TestCase {
Class[] classes = new Class[1];
URL[] urls = new URL[1];
- File f = new File("./org/eclipse/persistence/testing/jaxb/classloader/enum.jar");
- urls[0] = f.toURL();
+ urls[0] = Thread.currentThread().getContextClassLoader().getResource("./org/eclipse/persistence/testing/jaxb/classloader/enum.jar");
URLClassLoader classLoader = new URLClassLoader(urls);
Class classAClass = classLoader.loadClass("org.eclipse.persistence.testing.jaxb.classloader.Root");
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestCases.java
index 20c2943..9d98820 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -11,12 +11,13 @@
* dmccann - June 12/2009 - 2.0 - Initial implementation
******************************************************************************/
package org.eclipse.persistence.testing.jaxb.schemagen;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
@@ -26,18 +27,16 @@ import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.eclipse.persistence.jaxb.JAXBContext;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.oxm.XMLConstants;
-import org.eclipse.persistence.testing.jaxb.schemagen.deploymentxml.Employee;
-
-import junit.framework.TestCase;
-
-public class SchemaGenTestCases extends TestCase {
- protected static String tmpdir = (System.getenv("T_WORK") == null ? "" : (System.getenv("T_WORK") + "/"));
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.persistence.jaxb.JAXBContext;
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+
+public class SchemaGenTestCases extends TestCase {
+ protected static String tmpdir = (System.getenv("T_WORK") == null ? "" : (System.getenv("T_WORK") + "/"));
protected static ClassLoader loader = Thread.currentThread().getContextClassLoader();
/**
@@ -117,20 +116,28 @@ public class SchemaGenTestCases extends TestCase {
* @param schemaIndex index in output resolver's list of generated schemas
* @param outputResolver contains one or more schemas to validate against
*/
- protected String validateAgainstSchema(String src, int schemaIndex, MySchemaOutputResolver outputResolver) {
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema;
- try {
- theSchema = sFact.newSchema(outputResolver.schemaFiles.get(schemaIndex));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception e) {
- return e.getMessage();
- }
- return null;
- }
-
+ protected String validateAgainstSchema(String src, int schemaIndex, MySchemaOutputResolver outputResolver) {
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema;
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(src);
+ try {
+ theSchema = sFact.newSchema(outputResolver.schemaFiles.get(schemaIndex));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(is);
+ validator.validate(ss);
+ } catch (Exception e) {
+ return e.getMessage();
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return null;
+ }
+
/**
* SchemaOutputResolver for writing out the generated schema.
*
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java
index 87ebdd9..6406596 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java
@@ -15,13 +15,13 @@ package org.eclipse.persistence.testing.jaxb.schemagen;
import org.eclipse.persistence.testing.jaxb.schemagen.date.DateTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.deploymentxml.DeploymentXMLSchemaGenTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.employee.SchemaGenEmployeeTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.imports.SchemaGenImportTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.imports.inheritance.InheritanceImportsTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.imports.url.SchemaGenImportURLTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.inheritance.InherianceWithTransientTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.inheritance.SchemaGenInheritanceTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.scope.SchemaGenScopeTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.typearray.TypeArraySchemaGenTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.imports.SchemaGenImportTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.imports.inheritance.InheritanceImportsTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.imports.url.SchemaGenImportURLTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.inheritance.InheritanceWithTransientTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.inheritance.SchemaGenInheritanceTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.scope.SchemaGenScopeTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.typearray.TypeArraySchemaGenTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.xmlpath.SchemaGenXmlPathTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.anonymoustype.AnonymousTypeTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.anonymoustype.inheritance.AnonymousTypeInheritanceTestCases;
@@ -34,9 +34,9 @@ import org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlidref
import org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmllist.SchemaGenXmlListTestCases;
import org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlrootelement.SchemaGenXMLRootElementTestCases;
import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class SchemaGenTestSuite extends TestSuite {
+import junit.framework.TestSuite;
+
+public class SchemaGenTestSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("JAXB 2.0 Schema Generation Test Suite");
suite.addTestSuite(SchemaGenEmployeeTestCases.class);
@@ -44,9 +44,9 @@ public class SchemaGenTestSuite extends TestSuite {
suite.addTestSuite(SchemaGenXMLTypeTestCases.class);
suite.addTestSuite(SchemaGenXMLRootElementTestCases.class);
suite.addTestSuite(DeploymentXMLSchemaGenTestCases.class);
- suite.addTestSuite(SchemaGenXmlElementWrapperTestCases.class);
- suite.addTestSuite(SchemaGenXmlElementRefByteArrayTestCases.class);
- suite.addTestSuite(SchemaGenXmlElementRefTestCases.class);
+ suite.addTestSuite(SchemaGenXmlElementWrapperTestCases.class);
+ suite.addTestSuite(SchemaGenXmlElementRefByteArrayTestCases.class);
+ suite.addTestSuite(SchemaGenXmlElementRefTestCases.class);
suite.addTestSuite(SchemaGenXmlListTestCases.class);
suite.addTestSuite(SchemaGenXmlIDREFTestCases.class);
suite.addTestSuite(ClassArraySchemaGenTestCases.class);
@@ -55,18 +55,18 @@ public class SchemaGenTestSuite extends TestSuite {
suite.addTestSuite(SchemaGenImportTestCases.class);
suite.addTestSuite(SchemaGenImportURLTestCases.class);
suite.addTestSuite(DateTestCases.class);
- suite.addTestSuite(AnonymousTypeTestCases.class);
- suite.addTestSuite(AnonymousTypeInheritanceTestCases.class);
- suite.addTestSuite(SchemaGenInheritanceTestCases.class);
- suite.addTestSuite(InherianceWithTransientTestCases.class);
- suite.addTestSuite(InheritanceImportsTestCases.class);
- suite.addTestSuite(SchemaGenXmlPathTestCases.class);
- return suite;
+ suite.addTestSuite(AnonymousTypeTestCases.class);
+ suite.addTestSuite(AnonymousTypeInheritanceTestCases.class);
+ suite.addTestSuite(SchemaGenInheritanceTestCases.class);
+ suite.addTestSuite(InheritanceWithTransientTestCases.class);
+ suite.addTestSuite(InheritanceImportsTestCases.class);
+ suite.addTestSuite(SchemaGenXmlPathTestCases.class);
+ return suite;
}
public static void main(String[] args) {
String[] arguments = { "-c", "org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestSuite" };
- junit.textui.TestRunner.main(arguments);
- }
-
-} \ No newline at end of file
+ junit.textui.TestRunner.main(arguments);
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/AnonymousTypeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/AnonymousTypeTestCases.java
index 07aec08..1ae04e8 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/AnonymousTypeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/AnonymousTypeTestCases.java
@@ -1,33 +1,28 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* dmccann - Sept.22/2010 - 2.2 - Initial implementation
- ******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.anonymoustype;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.namespace.QName;
-import javax.xml.transform.Result;
-import javax.xml.transform.stream.StreamResult;
-
-import junit.framework.TestCase;
-
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.anonymoustype;
+
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.TypeMappingInfo;
import org.eclipse.persistence.testing.jaxb.externalizedmetadata.ExternalizedMetadataTestCases;
@@ -53,10 +48,14 @@ public class AnonymousTypeTestCases extends TestCase {
JAXBContext cxt = JAXBContextFactory.createContext(types, properties, Thread.currentThread().getContextClassLoader());
MySchemaOutputResolver mysr = new MySchemaOutputResolver();
- cxt.generateSchema(mysr);
-
- assertTrue("Expected two schemas to be generated, but there were [" + mysr.schemaFiles.size() + "]", mysr.schemaFiles.size() == 2);
- ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(TNS), new File(TNS_XSD));
- ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(TYPES_TNS), new File(TYPES_XSD));
- }
+ cxt.generateSchema(mysr);
+
+ assertTrue("Expected two schemas to be generated, but there were [" + mysr.schemaFiles.size() + "]", mysr.schemaFiles.size() == 2);
+ ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(TNS), getFile(TNS_XSD));
+ ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(TYPES_TNS), getFile(TYPES_XSD));
+ }
+
+ private File getFile(String resourceName) {
+ return new File(Thread.currentThread().getContextClassLoader().getResource(resourceName).getPath());
+ }
} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/inheritance/AnonymousTypeInheritanceTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/inheritance/AnonymousTypeInheritanceTestCases.java
index f3e7400..f99967c 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/inheritance/AnonymousTypeInheritanceTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/anonymoustype/inheritance/AnonymousTypeInheritanceTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -35,9 +35,9 @@ public class AnonymousTypeInheritanceTestCases extends TestCase {
JAXBContext cxt = JAXBContextFactory.createContext(new Class[]{ObjectFactory.class}, null);
MySchemaOutputResolver mysr = new MySchemaOutputResolver();
- cxt.generateSchema(mysr);
-
- assertTrue("Expected 1 schema to be generated, but there were [" + mysr.schemaFiles.size() + "]", mysr.schemaFiles.size() == 1);
- ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(""), new File(CONTROL_XSD));
- }
-}
+ cxt.generateSchema(mysr);
+
+ assertTrue("Expected 1 schema to be generated, but there were [" + mysr.schemaFiles.size() + "]", mysr.schemaFiles.size() == 1);
+ ExternalizedMetadataTestCases.compareSchemas(mysr.schemaFiles.get(""), new File(Thread.currentThread().getContextClassLoader().getResource(CONTROL_XSD).getPath()));
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/SchemaGenXmlElementRefByteArrayTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/SchemaGenXmlElementRefByteArrayTestCases.java
index 4e22e8b..016c69d 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/SchemaGenXmlElementRefByteArrayTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/SchemaGenXmlElementRefByteArrayTestCases.java
@@ -10,30 +10,29 @@
* Contributors:
* mmacivor - June 10/2009 - 2.0 - Initial implementation
******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlelementref;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
+package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlelementref;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.eclipse.persistence.jaxb.JAXBContext;
-import org.eclipse.persistence.oxm.XMLConstants;
-
-import junit.framework.TestCase;
-
-public class SchemaGenXmlElementRefByteArrayTestCases extends TestCase {
- static String tmpdir;
- MySchemaOutputResolver outputResolver = new MySchemaOutputResolver();
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.persistence.jaxb.JAXBContext;
+
+public class SchemaGenXmlElementRefByteArrayTestCases extends TestCase {
+ static String tmpdir;
+ MySchemaOutputResolver outputResolver = new MySchemaOutputResolver();
boolean shouldGenerateSchema = true;
public SchemaGenXmlElementRefByteArrayTestCases(String name) throws Exception {
@@ -62,21 +61,30 @@ public class SchemaGenXmlElementRefByteArrayTestCases extends TestCase {
}
}
- public void testGenerateSchema() {
- generateSchema();
-
- try {
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(outputResolver.schemaFiles.get(0));
- Validator validator = theSchema.newValidator();
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/bytearray.xml";
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- fail("Schema validation failed unexpectedly: " + ex.toString());
- }
-
- }
+ public void testGenerateSchema() {
+ generateSchema();
+
+ InputStream src = null;
+ try {
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(outputResolver.schemaFiles.get(0));
+ Validator validator = theSchema.newValidator();
+ src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlelementref/bytearray.xml");
+ StreamSource ss = new StreamSource(src);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ fail("Schema validation failed unexpectedly: " + ex.toString());
+ } finally {
+ if (null != src) {
+ try {
+ src.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
class MySchemaOutputResolver extends SchemaOutputResolver {
// keep a list of processed schemas for the validation phase of the test(s)
public List<File> schemaFiles;
@@ -88,7 +96,7 @@ public class SchemaGenXmlElementRefByteArrayTestCases extends TestCase {
public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
File schemaFile = new File(tmpdir + suggestedFileName);
schemaFiles.add(schemaFile);
- return new StreamResult(schemaFile);
- }
- }
-} \ No newline at end of file
+ return new StreamResult(schemaFile);
+ }
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/SchemaGenXMLRootElementTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/SchemaGenXMLRootElementTestCases.java
index 5348dff..9628b4c 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/SchemaGenXMLRootElementTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/SchemaGenXMLRootElementTestCases.java
@@ -1,31 +1,31 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlrootelement;
-
-import org.eclipse.persistence.jaxb.compiler.Generator;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
-
-import java.io.File;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import junit.framework.TestCase;
-import org.eclipse.persistence.oxm.XMLConstants;
-import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestCases;
-
-/**
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmlrootelement;
+
+import java.io.File;
+import java.io.InputStream;
+
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.eclipse.persistence.jaxb.compiler.Generator;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestCases;
+
+/**
* Schema generation tests - based on the JAXB 2.0 TCK:
* java2schema/CustomizedMapping/classes/XMLRootElement
*/
@@ -40,25 +40,34 @@ public class SchemaGenXMLRootElementTestCases extends SchemaGenTestCases {
super(name);
}
- public void testName001Positive() throws Exception {
- boolean exception = false;
- String msg = null;
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name001p.xml";
- try {
- Class[] jClasses = new Class[] { Name001.class };
- Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
- gen.generateSchemaFiles(tmpdir, null);
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- exception = true;
- msg = ex.toString();
- }
- assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
- }
+ public void testName001Positive() throws Exception {
+ boolean exception = false;
+ String msg = null;
+ InputStream src = null;
+ try {
+ src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name001p.xml");
+ Class[] jClasses = new Class[] { Name001.class };
+ Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
+ gen.generateSchemaFiles(tmpdir, null);
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(src);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ exception = true;
+ msg = ex.toString();
+ } finally {
+ if (null != src) {
+ try {
+ src.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
+ }
public void testName001Negative() throws Exception {
boolean exception = false;
@@ -79,25 +88,30 @@ public class SchemaGenXMLRootElementTestCases extends SchemaGenTestCases {
assertFalse("Schema validation did not fail as expected: ", exception==false);
}
- public void testName002Positive() throws Exception {
- boolean exception = false;
- String msg = null;
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name002p.xml";
- String tmpdir = System.getenv("T_WORK");
- try {
- Class[] jClasses = new Class[] { Name002.class };
- Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
- gen.generateSchemaFiles(tmpdir, null);
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- exception = true;
- }
- assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
- }
+ public void testName002Positive() throws Exception {
+ boolean exception = false;
+ String msg = null;
+ InputStream src = null;
+ try {
+ src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/Name002p.xml");
+ Class[] jClasses = new Class[] { Name002.class };
+ Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
+ gen.generateSchemaFiles(tmpdir, null);
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(src);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ msg = ex.getMessage();
+ exception = true;
+ } finally {
+ if (null != src) {
+ src.close();
+ }
+ }
+ assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
+ }
public void testName002Negative() throws Exception {
boolean exception = false;
@@ -120,26 +134,30 @@ public class SchemaGenXMLRootElementTestCases extends SchemaGenTestCases {
assertFalse("Schema validation did not fail as expected: " + msg, exception==false);
}
- public void testNamespace001Positive() throws Exception {
- boolean exception = false;
- String msg = null;
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/NameSpace001p.xml";
- String tmpdir = System.getenv("T_WORK");
- try {
- Class[] jClasses = new Class[] { NameSpace001.class };
- Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
- gen.generateSchemaFiles(tmpdir, null);
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema2.xsd"));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- exception = true;
- msg = ex.getMessage();
- }
- assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
- }
+ public void testNamespace001Positive() throws Exception {
+ boolean exception = false;
+ String msg = null;
+ InputStream src = null;
+ try {
+ src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmlrootelement/NameSpace001p.xml");
+ Class[] jClasses = new Class[] { NameSpace001.class };
+ Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
+ gen.generateSchemaFiles(tmpdir, null);
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema2.xsd"));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(src);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ exception = true;
+ msg = ex.getMessage();
+ } finally {
+ if (null != src) {
+ src.close();
+ }
+ }
+ assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
+ }
public void testNamespace001Negative() throws Exception {
boolean exception = false;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/SchemaGenXMLTypeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/SchemaGenXMLTypeTestCases.java
index 5234cc8..99cf3e4 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/SchemaGenXMLTypeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/SchemaGenXMLTypeTestCases.java
@@ -1,31 +1,31 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmltype;
-
-import org.eclipse.persistence.jaxb.compiler.Generator;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
-
-import java.io.File;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-import junit.framework.TestCase;
-import org.eclipse.persistence.oxm.XMLConstants;
-import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestCases;
-
-/**
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.customizedmapping.xmltype;
+
+import java.io.File;
+import java.io.InputStream;
+
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.eclipse.persistence.jaxb.compiler.Generator;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestCases;
+
+/**
* Schema generation tests - based on the JAXB 2.0 TCK:
* java2schema/CustomizedMapping/classes/XMLRootElement
*/
@@ -40,25 +40,34 @@ public class SchemaGenXMLTypeTestCases extends SchemaGenTestCases {
super(name);
}
- public void testBaseType001cPositive() throws Exception {
- boolean exception = false;
- String msg = null;
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/BaseType001p.xml";
- try {
- Class[] jClasses = new Class[] { BaseType001c.class };
- Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
- gen.generateSchemaFiles(tmpdir, null);
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- exception = true;
- msg = ex.toString();
- }
- assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
- }
+ public void testBaseType001cPositive() throws Exception {
+ boolean exception = false;
+ String msg = null;
+ InputStream src = null;
+ try {
+ src = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/customizedmapping/xmltype/BaseType001p.xml");
+ Class[] jClasses = new Class[] { BaseType001c.class };
+ Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
+ gen.generateSchemaFiles(tmpdir, null);
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(src);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ exception = true;
+ msg = ex.toString();
+ } finally {
+ if (null != src) {
+ try {
+ src.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
+ }
public void testBaseType001cNegative() throws Exception {
boolean exception = false;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/date/DateTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/date/DateTestCases.java
index 6d65442..d44c6f0 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/date/DateTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/date/DateTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
-* Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
-* This program and the accompanying materials are made available under the
-* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
-* which accompanies this distribution.
+/*******************************************************************************
+* Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+* This program and the accompanying materials are made available under the
+* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -54,13 +54,13 @@ public class DateTestCases extends SchemaGenTestCases {
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
- Document testSchemaDocument = db.parse(testSchemaInputSource);
-
- InputStream controlSchemaInputStream = new FileInputStream(new File("org/eclipse/persistence/testing/jaxb/schemagen/date/Date.xsd"));
- Document controlSchemaDocument = db.parse(controlSchemaInputStream);
-
- JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
+ InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
+ Document testSchemaDocument = db.parse(testSchemaInputSource);
+
+ InputStream controlSchemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/date/Date.xsd");
+ Document controlSchemaDocument = db.parse(controlSchemaInputStream);
+
+ JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
assertTrue("test did not match control document", xmlComparer.isSchemaEqual(controlSchemaDocument, testSchemaDocument));
}
@@ -80,7 +80,7 @@ public class DateTestCases extends SchemaGenTestCases {
private String getSchema() {
return stringWriter.toString();
}
-
- }
-
-} \ No newline at end of file
+
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/SchemaGenEmployeeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/SchemaGenEmployeeTestCases.java
index eb1a7b8..529c262 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/SchemaGenEmployeeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/SchemaGenEmployeeTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -54,39 +54,49 @@ public class SchemaGenEmployeeTestCases extends TestCase {
super(name);
}
- public void testEmployeeSchemaGeneration() throws Exception {
- boolean exception = false;
- String msg = null;
- String src = "org/eclipse/persistence/testing/jaxb/schemagen/employee/employee.xml";
- String tmpdir = System.getenv("T_WORK");
- if (tmpdir == null) {
- tmpdir = System.getProperty("java.io.tmpdir");
- }
-
- try {
- Class[] jClasses = new Class[] { Address.class, Employee.class, PhoneNumber.class, Department.class, MyTestType.class };
- Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
- gen.generateSchemaFiles(tmpdir, null);
- SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
- Validator validator = theSchema.newValidator();
- StreamSource ss = new StreamSource(new File(src));
- validator.validate(ss);
- } catch (Exception ex) {
- exception = true;
- msg = ex.toString();
- }
- assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
-
+ public void testEmployeeSchemaGeneration() throws Exception {
+ boolean exception = false;
+ String msg = null;
+ InputStream employeeXml = null;
+ String tmpdir = System.getenv("T_WORK");
+ if (tmpdir == null) {
+ tmpdir = System.getProperty("java.io.tmpdir");
+ }
+
+ try {
+ employeeXml = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/employee/employee.xml");
+
+ Class[] jClasses = new Class[] { Address.class, Employee.class, PhoneNumber.class, Department.class, MyTestType.class };
+ Generator gen = new Generator(new JavaModelInputImpl(jClasses, new JavaModelImpl(Thread.currentThread().getContextClassLoader())));
+ gen.generateSchemaFiles(tmpdir, null);
+ SchemaFactory sFact = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema theSchema = sFact.newSchema(new File(tmpdir + "/schema1.xsd"));
+ Validator validator = theSchema.newValidator();
+ StreamSource ss = new StreamSource(employeeXml);
+ validator.validate(ss);
+ } catch (Exception ex) {
+ exception = true;
+ msg = ex.toString();
+ } finally {
+ if (null != employeeXml) {
+ try {
+ employeeXml.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ assertTrue("Schema validation failed unexpectedly: " + msg, exception==false);
+
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setIgnoringElementContentWhitespace(true);
- builderFactory.setNamespaceAware(true);
- DocumentBuilder parser = builderFactory.newDocumentBuilder();
-
- InputStream stream = new FileInputStream(new File("org/eclipse/persistence/testing/jaxb/schemagen/employee/schema1.xsd"));
- Document control = parser.parse(stream);
-
- stream = new FileInputStream(new File(tmpdir + "/schema1.xsd"));
+ builderFactory.setNamespaceAware(true);
+ DocumentBuilder parser = builderFactory.newDocumentBuilder();
+
+ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/jaxb/schemagen/employee/schema1.xsd");
+ Document control = parser.parse(stream);
+
+ stream = new FileInputStream(new File(tmpdir + "/schema1.xsd"));
Document test = parser.parse(stream);
JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/SchemaGenImportTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/SchemaGenImportTestCases.java
index 8a83c2c..dad5a7e 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/SchemaGenImportTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/SchemaGenImportTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -11,12 +11,13 @@
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.testing.jaxb.schemagen.imports;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
@@ -29,31 +30,34 @@ import javax.xml.validation.Validator;
import junit.framework.TestCase;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.jaxb.compiler.Generator;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
-import org.eclipse.persistence.oxm.XMLConstants;
-import org.eclipse.persistence.testing.jaxb.externalizedmetadata.ExternalizedMetadataTestCases;
-import org.eclipse.persistence.testing.jaxb.schemagen.imports.address.Address;
-import org.eclipse.persistence.testing.jaxb.schemagen.imports.relativeschemalocation.test.Foo;
+import org.eclipse.persistence.jaxb.compiler.Generator;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+import org.eclipse.persistence.testing.jaxb.externalizedmetadata.ExternalizedMetadataTestCases;
+import org.eclipse.persistence.testing.jaxb.schemagen.imports.address.Address;
+import org.eclipse.persistence.testing.jaxb.schemagen.imports.relativeschemalocation.test.Foo;
import org.eclipse.persistence.testing.jaxb.schemagen.imports.relativeschemalocation.test2.Bar;
-import org.xml.sax.SAXException;
-
-public class SchemaGenImportTestCases extends TestCase {
- static String XML_RESOURCE = "org/eclipse/persistence/testing/jaxb/schemagen/imports/imports.xml";
- static String INVALID_XML_RESOURCE = "org/eclipse/persistence/testing/jaxb/schemagen/imports/invalid_imports.xml";
- static String EMPLOYEE_XSD_RESOURCE = "org/eclipse/persistence/testing/jaxb/schemagen/imports/employee.xsd";
- static String ADDRESS_XSD_RESOURCE = "org/eclipse/persistence/testing/jaxb/schemagen/imports/address.xsd";
- static String EMPLOYEE_NS = "employeeNamespace";
- static String ADDRESS_NS = "addressNamespace";
- static String FILE = "file:///";
- static String FOO_URI = "http://test.org";
- static String FOO_SCHEMA = "org/eclipse/persistence/testing/jaxb/schemagen/imports/foo.xsd";
- static String BAR_URI = "http://test2.org";
- static String BAR_SCHEMA = "org/eclipse/persistence/testing/jaxb/schemagen/imports/bar.xsd";
-
- public SchemaGenImportTestCases(String name) throws Exception {
- super(name);
+import org.xml.sax.SAXException;
+
+public class SchemaGenImportTestCases extends TestCase {
+
+ private static final String PACKAGE_RESOURCE = "org/eclipse/persistence/testing/jaxb/schemagen/imports/";
+ private static final String IMPORTS_XML = "imports.xml";
+ private static final String XML_RESOURCE = PACKAGE_RESOURCE + IMPORTS_XML;
+ private static final String INVALID_XML_RESOURCE = PACKAGE_RESOURCE + "invalid_imports.xml";
+ private static final String EMPLOYEE_XSD_RESOURCE = PACKAGE_RESOURCE + "employee.xsd";
+ private static final String ADDRESS_XSD_RESOURCE = PACKAGE_RESOURCE + "address.xsd";
+
+ private static final String EMPLOYEE_NS = "employeeNamespace";
+ private static final String ADDRESS_NS = "addressNamespace";
+ private static final String FILE = "file:///";
+ private static final String FOO_URI = "http://test.org";
+ private static final String FOO_SCHEMA = PACKAGE_RESOURCE + "foo.xsd";
+ private static final String BAR_URI = "http://test2.org";
+ private static final String BAR_SCHEMA = PACKAGE_RESOURCE + "bar.xsd";
+
+ public SchemaGenImportTestCases(String name) throws Exception {
+ super(name);
}
public void testSchemaGenerationWithImport() {
@@ -73,20 +77,20 @@ public class SchemaGenImportTestCases extends TestCase {
fail("SchemaFactory could not create Employee schema");
}
- StreamSource ss;
- Validator validator = employeeSchema.newValidator();
- try {
- ss = new StreamSource(new File(XML_RESOURCE));
- validator.validate(ss);
- } catch (Exception ex) {
- ex.printStackTrace();
- fail("An unexpected exception occurred");
- }
- try {
- ss = new StreamSource(new File(INVALID_XML_RESOURCE));
- validator.validate(ss);
- } catch (Exception ex) {
- return;
+ StreamSource ss;
+ Validator validator = employeeSchema.newValidator();
+ try {
+ ss = new StreamSource(getFile(XML_RESOURCE));
+ validator.validate(ss);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ fail("An unexpected exception occurred");
+ }
+ try {
+ ss = new StreamSource(getFile(INVALID_XML_RESOURCE));
+ validator.validate(ss);
+ } catch (Exception ex) {
+ return;
}
fail("The expected exception never occurred");
}
@@ -106,20 +110,32 @@ public class SchemaGenImportTestCases extends TestCase {
public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException {
File schemaFile = null;
Result res = null;
- if (namespaceURI == null) {
- namespaceURI = "";
- } else if (namespaceURI.equals(EMPLOYEE_NS)) {
- schemaFile = new File(EMPLOYEE_XSD_RESOURCE);
- } else if (namespaceURI.equals(ADDRESS_NS)) {
- schemaFile = new File(ADDRESS_XSD_RESOURCE);
- }
- schemaFiles.put(namespaceURI, schemaFile);
- res = new StreamResult(schemaFile);
- return res;
- }
- }
-
- /**
+ if (namespaceURI == null) {
+ namespaceURI = "";
+ } else if (namespaceURI.equals(EMPLOYEE_NS)) {
+ schemaFile = new File(getRelativePath() + EMPLOYEE_XSD_RESOURCE);
+ } else if (namespaceURI.equals(ADDRESS_NS)) {
+ schemaFile = new File(getRelativePath() + ADDRESS_XSD_RESOURCE);
+ }
+ schemaFiles.put(namespaceURI, schemaFile);
+ res = new StreamResult(schemaFile);
+ return res;
+ }
+
+ private String getRelativePath() {
+ URL importsURL = SchemaGenImportTestCases.class.getResource(IMPORTS_XML);
+ URL rootURL = SchemaGenImportTestCases.class.getResource("/");
+
+ //this condition can be improved in JDK7 with java.nio.file.Path.startsWith
+ if (!importsURL.getPath().startsWith(rootURL.getPath())) {
+ return "";
+ } else {
+ return rootURL.getPath();
+ }
+ }
+ }
+
+ /**
* Test's that the import schema location can be relativized given a
* source schema with no path info in the name, i.e. "employee.xsd".
* No exception should occur.
@@ -144,16 +160,20 @@ public class SchemaGenImportTestCases extends TestCase {
assertTrue("No schemas were generated", map.size() > 0);
File fooFile = map.get(FOO_URI);
File barFile = map.get(BAR_URI);
- assertTrue("No schema was generated for Foo", fooFile != null);
- assertTrue("No schema was generated for Bar", barFile != null);
-
- ExternalizedMetadataTestCases.compareSchemas(fooFile, new File(FOO_SCHEMA));
- ExternalizedMetadataTestCases.compareSchemas(barFile, new File(BAR_SCHEMA));
- }
-
- /**
- * SchemaOutputResolver for writing out the generated schema. Returns a StreamResult
- * wrapping a StringWriter.
+ assertTrue("No schema was generated for Foo", fooFile != null);
+ assertTrue("No schema was generated for Bar", barFile != null);
+
+ ExternalizedMetadataTestCases.compareSchemas(fooFile, getFile(FOO_SCHEMA));
+ ExternalizedMetadataTestCases.compareSchemas(barFile, getFile(BAR_SCHEMA));
+ }
+
+ private static File getFile(String resourceName) {
+ return new File(Thread.currentThread().getContextClassLoader().getResource(resourceName).getPath());
+ }
+
+ /**
+ * SchemaOutputResolver for writing out the generated schema. Returns a StreamResult
+ * wrapping a StringWriter.
*
*/
public static class MyStreamSchemaOutputResolver extends SchemaOutputResolver {
@@ -176,7 +196,7 @@ public class SchemaGenImportTestCases extends TestCase {
private String modifyFileName(String namespaceURI) throws IOException {
String fileName = namespaceURI.substring(7);
fileName = fileName.replaceAll("/", "_");
- return fileName + ".xsd";
- }
- }
-} \ No newline at end of file
+ return fileName + ".xsd";
+ }
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/SchemaGenImportURLTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/SchemaGenImportURLTestCases.java
index e7b38e6..4d1de83 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/SchemaGenImportURLTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/imports/url/SchemaGenImportURLTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -54,13 +54,13 @@ public class SchemaGenImportURLTestCases extends TestCase {
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
- Document testSchemaDocument = db.parse(testSchemaInputSource);
-
- InputStream controlSchemaInputStream = new FileInputStream(new File(CONTROL_SCHEMA));
- Document controlSchemaDocument = db.parse(controlSchemaInputStream);
-
- JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
+ InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
+ Document testSchemaDocument = db.parse(testSchemaInputSource);
+
+ InputStream controlSchemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONTROL_SCHEMA);
+ Document controlSchemaDocument = db.parse(controlSchemaInputStream);
+
+ JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
assertTrue("Test schema did not match control schema.", xmlComparer.isSchemaEqual(controlSchemaDocument, testSchemaDocument));
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InherianceWithTransientTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InheritanceWithTransientTestCases.java
index 6817fc7..833375e 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InherianceWithTransientTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/InheritanceWithTransientTestCases.java
@@ -1,84 +1,84 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Matt MacIvor - 2.3 - Initial implementation
- ******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.inheritance;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.SchemaOutputResolver;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Result;
-import javax.xml.transform.stream.StreamResult;
-
-import junit.framework.TestCase;
-
-import org.eclipse.persistence.testing.jaxb.JAXBXMLComparer;
-import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
-
-public class InherianceWithTransientTestCases extends TestCase {
- private static final String CONTROL_SCHEMA = "org/eclipse/persistence/testing/jaxb/schemagen/inheritance/transient.xsd";
-
- public InherianceWithTransientTestCases(String name) throws Exception {
- super(name);
- }
-
- public String getName() {
- return "JAXB SchemaGen: Inheritance: " + super.getName();
- }
-
- public void testSchemaGen() throws Exception {
- JAXBContext jaxbContext = JAXBContext.newInstance(new Class[]{Z.class, X.class, Y.class, X2.class});
- StringOutputResolver sor = new StringOutputResolver();
- jaxbContext.generateSchema(sor);
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- DocumentBuilder db = dbf.newDocumentBuilder();
-
- InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
- Document testSchemaDocument = db.parse(testSchemaInputSource);
-
- InputStream controlSchemaInputStream = new FileInputStream(new File(CONTROL_SCHEMA));
- Document controlSchemaDocument = db.parse(controlSchemaInputStream);
-
- JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
- assertTrue("Test schema did not match control schema.", xmlComparer.isSchemaEqual(controlSchemaDocument, testSchemaDocument));
- }
-
- private class StringOutputResolver extends SchemaOutputResolver {
-
- private StringWriter stringWriter;
-
- public StringOutputResolver() {
- stringWriter = new StringWriter();
- }
-
- @Override
- public Result createOutput(String arg0, String arg1) throws IOException {
- return new StreamResult(stringWriter);
- }
-
- private String getSchema() {
- return stringWriter.toString();
- }
-
- }
-
-} \ No newline at end of file
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Matt MacIvor - 2.3 - Initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.inheritance;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+
+import org.eclipse.persistence.testing.jaxb.JAXBXMLComparer;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+public class InheritanceWithTransientTestCases extends TestCase {
+ private static final String CONTROL_SCHEMA = "org/eclipse/persistence/testing/jaxb/schemagen/inheritance/transient.xsd";
+
+ public InheritanceWithTransientTestCases(String name) throws Exception {
+ super(name);
+ }
+
+ public String getName() {
+ return "JAXB SchemaGen: Inheritance: " + super.getName();
+ }
+
+ public void testSchemaGen() throws Exception {
+ JAXBContext jaxbContext = JAXBContext.newInstance(new Class[]{Z.class, X.class, Y.class, X2.class});
+ StringOutputResolver sor = new StringOutputResolver();
+ jaxbContext.generateSchema(sor);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+
+ InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
+ Document testSchemaDocument = db.parse(testSchemaInputSource);
+
+ InputStream controlSchemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONTROL_SCHEMA);
+ Document controlSchemaDocument = db.parse(controlSchemaInputStream);
+
+ JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
+ assertTrue("Test schema did not match control schema.", xmlComparer.isSchemaEqual(controlSchemaDocument, testSchemaDocument));
+ }
+
+ private class StringOutputResolver extends SchemaOutputResolver {
+
+ private StringWriter stringWriter;
+
+ public StringOutputResolver() {
+ stringWriter = new StringWriter();
+ }
+
+ @Override
+ public Result createOutput(String arg0, String arg1) throws IOException {
+ return new StreamResult(stringWriter);
+ }
+
+ private String getSchema() {
+ return stringWriter.toString();
+ }
+
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/SchemaGenInheritanceTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/SchemaGenInheritanceTestCases.java
index 2623ac8..a000f03 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/SchemaGenInheritanceTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/inheritance/SchemaGenInheritanceTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -56,13 +56,13 @@ public class SchemaGenInheritanceTestCases extends TestCase {
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
- Document testSchemaDocument = db.parse(testSchemaInputSource);
-
- InputStream controlSchemaInputStream = new FileInputStream(new File(CONTROL_SCHEMA));
- Document controlSchemaDocument = db.parse(controlSchemaInputStream);
-
- JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
+ InputSource testSchemaInputSource = new InputSource(new StringReader(sor.getSchema()));
+ Document testSchemaDocument = db.parse(testSchemaInputSource);
+
+ InputStream controlSchemaInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONTROL_SCHEMA);
+ Document controlSchemaDocument = db.parse(controlSchemaInputStream);
+
+ JAXBXMLComparer xmlComparer = new JAXBXMLComparer();
assertTrue("Test schema did not match control schema.", xmlComparer.isSchemaEqual(controlSchemaDocument, testSchemaDocument));
}
@@ -92,7 +92,7 @@ public class SchemaGenInheritanceTestCases extends TestCase {
private String getSchema() {
return stringWriter.toString();
}
-
- }
-
-} \ No newline at end of file
+
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/unmarshaller/DefaultValueTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/unmarshaller/DefaultValueTestCases.java
index d750b2b..a899a80 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/unmarshaller/DefaultValueTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/unmarshaller/DefaultValueTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -35,13 +35,13 @@ public class DefaultValueTestCases extends JAXBTestCases {
}
@Override
- public void setUp() throws Exception {
- super.setUp();
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- schema = sf.newSchema(new File(XSD_RESOURCE));
- }
-
-
+ public void setUp() throws Exception {
+ super.setUp();
+ SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ schema = sf.newSchema(Thread.currentThread().getContextClassLoader().getResource(XSD_RESOURCE));
+ }
+
+
@Override
public Unmarshaller getJAXBUnmarshaller() {
Unmarshaller unmarshaller = super.getJAXBUnmarshaller();
@@ -53,7 +53,7 @@ public class DefaultValueTestCases extends JAXBTestCases {
protected DefaultValueRoot getControlObject() {
DefaultValueRoot root = new DefaultValueRoot();
root.setElement("");
- return root;
- }
-
-} \ No newline at end of file
+ return root;
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlAnyMixed/XmlAnyMixedTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlAnyMixed/XmlAnyMixedTestCases.java
index cc165b7..0e1417d 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlAnyMixed/XmlAnyMixedTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlAnyMixed/XmlAnyMixedTestCases.java
@@ -31,7 +31,7 @@ public class XmlAnyMixedTestCases extends TestCase {
try {
JAXBContext jc = JAXBContextFactory.createContext(new Class[]{Main.class}, null);
Unmarshaller um = jc.createUnmarshaller();
- Object o = um.unmarshal(new File("org/eclipse/persistence/testing/jaxb/xmlAnyMixed/rootAnyMixed.xml"));
+ Object o = um.unmarshal(Thread.currentThread().getContextClassLoader().getResource("org/eclipse/persistence/testing/jaxb/xmlAnyMixed/rootAnyMixed.xml"));
Marshaller m = jc.createMarshaller();
StringWriter sw = new StringWriter();
m.marshal(o, sw);
@@ -41,4 +41,4 @@ public class XmlAnyMixedTestCases extends TestCase {
fail(e.getMessage());
}
}
-} \ No newline at end of file
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlidref/object/XmlIdRefObjectWhitespaceTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlidref/object/XmlIdRefObjectWhitespaceTestCases.java
index d06fd5f..ecc7408 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlidref/object/XmlIdRefObjectWhitespaceTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlidref/object/XmlIdRefObjectWhitespaceTestCases.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
@@ -57,7 +57,8 @@ public class XmlIdRefObjectWhitespaceTestCases extends JAXBWithJSONTestCases {
public void testValidatingMarshal() {
try {
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = sf.newSchema(new File(XSD_RESOURCE));
+
+ Schema schema = sf.newSchema(Thread.currentThread().getContextClassLoader().getResource(XSD_RESOURCE));
Marshaller m = getJAXBContext().createMarshaller();
m.setSchema(schema);
@@ -68,4 +69,4 @@ public class XmlIdRefObjectWhitespaceTestCases extends JAXBWithJSONTestCases {
}
}
-} \ No newline at end of file
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlmarshaller/UnmarshalSchemaValidationTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlmarshaller/UnmarshalSchemaValidationTestCases.java
index 4233e5a..a813543 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlmarshaller/UnmarshalSchemaValidationTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/xmlmarshaller/UnmarshalSchemaValidationTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 2011, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -68,16 +68,15 @@ public class UnmarshalSchemaValidationTestCases extends OXTestCase {
this.schema = schema;
}
- public void testFailOnSecondErrorFile() throws Exception {
- CustomErrorValidationEventHandler eventHandler = new CustomErrorValidationEventHandler();
- unmarshaller.setEventHandler(eventHandler);
- File file = new File(DOUBLE_ERROR_XML);
- try {
- unmarshaller.setSchema(this.schema);
- unmarshaller.unmarshal(file);
- } catch (UnmarshalException ex) {
- assertEquals(2, eventHandler.getErrorCount());
- return;
+ public void testFailOnSecondErrorFile() throws Exception {
+ CustomErrorValidationEventHandler eventHandler = new CustomErrorValidationEventHandler();
+ unmarshaller.setEventHandler(eventHandler);
+ try {
+ unmarshaller.setSchema(this.schema);
+ unmarshaller.unmarshal(Thread.currentThread().getContextClassLoader().getResource(DOUBLE_ERROR_XML));
+ } catch (UnmarshalException ex) {
+ assertEquals(2, eventHandler.getErrorCount());
+ return;
}
fail("No Exceptions thrown.");
}
@@ -408,7 +407,7 @@ public class UnmarshalSchemaValidationTestCases extends OXTestCase {
return xmlStreamReader;
} catch(XMLStreamException e) {
return null;
- }
- }
-
-} \ No newline at end of file
+ }
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/OXTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/OXTestCase.java
index 56e0489..d28a3ee 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/OXTestCase.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/OXTestCase.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -388,26 +388,27 @@ public abstract class OXTestCase extends XMLTestCase {
if(controlValue instanceof JAXBElement && testValue instanceof JAXBElement){
compareJAXBElementObjects((JAXBElement)controlValue, (JAXBElement)testValue);
}else{
- super.compareValues(controlValue, testValue);
- }
- }
- protected String loadFileToString(String fileName){
- InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
- return loadInputStreamToString(inputStream);
- }
-
- protected String loadInputStreamToString(InputStream inputStream){
- StringBuffer sb = new StringBuffer();
- String lineSep = System.getProperty("line.separator");
-
- try {
- InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
- String str;
- //Don't add teh lineSep the first time
- if(bufferedReader.ready()){
- sb.append(bufferedReader.readLine());
- }
+ super.compareValues(controlValue, testValue);
+ }
+ }
+
+ protected String loadFileToString(String fileName){
+ InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
+ return loadInputStreamToString(inputStream);
+ }
+
+ protected String loadInputStreamToString(InputStream inputStream){
+ StringBuilder sb = new StringBuilder();
+ String lineSep = System.getProperty("line.separator");
+
+ try {
+ InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
+ BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+ String str;
+ //Don't add the lineSep the first time
+ if(bufferedReader.ready()){
+ sb.append(bufferedReader.readLine());
+ }
while (bufferedReader.ready()) {
sb.append(lineSep);
sb.append(bufferedReader.readLine());
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/readonly/DirectMappingTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/readonly/DirectMappingTestCases.java
index a4e8f7b..8990b66 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/readonly/DirectMappingTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/oxm/readonly/DirectMappingTestCases.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
- * which accompanies this distribution.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
@@ -62,13 +62,13 @@ public class DirectMappingTestCases extends OXTestCase {
DOMPlatform platform = new DOMPlatform();
project.setLogin(new XMLLogin(platform));
XMLContext context = getXMLContext(project);
- XMLMarshaller marshaller = context.createMarshaller();
- XMLUnmarshaller unmarshaller = context.createUnmarshaller();
-
- InputStream in = getClass().getClassLoader().getResourceAsStream("org/eclipse/persistence/testing/oxm/readonly/employee.xml");
- Employee emp = (Employee)unmarshaller.unmarshal(in);
- if (emp.firstName == null) {
- fail("read only attribute was not set on a read");
+ XMLMarshaller marshaller = context.createMarshaller();
+ XMLUnmarshaller unmarshaller = context.createUnmarshaller();
+
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/oxm/readonly/employee.xml");
+ Employee emp = (Employee)unmarshaller.unmarshal(in);
+ if (emp.firstName == null) {
+ fail("read only attribute was not set on a read");
}
emp.firstName = "Bill";
@@ -83,13 +83,13 @@ public class DirectMappingTestCases extends OXTestCase {
public void testTwoAttributesOneReadOnly() throws Exception {
TwoDirectMappingProject project = new TwoDirectMappingProject();
XMLContext context = getXMLContext(project);
- XMLMarshaller marshaller = context.createMarshaller();
- XMLUnmarshaller unmarshaller = context.createUnmarshaller();
-
- InputStream in = getClass().getClassLoader().getResourceAsStream("org/eclipse/persistence/testing/oxm/readonly/employee.xml");
- Employee emp = (Employee)unmarshaller.unmarshal(in);
- if (emp.firstName == null) {
- fail("read only attribute was not set on a read");
+ XMLMarshaller marshaller = context.createMarshaller();
+ XMLUnmarshaller unmarshaller = context.createUnmarshaller();
+
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/eclipse/persistence/testing/oxm/readonly/employee.xml");
+ Employee emp = (Employee)unmarshaller.unmarshal(in);
+ if (emp.firstName == null) {
+ fail("read only attribute was not set on a read");
}
emp.firstName = "Bill";
@@ -113,12 +113,12 @@ public class DirectMappingTestCases extends OXTestCase {
fail("No Exception was thrown with 2 writeable mappings to the same field");
} catch (IntegrityException ex) {
}
- }*/
-
- private Document parse(String resource) throws Exception {
- InputStream stream = getClass().getClassLoader().getResourceAsStream(resource);
- Document document = parser.parse(stream);
- removeEmptyTextNodes(document);
- return document;
+ }*/
+
+ private Document parse(String resource) throws Exception {
+ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ Document document = parser.parse(stream);
+ removeEmptyTextNodes(document);
+ return document;
}
}