diff options
author | pfullbright | 2011-05-11 14:56:52 +0000 |
---|---|---|
committer | pfullbright | 2011-05-11 14:56:52 +0000 |
commit | 1d1ee9cf7c65d5206e7439aa03225d34eae579a8 (patch) | |
tree | 9ca63ab9a7230e86a20239d4ad175b3f1fa68726 /jaxb/tests | |
parent | 74b100290c4fcb56e96bacae6fa7ca3f932952df (diff) | |
download | webtools.dali-1d1ee9cf7c65d5206e7439aa03225d34eae579a8.tar.gz webtools.dali-1d1ee9cf7c65d5206e7439aa03225d34eae579a8.tar.xz webtools.dali-1d1ee9cf7c65d5206e7439aa03225d34eae579a8.zip |
bug 343851 - minimal support for XmlElements, XmlElementRef, XmlElementRefs, (EclipseLink) XmlInverseReference, and (EclipseLink) XmlTransformation attribute mappings
Diffstat (limited to 'jaxb/tests')
15 files changed, 582 insertions, 0 deletions
diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.classpath b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.classpath new file mode 100644 index 0000000000..f8b7c93a43 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.classpath @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <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/common/core/**"/> + <accessrule kind="accessible" pattern="org/eclipse/jpt/common/utility/**"/> + <accessrule kind="accessible" pattern="org/eclipse/jpt/jaxb/core/**"/> + <accessrule kind="accessible" pattern="org/eclipse/jpt/jaxb/eclipselink/core/**"/> + </accessrules> + </classpathentry> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.cvsignore b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.cvsignore new file mode 100644 index 0000000000..ba077a4031 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.project b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.project new file mode 100644 index 0000000000..71513f6b6e --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.jpt.jaxb.eclipselink.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.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..ee129ed60e --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu May 05 17:25:11 EDT 2011 +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.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +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.eclipselink.core.tests/META-INF/MANIFEST.MF b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..e8ceb8908e --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %providerName +Bundle-SymbolicName: org.eclipse.jpt.jaxb.eclipselink.core.tests;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Localization: plugin +Dali-Comment: jdk 1.6 has the javax.xml.bind annotations +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Activator: org.eclipse.jpt.jaxb.eclipselink.core.tests.JptJaxbEclipseLinkCoreTestsPlugin +Bundle-ActivationPolicy: lazy +Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.7.0,4.0.0)", + org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)", + org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)", + org.eclipse.jpt.common.core.tests;bundle-version="[1.0.0,2.0.0)", + org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)", + org.eclipse.jpt.jaxb.core;bundle-version="[1.0.0,2.0.0)", + org.eclipse.jpt.jaxb.core.tests;bundle-version="[1.0.0,2.0.0)", + org.eclipse.jpt.jaxb.eclipselink.core;bundle-version="[1.0.0,2.0.0)", + org.junit;bundle-version="3.8.0" +Export-Package: org.eclipse.jpt.jaxb.eclipselink.core.tests, + org.eclipse.jpt.jaxb.eclipselink.core.tests.internal, + org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource, + org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.java diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/about.html b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/about.html new file mode 100644 index 0000000000..be534ba44f --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.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.eclipselink.core.tests/build.properties b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/build.properties new file mode 100644 index 0000000000..38c93513e7 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/build.properties @@ -0,0 +1,15 @@ +################################################################################ +# Copyright (c) 2011 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 +################################################################################ +bin.includes = .,\ + META-INF/,\ + about.html,\ + plugin.properties +source.. = src/ +output.. = bin/ diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/plugin.properties b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/plugin.properties new file mode 100644 index 0000000000..583cd43a66 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/plugin.properties @@ -0,0 +1,23 @@ +################################################################################ +# Copyright (c) 2011 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 EclipseLink Core Tests +providerName=Eclipse Web Tools Platform diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java new file mode 100644 index 0000000000..2d7824687e --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/JptJaxbEclipseLinkCoreTestsPlugin.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests; + +import org.eclipse.core.runtime.Plugin; +import org.eclipse.jpt.common.utility.internal.ReflectionTools; +import org.eclipse.jpt.jaxb.core.JaxbProjectManager; +import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; +import org.osgi.framework.BundleContext; + +/** + * configure the core to handle events synchronously when we are + * running tests + */ +@SuppressWarnings("nls") +public class JptJaxbEclipseLinkCoreTestsPlugin + extends Plugin { + + private static JptJaxbEclipseLinkCoreTestsPlugin INSTANCE; + + public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar"; + + + public static JptJaxbEclipseLinkCoreTestsPlugin instance() { + return INSTANCE; + } + + public static String eclipseLinkJarName() { + return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY); + } + + private static String getSystemProperty(String propertyName) { + return System.getProperty(propertyName); + } + + + // ********** plug-in implementation ********** + + public JptJaxbEclipseLinkCoreTestsPlugin() { + 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); + JaxbProjectManager jaxbProjectManager = JptJaxbCorePlugin.getProjectManager(); + ReflectionTools.executeMethod(jaxbProjectManager, "handleEventsSynchronously"); + ReflectionTools.executeStaticMethod(JptJaxbCorePlugin.class, "doNotFlushPreferences"); + } + + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/JaxbEclipseLinkCoreTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/JaxbEclipseLinkCoreTests.java new file mode 100644 index 0000000000..403948f9b6 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/JaxbEclipseLinkCoreTests.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.JaxbEclipseLinkCoreResourceModelTests; + + +public class JaxbEclipseLinkCoreTests { + + public static Test suite() { + TestSuite suite = new TestSuite(JaxbEclipseLinkCoreTests.class.getPackage().getName()); + suite.addTest(JaxbEclipseLinkCoreResourceModelTests.suite()); + return suite; + } + + + private JaxbEclipseLinkCoreTests() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/JaxbEclipseLinkCoreResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/JaxbEclipseLinkCoreResourceModelTests.java new file mode 100644 index 0000000000..09d8199946 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/JaxbEclipseLinkCoreResourceModelTests.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal.resource; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.internal.resource.java.ELJaxbJavaResourceModelTests; + + +public class JaxbEclipseLinkCoreResourceModelTests + extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(JaxbEclipseLinkCoreResourceModelTests.class.getName()); + + suite.addTest(ELJaxbJavaResourceModelTests.suite()); + return suite; + } + + + private JaxbEclipseLinkCoreResourceModelTests() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java new file mode 100644 index 0000000000..28746a2574 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTestCase.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal.resource.java; + +import org.eclipse.jpt.jaxb.core.resource.java.AnnotationDefinition; +import org.eclipse.jpt.jaxb.core.resource.java.NestableAnnotationDefinition; +import org.eclipse.jpt.jaxb.core.tests.internal.resource.java.JavaResourceModelTestCase; +import org.eclipse.jpt.jaxb.eclipselink.core.internal.v2_1.ELJaxb_2_1_PlatformDefinition; +import org.eclipse.jpt.jaxb.eclipselink.core.tests.JptJaxbEclipseLinkCoreTestsPlugin; + + +public class ELJaxbJavaResourceModelTestCase + extends JavaResourceModelTestCase { + + public ELJaxbJavaResourceModelTestCase(String name) { + super(name); + } + + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.javaProject.addJar(JptJaxbEclipseLinkCoreTestsPlugin.eclipseLinkJarName()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + // nothing as of yet + } + + @Override + protected AnnotationDefinition[] annotationDefinitions() { + return ELJaxb_2_1_PlatformDefinition.instance().getAnnotationDefinitions(); + } + + @Override + protected NestableAnnotationDefinition[] nestableAnnotationDefinitions() { + return ELJaxb_2_1_PlatformDefinition.instance().getNestableAnnotationDefinitions(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTests.java new file mode 100644 index 0000000000..30f9ffe04f --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/ELJaxbJavaResourceModelTests.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal.resource.java; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +public class ELJaxbJavaResourceModelTests + extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(ELJaxbJavaResourceModelTests.class.getName()); + suite.addTestSuite(XmlInverseReferenceAnnotationTests.class); + suite.addTestSuite(XmlTransformationAnnotationTests.class); + + return suite; + } + + + private ELJaxbJavaResourceModelTests() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlInverseReferenceAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlInverseReferenceAnnotationTests.java new file mode 100644 index 0000000000..44b3bcd16b --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlInverseReferenceAnnotationTests.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal.resource.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlInverseReferenceAnnotation; + + +public class XmlInverseReferenceAnnotationTests + extends ELJaxbJavaResourceModelTestCase { + + public XmlInverseReferenceAnnotationTests(String name) { + super(name); + } + + + private ICompilationUnit createTestXmlInverseReference() + throws Exception { + + return this.createTestType(new DefaultAnnotationWriter() { + + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(ELJaxb.XML_INVERSE_REFERENCE); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlInverseReference"); + } + }); + } + + private ICompilationUnit createTestXmlInverseReferenceWithMappedBy() + throws Exception { + + return this.createTestType(new DefaultAnnotationWriter() { + + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(ELJaxb.XML_INVERSE_REFERENCE); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlInverseReference(mappedBy = \"foo\")"); + } + }); + } + + private XmlInverseReferenceAnnotation getXmlInverseReferenceAnnotation(JavaResourceAttribute resourceAttribute) { + return (XmlInverseReferenceAnnotation) resourceAttribute.getAnnotation(ELJaxb.XML_INVERSE_REFERENCE); + } + + + public void testGetNull() throws Exception { + ICompilationUnit cu = createTestXmlInverseReference(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlInverseReferenceAnnotation annotation = getXmlInverseReferenceAnnotation(resourceAttribute); + + assertTrue(annotation != null); + assertNull(annotation.getMappedBy()); + } + + public void testGetMappedBy() throws Exception { + ICompilationUnit cu = createTestXmlInverseReferenceWithMappedBy(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlInverseReferenceAnnotation annotation = getXmlInverseReferenceAnnotation(resourceAttribute); + + assertEquals("foo", annotation.getMappedBy()); + } + + public void testSetMappedBy() throws Exception { + ICompilationUnit cu = createTestXmlInverseReference(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlInverseReferenceAnnotation annotation = getXmlInverseReferenceAnnotation(resourceAttribute); + + assertNull(annotation.getMappedBy()); + + annotation.setMappedBy("bar"); + + assertEquals("bar", annotation.getMappedBy()); + assertSourceContains("@XmlInverseReference(mappedBy = \"bar\")", cu); + + annotation.setMappedBy(""); + + assertEquals("", annotation.getMappedBy()); + assertSourceContains("@XmlInverseReference(mappedBy = \"\")", cu); + + annotation.setMappedBy(null); + + assertNull(annotation.getMappedBy()); + assertSourceContains("@XmlInverseReference", cu); + assertSourceDoesNotContain("mappedBy", cu); + } +} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlTransformationAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlTransformationAnnotationTests.java new file mode 100644 index 0000000000..ca4c690d39 --- /dev/null +++ b/jaxb/tests/org.eclipse.jpt.jaxb.eclipselink.core.tests/src/org/eclipse/jpt/jaxb/eclipselink/core/tests/internal/resource/java/XmlTransformationAnnotationTests.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2011 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.eclipselink.core.tests.internal.resource.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAttribute; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; +import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.ELJaxb; +import org.eclipse.jpt.jaxb.eclipselink.core.resource.java.XmlTransformationAnnotation; + + +public class XmlTransformationAnnotationTests + extends ELJaxbJavaResourceModelTestCase { + + public XmlTransformationAnnotationTests(String name) { + super(name); + } + + + private ICompilationUnit createTestXmlTransformation() + throws Exception { + + return this.createTestType(new DefaultAnnotationWriter() { + + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(ELJaxb.XML_TRANSFORMATION); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlTransformation"); + } + }); + } + + private ICompilationUnit createTestXmlTransformationWithOptional() + throws Exception { + + return this.createTestType(new DefaultAnnotationWriter() { + + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(ELJaxb.XML_TRANSFORMATION); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@XmlTransformation(optional = true)"); + } + }); + } + + private XmlTransformationAnnotation getXmlTransformationAnnotation(JavaResourceAttribute resourceAttribute) { + return (XmlTransformationAnnotation) resourceAttribute.getAnnotation(ELJaxb.XML_TRANSFORMATION); + } + + + public void testGetNull() throws Exception { + ICompilationUnit cu = createTestXmlTransformation(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlTransformationAnnotation annotation = getXmlTransformationAnnotation(resourceAttribute); + + assertTrue(annotation != null); + assertNull(annotation.getOptional()); + } + + public void testGetOptional() throws Exception { + ICompilationUnit cu = createTestXmlTransformationWithOptional(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlTransformationAnnotation annotation = getXmlTransformationAnnotation(resourceAttribute); + + assertEquals(Boolean.TRUE, annotation.getOptional()); + } + + public void testSetOptional() throws Exception { + ICompilationUnit cu = createTestXmlTransformation(); + JavaResourceType resourceType = buildJavaResourceType(cu); + JavaResourceField resourceAttribute = getField(resourceType, 0); + XmlTransformationAnnotation annotation = getXmlTransformationAnnotation(resourceAttribute); + + assertNull(annotation.getOptional()); + + annotation.setOptional(Boolean.FALSE); + + assertEquals(Boolean.FALSE, annotation.getOptional()); + assertSourceContains("@XmlTransformation(optional = false)", cu); + + annotation.setOptional(null); + + assertNull(annotation.getOptional()); + assertSourceContains("@XmlTransformation", cu); + assertSourceDoesNotContain("optional", cu); + } +} |