Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jaxb
diff options
context:
space:
mode:
authorkmoore2010-10-14 15:43:11 -0400
committerkmoore2010-10-14 15:43:11 -0400
commit2be106bb2b625526695e1ea1d1c6b5e0cf8dca8b (patch)
tree5fd0899694d8733dbecb207f13cef90f645e145a /jaxb
parentca77a0ddd8abdef1ff267df7ab666b6100dc895a (diff)
downloadwebtools.dali-2be106bb2b625526695e1ea1d1c6b5e0cf8dca8b.tar.gz
webtools.dali-2be106bb2b625526695e1ea1d1c6b5e0cf8dca8b.tar.xz
webtools.dali-2be106bb2b625526695e1ea1d1c6b5e0cf8dca8b.zip
new JAXB core tests plug-in
Diffstat (limited to 'jaxb')
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.classpath13
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.project28
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/META-INF/MANIFEST.MF17
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/about.html34
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/build.properties18
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/plugin.properties23
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java53
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java70
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java40
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTestCase.java28
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java29
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTypeAnnotationTests.java375
-rw-r--r--jaxb/tests/org.eclipse.jpt.jaxb.core.tests/test.xml35
14 files changed, 771 insertions, 0 deletions
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.classpath b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.classpath
new file mode 100644
index 0000000000..d8d4b3768f
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.classpath
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/jaxb/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.project b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.project
new file mode 100644
index 0000000000..bcbed7f5b7
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.jaxb.core.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.settings/org.eclipse.jdt.core.prefs b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..e12c77c17f
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Oct 13 12:29:08 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/META-INF/MANIFEST.MF b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..b12f39357b
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Vendor: %providerName
+Bundle-SymbolicName: org.eclipse.jpt.jaxb.core.tests;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Activator: org.eclipse.jpt.jaxb.core.tests.JptJaxbCoreTestsPlugin
+Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)",
+ org.eclipse.jpt.core;bundle-version="[2.4.0,3.0.0)",
+ org.eclipse.jpt.core.tests;bundle-version="[2.4.0,3.0.0)",
+ org.eclipse.jpt.jaxb.core;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.jpt.utility;bundle-version="[1.6.0,2.0.0)",
+ org.junit;bundle-version="3.8.0"
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/about.html b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/about.html
new file mode 100644
index 0000000000..be534ba44f
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>May 02, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributor's license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/build.properties b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/build.properties
new file mode 100644
index 0000000000..1763dfa92b
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/build.properties
@@ -0,0 +1,18 @@
+################################################################################
+# Copyright (c) 2010 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+javacSource = 1.5
+javacTarget = 1.5
+bin.includes = .,\
+ META-INF/,\
+ about.html,\
+ test.xml,\
+ plugin.properties
+source.. = src/
+output.. = bin/
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/plugin.properties b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/plugin.properties
new file mode 100644
index 0000000000..01a0b633cd
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/plugin.properties
@@ -0,0 +1,23 @@
+################################################################################
+# Copyright (c) 2010 Oracle. All rights reserved.
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0, which accompanies this distribution
+# and is available at http://www.eclipse.org/legal/epl-v10.html.
+#
+# Contributors:
+# Oracle - initial API and implementation
+################################################################################
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName=Dali Java Persistence Tools - JAXB Core Tests
+providerName=Eclipse Web Tools Platform
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java
new file mode 100644
index 0000000000..2037b78472
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * configure the core to handle events synchronously when we are
+ * running tests
+ */
+public class JptJaxbCoreTestsPlugin extends Plugin {
+
+ private static JptJaxbCoreTestsPlugin INSTANCE;
+
+ public static JptJaxbCoreTestsPlugin instance() {
+ return INSTANCE;
+ }
+
+
+ // ********** plug-in implementation **********
+
+ public JptJaxbCoreTestsPlugin() {
+ super();
+ if (INSTANCE != null) {
+ throw new IllegalStateException();
+ }
+ // this convention is *wack*... ~bjv
+ INSTANCE = this;
+ }
+
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+// JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager();
+// ReflectionTools.executeMethod(jpaProjectManager, "handleEventsSynchronously");
+// ReflectionTools.executeStaticMethod(JptCorePlugin.class, "doNotFlushPreferences");
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java
new file mode 100644
index 0000000000..78917e5038
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal;
+
+import java.io.File;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject;
+import org.eclipse.jpt.jaxb.core.tests.internal.resource.JaxbCoreResourceModelTests;
+
+/**
+ * decentralize test creation code
+ *
+ * Required Java system property:
+ * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path>
+ */
+@SuppressWarnings("nls")
+public class JaxbCoreTests {
+ private static final String JPA_JAR_PROPERTY = TestJpaProject.JPA_JAR_NAME_SYSTEM_PROPERTY;
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JaxbCoreTests.class.getPackage().getName());
+ suite.addTest(JaxbCoreResourceModelTests.suite());
+ return suite;
+ }
+
+ public static boolean requiredJarsExists() {
+ return jpaJarPropertyExists() && jpaJarFileExists();
+ }
+
+ public static boolean jpaJarPropertyExists() {
+ return getSystemProperty(JPA_JAR_PROPERTY) != null;
+ }
+
+ public static boolean jpaJarFileExists() {
+ return (new File(getSystemProperty(JPA_JAR_PROPERTY))).exists();
+ }
+
+ public static String buildMissingJarErrorMessage() {
+ if( ! jpaJarPropertyExists()) {
+ return errorMissingProperty(JPA_JAR_PROPERTY);
+ }
+ return errorJarFileDoesNotExist(getSystemProperty(JPA_JAR_PROPERTY));
+ }
+
+ /*********** private **********/
+ private static String errorMissingProperty(String propertyName) {
+ return "missing Java system property: \"" + propertyName + "\"";
+ }
+
+ private static String errorJarFileDoesNotExist(String propertyValue) {
+ return "JAR file doesn't exist: \"" + propertyValue + "\"";
+ }
+
+ private static String getSystemProperty(String propertyName) {
+ return System.getProperty(propertyName);
+ }
+
+ private JaxbCoreTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java
new file mode 100644
index 0000000000..8b05650bf8
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.jpt.jaxb.core.tests.internal.resource.java.JaxbJavaResourceModelTests;
+
+/**
+ * Required Java system property:
+ * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path>
+ */
+public class JaxbCoreResourceModelTests extends TestCase
+{
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JaxbCoreResourceModelTests.class.getName());
+
+// if(JptCoreTests.requiredJarsExists()) {
+ suite.addTest(JaxbJavaResourceModelTests.suite());
+// }
+// else {
+// suite.addTest(TestSuite.warning(JptCoreTests.buildMissingJarErrorMessage()));
+// }
+ return suite;
+ }
+
+ private JaxbCoreResourceModelTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTestCase.java
new file mode 100644
index 0000000000..65df883dda
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTestCase.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import org.eclipse.jpt.core.JpaAnnotationProvider;
+import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider;
+import org.eclipse.jpt.core.tests.internal.resource.java.JavaResourceModelTestCase;
+import org.eclipse.jpt.jaxb.core.internal.GenericJaxbJpaAnnotationDefinitionProvider;
+
+public class JaxbJavaResourceModelTestCase extends JavaResourceModelTestCase
+{
+
+ public JaxbJavaResourceModelTestCase(String name) {
+ super(name);
+ }
+
+ @Override
+ protected JpaAnnotationProvider buildAnnotationProvider() {
+ return new GenericJpaAnnotationProvider(GenericJaxbJpaAnnotationDefinitionProvider.instance());
+ }
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java
new file mode 100644
index 0000000000..ff28fc0bff
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class JaxbJavaResourceModelTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(JaxbJavaResourceModelTests.class.getName());
+ suite.addTestSuite(XmlTypeAnnotationTests.class);
+
+ return suite;
+ }
+
+ private JaxbJavaResourceModelTests() {
+ super();
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTypeAnnotationTests.java
new file mode 100644
index 0000000000..d39f19511d
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTypeAnnotationTests.java
@@ -0,0 +1,375 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jaxb.core.tests.internal.resource.java;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.jaxb.core.resource.java.JAXB;
+import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+
+@SuppressWarnings("nls")
+public class XmlTypeAnnotationTests extends JaxbJavaResourceModelTestCase {
+
+ private static final String XML_TYPE_NAME = "XmlTypeName";
+ private static final String XML_TYPE_NAMESPACE = "XmlTypeNamespace";
+ private static final String XML_TYPE_FACTORY_METHOD = "myFactoryMethod";
+ private static final String XML_TYPE_FACTORY_CLASS = "MyFactoryClass";
+
+ public XmlTypeAnnotationTests(String name) {
+ super(name);
+ }
+
+ private ICompilationUnit createTestXmlType() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlTypeWithName() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType(name = \"" + XML_TYPE_NAME + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlTypeWithNamespace() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType(namespace = \"" + XML_TYPE_NAMESPACE + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlTypeWithFactoryMethod() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType(factoryMethod = \"" + XML_TYPE_FACTORY_METHOD + "\")");
+ }
+ });
+ }
+
+ private ICompilationUnit createTestXmlTypeWithFactoryClass() throws Exception {
+ this.createTestFactoryClass();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType(factoryClass = " + XML_TYPE_FACTORY_CLASS + ".class)");
+ }
+ });
+ }
+
+ private void createTestFactoryClass() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("public class ").append(XML_TYPE_FACTORY_CLASS).append(" ");
+ sb.append("{}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "MyFactoryClass.java", sourceWriter);
+ }
+
+ private ICompilationUnit createTestXmlTypeWithPropOrder() throws Exception {
+ this.createTestFactoryClass();
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JAXB.XML_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@XmlType(propOrder = {\"foo\", \"bar\"})");
+ }
+ });
+ }
+
+
+ public void testGetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertEquals(XML_TYPE_NAME, xmlTypeAnnotation.getName());
+ }
+
+ public void testGetNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertNull(xmlTypeAnnotation.getName());
+ assertNull(xmlTypeAnnotation.getNamespace());
+ assertNull(xmlTypeAnnotation.getFactoryClass());
+ assertNull(xmlTypeAnnotation.getFullyQualifiedFactoryClassName());
+ assertNull(xmlTypeAnnotation.getFactoryMethod());
+ }
+
+ public void testSetName() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertNull(xmlTypeAnnotation.getName());
+ xmlTypeAnnotation.setName(XML_TYPE_NAME);
+ assertEquals(XML_TYPE_NAME, xmlTypeAnnotation.getName());
+
+ assertSourceContains("@XmlType(name = \"" + XML_TYPE_NAME + "\")", cu);
+ }
+
+ public void testSetNameNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithName();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertEquals(XML_TYPE_NAME, xmlTypeAnnotation.getName());
+
+ xmlTypeAnnotation.setName(null);
+ assertNull(xmlTypeAnnotation.getName());
+
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("@XmlType(name = \"" + XML_TYPE_NAME + "\")", cu);
+ }
+
+ public void testGetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithNamespace();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertEquals(XML_TYPE_NAMESPACE, xmlTypeAnnotation.getNamespace());
+ }
+
+ public void testSetNamespace() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertNull(xmlTypeAnnotation.getNamespace());
+ xmlTypeAnnotation.setNamespace(XML_TYPE_NAMESPACE);
+ assertEquals(XML_TYPE_NAMESPACE, xmlTypeAnnotation.getNamespace());
+
+ assertSourceContains("@XmlType(namespace = \"" + XML_TYPE_NAMESPACE + "\")", cu);
+ }
+
+ public void testSetNamespaceNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithNamespace();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertEquals(XML_TYPE_NAMESPACE, xmlTypeAnnotation.getNamespace());
+
+ xmlTypeAnnotation.setNamespace(null);
+ assertNull(xmlTypeAnnotation.getNamespace());
+
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("@XmlType(namespace = \"" + XML_TYPE_NAMESPACE + "\")", cu);
+ }
+
+ public void testGetFactoryMethod() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithFactoryMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertEquals(XML_TYPE_FACTORY_METHOD, xmlTypeAnnotation.getFactoryMethod());
+ }
+
+ public void testSetFactoryMethod() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertNull(xmlTypeAnnotation.getFactoryMethod());
+ xmlTypeAnnotation.setFactoryMethod(XML_TYPE_FACTORY_METHOD);
+ assertEquals(XML_TYPE_FACTORY_METHOD, xmlTypeAnnotation.getFactoryMethod());
+
+ assertSourceContains("@XmlType(factoryMethod = \"" + XML_TYPE_FACTORY_METHOD + "\")", cu);
+ }
+
+ public void testSetFactoryMethodNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithFactoryMethod();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertEquals(XML_TYPE_FACTORY_METHOD, xmlTypeAnnotation.getFactoryMethod());
+
+ xmlTypeAnnotation.setFactoryMethod(null);
+ assertNull(xmlTypeAnnotation.getFactoryMethod());
+
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("@XmlType(factoryMethod = \"" + XML_TYPE_FACTORY_METHOD + "\")", cu);
+ }
+
+ public void testGetFactoryClass() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithFactoryClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertEquals(XML_TYPE_FACTORY_CLASS, xmlTypeAnnotation.getFactoryClass());
+ assertEquals("test." + XML_TYPE_FACTORY_CLASS, xmlTypeAnnotation.getFullyQualifiedFactoryClassName());
+ }
+
+ public void testSetFactoryClass() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertNull(xmlTypeAnnotation.getFactoryClass());
+ xmlTypeAnnotation.setFactoryClass(XML_TYPE_FACTORY_CLASS);
+ assertEquals(XML_TYPE_FACTORY_CLASS, xmlTypeAnnotation.getFactoryClass());
+
+ assertSourceContains("@XmlType(factoryClass = " + XML_TYPE_FACTORY_CLASS + ".class", cu);
+ }
+
+ public void testSetFactoryClassNull() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithFactoryClass();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertEquals(XML_TYPE_FACTORY_CLASS, xmlTypeAnnotation.getFactoryClass());
+
+ xmlTypeAnnotation.setFactoryClass(null);
+ assertNull(xmlTypeAnnotation.getFactoryClass());
+
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("@XmlType(factoryClass = " + XML_TYPE_FACTORY_CLASS + ".class", cu);
+ }
+
+ public void testGetPropOrder() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithPropOrder();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ ListIterator<String> propOrder = xmlTypeAnnotation.getPropOrder().iterator();
+ assertEquals("foo", propOrder.next());
+ assertEquals("bar", propOrder.next());
+ }
+
+ public void testGetPropOrderSize() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithPropOrder();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+ assertEquals(2, xmlTypeAnnotation.getPropOrderSize());
+ }
+
+ public void testAddProp() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+
+ xmlTypeAnnotation.addProp("fooo");
+ xmlTypeAnnotation.addProp("barr");
+
+ assertSourceContains("@XmlType(propOrder = { \"fooo\", \"barr\" })", cu);
+ }
+
+ public void testAddPropIndex() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+
+ xmlTypeAnnotation.addProp(0, "fooo");
+ xmlTypeAnnotation.addProp(0, "barr");
+ xmlTypeAnnotation.addProp(1, "blah");
+
+ assertSourceContains("@XmlType(propOrder = { \"barr\", \"blah\", \"fooo\" })", cu);
+ }
+
+ public void testRemoveProp() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithPropOrder();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+
+ xmlTypeAnnotation.removeProp("foo");
+ assertSourceContains("@XmlType(propOrder = \"bar\")", cu);
+
+ xmlTypeAnnotation.removeProp("bar");
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("propOrder", cu);
+ }
+
+ public void testRemovePropIndex() throws Exception {
+ ICompilationUnit cu = this.createTestXmlTypeWithPropOrder();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+
+ xmlTypeAnnotation.removeProp(0);
+ assertSourceContains("@XmlType(propOrder = \"bar\")", cu);
+
+ xmlTypeAnnotation.removeProp(0);
+ assertSourceContains("@XmlType", cu);
+ assertSourceDoesNotContain("propOrder", cu);
+ }
+
+ public void testMovePropx() throws Exception {
+ ICompilationUnit cu = this.createTestXmlType();
+ JavaResourcePersistentType typeResource = buildJavaTypeResource(cu);
+
+ XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) typeResource.getAnnotation(JAXB.XML_TYPE);
+ assertTrue(xmlTypeAnnotation != null);
+
+ xmlTypeAnnotation.addProp("fooo");
+ xmlTypeAnnotation.addProp("barr");
+ xmlTypeAnnotation.addProp("blah");
+ assertSourceContains("@XmlType(propOrder = { \"fooo\", \"barr\", \"blah\" })", cu);
+
+ xmlTypeAnnotation.moveProp(0, 1);
+ assertSourceContains("@XmlType(propOrder = { \"barr\", \"fooo\", \"blah\" })", cu);
+
+ xmlTypeAnnotation.moveProp(2, 1);
+ assertSourceContains("@XmlType(propOrder = { \"barr\", \"blah\", \"fooo\" })", cu);
+ }
+
+}
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/test.xml b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/test.xml
new file mode 100644
index 0000000000..f42ea81f67
--- /dev/null
+++ b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/test.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0"?> <!--
+ Copyright (c) 2010 Oracle. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0, which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: Oracle - initial API and implementation -->
+
+<project name="testsuite" default="run" basedir=".">
+ <!-- The property ${eclipse-home} should be passed into this script -->
+ <!-- Set a meaningful default value for when it is not. -->
+ <echo message="basedir ${basedir}" />
+ <echo message="eclipse place ${eclipse-home}" />
+ <!-- sets the properties plugin-name -->
+ <property name="plugin-name" value="org.eclipse.jpt.core.tests"/> <echo level="debug" message="testRoot: ${testRoot}" />
+ <fail message="testRoot must be set" unless="testRoot" />
+
+ <!-- This target holds all initialization code that needs to be done for -->
+ <!-- all tests that are to be run. Initialization for individual tests -->
+ <!-- should be done within the body of the suite target. -->
+ <target name="init">
+ <tstamp/>
+ <delete>
+ <fileset dir="${eclipse-home}" includes="org*.xml"/>
+ </delete>
+ </target>
+
+ <!-- This target defines the tests that need to be run. -->
+ <target name="suite1"> <property file="${testRoot}/testServer.properties"/> <property name="jpt-folder" value="${eclipse-home}/jpt_folder"/> <delete dir="${jpt-folder}" quiet="true"/> <ant target="core-test" antfile="${library-file}" dir="${eclipse-home}"> <property name="data-dir" value="${jpt-folder}"/> <property name="plugin-name" value="${plugin-name}"/> <property name="classname" value="org.eclipse.jpt.jaxb.core.tests.internal.resource.JaxbCoreResourceModelTests" /> <property name="plugin-path" value="${eclipse-home}/plugins/${plugin-name}"/> </ant> </target>
+ <!-- This target holds code to cleanup the testing environment after -->
+ <!-- after all of the tests have been run. You can use this target to -->
+ <!-- delete temporary files that have been created. -->
+ <target name="cleanup">
+ </target>
+
+ <!-- This target runs the test suite. Any actions that need to happen -->
+ <!-- after all the tests have been run should go here. -->
+ <target name="run" depends="init, suite1, cleanup">
+ </target>
+</project> \ No newline at end of file

Back to the top