aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'moxy/eclipselink.moxy.test/src/org/eclipse')
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBSRGTestSuite.java28
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java3
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite5.java43
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/annotations/PropertyTypeTestCases.java3
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationBindingsTestCase.java401
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationRuntimeTestCase.java240
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/ContentComparator.java157
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Department.java24
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Drivers.java21
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/DrivingLicense.java77
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Employee.java146
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java4
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/externalizedmetadata/xmlnametransformer/NameTransformerExceptionTestCases.java14
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/emptyroot/EmptyNullMarshalUnmarshalTestCases.java235
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsNonRootTestCases.java37
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsNamespaceTestCases.java14
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsTestCases.java14
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/SchemaGenTestSuite.java13
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/Employee.java46
19 files changed, 1317 insertions, 203 deletions
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBSRGTestSuite.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBSRGTestSuite.java
index bb5bf6f..9931d8a 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBSRGTestSuite.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBSRGTestSuite.java
@@ -13,20 +13,20 @@
package org.eclipse.persistence.testing.jaxb;
import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestSuite;
-import org.eclipse.persistence.testing.jaxb.xmlmarshaller.JAXBDOMTestSuite;
-import org.eclipse.persistence.testing.jaxb.xmlmarshaller.JAXBSAXTestSuite;
-
-public class JAXBSRGTestSuite extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite("JAXB SRG Test Suite");
- suite.addTest(SchemaGenTestSuite.suite());
- suite.addTest(JAXBSAXTestSuite.suite());
- suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlrootelement.XmlRootElementNamespaceTestCases.class);
- suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlrootelement.XmlRootElementNoNamespaceTestCases.class);
- suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlelement.XmlElementNamespaceTestCases.class);
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.persistence.testing.jaxb.schemagen.SchemaGenTestSuite;
+import org.eclipse.persistence.testing.jaxb.xmlmarshaller.JAXBSAXTestSuite;
+
+public class JAXBSRGTestSuite extends TestCase {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("JAXB SRG Test Suite");
+
+ suite.addTest(SchemaGenTestSuite.suite());
+ suite.addTest(JAXBSAXTestSuite.suite());
+ suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlrootelement.XmlRootElementNamespaceTestCases.class);
+ suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlrootelement.XmlRootElementNoNamespaceTestCases.class);
+ suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlelement.XmlElementNamespaceTestCases.class);
suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlelement.XmlElementCollectionTestCases.class);
suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlattribute.XmlAttributeNamespaceTestCases.class);
suite.addTestSuite(org.eclipse.persistence.testing.jaxb.xmlattribute.XmlAttributeNoNamespaceTestCases.class);
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
index 8d1664c..e8cafe7 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
@@ -12,7 +12,6 @@
******************************************************************************/
package org.eclipse.persistence.testing.jaxb;
-import org.eclipse.persistence.testing.jaxb.casesensitivity.JAXBCaseInsensitivityTestCase;
import org.eclipse.persistence.testing.jaxb.collections.CollectionsTestSuite;
import org.eclipse.persistence.testing.jaxb.defaultvalue.DefaultValueTestSuite;
import org.eclipse.persistence.testing.jaxb.employee.JAXBEmployeeNSTestCases;
@@ -82,8 +81,6 @@ public class JAXBTestSuite4 {
suite.addTestSuite(TypeAttributeInheritanceTestCases.class);
suite.addTestSuite(OtherRootTestCases.class);
suite.addTest(TypeVariableTestSuite.suite());
-
- suite.addTestSuite(JAXBCaseInsensitivityTestCase.class);
return suite;
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite5.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite5.java
new file mode 100644
index 0000000..7b5486d
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite5.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.BeanValidationBindingsTestCase;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.BeanValidationRuntimeTestCase;
+import org.eclipse.persistence.testing.jaxb.casesensitivity.JAXBCaseInsensitivityTestCase;
+
+/**
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ * @since 2.6
+ */
+public class JAXBTestSuite5 {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("JAXB20 Compiler Test Suite5");
+
+ suite.addTestSuite(JAXBCaseInsensitivityTestCase.class);
+ suite.addTestSuite(BeanValidationRuntimeTestCase.class);
+ suite.addTestSuite(BeanValidationBindingsTestCase.class);
+
+ return suite;
+ }
+
+
+ public static void main(String[] args) {
+ String[] arguments = { "-c", "org.eclipse.persistence.testing.jaxb.JAXBTestSuite5" };
+ junit.textui.TestRunner.main(arguments);
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/annotations/PropertyTypeTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/annotations/PropertyTypeTestCases.java
index fdfbdb8..3bab055 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/annotations/PropertyTypeTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/annotations/PropertyTypeTestCases.java
@@ -27,7 +27,6 @@ import org.eclipse.persistence.jaxb.compiler.TypeInfo;
import org.eclipse.persistence.jaxb.javamodel.JavaClass;
import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
-import org.eclipse.persistence.sessions.Project;
import org.eclipse.persistence.testing.jaxb.JAXBWithJSONTestCases;
public class PropertyTypeTestCases extends JAXBWithJSONTestCases {
@@ -71,7 +70,7 @@ public class PropertyTypeTestCases extends JAXBWithJSONTestCases {
Generator generator = new Generator(new JavaModelInputImpl(new Class[] { TestObject.class }, new JavaModelImpl(this.classLoader)));
CoreProject proj = generator.generateProject();
- TypeInfo info = generator.getAnnotationsProcessor().getTypeInfo().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
+ TypeInfo info = generator.getAnnotationsProcessor().getTypeInfos().get("org.eclipse.persistence.testing.jaxb.annotations.TestObject");
Property booleanProp = info.getProperties().get("booleanTest");
JavaClass type = booleanProp.getType();
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationBindingsTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationBindingsTestCase.java
new file mode 100644
index 0000000..f1afc9e
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationBindingsTestCase.java
@@ -0,0 +1,401 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation;
+
+import com.sun.tools.xjc.Driver;
+import junit.framework.Assert;
+import org.eclipse.persistence.jaxb.compiler.Generator;
+
+import javax.tools.Diagnostic;
+import javax.validation.Valid;
+import javax.validation.constraints.AssertFalse;
+import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Future;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Past;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+
+import javax.tools.DiagnosticCollector;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlValue;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.OutputStreamWriter;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+
+import static org.eclipse.persistence.testing.jaxb.beanvalidation.ContentComparator.equalsXML;
+
+/**
+ * Tests the generation of JAXB Facets and Bean Validation annotations during Schemagen and XJC, respectively.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+public class BeanValidationBindingsTestCase extends junit.framework.TestCase {
+
+ private static final String PATH_TO_SCHEMA_DIRECTORY = "org/eclipse/persistence/testing/jaxb/beanvalidation/sgen_xjc";
+ private static final String GOLDEN_FILE_PATH = PATH_TO_SCHEMA_DIRECTORY + "/golden_file.xsd";
+ private static final String RICH_SCHEMA_PATH = PATH_TO_SCHEMA_DIRECTORY + "/rich_schema.xsd";
+ private static final String CUSTOMIZED_SCHEMA_PATH = PATH_TO_SCHEMA_DIRECTORY + "/customized_schema.xsd";
+ private static final String GENERATED_SCHEMA_PATH = PATH_TO_SCHEMA_DIRECTORY + "/schema1.xsd";
+
+ // Handles error case where no BV annotations would be generated on class fields and would still pass the equality test.
+ boolean annotationsGenerated;
+
+ private String pkg;
+
+ @Override
+ public void tearDown() throws Exception {
+ assertTrue(deleteDir(new File(pkg)));
+ //noinspection ResultOfMethodCallIgnored
+ new File(GENERATED_SCHEMA_PATH).delete();
+ }
+
+ /**
+ * A fancy test demonstrating (and testing) that it is possible to perform
+ * a round-trip in a lucky case where the XML Schema is identical to the
+ * original golden file.
+ * In practice, the XJC/Schemagen transformations guarantee only equality
+ * of post round-trip schema with the original, not identity.
+ * This test should still pass even if changes are done to our code.
+ */
+ public void testGoldenFileIdentity() throws Exception {
+ pkg = "gf";
+
+ roundTrip(GOLDEN_FILE_PATH, pkg);
+ assertTrue(equalsXML(new File(GOLDEN_FILE_PATH), new File(GENERATED_SCHEMA_PATH)));
+ }
+
+ /**
+ * Tests equality of the original schema and schema after round-trip, with
+ * bean validation annotations and facets.
+ * Also tests equality of generated Java classes from the original schema
+ * and from the schema after round-trip.
+ */
+ public void testEqualitySchemaAndJava() throws Exception {
+ pkg = "rs";
+
+ Class<?>[] cTenured = roundTrip(RICH_SCHEMA_PATH, pkg);
+
+ xjcGenerateJavaSources(RICH_SCHEMA_PATH); // Regenerate the sources.
+ compileGeneratedSources(createCompileList(pkg));
+ Class<?>[] cYoung = loadCompiledClasses(createLoadList(pkg));
+
+ assertTrue(equalsClasses(cTenured, cYoung));
+ }
+
+ /**
+ * Tests customizations, i.e. facet customizations + custom facets, i.e.
+ * Future, Past, AssertTrue, AssertFalse.
+ */
+ public void testFacetCustomizationsAndCustomFacets() throws Exception {
+ pkg = "cs";
+
+ xjcGenerateJavaSourcesWithCustomizations(CUSTOMIZED_SCHEMA_PATH);
+ compileGeneratedSources(createCompileList(pkg));
+ Class<?> custom = loadCompiledClasses(createLoadList(pkg))[0];
+
+ Field generic = custom.getDeclaredField("generic");
+ Size s = generic.getAnnotation(Size.class);
+ assertEquals(s.message(), "Hello, world!");
+ assertEquals(s.groups()[0], BindingTeam.class);
+ assertEquals(s.groups()[1], RocketTeam.class);
+ assertEquals(s.max(), 4);
+
+ Pattern p1 = generic.getAnnotation(Pattern.List.class).value()[0];
+ Pattern p2 = generic.getAnnotation(Pattern.List.class).value()[1];
+ assertEquals(p1.message(), p2.message());
+ assertTrue(Arrays.equals(p1.groups(), p2.groups()));
+ assertEquals(p1.message(), "Hello.");
+ assertEquals(p1.groups()[0], Object.class);
+ assertEquals(p1.regexp(), "10");
+
+ Future f = generic.getAnnotation(Future.class);
+ assertEquals(f.message(), "Welcome to the Future!");
+ assertEquals(f.groups()[0], BindingTeam.class);
+
+ Past p = generic.getAnnotation(Past.class);
+ assertEquals(p.message(), "Farewell from the ancestors.");
+ assertEquals(p.groups()[0], Ancestors.class);
+
+ AssertTrue at = generic.getAnnotation(AssertTrue.class);
+ assertEquals(at.message(), "True fan of the team!");
+ assertEquals(at.groups()[0], BindingTeam.class);
+
+ AssertFalse af = generic.getAnnotation(AssertFalse.class);
+ assertEquals(af.message(), "false");
+ assertEquals(af.groups()[0], Object.class);
+
+ // To test a user custom annotation.
+ CustomAnnotation xmlKey = generic.getAnnotation(CustomAnnotation.class);
+ assertNotNull(xmlKey);
+ }
+
+ /**
+ * Tests that the XJC detects all facets and generates their respective
+ * annotations correctly.
+ */
+ @SuppressWarnings({ "UnusedAssignment", "UnusedDeclaration" })
+ public void testAllFacetsAndAnnotations() throws Exception {
+ pkg = "rs";
+
+ Class<?>[] c = roundTrip(RICH_SCHEMA_PATH, pkg);
+ Class<?> Main = c[0];
+ Class<?> Numbers = c[1];
+ Class<?> NumberWithHiddenValueAttribute = c[2];
+ Class<?> Strings = c[4];
+
+ XmlElement xmlElement;
+ Size size;
+ DecimalMax decimalMax;
+ DecimalMin decimalMin;
+ Pattern.List patternList;
+ Pattern pattern;
+
+ /* Main.class */
+ Field numbers = Main.getDeclaredField("numbers");
+ assertNotNull(numbers.getAnnotation(Valid.class));
+ assertNotNull(numbers.getAnnotation(NotNull.class));
+ xmlElement = numbers.getAnnotation(XmlElement.class);
+ assertFalse(xmlElement.nillable());
+
+ Field strings = Main.getDeclaredField("strings");
+ size = strings.getAnnotation(Size.class);
+ assertTrue(size.min() == 1 && size.max() == 2);
+ assertNotNull(strings.getAnnotation(Valid.class));
+ assertNotNull(strings.getAnnotation(NotNull.class));
+ xmlElement = strings.getAnnotation(XmlElement.class);
+ assertFalse(xmlElement.nillable());
+
+ Field unsignedByte = Main.getDeclaredField("unsignedByte");
+ decimalMax = unsignedByte.getAnnotation(DecimalMax.class);
+ assertEquals(decimalMax.value(), "255");
+ assertTrue(decimalMax.inclusive());
+ decimalMin = unsignedByte.getAnnotation(DecimalMin.class);
+ assertEquals(decimalMin.value(), "0");
+ assertTrue(decimalMin.inclusive());
+
+ Field byteArray = Main.getDeclaredField("byteArray");
+ size = byteArray.getAnnotation(Size.class);
+ assertTrue(size.max() == 18);
+
+ Field someCollection = Main.getDeclaredField("someCollection");
+ size = someCollection.getAnnotation(Size.class);
+ assertTrue(size.min() == 1);
+ assertNotNull(someCollection.getAnnotation(Valid.class));
+ assertNotNull(someCollection.getAnnotation(NotNull.class));
+
+ /* Numbers.class */
+ Field minInclusive = Numbers.getDeclaredField("minInclusive");
+ decimalMin = minInclusive.getAnnotation(DecimalMin.class);
+ assertEquals(decimalMin.value(), "1000");
+ assertTrue(decimalMin.inclusive());
+
+ Field maxInclusive = Numbers.getDeclaredField("maxInclusive");
+ decimalMax = maxInclusive.getAnnotation(DecimalMax.class);
+ assertEquals(decimalMax.value(), "1000");
+ assertTrue(decimalMax.inclusive());
+
+ Field minExclusive = Numbers.getDeclaredField("minExclusive");
+ decimalMin = minExclusive.getAnnotation(DecimalMin.class);
+ assertEquals(decimalMin.value(), "0");
+ assertFalse(decimalMin.inclusive());
+
+ Field maxExclusive = Numbers.getDeclaredField("maxExclusive");
+ decimalMax = maxExclusive.getAnnotation(DecimalMax.class);
+ assertEquals(decimalMax.value(), "1000");
+ assertFalse(decimalMax.inclusive());
+
+ Field minMaxExclusive = Numbers.getDeclaredField("minMaxExclusive");
+ decimalMax = minMaxExclusive.getAnnotation(DecimalMax.class);
+ assertEquals(decimalMax.value(), "9223372");
+ assertFalse(decimalMax.inclusive());
+ decimalMin = minMaxExclusive.getAnnotation(DecimalMin.class);
+ assertEquals(decimalMin.value(), "0");
+ assertFalse(decimalMin.inclusive());
+
+ /* NumberWithHiddenValueAttribute.class */
+ Field value = NumberWithHiddenValueAttribute.getDeclaredField("value");
+ assertNotNull(value.getAnnotation(XmlValue.class));
+ size = value.getAnnotation(Size.class);
+ assertTrue(size.min() == 1 && size.max() == 5);
+
+ Field code = NumberWithHiddenValueAttribute.getDeclaredField("code");
+ assertNotNull(code.getAnnotation(NotNull.class));
+
+ Field whatNumber = NumberWithHiddenValueAttribute.getDeclaredField("whatNumber");
+ XmlAttribute xmlAttribute = whatNumber.getAnnotation(XmlAttribute.class);
+ assertTrue(xmlAttribute.required());
+
+ /* Strings.class */
+ Field regexShorthands = Strings.getDeclaredField("regexShorthands");
+ patternList = regexShorthands.getAnnotation(Pattern.List.class);
+ Pattern[] patterns = patternList.value();
+ assertEquals("[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[0].regexp());
+ assertEquals("[^:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[1].regexp());
+ assertEquals("[-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[2].regexp());
+ assertEquals("[^-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]", patterns[3].regexp());
+ assertEquals("\\p{Nd}", patterns[4].regexp());
+ assertEquals("\\P{Nd}", patterns[5].regexp());
+ assertEquals("[\\u0009-\\u000D\\u0020\\u0085\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]", patterns[6].regexp());
+ assertEquals("[^\\u0009-\\u000D\\u0020\\u0085\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]", patterns[7].regexp());
+ assertEquals("[\\u0009\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]", patterns[8].regexp());
+ assertEquals("[^\\u0009\\u0020\\u00A0\\u1680\\u180E\\u2000\\u2001-\\u200A\\u202F\\u205F\\u3000]", patterns[9].regexp());
+ assertEquals("[^\\u000A-\\u000D\\u0085\\u2028\\u2029]", patterns[10].regexp());
+ assertEquals("(?:(?>\\u000D\\u000A)|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029])", patterns[11].regexp());
+
+ Field idType = Strings.getDeclaredField("idType");
+ pattern = idType.getAnnotation(Pattern.class);
+ assertEquals(pattern.regexp(), "[[:A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]-[:]][[-.0-9:A-Z_a-z\\u00B7\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u203F\\u2040\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]-[:]]*");
+ assertTrue(idType.getAnnotation(Size.class).max() == 100);
+
+ Field genericString = Strings.getDeclaredField("genericString");
+ assertTrue(genericString.getAnnotation(Size.class).min() == 0);
+ assertTrue(genericString.getAnnotation(Size.class).max() == 1024);
+
+ Field maxLength = Strings.getDeclaredField("maxLength");
+ assertTrue(maxLength.getAnnotation(Size.class).max() == 1024);
+
+ Field minLength = Strings.getDeclaredField("minLength");
+ assertTrue(minLength.getAnnotation(Size.class).min() == 0);
+ }
+
+ private Class<?>[] roundTrip(String schemaPath, String pkg) throws Exception {
+ xjcGenerateJavaSources(schemaPath);
+ compileGeneratedSources(createCompileList(pkg));
+ Class<?>[] classes = loadCompiledClasses(createLoadList(pkg));
+ generateSchema(classes); // Generates resource/PATH_TO_SCHEMA_DIRECTORY/schema1.xsd.
+ return classes;
+ }
+
+ public void xjcGenerateJavaSources(String schemaPath) throws Exception {
+ Driver.run(new String[] { schemaPath, "-XBeanVal" }, System.out, System.out);
+ }
+
+ public void xjcGenerateJavaSourcesWithCustomizations(String schemaPath) throws Exception {
+ Driver.run(new String[] { schemaPath, "-extension", "-XBeanVal" }, System.out, System.out);
+ }
+
+ private void generateSchema(Class<?>[] classes) throws FileNotFoundException {
+ JavaModelImpl javaModel = new JavaModelImpl(Thread.currentThread().getContextClassLoader());
+ JavaModelInputImpl modelInput = new JavaModelInputImpl(classes, javaModel);
+ modelInput.setFacets(true);
+ Generator gen = new Generator(modelInput);
+ gen.generateSchemaFiles(PATH_TO_SCHEMA_DIRECTORY, null);
+ }
+
+ private void compileGeneratedSources(File... compileList) {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ DiagnosticCollector<? super JavaFileObject> diag = new DiagnosticCollector<JavaFileObject>();
+ StandardJavaFileManager fm = compiler.getStandardFileManager(diag, null, null);
+ Iterable<? extends JavaFileObject> compilationUnits = fm.getJavaFileObjectsFromFiles(Arrays.asList(compileList));
+ JavaCompiler.CompilationTask task = compiler.getTask(new OutputStreamWriter(System.out),fm,diag, null, null, compilationUnits);
+
+ if (!task.call()) {
+ for (Diagnostic diagnostic : diag.getDiagnostics())
+ System.out.format("Error on line %d in %s", diagnostic.getLineNumber(), diagnostic);
+ Assert.fail("Compilation of generated classes failed. See the diagnostics output.");
+ }
+ }
+
+ private File[] createCompileList(String pkg) {
+ return "cs".equals(pkg)
+ ? new File[]{new File(pkg + "/Custom.java"),
+ new File(pkg + "/ObjectFactory.java"),
+ new File(pkg + "/package-info.java")}
+ : new File[]{new File(pkg + "/Main.java"),
+ new File(pkg + "/Numbers.java"),
+ new File(pkg + "/NumberWithHiddenValueAttribute.java"),
+ new File(pkg + "/ObjectFactory.java"),
+ new File(pkg + "/package-info.java"),
+ new File(pkg + "/Strings.java")};
+ }
+
+ private Class<?>[] loadCompiledClasses(String... loadList) throws ClassNotFoundException {
+ ClassLoader cl = this.getClass().getClassLoader();
+ Class<?>[] loadedClasses = new Class[loadList.length];
+ for (int i = 0; i < loadedClasses.length; i++)
+ loadedClasses[i] = cl.loadClass(loadList[i]);
+ return loadedClasses;
+ }
+
+ private String[] createLoadList(String pkg) throws ClassNotFoundException {
+ return "cs".equals(pkg)
+ ? new String[]{pkg + ".Custom", pkg + ".ObjectFactory" }
+ : new String[]{pkg + ".Main", pkg + ".Numbers",
+ pkg + ".NumberWithHiddenValueAttribute", pkg + ".ObjectFactory",
+ pkg + ".Strings"};
+ }
+
+ private boolean equalsClasses(Class<?>[] cTenured, Class<?>[] cYoung) {
+ if (cTenured.length != cYoung.length) return false;
+ for (int i = 0; i < cTenured.length; i++)
+ if (!equalsAnnotations(cTenured[i], cYoung[i])) return false;
+ return true;
+ }
+
+ private boolean equalsAnnotations(Class<?> c1, Class<?> c2) {
+ Field[] f1 = c1.getDeclaredFields();
+ Field[] f2 = c2.getDeclaredFields();
+ if (f1.length != f2.length) return false;
+ for (int i = 0; i<f2.length; i++) {
+ Annotation[] a1 = f1[i].getDeclaredAnnotations();
+ Annotation[] a2 = f2[i].getDeclaredAnnotations();
+ if (!Arrays.equals(a1, a2)) return false;
+ // Returns false if no BV annotations were generated.
+ if (!annotationsGenerated)
+ for (Annotation a : a1)
+ if (a.annotationType().equals(NotNull.class)) {
+ annotationsGenerated = true;
+ break;
+ }
+ }
+ return annotationsGenerated;
+ }
+
+ private static boolean deleteDir(File file) {
+ if (file.isDirectory()) {
+ String[] children = file.list();
+ for (String child : children)
+ deleteDir(new File(file, child));
+ return file.delete();
+ } else
+ // The directory is now empty so delete it
+ return file.delete();
+ }
+
+ public interface BindingTeam{}
+ public @interface RocketTeam{}
+ public abstract class Ancestors{}
+ @Target({ ElementType.FIELD})
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface CustomAnnotation {
+ String value();
+ }
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationRuntimeTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationRuntimeTestCase.java
new file mode 100644
index 0000000..9395056
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/BeanValidationRuntimeTestCase.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation;
+
+import org.eclipse.persistence.exceptions.BeanValidationException;
+import org.eclipse.persistence.jaxb.BeanValidationMode;
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+import org.eclipse.persistence.jaxb.JAXBMarshaller;
+import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
+import org.eclipse.persistence.jaxb.MarshallerProperties;
+import org.eclipse.persistence.jaxb.UnmarshallerProperties;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom.Department;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom.Drivers;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom.DrivingLicense;
+import org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom.Employee;
+import org.junit.After;
+import org.junit.Before;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+import javax.validation.groups.Default;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
+import java.io.File;
+import java.util.AbstractSequentialList;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Tests the Bean Validation for MOXy Runtime, with Target groups.
+ * Tests include:
+ * - setting properties (mode, preferred validation factory) through JAXBContext,
+ * marshaller and unmarshaller, and overriding them,
+ * - validation on valid objects before marshalling and after unmarshalling,
+ * - validation on invalid objects before marshalling and after unmarshalling,
+ * - validation with Target groups,
+ * - retrieval of correct error messages when constraint violations happen.
+ * Everything is tested with both XML and JSON marshalling and unmarshalling.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+public class BeanValidationRuntimeTestCase extends junit.framework.TestCase {
+
+ private static final File FILE_VALID = new File("org/eclipse/persistence/testing/jaxb/beanvalidation/rt/employee.xml");
+ private static final File FILE_INVALID = new File("org/eclipse/persistence/testing/jaxb/beanvalidation/rt/employeeInvalid.xml");
+ private static final File FILE_JSON_VALID = new File("org/eclipse/persistence/testing/jaxb/beanvalidation/rt/employee.json");
+ private static final File FILE_JSON_INVALID = new File("org/eclipse/persistence/testing/jaxb/beanvalidation/rt/employeeInvalid.json");
+ private static final Class[] EMPLOYEE = new Class[]{Employee.class};
+ private static final boolean DEBUG = true;
+
+ private boolean toggle = true; // Value is sensitive to the order of methods in testBeanValidation() method.
+ private ValidatorFactory preferredValidatorFactory;
+ private JAXBMarshaller marshallerValidOn;
+ private JAXBMarshaller marshallerValidOff;
+ private JAXBUnmarshaller unmarshallerValidOn;
+ private JAXBUnmarshaller unmarshallerValidOff;
+ private Employee employeeValid = new Employee()
+ .withId(0xCAFEBABE)
+ .withAge(15)
+ .withPersonalName("Richard")
+ .withPhoneNumber("(420)287-4422")
+ .withDepartment(Department.JavaEE)
+ .withDrivingLicense(new DrivingLicense(3326, new GregorianCalendar(2029, 12, 31).getTime()));
+ private Employee employeeInvalid = new Employee()
+ .withAge(15)
+ .withPersonalName("Wo")
+ .withPhoneNumber("287-4422")
+ .withDrivingLicense(new DrivingLicense(1234567, new GregorianCalendar(2010, 5, 20).getTime()));
+ private AbstractSequentialList<String> violationMessages = new LinkedList<String>(){ // Order is good just for debug. The CVs themselves aren't ordered.
+ {
+ add("may not be null"); // id
+ add("must be greater than or equal to 18"); // age
+ add("size must be between 3 and 15"); // personalName
+ add("must match \"\\(\\d{3}\\)\\d{3}-\\d{4}\""); // phoneNumber
+ add("may not be null"); // department
+ add("must be in the future"); // drivingLicense.validThrough
+ add("numeric value out of bounds (<6 digits>.<0 digits> expected)"); // drivingLicense.id
+ }};
+ private AbstractSequentialList<String> violationMessagesWithoutGroup = new LinkedList<String>(){
+ {
+ add("may not be null"); // id
+ add("size must be between 3 and 15"); // personalName
+ add("must match \"\\(\\d{3}\\)\\d{3}-\\d{4}\""); // phoneNumber
+ add("may not be null"); // department
+ }};
+
+
+ public void testBeanValidation() throws Exception{
+ validEmployee(FILE_VALID);
+ invalidEmployee(FILE_INVALID);
+ switchToJson();
+ validEmployee(FILE_JSON_VALID);
+ invalidEmployee(FILE_JSON_INVALID);
+ }
+
+ private void validEmployee(File file) throws Exception {
+
+ toggleDriversGroupOnOff();
+
+ marshallerValidOn.marshal(employeeValid, file);
+ assertTrue(marshallerValidOn.getConstraintViolations().isEmpty());
+
+ Employee employeeUnm = (Employee) unmarshallerValidOn.unmarshal(file);
+ assertTrue(unmarshallerValidOn.getConstraintViolations().isEmpty());
+
+ assertEquals(employeeValid, employeeUnm);
+ }
+
+ private void invalidEmployee(File fileInvalid) throws Exception {
+
+ JAXBException exception = null;
+ toggleDriversGroupOnOff();
+
+ /* Marshal w/ validation - doesn't pass (we want to check that). */
+ try {
+ marshallerValidOn.marshal(employeeInvalid, fileInvalid);
+ } catch (JAXBException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ assertEquals(String.valueOf(BeanValidationException.CONSTRAINT_VIOLATION), exception.getErrorCode());
+ if (DEBUG) System.out.println(exception.getMessage());
+ checkValidationMessages(marshallerValidOn.getConstraintViolations(), violationMessages);
+
+ /* Marshal w/o validation - creates file for the next part of the test. */
+ marshallerValidOff.marshal(employeeInvalid, fileInvalid);
+ Set<? extends ConstraintViolation<?>> marshalCV = marshallerValidOff.getConstraintViolations();
+ assertTrue(marshalCV.isEmpty());
+
+ /* Unmarshal w/ validation - doesn't pass (we want to check that). */
+ exception = null;
+ try { unmarshallerValidOn.unmarshal(fileInvalid); }
+ catch (JAXBException e) { exception = e; }
+ assertNotNull(exception);
+ assertEquals(String.valueOf(BeanValidationException.CONSTRAINT_VIOLATION), exception.getErrorCode());
+ if (DEBUG) System.out.println(exception.getMessage());
+ checkValidationMessages(unmarshallerValidOn.getConstraintViolations(), violationMessages);
+
+ /* Unmarshal w/ validation AND no groups - doesn't pass (we want to check that). */
+ toggleDriversGroupOnOff();
+ exception = null;
+
+ try { unmarshallerValidOn.unmarshal(fileInvalid); }
+ catch (JAXBException e) { exception = e; }
+ assertNotNull(exception);
+ assertEquals(String.valueOf(BeanValidationException.CONSTRAINT_VIOLATION), exception.getErrorCode());
+ if (DEBUG) System.out.println(exception.getMessage());
+ checkValidationMessages(unmarshallerValidOn.getConstraintViolations(), violationMessagesWithoutGroup);
+ toggleDriversGroupOnOff();
+
+ /* Unmarshal w/o validation - testing that invalid objects are correctly unmarshalled when validation is NONE. */
+ Employee employeeUnm = (Employee) unmarshallerValidOff.unmarshal(fileInvalid);
+ assertTrue(unmarshallerValidOff.getConstraintViolations().isEmpty());
+
+ /* Final check that the validation feature did not affect original behavior of JAXB. */
+ assertEquals(employeeInvalid, employeeUnm);
+ }
+
+ private void checkValidationMessages(Set<? extends ConstraintViolation<?>> constraintViolations, List<String> expectedMessages) {
+ List<String> violationMessages = new ArrayList<String>();
+ for (ConstraintViolation<?> cv : constraintViolations)
+ violationMessages.add(cv.getMessage());
+ assertSame(expectedMessages.size(), violationMessages.size());
+ assertTrue(violationMessages.containsAll(expectedMessages));
+ }
+
+ private void toggleDriversGroupOnOff() throws PropertyException {
+ if (toggle ^= true) {
+ marshallerValidOn.setProperty(MarshallerProperties.BEAN_VALIDATION_GROUPS, new Class[]{Default.class, Drivers.class});
+ unmarshallerValidOn.setProperty(MarshallerProperties.BEAN_VALIDATION_GROUPS, new Class[] { Default.class, Drivers.class });
+ } else {
+ marshallerValidOn.setProperty(MarshallerProperties.BEAN_VALIDATION_GROUPS, new Class[0]);
+ unmarshallerValidOn.setProperty(MarshallerProperties.BEAN_VALIDATION_GROUPS, new Class[0]);
+ }
+ }
+
+ private void switchToJson() throws PropertyException {
+ marshallerValidOn.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
+ marshallerValidOn.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
+ unmarshallerValidOn.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
+ unmarshallerValidOn.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
+ marshallerValidOff.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
+ marshallerValidOff.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
+ unmarshallerValidOff.setProperty(JAXBContextProperties.MEDIA_TYPE, "application/json");
+ unmarshallerValidOff.setProperty(JAXBContextProperties.JSON_INCLUDE_ROOT, true);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ preferredValidatorFactory = Validation.buildDefaultValidatorFactory();
+
+ JAXBContext ctx = JAXBContextFactory.createContext(EMPLOYEE, null);
+ marshallerValidOn = (JAXBMarshaller) ctx.createMarshaller();
+ marshallerValidOn.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshallerValidOff = (JAXBMarshaller) ctx.createMarshaller();
+ marshallerValidOff.setProperty(UnmarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE); // tests setting the property through mar
+ marshallerValidOff.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+
+ JAXBContext ctxValidationOff = JAXBContextFactory.createContext(EMPLOYEE,
+ new HashMap<String, Object>(){{
+ put(JAXBContextProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE);
+ put(JAXBContextProperties.BEAN_VALIDATION_FACTORY, preferredValidatorFactory);}});
+ unmarshallerValidOn = (JAXBUnmarshaller) ctxValidationOff.createUnmarshaller();
+ unmarshallerValidOn.setProperty(UnmarshallerProperties.BEAN_VALIDATION_MODE, BeanValidationMode.CALLBACK); // tests setting the property through unm
+ unmarshallerValidOff = (JAXBUnmarshaller) ctxValidationOff.createUnmarshaller();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ assertTrue(FILE_VALID.delete());
+ assertTrue(FILE_INVALID.delete());
+ assertTrue(FILE_JSON_VALID.delete());
+ assertTrue(FILE_JSON_INVALID.delete());
+ marshallerValidOn = marshallerValidOff = null;
+ unmarshallerValidOn = unmarshallerValidOff = null;
+ employeeValid = employeeInvalid = null;
+ violationMessages = null;
+ preferredValidatorFactory = null;
+ }
+
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/ContentComparator.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/ContentComparator.java
new file mode 100644
index 0000000..a56a5c0
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/ContentComparator.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ *
+ * @author jungi
+ */
+public final class ContentComparator {
+
+ private static final Logger LOGGER = Logger.getLogger(ContentComparator.class.getName());
+
+ /** Creates a new instance of ContentComparator */
+ private ContentComparator() {
+ }
+
+ /**
+ * Compares the content of two xml files. Ignores whitespaces.
+ *
+ *@param f1 usually golden file
+ *@param f2 other file which we want to compare against golden file (or any other file)
+ *@return true iff both files have the same content except of whitespaces
+ */
+ public static boolean equalsXML(File f1, File f2) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document d1 = db.parse(f1);
+ Document d2 = db.parse(f2);
+ return compare(d1.getDocumentElement(), d2.getDocumentElement());
+ } catch (ParserConfigurationException e) {
+ LOGGER.log(Level.WARNING, "Exception from test - comparing XML files", e); //NOI18N
+ } catch (SAXException e) {
+ LOGGER.log(Level.WARNING, "Exception from test - comparing XML files", e); //NOI18N
+ } catch (IOException e) {
+ LOGGER.log(Level.WARNING, "Exception from test - comparing XML files", e); //NOI18N
+ }
+ return false;
+ }
+
+ private static boolean compare(Node n1, Node n2) {
+ List<Node> l1 = new LinkedList<Node>();
+ List<Node> l2 = new LinkedList<Node>();
+ l1.add(n1);
+ l2.add(n2);
+ while (!l1.isEmpty() && !l2.isEmpty()) {
+ Node m1 = l1.remove(0);
+ Node m2 = l2.remove(0);
+ //check basic things - node name, value, attributes - if they're OK, we can continue
+ if (sameNode(m1, m2)) {
+ //now compare children
+ NodeList nl = m1.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node e = nl.item(i);
+ if (e.getNodeType() == Node.TEXT_NODE) {
+ //ignore empty places
+ if (e.getNodeValue().trim().equals("")) {
+ continue;
+ }
+ }
+ l1.add(nl.item(i));
+ }
+ nl = m2.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node e = nl.item(i);
+ if (e.getNodeType() == Node.TEXT_NODE) {
+ //ignore empty places
+ if (e.getNodeValue().trim().equals("")) {
+ continue;
+ }
+ }
+ l2.add(nl.item(i));
+ }
+ } else {
+ //nodes are not equals - print some info
+ LOGGER.warning("================================================"); //NOI18N
+ LOGGER.warning("m1: " + m1.getNodeName() + "; \'" + m1.getNodeValue() + "\'"); //NOI18N
+ LOGGER.warning("m2: " + m2.getNodeName() + "; \'" + m2.getNodeValue() + "\'"); //NOI18N
+ LOGGER.warning("================================================"); //NOI18N
+ return false;
+ }
+ }
+ return true;
+ }
+
+ //attrs, name, value
+ private static boolean sameNode(Node n1, Node n2) {
+ //check node name
+ if (!n1.getNodeName().equals(n2.getNodeName())) {
+ LOGGER.warning("================================================"); //NOI18N
+ LOGGER.warning("Expected node: " + n1.getNodeName() + ", got: " + n2.getNodeName()); //NOI18N
+ LOGGER.warning("================================================"); //NOI18N
+ return false;
+ }
+ //check node value
+ if (!((n1.getNodeValue() != null)
+ ? n1.getNodeValue().equals(n2.getNodeValue())
+ : (n2.getNodeValue() == null))) {
+ LOGGER.warning("================================================"); //NOI18N
+ LOGGER.warning("Expected node value: " + n1.getNodeValue() + ", got: " + n2.getNodeValue()); //NOI18N
+ LOGGER.warning("================================================"); //NOI18N
+ return false;
+ }
+ //check node attributes
+ NamedNodeMap nnm1 = n1.getAttributes();
+ NamedNodeMap nnm2 = n2.getAttributes();
+ if ((nnm1 == null && nnm2 != null)
+ || (nnm1 != null && nnm2 == null)) {
+ return false;
+ }
+ if (nnm1 == null) {
+ return true;
+ }
+ for (int i = 0; i < nnm1.getLength(); i++) {
+ Node x = nnm1.item(i);
+ Node y = nnm2.item(i);
+ if (!(x.getNodeName().equals(y.getNodeName())
+ && x.getNodeValue().equals(y.getNodeValue()))) {
+ //nodes are not equals - print some info
+ LOGGER.warning("================================================"); //NOI18N
+ LOGGER.warning("Expected attribute: " + x.getNodeName() + "=\'" + x.getNodeValue() + "\'," //NOI18N
+ + " got: " + y.getNodeName() + "=\'" + y.getNodeValue() + "\'"); //NOI18N
+ LOGGER.warning("================================================"); //NOI18N
+ return false;
+ }
+ }
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Department.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Department.java
new file mode 100644
index 0000000..5b88bfc
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Department.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ * @since 2.6
+ */
+@XmlRootElement
+public enum Department {
+ RDBMS, JavaSE, JavaEE, Sales, Support
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Drivers.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Drivers.java
new file mode 100644
index 0000000..df23867
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Drivers.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom;
+
+/**
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ * @since 2.6
+ */
+public interface Drivers {
+
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/DrivingLicense.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/DrivingLicense.java
new file mode 100644
index 0000000..f1cd9a1
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/DrivingLicense.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom;
+
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Future;
+import javax.xml.bind.annotation.XmlAttribute;
+import java.util.Date;
+
+/**
+* @author Marcel Valovy - marcel.valovy@oracle.com
+* @since 2.6
+*/
+public class DrivingLicense {
+
+ @Digits(integer = 6, fraction = 0, groups = Drivers.class)
+ @XmlAttribute
+ int id;
+
+ @Future(groups = Drivers.class)
+ @XmlAttribute
+ Date validThrough;
+
+ public DrivingLicense(){
+ }
+
+ public DrivingLicense(int id, Date validThrough){
+ this.id = id;
+ this.validThrough = validThrough;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ DrivingLicense that = (DrivingLicense) o;
+
+ if (id != that.id) {
+ return false;
+ }
+ if (validThrough != null ? !validThrough.equals(that.validThrough) : that.validThrough != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id;
+ result = 31 * result + (validThrough != null ? validThrough.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DrivingLicense{" +
+ "id=" + id +
+ ", validThrough=" + validThrough +
+ '}';
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Employee.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Employee.java
new file mode 100644
index 0000000..87a36ef
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/beanvalidation/rt_dom/Employee.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 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:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.beanvalidation.rt_dom;
+
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ * @since 2.6
+ */
+@XmlRootElement
+public class Employee {
+
+ @NotNull
+ @XmlAttribute
+ private Integer id;
+
+ @Min(value=18, groups=Drivers.class)
+ @XmlAttribute
+ @NotNull
+ private int age;
+
+ @NotNull
+ @Size(min = 3, max = 15)
+ @XmlElement
+ private String personalName;
+
+ @Pattern(regexp="\\(\\d{3}\\)\\d{3}-\\d{4}")
+ @XmlElement
+ private String phoneNumber;
+
+ @NotNull
+ @XmlElement
+ private Department department;
+
+ @NotNull(groups=Drivers.class)
+ @Valid
+ @XmlElement
+ private DrivingLicense drivingLicense;
+
+ public Employee(){
+ }
+
+ public Employee withId(int id){
+ this.id = id;
+ return this;
+ }
+
+ public Employee withAge(int age){
+ this.age = age;
+ return this;
+ }
+
+ public Employee withPersonalName(String personalName){
+ this.personalName = personalName;
+ return this;
+ }
+
+ public Employee withPhoneNumber(String phoneNumber){
+ this.phoneNumber = phoneNumber;
+ return this;
+ }
+
+ public Employee withDepartment(Department department){
+ this.department = department;
+ return this;
+ }
+
+ public Employee withDrivingLicense(DrivingLicense drivingLicense){
+ this.drivingLicense = drivingLicense;
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ Employee employee = (Employee) o;
+
+ if (age != employee.age) {
+ return false;
+ }
+ if (department != employee.department) {
+ return false;
+ }
+ if (drivingLicense != null ? !drivingLicense.equals(employee.drivingLicense) : employee.drivingLicense != null) {
+ return false;
+ }
+ if (id != null ? !id.equals(employee.id) : employee.id != null) {
+ return false;
+ }
+ if (personalName != null ? !personalName.equals(employee.personalName) : employee.personalName != null) {
+ return false;
+ }
+ if (phoneNumber != null ? !phoneNumber.equals(employee.phoneNumber) : employee.phoneNumber != null) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = age;
+ result = 31 * result + (id == null ? 0 : id);
+ result = 31 * result + (personalName != null ? personalName.hashCode() : 0);
+ result = 31 * result + (phoneNumber != null ? phoneNumber.hashCode() : 0);
+ result = 31 * result + (department != null ? department.hashCode() : 0);
+ result = 31 * result + (drivingLicense != null ? drivingLicense.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "Employee{" +
+ "id=" + id +
+ ", age=" + age +
+ ", personalName='" + personalName + '\'' +
+ ", phoneNumber='" + phoneNumber + '\'' +
+ ", department=" + department +
+ ", drivingLicense=" + drivingLicense +
+ '}';
+ }
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java
index e950eb8..8730b0e 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java
@@ -52,8 +52,8 @@ public abstract class Customer {
* Bridge for {@link org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.CustomerImpl#equals(Object)} and
* {@link org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl#equals(Object)}
*
- * @param o CustomerImpl object.
- * @return true if the CustomerImpl classes' attributes match the same values.
+ * @param o Employee object.
+ * @return true if the Employee classes' attributes match the same values.
*/
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/externalizedmetadata/xmlnametransformer/NameTransformerExceptionTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/externalizedmetadata/xmlnametransformer/NameTransformerExceptionTestCases.java
index d929e75..9b1b835 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/externalizedmetadata/xmlnametransformer/NameTransformerExceptionTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/externalizedmetadata/xmlnametransformer/NameTransformerExceptionTestCases.java
@@ -57,13 +57,13 @@ public class NameTransformerExceptionTestCases extends OXTestCase{
public void testExceptionDuringTransform(){
Type[] types = new Type[1];
types[0] = Employee.class;
- try{
- JAXBContext jaxbContext = JAXBContextFactory.createContext(types, getPropertiesWithException(), Thread.currentThread().getContextClassLoader());
- } catch (javax.xml.bind.JAXBException e) {
- e.printStackTrace();
-
- Exception linkedException = (Exception) e.getLinkedException();
- Exception nestedExcpetion = (Exception) e.getCause();
+ try{
+ JAXBContext jaxbContext = JAXBContextFactory.createContext(types, getPropertiesWithException(), Thread.currentThread().getContextClassLoader());
+ } catch (javax.xml.bind.JAXBException e) {
+// e.printStackTrace();
+
+ Exception linkedException = (Exception) e.getLinkedException();
+ Exception nestedExcpetion = (Exception) e.getCause();
assertTrue(nestedExcpetion instanceof JAXBException);
assertEquals(JAXBException.EXCEPTION_DURING_NAME_TRANSFORMATION,((JAXBException)nestedExcpetion).getErrorCode());
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/emptyroot/EmptyNullMarshalUnmarshalTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/emptyroot/EmptyNullMarshalUnmarshalTestCases.java
index b19e5d1..4516832 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/emptyroot/EmptyNullMarshalUnmarshalTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/json/emptyroot/EmptyNullMarshalUnmarshalTestCases.java
@@ -14,24 +14,24 @@ package org.eclipse.persistence.testing.jaxb.json.emptyroot;
import java.io.StringReader;
import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.Marshaller;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
-import javax.xml.transform.stream.StreamSource;
-
-import org.eclipse.persistence.jaxb.JAXBContext;
-import org.eclipse.persistence.jaxb.JAXBContextFactory;
-import org.eclipse.persistence.jaxb.JAXBContextProperties;
-import org.eclipse.persistence.jaxb.JAXBMarshaller;
-import org.eclipse.persistence.jaxb.JAXBUnmarshaller;
-import org.eclipse.persistence.jaxb.MarshallerProperties;
-import org.eclipse.persistence.jaxb.UnmarshallerProperties;
-import org.eclipse.persistence.oxm.XMLConstants;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.persistence.jaxb.BeanValidationMode;
+import org.eclipse.persistence.jaxb.JAXBContext;
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+import org.eclipse.persistence.jaxb.MarshallerProperties;
+import org.eclipse.persistence.jaxb.UnmarshallerProperties;
+import org.eclipse.persistence.oxm.XMLConstants;
import org.eclipse.persistence.testing.oxm.OXTestCase;
public class EmptyNullMarshalUnmarshalTestCases extends OXTestCase{
@@ -43,111 +43,112 @@ public class EmptyNullMarshalUnmarshalTestCases extends OXTestCase{
public EmptyNullMarshalUnmarshalTestCases(String name) throws Exception {
super(name);
}
-
- public void setUp() throws Exception{
- super.setUp();
- HashMap props = new HashMap();
- props.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
-
- ctx = (JAXBContext) JAXBContextFactory.createContext(new Class[]{Root.class}, props);
- ctxNoRoot = (JAXBContext) JAXBContextFactory.createContext(new Class[]{RootNoXmlRootElement.class}, props);
- }
-
- public void testJAXBElementNullValueIncludeRootTrue() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, null );
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- m.marshal(obj, sw);
+
+ public void setUp() throws Exception{
+ super.setUp();
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(JAXBContextProperties.MEDIA_TYPE, "application/json");
+ props.put(JAXBContextProperties.BEAN_VALIDATION_MODE, BeanValidationMode.NONE);
+
+ ctx = (JAXBContext) JAXBContextFactory.createContext(new Class[]{Root.class}, props);
+ ctxNoRoot = (JAXBContext) JAXBContextFactory.createContext(new Class[]{RootNoXmlRootElement.class}, props);
+ }
+
+ public void testJAXBElementNullValueIncludeRootTrue() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, null );
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ m.marshal(obj, sw);
compareStrings("testJAXBElementNullValueIncludeRootTrue", EMPTY_JSON, sw.getBuffer().toString());
}
-
- public void testJAXBElementNullValueIncludeRootFalse() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, null );
-
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
+
+ public void testJAXBElementNullValueIncludeRootFalse() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, null );
+
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
m.marshal(obj, sw);
compareStrings("testJAXBElementNullValueIncludeRootFalse", EMPTY_JSON, sw.getBuffer().toString());
}
-
- public void testJAXBElementEmptyValueIncludeRootTrue() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new Root() );
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- m.marshal(obj, sw);
+
+ public void testJAXBElementEmptyValueIncludeRootTrue() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new Root() );
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ m.marshal(obj, sw);
String expectedString = "{\"type\":\"root\"}";
compareStrings("testJAXBElementEmptyValueIncludeRootTrue", expectedString, sw.getBuffer().toString());
}
-
- public void testJAXBElementEmptyValueIncludeRootFalse() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new Root() );
-
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
+
+ public void testJAXBElementEmptyValueIncludeRootFalse() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new Root() );
+
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
m.marshal(obj, sw);
String expectedString = "{\"type\":\"root\"}";
compareStrings("testJAXBElementEmptyValueIncludeRootFalse", expectedString, sw.getBuffer().toString());
}
-
- public void testJAXBElementEmptyValueNoRootIncludeRootTrue() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new RootNoXmlRootElement() );
- Marshaller m = ctxNoRoot.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- m.marshal(obj, sw);
+
+ public void testJAXBElementEmptyValueNoRootIncludeRootTrue() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new RootNoXmlRootElement() );
+ Marshaller m = ctxNoRoot.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ m.marshal(obj, sw);
String expectedString = "{\"type\":\"rootNoXmlRootElement\"}";
compareStrings("testJAXBElementEmptyValueNoRootIncludeRootTrue", expectedString, sw.getBuffer().toString());
}
-
- public void testJAXBElementEmptyValueNoRootIncludeRootFalse() throws Exception{
- StringWriter sw = new StringWriter();
- JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new RootNoXmlRootElement() );
-
- Marshaller m = ctxNoRoot.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
+
+ public void testJAXBElementEmptyValueNoRootIncludeRootFalse() throws Exception{
+ StringWriter sw = new StringWriter();
+ JAXBElement obj = new JAXBElement<Object>(new QName(XMLConstants.EMPTY_STRING),Object.class, new RootNoXmlRootElement() );
+
+ Marshaller m = ctxNoRoot.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
m.marshal(obj, sw);
String expectedString = "{\"type\":\"rootNoXmlRootElement\"}";
compareStrings("testJAXBElementEmptyValueNoRootIncludeRootFalse", expectedString, sw.getBuffer().toString());
}
-
- public void testEmptyIncludeRootTrue() throws Exception{
- StringWriter sw = new StringWriter();
- Object obj = new Root();
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- m.marshal(obj, sw);
+
+ public void testEmptyIncludeRootTrue() throws Exception{
+ StringWriter sw = new StringWriter();
+ Object obj = new Root();
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ m.marshal(obj, sw);
String expected = "{\"root\":{}}";
compareStrings("testEmptyIncludeRootTrue", expected, sw.getBuffer().toString());
}
-
- public void testEmptyIncludeRootFalse() throws Exception{
- StringWriter sw = new StringWriter();
- Object obj = new Root();
- Marshaller m = ctx.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
- m.marshal(obj, sw);
+
+ public void testEmptyIncludeRootFalse() throws Exception{
+ StringWriter sw = new StringWriter();
+ Object obj = new Root();
+ Marshaller m = ctx.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
+ m.marshal(obj, sw);
compareStrings("testEmptyIncludeRootFalse", EMPTY_JSON, sw.getBuffer().toString());
}
-
- public void testEmptyNoRootIncludeRootTrue() throws Exception{
- StringWriter sw = new StringWriter();
- Object obj = new RootNoXmlRootElement();
- Marshaller m = ctxNoRoot.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
- m.marshal(obj, sw);
+
+ public void testEmptyNoRootIncludeRootTrue() throws Exception{
+ StringWriter sw = new StringWriter();
+ Object obj = new RootNoXmlRootElement();
+ Marshaller m = ctxNoRoot.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true);
+ m.marshal(obj, sw);
compareStrings("testEmptyNoRootIncludeRootTrue", EMPTY_JSON, sw.getBuffer().toString());
}
-
- public void testEmptyNoRootIncludeRootFalse() throws Exception{
- StringWriter sw = new StringWriter();
- Object obj = new RootNoXmlRootElement();
- Marshaller m = ctxNoRoot.createMarshaller();
- m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
- m.marshal(obj, sw);
+
+ public void testEmptyNoRootIncludeRootFalse() throws Exception{
+ StringWriter sw = new StringWriter();
+ Object obj = new RootNoXmlRootElement();
+ Marshaller m = ctxNoRoot.createMarshaller();
+ m.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
+ m.marshal(obj, sw);
compareStrings("testEmptyNoRootIncludeRootFalse", EMPTY_JSON, sw.getBuffer().toString());
}
@@ -200,24 +201,24 @@ public class EmptyNullMarshalUnmarshalTestCases extends OXTestCase{
Unmarshaller unmarshaller = ctx.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, true);
StringReader reader = new StringReader("{}");
- Object o = unmarshaller.unmarshal(new StreamSource(reader), Root.class);
- assertTrue (o instanceof JAXBElement);
- JAXBElement controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, null );
- compareJAXBElementObjects(controlObj, (JAXBElement)o);
- }
-
- public void testUnmarshalClassIncludeRootFalse() throws Exception{
+ Object o = unmarshaller.unmarshal(new StreamSource(reader), Root.class);
+ assertTrue (o instanceof JAXBElement);
+ JAXBElement controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, null );
+ compareJAXBElementObjects(controlObj, (JAXBElement)o);
+ }
+
+ public void testUnmarshalClassIncludeRootFalse() throws Exception{
Unmarshaller unmarshaller = ctx.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
StringReader reader = new StringReader("{}");
Object o = unmarshaller.unmarshal(new StreamSource(reader), Root.class);
-
- assertTrue (o instanceof JAXBElement);
- JAXBElement controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, new Root() );
- compareJAXBElementObjects(controlObj, (JAXBElement)o);
- }
-
-
+
+ assertTrue (o instanceof JAXBElement);
+ JAXBElement controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, new Root() );
+ compareJAXBElementObjects(controlObj, (JAXBElement)o);
+ }
+
+
public void testUnmarshalNoRootTypeAttrIncludeRootFalse() throws Exception{
Unmarshaller unmarshaller = ctxNoRoot.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
@@ -245,13 +246,13 @@ public class EmptyNullMarshalUnmarshalTestCases extends OXTestCase{
JAXBElement controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, new Root() );
compareJAXBElementObjects(controlObj, (JAXBElement)o);
- Object o2 = unmarshaller.unmarshal(new StreamSource(reader2));
- assertTrue (o instanceof JAXBElement);
- controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, new Root() );
- compareJAXBElementObjects(controlObj, (JAXBElement)o);
-
- }
-
+ Object o2 = unmarshaller.unmarshal(new StreamSource(reader2));
+ assertTrue (o instanceof JAXBElement);
+ controlObj = new JAXBElement(new QName(XMLConstants.EMPTY_STRING),Root.class, new Root() );
+ compareJAXBElementObjects(controlObj, (JAXBElement)o);
+
+ }
+
public void testUnmarshalEmptyListIncludeRootTrue() throws Exception{
Unmarshaller unmarshaller = ctx.createUnmarshaller();
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsNonRootTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsNonRootTestCases.java
index dc56a8f..6208c4b 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsNonRootTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsNonRootTestCases.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.
@@ -18,12 +18,13 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Stack;
-import java.util.TreeSet;
-import java.util.Vector;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+import java.util.TreeSet;
+import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.JAXBElement;
@@ -210,12 +211,12 @@ public class JAXBListOfObjectsNonRootTestCases extends JAXBListOfObjectsNoJSONTe
protected String getNoXsiTypeControlResourceName() {
return XML_RESOURCE_NO_XSI_TYPE;
}
-
-
- public void testTypeToSchemaTypeMap(){
- HashMap<Type, javax.xml.namespace.QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
- int mapSize = typesMap.size();
- assertEquals(2, mapSize);
- }
+
+
+ public void testTypeToSchemaTypeMap(){
+ Map<Type, QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
+ int mapSize = typesMap.size();
+ assertEquals(2, mapSize);
+ }
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsNamespaceTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsNamespaceTestCases.java
index 9c49b1e..932ce9e 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsNamespaceTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsNamespaceTestCases.java
@@ -153,13 +153,13 @@ public class JAXBMultipleMapsNamespaceTestCases extends JAXBListOfObjectsNoJSONT
fail("An error occurred during getProperties");
}
return null;
- }
-
- public void testTypeToSchemaTypeMap(){
- HashMap<Type, javax.xml.namespace.QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
- int mapSize = typesMap.size();
- assertEquals(7, mapSize);
-
+ }
+
+ public void testTypeToSchemaTypeMap(){
+ Map<Type, javax.xml.namespace.QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
+ int mapSize = typesMap.size();
+ assertEquals(7, mapSize);
+
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[0]));
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[1]));
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[2]));
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsTestCases.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsTestCases.java
index 147caa1..034c56d 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsTestCases.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/listofobjects/externalizedmetadata/JAXBMultipleMapsTestCases.java
@@ -124,13 +124,13 @@ public class JAXBMultipleMapsTestCases extends JAXBListOfObjectsTestCases {
protected String getNoXsiTypeControlResourceName() {
return XML_RESOURCE;
- }
-
- public void testTypeToSchemaTypeMap(){
- HashMap<Type, javax.xml.namespace.QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
- int mapSize = typesMap.size();
- assertEquals(7, mapSize);
-
+ }
+
+ public void testTypeToSchemaTypeMap(){
+ Map<Type, javax.xml.namespace.QName> typesMap = ((org.eclipse.persistence.jaxb.JAXBContext)jaxbContext).getTypeToSchemaType();
+ int mapSize = typesMap.size();
+ assertEquals(7, mapSize);
+
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[0]));
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[1]));
assertNotNull("Type was not found in TypeToSchemaType map.", typesMap.get(types[2]));
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 489ccf3..87ebdd9 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
@@ -37,12 +37,13 @@ import junit.framework.Test;
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);
- suite.addTestSuite(SchemaGenXMLTypeTestCases.class);
- suite.addTestSuite(SchemaGenXMLRootElementTestCases.class);
- suite.addTestSuite(DeploymentXMLSchemaGenTestCases.class);
+ public static Test suite() {
+ TestSuite suite = new TestSuite("JAXB 2.0 Schema Generation Test Suite");
+ suite.addTestSuite(SchemaGenEmployeeTestCases.class);
+ suite.addTestSuite(SchemaGenXmlPathTestCases.class); // added twice, delete this one, should be at the end
+ suite.addTestSuite(SchemaGenXMLTypeTestCases.class);
+ suite.addTestSuite(SchemaGenXMLRootElementTestCases.class);
+ suite.addTestSuite(DeploymentXMLSchemaGenTestCases.class);
suite.addTestSuite(SchemaGenXmlElementWrapperTestCases.class);
suite.addTestSuite(SchemaGenXmlElementRefByteArrayTestCases.class);
suite.addTestSuite(SchemaGenXmlElementRefTestCases.class);
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/Employee.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/Employee.java
index 5d799b9..c2e2165 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/Employee.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/schemagen/employee/Employee.java
@@ -9,28 +9,34 @@
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.testing.jaxb.schemagen.employee;
-
-import javax.xml.bind.annotation.*;
-
-@XmlRootElement(name="employee-data")
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.schemagen.employee;
+
+import javax.validation.Valid;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.Size;
+import javax.xml.bind.annotation.*;
+
+@XmlRootElement(name="employee-data")
@XmlType(name = "employee-type", propOrder = {"firstName", "birthday", "id", "age", "lastName", "address", "department",
"startTime", "phoneNumbers", "responsibilities", "peeps"})
-@XmlAccessorType(XmlAccessType.FIELD)
-public class Employee
-{
- @XmlAttribute(name="id", required=true)
- public int id;
-
- @XmlElement(required = true)
- public String firstName;
-
- public String lastName;
-
- @XmlMixed
- public Address address;
-
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Employee
+{
+ @DecimalMax(value="10")
+ @XmlAttribute(name="id", required=true)
+ public int id;
+
+ @Size(min=2, max=10)
+ @XmlElement(required = true)
+ public String firstName;
+
+ public String lastName;
+
+ @Valid
+ @XmlMixed
+ public Address address;
+
@XmlAttribute
public Department department;