diff options
Diffstat (limited to 'jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse')
54 files changed, 0 insertions, 9409 deletions
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 deleted file mode 100644 index 69df17f13c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java +++ /dev/null @@ -1,56 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.jpt.jaxb.core.JaxbProjectManager; -import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; -import org.eclipse.jpt.utility.internal.ReflectionTools; -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); - 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.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 deleted file mode 100644 index 4aa0cef7f9..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java +++ /dev/null @@ -1,30 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbCoreContextModelTests; -import org.eclipse.jpt.jaxb.core.tests.internal.resource.JaxbCoreResourceModelTests; - -public class JaxbCoreTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JaxbCoreTests.class.getPackage().getName()); - suite.addTest(JaxbCoreResourceModelTests.suite()); - suite.addTest(JaxbCoreContextModelTests.suite()); - return suite; - } - - 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/context/GenericContextRootTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericContextRootTests.java deleted file mode 100644 index b83272e760..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericContextRootTests.java +++ /dev/null @@ -1,344 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context; - -import java.util.Iterator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackage; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum; -import org.eclipse.jpt.jaxb.core.context.JaxbRegistry; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.AbstractJavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericContextRootTests extends JaxbContextModelTestCase -{ - - public GenericContextRootTests(String name) { - super(name); - } - - private ICompilationUnit createPackageInfoWithAccessorOrder() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)", - JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER); - } - - private ICompilationUnit createUnannotatedPackageInfo(String packageName) throws CoreException { - return createTestPackageInfo(packageName); - } - - private ICompilationUnit createTypeWithXmlRegistry() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_REGISTRY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRegistry"); - } - }); - } - - private ICompilationUnit createTypeWithXmlType() 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 createUnannotatedTestTypeNamed(String typeName) throws Exception { - return this.createTestType(PACKAGE_NAME, typeName + ".java", typeName, new DefaultAnnotationWriter()); - } - - private ICompilationUnit createTestXmlEnum() throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnum"); - } - }); - } - - private ICompilationUnit createTestXmlEnumNoAnnotation(String enumName) throws Exception { - return this.createTestEnum(PACKAGE_NAME, enumName + ".java", enumName, new DefaultEnumAnnotationWriter()); - } - - public void testGetPackages() throws Exception { - this.createPackageInfoWithAccessorOrder(); - Iterator<JaxbPackage> packages = this.getContextRoot().getPackages().iterator(); - assertEquals(1, this.getContextRoot().getPackagesSize()); - assertEquals(PACKAGE_NAME, packages.next().getName()); - assertFalse(packages.hasNext()); - - //add an unannotated package-info.java and make sure it's not added to the root context node - this.createUnannotatedPackageInfo("foo"); - packages = this.getContextRoot().getPackages().iterator(); - assertEquals(1, this.getContextRoot().getPackagesSize()); - assertEquals(PACKAGE_NAME, packages.next().getName()); - assertFalse(packages.hasNext()); - - //annotate the package-info.java and test it's added to the root context node - JavaResourcePackage fooResourcePackage = getJaxbProject().getJavaResourcePackage("foo"); - AnnotatedElement annotatedElement = this.annotatedElement(fooResourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericContextRootTests.this.addXmlAccessorTypeAnnotation(declaration, JAXB.XML_ACCESS_TYPE__PROPERTY); - } - }); - - Iterable<String> packageNames = new TransformationIterable<JaxbPackage, String>(this.getContextRoot().getPackages()) { - @Override - protected String transform(JaxbPackage o) { - return o.getName(); - } - }; - assertEquals(2, this.getContextRoot().getPackagesSize()); - assertTrue(CollectionTools.contains(packageNames, PACKAGE_NAME)); - assertTrue(CollectionTools.contains(packageNames, "foo")); - - //remove the annotation from the package-info.java and test it's removed from the root context node - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericContextRootTests.this.removeXmlAccessorTypeAnnotation(declaration); - } - }); - - packages = this.getContextRoot().getPackages().iterator(); - assertEquals(1, this.getContextRoot().getPackagesSize()); - assertEquals(PACKAGE_NAME, packages.next().getName()); - assertFalse(packages.hasNext()); - } - - protected void addXmlAccessorTypeAnnotation(ModifiedDeclaration declaration, String accessType) { - NormalAnnotation annotation = this.addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_ACCESSOR_TYPE); - this.addEnumMemberValuePair(annotation, JAXB.XML_ACCESSOR_TYPE__VALUE, accessType); - } - - protected void removeXmlAccessorTypeAnnotation(ModifiedDeclaration declaration) { - this.removeAnnotation(declaration, JAXB.XML_ACCESSOR_TYPE); - } - - public void testGetRegistries() throws Exception { - createTypeWithXmlRegistry(); - Iterator<JaxbRegistry> registries = getContextRoot().getRegistries().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, registries.next().getFullyQualifiedName()); - assertFalse(registries.hasNext()); - - //add an unannotated class and make sure it's not added to the context root - createUnannotatedTestTypeNamed("Foo"); - registries = getContextRoot().getRegistries().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, registries.next().getFullyQualifiedName()); - assertFalse(registries.hasNext()); - - //annotate the class with @XmlRegistry and test it's added to the root context node - AbstractJavaResourceType fooResourceType = getJaxbProject().getJavaResourceType("test.Foo"); - AnnotatedElement annotatedElement = annotatedElement(fooResourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_REGISTRY); - } - }); - - Iterable<String> registryNames = - new TransformationIterable<JaxbRegistry, String>( - getContextRoot().getRegistries()) { - @Override - protected String transform(JaxbRegistry o) { - return o.getFullyQualifiedName(); - } - }; - assertEquals(2, CollectionTools.size(getContextRoot().getRegistries())); - assertTrue(CollectionTools.contains(registryNames, "test.Foo")); - assertTrue(CollectionTools.contains(registryNames, FULLY_QUALIFIED_TYPE_NAME)); - - //remove the annotation from the class and test it's removed from the context root - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_REGISTRY); - } - }); - - registries = getContextRoot().getRegistries().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, registries.next().getFullyQualifiedName()); - assertFalse(registries.hasNext()); - } - - public void testGetPersistentClasses() throws Exception { - this.createTypeWithXmlType(); - Iterator<JaxbPersistentClass> persistentClasses = this.getContextRoot().getPersistentClasses().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getFullyQualifiedName()); - assertFalse(persistentClasses.hasNext()); - - //add an unannotated class and make sure it's not added to the context root - createUnannotatedTestTypeNamed("Foo"); - persistentClasses = this.getContextRoot().getPersistentClasses().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getFullyQualifiedName()); - assertFalse(persistentClasses.hasNext()); - - //annotate the class with @XmlType and test it's added to the context root - AbstractJavaResourceType fooResourceType = getJaxbProject().getJavaResourceType("test.Foo"); - AnnotatedElement annotatedElement = annotatedElement(fooResourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - } - }); - - Iterable<String> persistentClassNames = - new TransformationIterable<JaxbPersistentClass, String>( - getContextRoot().getPersistentClasses()) { - @Override - protected String transform(JaxbPersistentClass o) { - return o.getFullyQualifiedName(); - } - }; - assertEquals(2, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertTrue(CollectionTools.contains(persistentClassNames, "test.Foo")); - assertTrue(CollectionTools.contains(persistentClassNames, FULLY_QUALIFIED_TYPE_NAME)); - - //remove the annotation from the class and test it's removed from the root context node - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_TYPE); - } - }); - - persistentClasses = getContextRoot().getPersistentClasses().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentClasses.next().getFullyQualifiedName()); - assertFalse(persistentClasses.hasNext()); - } - - public void testGetPersistentEnums() throws Exception { - this.createTestXmlEnum(); - Iterator<JaxbPersistentEnum> persistentEnums = this.getContextRoot().getPersistentEnums().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentEnums())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentEnums.next().getFullyQualifiedName()); - assertFalse(persistentEnums.hasNext()); - - //add an unannotated class and make sure it's not added to the context root - createTestXmlEnumNoAnnotation("Foo"); - persistentEnums = this.getContextRoot().getPersistentEnums().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentEnums())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentEnums.next().getFullyQualifiedName()); - assertFalse(persistentEnums.hasNext()); - - //annotate the class with @XmlEnum and test it's added to the context root - JavaResourceEnum fooResourceType = getJaxbProject().getJavaResourceEnum("test.Foo"); - AnnotatedElement annotatedElement = annotatedElement(fooResourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ENUM); - } - }); - - Iterable<String> persistentEnumNames = - new TransformationIterable<JaxbPersistentEnum, String>( - getContextRoot().getPersistentEnums()) { - @Override - protected String transform(JaxbPersistentEnum o) { - return o.getFullyQualifiedName(); - } - }; - assertEquals(2, CollectionTools.size(getContextRoot().getPersistentEnums())); - assertTrue(CollectionTools.contains(persistentEnumNames, "test.Foo")); - assertTrue(CollectionTools.contains(persistentEnumNames, FULLY_QUALIFIED_TYPE_NAME)); - - //remove the annotation from the class and test it's removed from the root context node - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_ENUM); - } - }); - - persistentEnums = getContextRoot().getPersistentEnums().iterator(); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentEnums())); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, persistentEnums.next().getFullyQualifiedName()); - assertFalse(persistentEnums.hasNext()); - } - - public void testChangeTypeKind() throws Exception { - createTypeWithXmlRegistry(); - createUnannotatedTestTypeNamed("Foo"); - AbstractJavaResourceType fooResourceType = getJaxbProject().getJavaResourceType("test.Foo"); - AnnotatedElement annotatedElement = annotatedElement(fooResourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_REGISTRY); - } - }); - - assertEquals(2, getContextRoot().getTypesSize()); - assertEquals(2, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(0, CollectionTools.size(getContextRoot().getPersistentClasses())); - - // remove the @XmlRegistry annotation and add an @XmlType annotation - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_REGISTRY); - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - } - }); - - assertEquals(2, getContextRoot().getTypesSize()); - assertEquals(1, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - - // remove the @XmlType annotation and add an @XmlRegistry annotation - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_TYPE); - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_REGISTRY); - } - }); - - assertEquals(2, getContextRoot().getTypesSize()); - assertEquals(2, CollectionTools.size(getContextRoot().getRegistries())); - assertEquals(0, CollectionTools.size(getContextRoot().getPersistentClasses())); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbContextModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbContextModelTestCase.java deleted file mode 100644 index 1b950d382f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbContextModelTestCase.java +++ /dev/null @@ -1,77 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context; - -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.jaxb.core.JaxbFacet; -import org.eclipse.jpt.jaxb.core.JaxbProject; -import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; -import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; -import org.eclipse.jpt.jaxb.core.internal.facet.JaxbFacetInstallConfig; -import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.jaxb.core.tests.internal.projects.TestJaxbProject; -import org.eclipse.jpt.utility.internal.ReflectionTools; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -@SuppressWarnings("nls") -public abstract class JaxbContextModelTestCase extends AnnotationTestCase -{ - protected static final String BASE_PROJECT_NAME = "JaxbContextModelTestProject"; - - - protected JaxbContextModelTestCase(String name) { - super(name); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return buildJaxbProject(BASE_PROJECT_NAME, autoBuild, buildJaxbFacetInstallConfig()); - } - - protected TestJaxbProject buildJaxbProject(String projectName, boolean autoBuild, JaxbFacetInstallConfig jaxbConfig) - throws Exception { - return TestJaxbProject.buildJaxbProject(projectName, autoBuild, jaxbConfig); - } - - protected JaxbFacetInstallConfig buildJaxbFacetInstallConfig() { - JaxbFacetInstallConfig config = new JaxbFacetInstallConfig(); - config.setProjectFacetVersion(getProjectFacetVersion()); - config.setPlatform(getPlatform()); - return config; - } - - protected JaxbPlatformDescription getPlatform() { - return JptJaxbCorePlugin.getDefaultPlatform(getProjectFacetVersion()); - } - - protected IProjectFacetVersion getProjectFacetVersion() { - return JaxbFacet.VERSION_2_1; - } - - protected JaxbContextRoot getContextRoot() { - return this.getJaxbProject().getContextRoot(); - } - - protected AnnotatedElement annotatedElement(JavaResourceAnnotatedElement resource) { - return (AnnotatedElement) ReflectionTools.getFieldValue(resource, "annotatedElement"); - } - - @Override - protected TestJaxbProject getJavaProject() { - return (TestJaxbProject) super.getJavaProject(); - } - - protected JaxbProject getJaxbProject() { - return this.getJavaProject().getJaxbProject(); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java deleted file mode 100644 index 7ecde92d62..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbCoreContextModelTests.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.jaxb.core.tests.internal.context.java.JaxbCoreJavaContextModelTests; - -public class JaxbCoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JaxbCoreContextModelTests.class.getName()); - - suite.addTestSuite(GenericContextRootTests.class); - suite.addTest(JaxbCoreJavaContextModelTests.suite()); - return suite; - } - - private JaxbCoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaElementFactoryMethodTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaElementFactoryMethodTests.java deleted file mode 100644 index 1689498a5f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaElementFactoryMethodTests.java +++ /dev/null @@ -1,404 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod; -import org.eclipse.jpt.jaxb.core.context.JaxbRegistry; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaElementFactoryMethodTests extends JaxbContextModelTestCase -{ - - public GenericJavaElementFactoryMethodTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlRegistry() throws Exception { - return this.createTestType(PACKAGE_NAME, "ObjectFactory.java", "ObjectFactory", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_REGISTRY, JAXB.XML_ELEMENT_DECL, "javax.xml.bind.JAXBElement"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRegistry"); - } - - @Override - public void appendGetNameMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementDecl").append(CR); - sb.append(" JAXBElement<AnnotationTestType> createFoo(AnnotationTestType value) {return null}").append(CR); - sb.append(CR); - sb.append(" @XmlElementDecl(name=\"bar\")").append(CR); - sb.append(" JAXBElement createBar(Object value) {return null}").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTypeWithXmlType() 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").append(CR); - } - }); - } - - public void testModifyElementName() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getElementName()); - - elementFactoryMethod.setElementName("bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("bar", elementDeclAnnotation.getName()); - assertEquals("bar", elementFactoryMethod.getElementName()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setElementName(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getName()); - assertNull(elementFactoryMethod.getElementName()); - } - - public void testUpdateElementName() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getElementName()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__NAME, "foo"); - } - }); - assertEquals("foo", elementFactoryMethod.getElementName()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - public void testModifyDefaultValue() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getDefaultValue()); - - elementFactoryMethod.setDefaultValue("bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("bar", elementDeclAnnotation.getDefaultValue()); - assertEquals("bar", elementFactoryMethod.getDefaultValue()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setDefaultValue(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getDefaultValue()); - assertNull(elementFactoryMethod.getDefaultValue()); - } - - public void testUpdateDefaultValue() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getDefaultValue()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__DEFAULT_VALUE, "foo"); - } - }); - assertEquals("foo", elementFactoryMethod.getDefaultValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - public void testModifyScope() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getScope()); - - elementFactoryMethod.setScope("Bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("Bar", elementDeclAnnotation.getScope()); - assertEquals("Bar", elementFactoryMethod.getScope()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setScope(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getScope()); - assertNull(elementFactoryMethod.getScope()); - } - - public void testUpdateScope() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getScope()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclTypeMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__SCOPE, "Foo"); - } - }); - assertEquals("Foo", elementFactoryMethod.getScope()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - public void testModifySubstitutionHeadName() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getSubstitutionHeadName()); - - elementFactoryMethod.setSubstitutionHeadName("bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("bar", elementDeclAnnotation.getSubstitutionHeadName()); - assertEquals("bar", elementFactoryMethod.getSubstitutionHeadName()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setSubstitutionHeadName(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getSubstitutionHeadName()); - assertNull(elementFactoryMethod.getSubstitutionHeadName()); - } - - public void testUpdateSubstitutionHeadName() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getSubstitutionHeadName()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__SUBSTITUTION_HEAD_NAME, "foo"); - } - }); - assertEquals("foo", elementFactoryMethod.getSubstitutionHeadName()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - public void testModifySubstitutionHeadNamespace() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getSubstitutionHeadNamespace()); - - elementFactoryMethod.setSubstitutionHeadNamespace("bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("bar", elementDeclAnnotation.getSubstitutionHeadNamespace()); - assertEquals("bar", elementFactoryMethod.getSubstitutionHeadNamespace()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setSubstitutionHeadNamespace(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getSubstitutionHeadNamespace()); - assertNull(elementFactoryMethod.getSubstitutionHeadNamespace()); - } - - public void testUpdateSubstitutionHeadNamespace() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getSubstitutionHeadNamespace()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__SUBSTITUTION_HEAD_NAMESPACE, "foo"); - } - }); - assertEquals("foo", elementFactoryMethod.getSubstitutionHeadNamespace()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - public void testModifyNamespace() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getNamespace()); - - elementFactoryMethod.setNamespace("bar"); - XmlElementDeclAnnotation elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertEquals("bar", elementDeclAnnotation.getNamespace()); - assertEquals("bar", elementFactoryMethod.getNamespace()); - - //verify the xml element decl annotation is not removed when the element name is set to null - elementFactoryMethod.setNamespace(null); - elementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(XmlElementDeclAnnotation.ANNOTATION_NAME); - assertNull(elementDeclAnnotation.getNamespace()); - assertNull(elementFactoryMethod.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - JavaResourceMethod resourceMethod = elementFactoryMethod.getResourceMethod(); - assertNull(elementFactoryMethod.getNamespace()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.addXmlElementDeclMemberValuePair(declaration, JAXB.XML_ELEMENT_DECL__NAMESPACE, "foo"); - } - }); - assertEquals("foo", elementFactoryMethod.getNamespace()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaElementFactoryMethodTests.this.removeXmlElementDeclAnnotation(declaration); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - } - - protected void addXmlElementDeclMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlElementDeclAnnotation(declaration), name, value); - } - - protected Annotation getXmlElementDeclAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlElementDeclAnnotation.ANNOTATION_NAME); - } - - protected void removeXmlElementDeclAnnotation(ModifiedDeclaration declaration) { - this.removeAnnotation(declaration, XmlElementDeclAnnotation.ANNOTATION_NAME); - } - - protected void addXmlElementDeclTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlElementDeclAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - -}
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaEnumConstantTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaEnumConstantTests.java deleted file mode 100644 index 7aa70543ab..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaEnumConstantTests.java +++ /dev/null @@ -1,135 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumValueAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaEnumConstantTests extends JaxbContextModelTestCase -{ - - public GenericJavaEnumConstantTests(String name) { - super(name); - } - - private ICompilationUnit createEnumWithXmlEnum() throws Exception { - return createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnum").append(CR); - } - }); - } - - public void testUpdateName() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JaxbEnumConstant contextEnumConstant = CollectionTools.get(contextEnum.getEnumConstants(), 1); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertEquals("MONDAY", contextEnumConstant.getName()); - - - //add a factoryClass member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaEnumConstantTests.this.changeEnumConstantName((EnumDeclaration) declaration.getDeclaration(), "MONDAY", "MONDAY2"); - } - }); - contextEnumConstant = CollectionTools.get(contextEnum.getEnumConstants(), 1); - assertEquals(2, contextEnum.getEnumConstantsSize()); - assertEquals("MONDAY2", contextEnumConstant.getName()); - } - - public void testModifyValue() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JaxbEnumConstant contextEnumConstant = CollectionTools.get(contextEnum.getEnumConstants(), 1); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - JavaResourceEnumConstant resourceEnumConstant = CollectionTools.get(resourceEnum.getEnumConstants(), 1); - - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("MONDAY", contextEnumConstant.getValue()); - assertNull(contextEnumConstant.getSpecifiedValue()); - - contextEnumConstant.setSpecifiedValue("foo"); - XmlEnumValueAnnotation enumValueAnnotation = (XmlEnumValueAnnotation) resourceEnumConstant.getAnnotation(XmlEnumValueAnnotation.ANNOTATION_NAME); - assertEquals("foo", enumValueAnnotation.getValue()); - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("foo", contextEnumConstant.getValue()); - assertEquals("foo", contextEnumConstant.getSpecifiedValue()); - - contextEnumConstant.setSpecifiedValue(null); - enumValueAnnotation = (XmlEnumValueAnnotation) resourceEnumConstant.getAnnotation(XmlEnumValueAnnotation.ANNOTATION_NAME); - assertNull(enumValueAnnotation); - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("MONDAY", contextEnumConstant.getValue()); - assertNull(contextEnumConstant.getSpecifiedValue()); - } - - public void testUpdateValue() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JaxbEnumConstant contextEnumConstant = CollectionTools.get(contextEnum.getEnumConstants(), 1); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - JavaResourceEnumConstant resourceEnumConstant = CollectionTools.get(resourceEnum.getEnumConstants(), 1); - - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("MONDAY", contextEnumConstant.getValue()); - assertNull(contextEnumConstant.getSpecifiedValue()); - - //add an XmlEnumValue annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnumConstant); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation enumValueAnnotation = GenericJavaEnumConstantTests.this.addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_ENUM_VALUE); - GenericJavaEnumConstantTests.this.addMemberValuePair(enumValueAnnotation, JAXB.XML_ENUM_VALUE__VALUE, "foo"); - } - }); - - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("foo", contextEnumConstant.getValue()); - assertEquals("foo", contextEnumConstant.getSpecifiedValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaEnumConstantTests.this.removeAnnotation(declaration, JAXB.XML_ENUM_VALUE); - } - }); - assertEquals("MONDAY", contextEnumConstant.getDefaultValue()); - assertEquals("MONDAY", contextEnumConstant.getValue()); - assertNull(contextEnumConstant.getSpecifiedValue()); - } - -}
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java deleted file mode 100644 index dbed61acb5..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageInfoTests.java +++ /dev/null @@ -1,797 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder; -import org.eclipse.jpt.jaxb.core.context.XmlAccessType; -import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter; -import org.eclipse.jpt.jaxb.core.context.XmlSchemaType; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.ListIterable; - - -@SuppressWarnings("nls") -public class GenericJavaPackageInfoTests extends JaxbContextModelTestCase -{ - - public GenericJavaPackageInfoTests(String name) { - super(name); - } - - private ICompilationUnit createPackageInfoWithAccessorType() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorType(value = XmlAccessType.PROPERTY)", - JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE); - } - - private ICompilationUnit createPackageInfoWithAccessorOrder() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)", - JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER); - } - - public void testModifyAccessType() throws Exception { - createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(XmlAccessType.PROPERTY, contextPackageInfo.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PROPERTY, contextPackageInfo.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getDefaultAccessType()); - - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - XmlAccessorTypeAnnotation accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourcePackage.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.FIELD, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.FIELD, contextPackageInfo.getAccessType()); - - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.PUBLIC_MEMBER); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.PUBLIC_MEMBER, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getAccessType()); - - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.NONE); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.NONE, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.NONE, contextPackageInfo.getAccessType()); - - contextPackageInfo.setSpecifiedAccessType(null); - accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourcePackage.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME); - assertNull(accessorTypeAnnotation); - assertNull(contextPackageInfo.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getDefaultAccessType()); - } - - public void testUpdateAccessType() throws Exception { - createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(XmlAccessType.PROPERTY, contextPackageInfo.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PROPERTY, contextPackageInfo.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getDefaultAccessType()); - - //set the accesser type value to FIELD - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__FIELD); - } - }); - assertEquals(XmlAccessType.FIELD, contextPackageInfo.getAccessType()); - - //set the accesser type value to PUBLIC_MEMBER - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - } - }); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getAccessType()); - - //set the accesser type value to NONE - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__NONE); - } - }); - assertEquals(XmlAccessType.NONE, contextPackageInfo.getAccessType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlAccessorTypeAnnotation(declaration); - } - }); - assertNull(contextPackageInfo.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, contextPackageInfo.getDefaultAccessType()); - } - - public void testModifyAccessOrder() throws Exception { - createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(XmlAccessOrder.ALPHABETICAL, contextPackageInfo.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.ALPHABETICAL, contextPackageInfo.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getDefaultAccessOrder()); - - contextPackageInfo.setSpecifiedAccessOrder(XmlAccessOrder.UNDEFINED); - XmlAccessorOrderAnnotation accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourcePackage.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder.UNDEFINED, accessorOrderAnnotation.getValue()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getAccessOrder()); - - contextPackageInfo.setSpecifiedAccessOrder(null); - accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourcePackage.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME); - assertNull(accessorOrderAnnotation); - assertNull(contextPackageInfo.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getDefaultAccessOrder()); - } - - public void testUpdateAccessOrder() throws Exception { - createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(XmlAccessOrder.ALPHABETICAL, contextPackageInfo.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.ALPHABETICAL, contextPackageInfo.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getDefaultAccessOrder()); - - //set the access order value to UNDEFINED - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.setEnumMemberValuePair(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_ORDER__UNDEFINED); - } - }); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getAccessOrder()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlAccessorOrderAnnotation(declaration); - } - }); - assertNull(contextPackageInfo.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, contextPackageInfo.getDefaultAccessOrder()); - } - - //add another package annotation so that the context model object doesn't get removed when - //removing the XmlAccessorType annotation. Only "annotated" packages are added to the context model - protected void removeXmlAccessorTypeAnnotation(ModifiedDeclaration declaration) { - this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaAnnotation.ANNOTATION_NAME); - this.removeAnnotation(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME); - } - - //add another package annotation so that the context model object doesn't get removed when - //removing the XmlAccessorOrder annotation. Only "annotated" packages are added to the context model - protected void removeXmlAccessorOrderAnnotation(ModifiedDeclaration declaration) { - this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaAnnotation.ANNOTATION_NAME); - this.removeAnnotation(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME); - } - - public void testGetXmlSchemaTypes() throws Exception { - this.createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - assertFalse(xmlSchemaTypes.iterator().hasNext()); - - //add 2 XmlSchemaTypes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar"); - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - } - - protected void addXmlSchemaType(ModifiedDeclaration declaration, int index, String name) { - NormalAnnotation arrayElement = this.newXmlSchemaTypeAnnotation(declaration.getAst(), name); - this.addArrayElement(declaration, JAXB.XML_SCHEMA_TYPES, index, JAXB.XML_SCHEMA_TYPES__VALUE, arrayElement); - } - - protected NormalAnnotation newXmlSchemaTypeAnnotation(AST ast, String name) { - NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_SCHEMA_TYPE); - this.addMemberValuePair(annotation, JAXB.XML_SCHEMA_TYPE__NAME, name); - return annotation; - } - - public void testGetXmlSchemaTypesSize() throws Exception { - this.createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(0, contextPackageInfo.getXmlSchemaTypesSize()); - - //add 2 XmlSchemaTypes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar"); - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo"); - } - }); - assertEquals(2, contextPackageInfo.getXmlSchemaTypesSize()); - } - - public void testAddXmlSchemaType() throws Exception { - //create a package info with an annotation other than XmlSchema to test - //adding things to the null schema annotation - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlSchemaType(0).setName("bar"); - contextPackageInfo.addXmlSchemaType(0).setName("foo"); - contextPackageInfo.addXmlSchemaType(0).setName("baz"); - - Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - } - - @SuppressWarnings("unchecked") - protected Iterator<XmlSchemaTypeAnnotation> getSchemaTypeAnnotations(JavaResourcePackage resourcePackage) { - return (Iterator<XmlSchemaTypeAnnotation>) resourcePackage.getAnnotations(JAXB.XML_SCHEMA_TYPE).iterator(); - } - - public void testAddXmlSchemaType2() throws Exception { - //create a package info with an annotation other than XmlSchema to test - //adding things to the null schema annotation - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlSchemaType(0).setName("bar"); - contextPackageInfo.addXmlSchemaType(1).setName("foo"); - contextPackageInfo.addXmlSchemaType(0).setName("baz"); - - Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - } - - public void testRemoveXmlSchemaType() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlSchemaType(0).setName("bar"); - contextPackageInfo.addXmlSchemaType(1).setName("foo"); - contextPackageInfo.addXmlSchemaType(2).setName("baz"); - - Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - - contextPackageInfo.removeXmlSchemaType(1); - - xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - - contextPackageInfo.removeXmlSchemaType(1); - xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - - contextPackageInfo.removeXmlSchemaType(0); - xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertFalse(xmlSchemaTypes.hasNext()); - } - - public void testMoveXmlSchemaType() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlSchemaType(0).setName("bar"); - contextPackageInfo.addXmlSchemaType(1).setName("foo"); - contextPackageInfo.addXmlSchemaType(2).setName("baz"); - - Iterator<XmlSchemaTypeAnnotation> xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - - contextPackageInfo.moveXmlSchemaType(2, 0); - xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - - contextPackageInfo.moveXmlSchemaType(0, 1); - xmlSchemaTypes = this.getSchemaTypeAnnotations(resourcePackage); - assertEquals("baz", xmlSchemaTypes.next().getName()); - assertEquals("foo", xmlSchemaTypes.next().getName()); - assertEquals("bar", xmlSchemaTypes.next().getName()); - assertFalse(xmlSchemaTypes.hasNext()); - } - - public void testSyncXmlSchemaTypes() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - assertFalse(xmlSchemaTypes.iterator().hasNext()); - - //add 3 XmlSchemaTypes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar"); - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo"); - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 2, "baz"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.moveXmlSchemaType(declaration, 2, 0); - } - }); - - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.moveXmlSchemaType(declaration, 0, 1); - } - }); - - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 1); - } - }); - - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 1); - } - }); - - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlSchemaType(declaration, 0); - } - }); - - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertFalse(xmlSchemaTypesIterator.hasNext()); - } - - public void testSyncAddXmlSchemaTypes() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlSchemaType> xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - assertFalse(xmlSchemaTypes.iterator().hasNext()); - - //add 1 XmlSchemaType when none exist - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "bar"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - ListIterator<XmlSchemaType> xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - - //add 1 XmlSchemaType when 1 standalone exists - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 1, "foo"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - //add 1 XmlSchemaType when a container annotations exists - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 2, "baz"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - - //add 1 XmlSchemaType to beginning of list when a container annotations exists - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlSchemaType(declaration, 0, "foobaz"); - } - }); - - xmlSchemaTypes = contextPackageInfo.getXmlSchemaTypes(); - xmlSchemaTypesIterator = xmlSchemaTypes.iterator(); - assertTrue(xmlSchemaTypesIterator.hasNext()); - assertEquals("foobaz", xmlSchemaTypesIterator.next().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getName()); - assertFalse(xmlSchemaTypesIterator.hasNext()); - } - - protected void moveXmlSchemaType(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - this.moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, targetIndex, sourceIndex); - } - - protected void removeXmlSchemaType(ModifiedDeclaration declaration, int index) { - this.removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_SCHEMA_TYPES), JAXB.XML_SCHEMA_TYPES__VALUE, index); - } - - - - - - public void testGetXmlJavaTypeAdapters() throws Exception { - this.createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlJavaTypeAdapter> xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - assertFalse(xmlJavaTypeAdapters.iterator().hasNext()); - - //add 2 XmlJavaTypeAdapters - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 0, "String"); - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 1, "Integer"); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - ListIterator<XmlJavaTypeAdapter> xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("String", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("Integer", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - } - - protected void addXmlJavaTypeAdapter(ModifiedDeclaration declaration, int index, String name) { - NormalAnnotation arrayElement = this.newXmlJavaTypeAdapterAnnotation(declaration.getAst(), name); - this.addArrayElement(declaration, JAXB.XML_JAVA_TYPE_ADAPTERS, index, JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, arrayElement); - } - - protected NormalAnnotation newXmlJavaTypeAdapterAnnotation(AST ast, String valueTypeName) { - NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_JAVA_TYPE_ADAPTER); - this.addMemberValuePair( - annotation, - JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, - this.newTypeLiteral(ast, valueTypeName)); - return annotation; - } - - public void testGetXmlJavaTypeAdaptersSize() throws Exception { - this.createPackageInfoWithAccessorOrder(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(0, contextPackageInfo.getXmlJavaTypeAdaptersSize()); - - //add 2 XmlJavaTypeAdapters - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 0, "String"); - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 1, "Integer"); - } - }); - assertEquals(2, contextPackageInfo.getXmlJavaTypeAdaptersSize()); - } - - public void testAddXmlJavaTypeAdapter() throws Exception { - //create a package info with an annotation other than XmlSchema to test - //adding things to the null schema annotation - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar"); - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("foo"); - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("baz"); - - Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertEquals("bar", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - } - - @SuppressWarnings("unchecked") - protected Iterator<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations(JavaResourcePackage resourcePackage) { - return (Iterator<XmlJavaTypeAdapterAnnotation>) resourcePackage.getAnnotations(JAXB.XML_JAVA_TYPE_ADAPTER).iterator(); - } - - public void testAddXmlJavaTypeAdapter2() throws Exception { - //create a package info with an annotation other than XmlSchema to test - //adding things to the null schema annotation - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar"); - contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo"); - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("baz"); - - Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertEquals("bar", xmlJavaTypeAdapters.next().getValue()); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - } - - public void testRemoveXmlJavaTypeAdapter() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("String"); - contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo"); - contextPackageInfo.addXmlJavaTypeAdapter(2).setValue("baz"); - - Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - XmlJavaTypeAdapterAnnotation adapterAnnotation = xmlJavaTypeAdapters.next(); - assertEquals("String", adapterAnnotation.getValue()); - assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue()); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - - contextPackageInfo.removeXmlJavaTypeAdapter(1); - - xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - adapterAnnotation = xmlJavaTypeAdapters.next(); - assertEquals("String", adapterAnnotation.getValue()); - assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue()); - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - - contextPackageInfo.removeXmlJavaTypeAdapter(1); - xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - adapterAnnotation = xmlJavaTypeAdapters.next(); - assertEquals("String", adapterAnnotation.getValue()); - assertEquals("java.lang.String", adapterAnnotation.getFullyQualifiedValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - - contextPackageInfo.removeXmlJavaTypeAdapter(0); - xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - assertFalse(xmlJavaTypeAdapters.hasNext()); - } - - public void testMoveXmlJavaTypeAdapter() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextPackageInfo.addXmlJavaTypeAdapter(0).setValue("bar"); - contextPackageInfo.addXmlJavaTypeAdapter(1).setValue("foo"); - contextPackageInfo.addXmlJavaTypeAdapter(2).setValue("baz"); - - Iterator<XmlJavaTypeAdapterAnnotation> xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - assertEquals("bar", xmlJavaTypeAdapters.next().getValue()); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - - contextPackageInfo.moveXmlJavaTypeAdapter(2, 0); - xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertEquals("bar", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - - contextPackageInfo.moveXmlJavaTypeAdapter(0, 1); - xmlJavaTypeAdapters = this.getXmlJavaTypeAdapterAnnotations(resourcePackage); - assertEquals("baz", xmlJavaTypeAdapters.next().getValue()); - assertEquals("foo", xmlJavaTypeAdapters.next().getValue()); - assertEquals("bar", xmlJavaTypeAdapters.next().getValue()); - assertFalse(xmlJavaTypeAdapters.hasNext()); - } - - public void testSyncXmlJavaTypeAdapters() throws Exception { - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlJavaTypeAdapter> xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - assertFalse(xmlJavaTypeAdapters.iterator().hasNext()); - - //add 3 XmlJavaTypeAdapters - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 0, "bar"); - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 1, "foo"); - GenericJavaPackageInfoTests.this.addXmlJavaTypeAdapter(declaration, 2, "baz"); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - ListIterator<XmlJavaTypeAdapter> xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.moveXmlJavaTypeAdapter(declaration, 2, 0); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.moveXmlJavaTypeAdapter(declaration, 0, 1); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("foo", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlJavaTypeAdapter(declaration, 1); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue()); - assertEquals("bar", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlJavaTypeAdapter(declaration, 1); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertTrue(xmlJavaTypeAdaptersIterator.hasNext()); - assertEquals("baz", xmlJavaTypeAdaptersIterator.next().getValue()); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageInfoTests.this.removeXmlJavaTypeAdapter(declaration, 0); - } - }); - - xmlJavaTypeAdapters = contextPackageInfo.getXmlJavaTypeAdapters(); - xmlJavaTypeAdaptersIterator = xmlJavaTypeAdapters.iterator(); - assertFalse(xmlJavaTypeAdaptersIterator.hasNext()); - } - - - protected void moveXmlJavaTypeAdapter(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - this.moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_JAVA_TYPE_ADAPTERS), JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, targetIndex, sourceIndex); - } - - protected void removeXmlJavaTypeAdapter(ModifiedDeclaration declaration, int index) { - this.removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_JAVA_TYPE_ADAPTERS), JAXB.XML_JAVA_TYPE_ADAPTERS__VALUE, index); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java deleted file mode 100644 index 1d37830624..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentClassTests.java +++ /dev/null @@ -1,827 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAccessOrder; -import org.eclipse.jpt.jaxb.core.context.XmlAccessType; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.AbstractJavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentClassTests extends JaxbContextModelTestCase -{ - - public GenericJavaPersistentClassTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlType() 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 void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TYPE); - sb.append(";"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append("AnnotationTestTypeChild").append(" "); - sb.append("extends " + TYPE_NAME + " "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private ICompilationUnit createXmlTypeWithAccessorType() throws CoreException { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").append(CR); - sb.append("@XmlAccessorType(value = XmlAccessType.PROPERTY)"); - } - }); - } - - private ICompilationUnit createXmlTypeWithAccessorOrder() throws CoreException { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").append(CR); - sb.append("@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)"); - } - }); - } - - private ICompilationUnit createPackageInfoWithAccessorType() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorType(value = XmlAccessType.PROPERTY)", - JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE); - } - - public void testModifyFactoryClass() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getFactoryClass()); - - persistentClass.setFactoryClass("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryClass()); - assertEquals("foo", persistentClass.getFactoryClass()); - - persistentClass.setFactoryClass(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getFactoryClass()); - assertNull(persistentClass.getFactoryClass()); - - //add another annotation so that the context model does not get blown away - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set factoryClass again, this time starting with no XmlType annotation - persistentClass.setFactoryClass("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryClass()); - assertEquals("foo", persistentClass.getFactoryClass()); - } - - public void testUpdateFactoryClass() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getFactoryClass()); - - - //add a factoryClass member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addXmlTypeTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_CLASS, "Foo"); - } - }); - assertEquals("Foo", persistentClass.getFactoryClass()); - - //remove the factoryClass member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(persistentClass.getFactoryClass()); - } - - public void testModifyFactoryMethod() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getFactoryMethod()); - - persistentClass.setFactoryMethod("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryMethod()); - assertEquals("foo", persistentClass.getFactoryMethod()); - - persistentClass.setFactoryMethod(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getFactoryMethod()); - assertNull(persistentClass.getFactoryMethod()); - - //add another annotation so that the context model does not get blown away - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set factoryMethod again, this time starting with no XmlType annotation - persistentClass.setFactoryMethod("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryMethod()); - assertEquals("foo", persistentClass.getFactoryMethod()); - } - - public void testUpdateFactoryMethod() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getFactoryMethod()); - - - //add a factoryMethod member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_METHOD, "foo"); - } - }); - assertEquals("foo", persistentClass.getFactoryMethod()); - - //remove the factoryMethod member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(persistentClass.getFactoryMethod()); - } - - public void testModifySchemaTypeName() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getSchemaTypeName()); - - persistentClass.setSchemaTypeName("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", persistentClass.getSchemaTypeName()); - - persistentClass.setSchemaTypeName(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getName()); - assertNull(persistentClass.getSchemaTypeName()); - - //add another annotation so that the context model does not get blown away - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set name again, this time starting with no XmlType annotation - persistentClass.setSchemaTypeName("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", persistentClass.getSchemaTypeName()); - } - - public void testUpdateSchemaTypeName() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getSchemaTypeName()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAME, "foo"); - } - }); - assertEquals("foo", persistentClass.getSchemaTypeName()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(persistentClass.getSchemaTypeName()); - } - - public void testModifyNamespace() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getNamespace()); - - persistentClass.setNamespace("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", persistentClass.getNamespace()); - - persistentClass.setNamespace(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getNamespace()); - assertNull(persistentClass.getNamespace()); - - //add another annotation so that the context model does not get blown away - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - resourceType.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set namespace again, this time starting with no XmlType annotation - persistentClass.setNamespace("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", persistentClass.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getNamespace()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAMESPACE, "foo"); - } - }); - assertEquals("foo", persistentClass.getNamespace()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentClassTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentClassTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(persistentClass.getNamespace()); - } - - public void testModifyAccessType() throws Exception { - createXmlTypeWithAccessorType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertEquals(XmlAccessType.PROPERTY, persistentClass.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PROPERTY, persistentClass.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType()); - - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - XmlAccessorTypeAnnotation accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.FIELD, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.FIELD, persistentClass.getAccessType()); - - persistentClass.setSpecifiedAccessType(XmlAccessType.PUBLIC_MEMBER); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.PUBLIC_MEMBER, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType()); - - persistentClass.setSpecifiedAccessType(XmlAccessType.NONE); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType.NONE, accessorTypeAnnotation.getValue()); - assertEquals(XmlAccessType.NONE, persistentClass.getAccessType()); - - persistentClass.setSpecifiedAccessType(null); - accessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(XmlAccessorTypeAnnotation.ANNOTATION_NAME); - assertNull(accessorTypeAnnotation); - assertNull(persistentClass.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType()); - } - - public void testUpdateAccessType() throws Exception { - createXmlTypeWithAccessorType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertEquals(XmlAccessType.PROPERTY, persistentClass.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PROPERTY, persistentClass.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType()); - - //set the accesser type value to FIELD - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__FIELD); - } - }); - assertEquals(XmlAccessType.FIELD, persistentClass.getAccessType()); - - //set the accesser type value to PUBLIC_MEMBER - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - } - }); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType()); - - //set the accesser type value to NONE - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_TYPE__NONE); - } - }); - assertEquals(XmlAccessType.NONE, persistentClass.getAccessType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME); - } - }); - assertNull(persistentClass.getSpecifiedAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getAccessType()); - assertEquals(XmlAccessType.PUBLIC_MEMBER, persistentClass.getDefaultAccessType()); - } - - /** - * If there is a @XmlAccessorType on a class, then it is used. - * Otherwise, if a @XmlAccessorType exists on one of its super classes, then it is inherited. - * Otherwise, the @XmlAccessorType on a package is inherited. - */ - public void testGetDefaultAccessType() throws Exception { - this.createTypeWithXmlType(); - this.createTestSubType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentClass childPersistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - assertEquals(XmlAccessType.PUBLIC_MEMBER, childPersistentClass.getDefaultAccessType()); - - this.createPackageInfoWithAccessorType(); - assertEquals(XmlAccessType.PROPERTY, childPersistentClass.getDefaultAccessType()); - - persistentClass.setSpecifiedAccessType(XmlAccessType.FIELD); - assertEquals(XmlAccessType.PROPERTY, childPersistentClass.getDefaultAccessType()); - - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - persistentClass.setSpecifiedAccessType(null); - assertEquals(XmlAccessType.PROPERTY, childPersistentClass.getDefaultAccessType()); - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - assertEquals(XmlAccessType.FIELD, childPersistentClass.getDefaultAccessType()); - - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.NONE); - assertEquals(XmlAccessType.NONE, childPersistentClass.getDefaultAccessType()); - - contextPackageInfo.setSpecifiedAccessType(null); - assertEquals(XmlAccessType.PUBLIC_MEMBER, childPersistentClass.getDefaultAccessType()); - } - - public void testGetSuperPersistentClass() throws Exception { - this.createTypeWithXmlType(); - this.createTestSubType(); - JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - JaxbPersistentClass childPersistentClass = getContextRoot().getPersistentClass(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - assertEquals(persistentClass, childPersistentClass.getSuperPersistentClass()); - - //This test will change when we no longer depend on there being an @XmlType annotation for something to be persistent - AnnotatedElement annotatedElement = this.annotatedElement(persistentClass.getJavaResourceType()); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlTypeAnnotation.ANNOTATION_NAME); - } - }); - assertNull(childPersistentClass.getSuperPersistentClass()); - } - - public void testModifyAccessOrder() throws Exception { - createXmlTypeWithAccessorOrder(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder()); - - persistentClass.setSpecifiedAccessOrder(XmlAccessOrder.UNDEFINED); - XmlAccessorOrderAnnotation accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder.UNDEFINED, accessorOrderAnnotation.getValue()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder()); - - persistentClass.setSpecifiedAccessOrder(null); - accessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(XmlAccessorOrderAnnotation.ANNOTATION_NAME); - assertNull(accessorOrderAnnotation); - assertNull(persistentClass.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder()); - } - - public void testUpdateAccessOrder() throws Exception { - createXmlTypeWithAccessorOrder(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.ALPHABETICAL, persistentClass.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder()); - - //set the access order value to UNDEFINED - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME, JAXB.XML_ACCESS_ORDER__UNDEFINED); - } - }); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAccessorOrderAnnotation.ANNOTATION_NAME); - } - }); - assertNull(persistentClass.getSpecifiedAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getAccessOrder()); - assertEquals(XmlAccessOrder.UNDEFINED, persistentClass.getDefaultAccessOrder()); - } - - public void testGetPropOrder() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - ListIterator<String> props = persistentClass.getPropOrder().iterator(); - assertFalse(props.hasNext()); - - //add 2 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo"); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertFalse(props.hasNext()); - } - - protected void addProp(ModifiedDeclaration declaration, int index, String prop) { - this.addArrayElement(declaration, JAXB.XML_TYPE, index, JAXB.XML_TYPE__PROP_ORDER, this.newStringLiteral(declaration.getAst(), prop)); - } - - public void testGetPropOrderSize() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertEquals(0, persistentClass.getPropOrderSize()); - - //add 2 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo"); - } - }); - assertEquals(2, persistentClass.getPropOrderSize()); - } - - public void testAddProp() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - persistentClass.addProp(0, "bar"); - persistentClass.addProp(0, "foo"); - persistentClass.addProp(0, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator(); - - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - } - - public void testAddProp2() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - persistentClass.addProp(0, "bar"); - persistentClass.addProp(1, "foo"); - persistentClass.addProp(0, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator(); - - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertFalse(props.hasNext()); - } - - public void testRemoveProp() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - persistentClass.addProp(0, "bar"); - persistentClass.addProp(1, "foo"); - persistentClass.addProp(2, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - persistentClass.removeProp(1); - - ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("bar", resourceProps.next()); - assertEquals("baz", resourceProps.next()); - assertFalse(resourceProps.hasNext()); - - persistentClass.removeProp(1); - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("bar", resourceProps.next()); - assertFalse(resourceProps.hasNext()); - - persistentClass.removeProp(0); - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertFalse(resourceProps.hasNext()); - } - - public void testMoveProp() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - persistentClass.addProp(0, "bar"); - persistentClass.addProp(1, "foo"); - persistentClass.addProp(2, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - assertEquals(3, xmlTypeAnnotation.getPropOrderSize()); - - persistentClass.moveProp(2, 0); - ListIterator<String> props = persistentClass.getPropOrder().iterator(); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("foo", resourceProps.next()); - assertEquals("baz", resourceProps.next()); - assertEquals("bar", resourceProps.next()); - - - persistentClass.moveProp(0, 1); - props = persistentClass.getPropOrder().iterator(); - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("baz", resourceProps.next()); - assertEquals("foo", resourceProps.next()); - assertEquals("bar", resourceProps.next()); - } - - public void testSyncXmlNsPrefixes() throws Exception { - this.createTypeWithXmlType(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - ListIterator<String> props = persistentClass.getPropOrder().iterator(); - assertFalse(props.hasNext()); - - //add 3 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentClassTests.this.addProp(declaration, 1, "foo"); - GenericJavaPersistentClassTests.this.addProp(declaration, 2, "baz"); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.moveProp(declaration, 2, 0); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.moveProp(declaration, 0, 1); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeProp(declaration, 1); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeProp(declaration, 1); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeProp(declaration, 0); - } - }); - - props = persistentClass.getPropOrder().iterator(); - assertFalse(props.hasNext()); - } - - protected void addXmlTypeMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlTypeAnnotation(declaration), name, value); - } - - protected void addXmlTypeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlTypeAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected Annotation getXmlTypeAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlTypeAnnotation.ANNOTATION_NAME); - } - - protected void moveProp(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - this.moveArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, targetIndex, sourceIndex); - } - - protected void removeProp(ModifiedDeclaration declaration, int index) { - this.removeArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, index); - } - - public void testModifyXmlRootElement() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getRootElement()); - assertFalse(persistentClass.isRootElement()); - - persistentClass.setRootElement("foo"); - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlRootElementAnnotation.getName()); - assertEquals("foo", persistentClass.getRootElement().getName()); - assertTrue(persistentClass.isRootElement()); - - persistentClass.setRootElement(null); - xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(xmlRootElementAnnotation); - assertNull(persistentClass.getRootElement()); - assertFalse(persistentClass.isRootElement()); - } - - public void testUpdateXmlRootElement() throws Exception { - createTypeWithXmlType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getRootElement()); - assertFalse(persistentClass.isRootElement()); - - - //add a XmlRootElement annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation annotation = GenericJavaPersistentClassTests.this.addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_ROOT_ELEMENT); - GenericJavaPersistentClassTests.this.addMemberValuePair(annotation, JAXB.XML_ROOT_ELEMENT__NAME, "foo"); - } - }); - assertEquals("foo", persistentClass.getRootElement().getName()); - assertTrue(persistentClass.isRootElement()); - - //remove the XmlRootElement annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, JAXB.XML_ROOT_ELEMENT); - } - }); - assertNull(persistentClass.getRootElement()); - assertFalse(persistentClass.isRootElement()); - } -}
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentEnumTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentEnumTests.java deleted file mode 100644 index 246c68a61d..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentEnumTests.java +++ /dev/null @@ -1,721 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.EnumDeclaration; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbEnumConstant; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentEnumTests extends JaxbContextModelTestCase -{ - - public GenericJavaPersistentEnumTests(String name) { - super(name); - } - - private ICompilationUnit createEnumWithXmlEnum() throws Exception { - return createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnum"); - } - }); - } - - public void testModifyFactoryClass() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getFactoryClass()); - - contextEnum.setFactoryClass("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryClass()); - assertEquals("foo", contextEnum.getFactoryClass()); - - contextEnum.setFactoryClass(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getFactoryClass()); - assertNull(contextEnum.getFactoryClass()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(contextEnum.getFactoryClass()); - } - - public void testUpdateFactoryClass() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getFactoryClass()); - - - //add a factoryClass member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - GenericJavaPersistentEnumTests.this.addXmlTypeTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_CLASS, "Foo"); - } - }); - assertEquals("Foo", contextEnum.getFactoryClass()); - - //remove the factoryClass member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentEnumTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentEnumTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(contextEnum.getFactoryClass()); - } - - public void testModifyFactoryMethod() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getFactoryMethod()); - - contextEnum.setFactoryMethod("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryMethod()); - assertEquals("foo", contextEnum.getFactoryMethod()); - - contextEnum.setFactoryMethod(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getFactoryMethod()); - assertNull(contextEnum.getFactoryMethod()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set factoryMethod again, this time starting with no XmlType annotation - contextEnum.setFactoryMethod("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getFactoryMethod()); - assertEquals("foo", contextEnum.getFactoryMethod()); - } - - public void testUpdateFactoryMethod() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getFactoryMethod()); - - - //add a factoryMethod member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - GenericJavaPersistentEnumTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__FACTORY_METHOD, "foo"); - } - }); - assertEquals("foo", contextEnum.getFactoryMethod()); - - //remove the factoryMethod member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentEnumTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentEnumTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(contextEnum.getFactoryMethod()); - } - - public void testModifySchemaTypeName() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getSchemaTypeName()); - - contextEnum.setSchemaTypeName("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", contextEnum.getSchemaTypeName()); - - contextEnum.setSchemaTypeName(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getName()); - assertNull(contextEnum.getSchemaTypeName()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set name again, this time starting with no XmlType annotation - contextEnum.setSchemaTypeName("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", contextEnum.getSchemaTypeName()); - } - - public void testUpdateSchemaTypeName() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getSchemaTypeName()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - GenericJavaPersistentEnumTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAME, "foo"); - } - }); - assertEquals("foo", contextEnum.getSchemaTypeName()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentEnumTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentEnumTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(contextEnum.getSchemaTypeName()); - } - - public void testModifyNamespace() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getNamespace()); - - contextEnum.setNamespace("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", contextEnum.getNamespace()); - - contextEnum.setNamespace(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getNamespace()); - assertNull(contextEnum.getNamespace()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set namespace again, this time starting with no XmlType annotation - contextEnum.setNamespace("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", contextEnum.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getNamespace()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - GenericJavaPersistentEnumTests.this.addXmlTypeMemberValuePair(declaration, JAXB.XML_TYPE__NAMESPACE, "foo"); - } - }); - assertEquals("foo", contextEnum.getNamespace()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlTypeAnnotation = (NormalAnnotation) GenericJavaPersistentEnumTests.this.getXmlTypeAnnotation(declaration); - GenericJavaPersistentEnumTests.this.values(xmlTypeAnnotation).remove(0); - } - }); - assertNull(contextEnum.getNamespace()); - } - - public void testGetPropOrder() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - ListIterator<String> props = contextEnum.getPropOrder().iterator(); - assertFalse(props.hasNext()); - - //add 2 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentEnumTests.this.addProp(declaration, 1, "foo"); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertFalse(props.hasNext()); - } - - protected void addProp(ModifiedDeclaration declaration, int index, String prop) { - this.addArrayElement(declaration, JAXB.XML_TYPE, index, JAXB.XML_TYPE__PROP_ORDER, this.newStringLiteral(declaration.getAst(), prop)); - } - - public void testGetPropOrderSize() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertEquals(0, contextEnum.getPropOrderSize()); - - //add 2 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentEnumTests.this.addProp(declaration, 1, "foo"); - } - }); - assertEquals(2, contextEnum.getPropOrderSize()); - } - - public void testAddProp() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - contextEnum.addProp(0, "bar"); - contextEnum.addProp(0, "foo"); - contextEnum.addProp(0, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator(); - - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - } - - public void testAddProp2() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - contextEnum.addProp(0, "bar"); - contextEnum.addProp(1, "foo"); - contextEnum.addProp(0, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - ListIterator<String> props = xmlTypeAnnotation.getPropOrder().iterator(); - - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertFalse(props.hasNext()); - } - - public void testRemoveProp() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - contextEnum.addProp(0, "bar"); - contextEnum.addProp(1, "foo"); - contextEnum.addProp(2, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - contextEnum.removeProp(1); - - ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("bar", resourceProps.next()); - assertEquals("baz", resourceProps.next()); - assertFalse(resourceProps.hasNext()); - - contextEnum.removeProp(1); - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("bar", resourceProps.next()); - assertFalse(resourceProps.hasNext()); - - contextEnum.removeProp(0); - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertFalse(resourceProps.hasNext()); - } - - public void testMoveProp() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - contextEnum.addProp(0, "bar"); - contextEnum.addProp(1, "foo"); - contextEnum.addProp(2, "baz"); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - assertEquals(3, xmlTypeAnnotation.getPropOrderSize()); - - contextEnum.moveProp(2, 0); - ListIterator<String> props = contextEnum.getPropOrder().iterator(); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - ListIterator<String> resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("foo", resourceProps.next()); - assertEquals("baz", resourceProps.next()); - assertEquals("bar", resourceProps.next()); - - - contextEnum.moveProp(0, 1); - props = contextEnum.getPropOrder().iterator(); - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - resourceProps = xmlTypeAnnotation.getPropOrder().iterator(); - assertEquals("baz", resourceProps.next()); - assertEquals("foo", resourceProps.next()); - assertEquals("bar", resourceProps.next()); - } - - public void testSyncXmlNsPrefixes() throws Exception { - this.createEnumWithXmlEnum(); - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - ListIterator<String> props = contextEnum.getPropOrder().iterator(); - assertFalse(props.hasNext()); - - //add 3 prop orders - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addProp(declaration, 0, "bar"); - GenericJavaPersistentEnumTests.this.addProp(declaration, 1, "foo"); - GenericJavaPersistentEnumTests.this.addProp(declaration, 2, "baz"); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("bar", props.next()); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.moveProp(declaration, 2, 0); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("foo", props.next()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.moveProp(declaration, 0, 1); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertEquals("foo", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeProp(declaration, 1); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertEquals("bar", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeProp(declaration, 1); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertTrue(props.hasNext()); - assertEquals("baz", props.next()); - assertFalse(props.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeProp(declaration, 0); - } - }); - - props = contextEnum.getPropOrder().iterator(); - assertFalse(props.hasNext()); - } - - protected void addXmlTypeMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlTypeAnnotation(declaration), name, value); - } - - protected void addXmlTypeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlTypeAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected void addXmlEnumTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlEnumAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected Annotation getXmlTypeAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlTypeAnnotation.ANNOTATION_NAME); - } - - protected Annotation getXmlEnumAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlEnumAnnotation.ANNOTATION_NAME); - } - - protected void moveProp(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - this.moveArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, targetIndex, sourceIndex); - } - - protected void removeProp(ModifiedDeclaration declaration, int index) { - this.removeArrayElement((NormalAnnotation) getXmlTypeAnnotation(declaration), JAXB.XML_TYPE__PROP_ORDER, index); - } - - public void testModifyXmlRootElement() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getRootElement()); - assertFalse(contextEnum.isRootElement()); - - contextEnum.setRootElement("foo"); - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceEnum.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlRootElementAnnotation.getName()); - assertEquals("foo", contextEnum.getRootElement().getName()); - assertTrue(contextEnum.isRootElement()); - - contextEnum.setRootElement(null); - xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceEnum.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(xmlRootElementAnnotation); - assertNull(contextEnum.getRootElement()); - assertFalse(contextEnum.isRootElement()); - } - - public void testUpdateXmlRootElement() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getRootElement()); - assertFalse(contextEnum.isRootElement()); - - - //add a XmlRootElement annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation annotation = GenericJavaPersistentEnumTests.this.addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_ROOT_ELEMENT); - GenericJavaPersistentEnumTests.this.addMemberValuePair(annotation, JAXB.XML_ROOT_ELEMENT__NAME, "foo"); - } - }); - assertEquals("foo", contextEnum.getRootElement().getName()); - assertTrue(contextEnum.isRootElement()); - - //remove the XmlRootElement annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeAnnotation(declaration, JAXB.XML_ROOT_ELEMENT); - } - }); - assertNull(contextEnum.getRootElement()); - assertFalse(contextEnum.isRootElement()); - } - - public void testModifyEnumType() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getEnumType()); - - contextEnum.setEnumType("Integer"); - XmlEnumAnnotation xmlEnumAnnotation = (XmlEnumAnnotation) resourceEnum.getAnnotation(XmlEnumAnnotation.ANNOTATION_NAME); - assertEquals("Integer", xmlEnumAnnotation.getValue()); - assertEquals("Integer", contextEnum.getEnumType()); - - contextEnum.setEnumType(null); - xmlEnumAnnotation = (XmlEnumAnnotation) resourceEnum.getAnnotation(XmlEnumAnnotation.ANNOTATION_NAME); - assertNull(xmlEnumAnnotation.getValue()); - assertNull(contextEnum.getEnumType()); - - resourceEnum.addAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - resourceEnum.removeAnnotation(XmlEnumAnnotation.ANNOTATION_NAME); - contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - assertNull(contextEnum.getEnumType()); - } - - public void testUpdateEnumType() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getEnumType()); - - - //add a factoryClass member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addXmlEnumTypeMemberValuePair(declaration, JAXB.XML_ENUM__VALUE, "String"); - } - }); - assertEquals("String", contextEnum.getEnumType()); - - //remove the factoryClass member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlEnumAnnotation = (NormalAnnotation) GenericJavaPersistentEnumTests.this.getXmlEnumAnnotation(declaration); - GenericJavaPersistentEnumTests.this.values(xmlEnumAnnotation).remove(0); - } - }); - assertNull(contextEnum.getEnumType()); - } - - public void testUpdateEnumConstants() throws Exception { - createEnumWithXmlEnum(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertEquals(2, contextEnum.getEnumConstantsSize()); - Iterator<JaxbEnumConstant> enumConstants = contextEnum.getEnumConstants().iterator(); - JaxbEnumConstant enumConstant = enumConstants.next(); - assertEquals("SUNDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("MONDAY", enumConstant.getName()); - assertFalse(enumConstants.hasNext()); - - - AnnotatedElement annotatedElement = this.annotatedElement(resourceEnum); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.addEnumConstant((EnumDeclaration) declaration.getDeclaration(), "TUESDAY"); - GenericJavaPersistentEnumTests.this.addEnumConstant((EnumDeclaration) declaration.getDeclaration(), "WEDNESDAY"); - } - }); - assertEquals(4, contextEnum.getEnumConstantsSize()); - enumConstants = contextEnum.getEnumConstants().iterator(); - enumConstant = enumConstants.next(); - assertEquals("SUNDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("MONDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("TUESDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("WEDNESDAY", enumConstant.getName()); - assertFalse(enumConstants.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeEnumConstant((EnumDeclaration) declaration.getDeclaration(), "SUNDAY"); - } - }); - assertEquals(3, contextEnum.getEnumConstantsSize()); - enumConstants = contextEnum.getEnumConstants().iterator(); - enumConstant = enumConstants.next(); - assertEquals("MONDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("TUESDAY", enumConstant.getName()); - enumConstant = enumConstants.next(); - assertEquals("WEDNESDAY", enumConstant.getName()); - assertFalse(enumConstants.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeEnumConstant((EnumDeclaration) declaration.getDeclaration(), "TUESDAY"); - GenericJavaPersistentEnumTests.this.removeEnumConstant((EnumDeclaration) declaration.getDeclaration(), "MONDAY"); - } - }); - assertEquals(1, contextEnum.getEnumConstantsSize()); - enumConstants = contextEnum.getEnumConstants().iterator(); - enumConstant = enumConstants.next(); - assertEquals("WEDNESDAY", enumConstant.getName()); - assertFalse(enumConstants.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentEnumTests.this.removeEnumConstant((EnumDeclaration) declaration.getDeclaration(), "WEDNESDAY"); - } - }); - assertEquals(0, contextEnum.getEnumConstantsSize()); - assertFalse(contextEnum.getEnumConstants().iterator().hasNext()); - - } -}
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java deleted file mode 100644 index ef45be0265..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaRegistryTests.java +++ /dev/null @@ -1,209 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Block; -import org.eclipse.jdt.core.dom.BodyDeclaration; -import org.eclipse.jdt.core.dom.IExtendedModifier; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbElementFactoryMethod; -import org.eclipse.jpt.jaxb.core.context.JaxbRegistry; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaRegistryTests extends JaxbContextModelTestCase -{ - - public GenericJavaRegistryTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlRegistry() throws Exception { - return this.createTestType(PACKAGE_NAME, "ObjectFactory.java", "ObjectFactory", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_REGISTRY, JAXB.XML_ELEMENT_DECL, "javax.xml.bind.JAXBElement"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRegistry"); - } - - @Override - public void appendGetNameMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementDecl(name=\"foo\")").append(CR); - sb.append(" JAXBElement<AnnotationTestType> createFoo(AnnotationTestType value) {return null}").append(CR); - sb.append(CR); - sb.append(" @XmlElementDecl(name=\"bar\")").append(CR); - sb.append(" JAXBElement createBar(Object value) {return null}").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTypeWithXmlType() 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").append(CR); - } - }); - } - - - protected void addElementFactoryMethod(TypeDeclaration typeDeclaration, String methodName) { - AST ast = typeDeclaration.getAST(); - MethodDeclaration methodDeclaration = this.newMethodDeclaration(ast, methodName); - Block body = ast.newBlock(); - methodDeclaration.setBody(body); - methodDeclaration.setReturnType2(ast.newSimpleType(ast.newName("JAXBElement"))); - SingleVariableDeclaration parameter = ast.newSingleVariableDeclaration(); - parameter.setName(ast.newSimpleName("value")); - parameter.setType(ast.newSimpleType(ast.newName("Object"))); - parameters(methodDeclaration).add(parameter); - NormalAnnotation elementDeclAnnotation = this.newNormalAnnotation(ast, "XmlElementDecl"); - modifiers(methodDeclaration).add(elementDeclAnnotation); - this.bodyDeclarations(typeDeclaration).add(methodDeclaration); - } - - protected MethodDeclaration newMethodDeclaration(AST ast, String methodName) { - MethodDeclaration methodDeclaration = ast.newMethodDeclaration(); - methodDeclaration.setName(ast.newSimpleName(methodName)); - return methodDeclaration; - } - - /** - * minimize the scope of the suppressed warnings - */ - @SuppressWarnings("unchecked") - protected List<BodyDeclaration> bodyDeclarations(TypeDeclaration td) { - return td.bodyDeclarations(); - } - - @SuppressWarnings("unchecked") - protected List<SingleVariableDeclaration> parameters(MethodDeclaration md) { - return md.parameters(); - } - - @SuppressWarnings("unchecked") - protected List<IExtendedModifier> modifiers(MethodDeclaration md) { - return md.modifiers(); - } - - protected void removeMethodDeclaration(TypeDeclaration typeDeclaration, String methodName) { - for (MethodDeclaration md : typeDeclaration.getMethods()) { - if (md.getName().getFullyQualifiedName().equals(methodName)) { - this.bodyDeclarations(typeDeclaration).remove(md); - break; - } - } - } - - public void testUpdateElementFactoryMethods() throws Exception { - createTypeWithXmlType(); - createTypeWithXmlRegistry(); - - JaxbRegistry contextRegistry = CollectionTools.get(getContextRoot().getRegistries(), 0); - JavaResourceType resourceType = contextRegistry.getJavaResourceType(); - - assertEquals(2, contextRegistry.getElementFactoryMethodsSize()); - Iterator<JaxbElementFactoryMethod> elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - JaxbElementFactoryMethod elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createFoo", elementFactoryMethod.getName()); - assertEquals("foo", elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar", elementFactoryMethod.getName()); - assertEquals("bar", elementFactoryMethod.getElementName()); - assertFalse(elementFactoryMethods.hasNext()); - - - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaRegistryTests.this.addElementFactoryMethod((TypeDeclaration) declaration.getDeclaration(), "createFoo2"); - GenericJavaRegistryTests.this.addElementFactoryMethod((TypeDeclaration) declaration.getDeclaration(), "createBar2"); - } - }); - assertEquals(4, contextRegistry.getElementFactoryMethodsSize()); - elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createFoo", elementFactoryMethod.getName()); - assertEquals("foo", elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar", elementFactoryMethod.getName()); - assertEquals("bar", elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createFoo2", elementFactoryMethod.getName()); - assertEquals(null, elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar2", elementFactoryMethod.getName()); - assertEquals(null, elementFactoryMethod.getElementName()); - assertFalse(elementFactoryMethods.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createFoo"); - } - }); - assertEquals(3, contextRegistry.getElementFactoryMethodsSize()); - elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar", elementFactoryMethod.getName()); - assertEquals("bar", elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createFoo2", elementFactoryMethod.getName()); - assertEquals(null, elementFactoryMethod.getElementName()); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar2", elementFactoryMethod.getName()); - assertEquals(null, elementFactoryMethod.getElementName()); - assertFalse(elementFactoryMethods.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createFoo2"); - GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createBar2"); - } - }); - assertEquals(1, contextRegistry.getElementFactoryMethodsSize()); - elementFactoryMethods = contextRegistry.getElementFactoryMethods().iterator(); - elementFactoryMethod = elementFactoryMethods.next(); - assertEquals("createBar", elementFactoryMethod.getName()); - assertEquals("bar", elementFactoryMethod.getElementName()); - assertFalse(elementFactoryMethods.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaRegistryTests.this.removeMethodDeclaration((TypeDeclaration) declaration.getDeclaration(), "createBar"); - } - }); - assertEquals(0, contextRegistry.getElementFactoryMethodsSize()); - assertFalse(contextRegistry.getElementFactoryMethods().iterator().hasNext()); - } -}
\ No newline at end of file diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java deleted file mode 100644 index 9501b0796b..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlJavaTypeAdapterTests.java +++ /dev/null @@ -1,155 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.XmlJavaTypeAdapter; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; - - -@SuppressWarnings("nls") -public class GenericJavaXmlJavaTypeAdapterTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlJavaTypeAdapterTests(String name) { - super(name); - } - - private ICompilationUnit createPackageInfoWithXmlJavaTypeAdapter() throws CoreException { - return createTestPackageInfo( - "@XmlJavaTypeAdapter", - JAXB.XML_JAVA_TYPE_ADAPTER); - } - - - public void testModifyValue() throws Exception { - this.createPackageInfoWithXmlJavaTypeAdapter(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - contextXmlJavaTypeAdapter.setValue("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertEquals("foo", javaTypeAdapterAnnotation.getValue()); - assertEquals("foo", contextXmlJavaTypeAdapter.getValue()); - - //verify the xml schema type annotation is not removed when the value is set to null - contextXmlJavaTypeAdapter.setValue(null); - javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getValue()); - assertNull(contextXmlJavaTypeAdapter.getValue()); - } - - public void testUpdateValue() throws Exception { - this.createPackageInfoWithXmlJavaTypeAdapter(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - //add a value member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertFalse(contextPackageInfo.getXmlJavaTypeAdapters().iterator().hasNext()); - } - - public void testModifyType() throws Exception { - this.createPackageInfoWithXmlJavaTypeAdapter(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlJavaTypeAdapter.getType()); - - contextXmlJavaTypeAdapter.setType("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertEquals("foo", javaTypeAdapterAnnotation.getType()); - assertEquals("foo", contextXmlJavaTypeAdapter.getType()); - - //verify the xml schema type annotation is not removed when the type is set to null - contextXmlJavaTypeAdapter.setType(null); - javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getType()); - assertNull(contextXmlJavaTypeAdapter.getType()); - } - - public void testUpdateType() throws Exception { - this.createPackageInfoWithXmlJavaTypeAdapter(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPackageInfo.getXmlJavaTypeAdapters().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlJavaTypeAdapter.getType()); - - //add a type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertFalse(contextPackageInfo.getXmlJavaTypeAdapters().iterator().hasNext()); - } - - protected void addXmlJavaTypeAdapterTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlJavaTypeAdapterAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected void addXmlJavaTypeAdapterMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlJavaTypeAdapterAnnotation(declaration), name, value); - } - - //add another package annotation so that the context model object doesn't get removed when - //removing the XmlJavaTypeAdapter annotation. Only "annotated" packages are added to the context model - protected void removeXmlJavaTypeAdapterAnnotation(ModifiedDeclaration declaration) { - this.addMarkerAnnotation(declaration.getDeclaration(), XmlAccessorOrderAnnotation.ANNOTATION_NAME); - this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - protected Annotation getXmlJavaTypeAdapterAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlRootElementTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlRootElementTests.java deleted file mode 100644 index 6e21ab2044..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlRootElementTests.java +++ /dev/null @@ -1,149 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlRootElement; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.AbstractJavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaXmlRootElementTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlRootElementTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlTypeWithXmlRootElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ROOT_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").append(CR); - sb.append("@XmlRootElement").append(CR); - } - }); - } - - - public void testModifyNamespace() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getNamespace()); - - contextRootElement.setNamespace("foo"); - XmlRootElementAnnotation rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", rootElementAnnotation.getNamespace()); - assertEquals("foo", contextRootElement.getNamespace()); - - contextRootElement.setNamespace(null); - rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(rootElementAnnotation.getNamespace()); - assertNull(contextRootElement.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getNamespace()); - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlRootElementTests.this.addXmlRootElementMemberValuePair(declaration, JAXB.XML_ROOT_ELEMENT__NAMESPACE, "foo"); - } - }); - assertEquals("foo", contextRootElement.getNamespace()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlRootElementTests.this.removeAnnotation(declaration, XmlRootElementAnnotation.ANNOTATION_NAME); - } - }); - contextRootElement = persistentClass.getRootElement(); - assertNull(contextRootElement); - } - - public void testModifyName() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getName()); - - contextRootElement.setName("foo"); - XmlRootElementAnnotation rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", rootElementAnnotation.getName()); - assertEquals("foo", contextRootElement.getName()); - - contextRootElement.setName(null); - rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(rootElementAnnotation.getName()); - assertNull(contextRootElement.getName()); - } - - public void testUpdateName() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - AbstractJavaResourceType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getName()); - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlRootElementTests.this.addXmlRootElementMemberValuePair(declaration, JAXB.XML_ROOT_ELEMENT__NAME, "foo"); - } - }); - assertEquals("foo", contextRootElement.getName()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlRootElementTests.this.removeAnnotation(declaration, XmlRootElementAnnotation.ANNOTATION_NAME); - } - }); - contextRootElement = persistentClass.getRootElement(); - assertNull(contextRootElement); - } - - protected void addXmlRootElementMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlRootElementAnnotation(declaration), name, value); - } - - protected Annotation getXmlRootElementAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlRootElementAnnotation.ANNOTATION_NAME); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java deleted file mode 100644 index 24bd638e08..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTests.java +++ /dev/null @@ -1,662 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.ListIterator; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.XmlAccessType; -import org.eclipse.jpt.jaxb.core.context.XmlNs; -import org.eclipse.jpt.jaxb.core.context.XmlNsForm; -import org.eclipse.jpt.jaxb.core.context.XmlSchema; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterables.ListIterable; - - -@SuppressWarnings("nls") -public class GenericJavaXmlSchemaTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlSchemaTests(String name) { - super(name); - } - - private ICompilationUnit createPackageInfoWithXmlSchema() throws CoreException { - return createTestPackageInfo( - "@XmlSchema", - JAXB.XML_SCHEMA); - } - - private ICompilationUnit createPackageInfoWithAccessorType() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorType(value = XmlAccessType.PROPERTY)", - JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE); - } - - public void testModifyNamespace() throws Exception { - createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals("", contextXmlSchema.getNamespace()); - assertNull(contextXmlSchema.getSpecifiedNamespace()); - - contextXmlSchema.setSpecifiedNamespace("foo"); - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaAnnotation.getNamespace()); - assertEquals("foo", contextXmlSchema.getNamespace()); - assertEquals("foo", contextXmlSchema.getSpecifiedNamespace()); - - //set another annotation so the context model is not blown away by removing the XmlSchema annotation - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - contextXmlSchema.setSpecifiedNamespace(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation); - assertEquals("", contextXmlSchema.getNamespace()); - assertNull(contextXmlSchema.getSpecifiedNamespace()); - - //set namespace again, this time starting with no XmlSchema annotation - contextXmlSchema.setSpecifiedNamespace("foo"); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaAnnotation.getNamespace()); - assertEquals("foo", contextXmlSchema.getSpecifiedNamespace()); - assertEquals("foo", contextXmlSchema.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals("", contextXmlSchema.getNamespace()); - assertNull(contextXmlSchema.getSpecifiedNamespace()); - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlSchemaMemberValuePair(declaration, JAXB.XML_SCHEMA__NAMESPACE, "foo"); - } - }); - assertEquals("foo", contextXmlSchema.getNamespace()); - assertEquals("foo", contextXmlSchema.getSpecifiedNamespace()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertEquals("", contextXmlSchema.getNamespace()); - assertNull(contextXmlSchema.getSpecifiedNamespace()); - } - - public void testModifyLocation() throws Exception { - createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getLocation()); - - contextXmlSchema.setLocation("foo"); - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaAnnotation.getLocation()); - assertEquals("foo", contextXmlSchema.getLocation()); - - //set another annotation so the context model is not blown away by removing the XmlSchema annotation - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - contextXmlSchema.setLocation(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation); - assertNull(contextXmlSchema.getLocation()); - - //set location again, this time starting with no XmlSchema annotation - contextXmlSchema.setLocation("foo"); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaAnnotation.getLocation()); - assertEquals("foo", contextXmlSchema.getLocation()); - } - - public void testUpdateLocation() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getLocation()); - - //add a location member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlSchemaMemberValuePair(declaration, JAXB.XML_SCHEMA__LOCATION, "foo"); - } - }); - - assertEquals("foo", contextXmlSchema.getLocation()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertNull(contextXmlSchema.getLocation()); - } - - public void testModifyAttributeFormDefault() throws Exception { - createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getAttributeFormDefault()); - - contextXmlSchema.setAttributeFormDefault(XmlNsForm.QUALIFIED); - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getAttributeFormDefault()); - - contextXmlSchema.setAttributeFormDefault(XmlNsForm.UNQUALIFIED); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.UNQUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getAttributeFormDefault()); - - //set another annotation so the context model is not blown away by removing the XmlSchema annotation - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - contextXmlSchema.setAttributeFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation); - assertNull(contextXmlSchema.getAttributeFormDefault()); - - //set attribute form default again, this time starting with no XmlSchema annotation - contextXmlSchema.setAttributeFormDefault(XmlNsForm.QUALIFIED); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getAttributeFormDefault()); - } - - public void testUpdateAttributeFormDefault() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getAttributeFormDefault()); - - //set the attribute form default value to QUALIFIED - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlSchemaEnumMemberValuePair( - declaration, - JAXB.XML_SCHEMA__ATTRIBUTE_FORM_DEFAULT, - JAXB.XML_NS_FORM__QUALIFIED); - } - }); - - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getAttributeFormDefault()); - - - //set the attribute form default value to UNQUALIFIED - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.setXmlSchemaEnumMemberValuePair( - declaration, - JAXB.XML_SCHEMA__ATTRIBUTE_FORM_DEFAULT, - JAXB.XML_NS_FORM__UNQUALIFIED); - } - }); - - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getAttributeFormDefault()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertNull(contextXmlSchema.getAttributeFormDefault()); - } - - public void testModifyElementFormDefault() throws Exception { - createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getElementFormDefault()); - - contextXmlSchema.setElementFormDefault(XmlNsForm.QUALIFIED); - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getElementFormDefault()); - - contextXmlSchema.setElementFormDefault(XmlNsForm.UNQUALIFIED); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.UNQUALIFIED, schemaAnnotation.getElementFormDefault()); - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getElementFormDefault()); - - //set another annotation so the context model is not blown away by removing the XmlSchema annotation - contextPackageInfo.setSpecifiedAccessType(XmlAccessType.FIELD); - contextXmlSchema.setElementFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation); - assertNull(contextXmlSchema.getElementFormDefault()); - - //set element form default again, this time starting with no XmlSchema annotation - contextXmlSchema.setElementFormDefault(XmlNsForm.QUALIFIED); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getElementFormDefault()); - } - - public void testUpdateElementFormDefault() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchema.getElementFormDefault()); - - //set the element form default value to QUALIFIED - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlSchemaEnumMemberValuePair( - declaration, - JAXB.XML_SCHEMA__ELEMENT_FORM_DEFAULT, - JAXB.XML_NS_FORM__QUALIFIED); - } - }); - - assertEquals(XmlNsForm.QUALIFIED, contextXmlSchema.getElementFormDefault()); - - - //set the element form default value to UNQUALIFIED - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.setXmlSchemaEnumMemberValuePair( - declaration, - JAXB.XML_SCHEMA__ELEMENT_FORM_DEFAULT, - JAXB.XML_NS_FORM__UNQUALIFIED); - } - }); - - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getElementFormDefault()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertNull(contextXmlSchema.getElementFormDefault()); - } - - public void testGetXmlNsPrefixes() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes(); - assertFalse(xmlNsPrefixes.iterator().hasNext()); - - //add 2 XmlNs prefixes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix"); - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix"); - } - }); - - xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes(); - ListIterator<XmlNs> xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - XmlNs xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("bar", xmlNsPref.getNamespaceURI()); - assertEquals("barPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("foo", xmlNsPref.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - } - - protected void addXmlNs(ModifiedDeclaration declaration, int index, String namespaceURI, String prefix) { - NormalAnnotation arrayElement = this.newXmlNsAnnotation(declaration.getAst(), namespaceURI, prefix); - this.addArrayElement(declaration, JAXB.XML_SCHEMA, index, JAXB.XML_SCHEMA__XMLNS, arrayElement); - } - - protected NormalAnnotation newXmlNsAnnotation(AST ast, String namespaceURI, String prefix) { - NormalAnnotation annotation = this.newNormalAnnotation(ast, JAXB.XML_NS); - this.addMemberValuePair(annotation, JAXB.XML_NS__NAMESPACE_URI, namespaceURI); - this.addMemberValuePair(annotation, JAXB.XML_NS__PREFIX, prefix); - return annotation; - } - - public void testGetXmlNsPrexiesSize() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertEquals(0, contextXmlSchema.getXmlNsPrefixesSize()); - - //add 2 XmlNs prefixes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix"); - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix"); - } - }); - assertEquals(2, contextXmlSchema.getXmlNsPrefixesSize()); - } - - public void testAddXmlNsPrefix() throws Exception { - //create a package info with an annotation other than XmlSchema to test - //adding things to the null schema annotation - this.createPackageInfoWithAccessorType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - XmlNs xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0); - xmlNsPrefix.setNamespaceURI("bar"); - xmlNsPrefix.setPrefix("barPrefix"); - xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0); - xmlNsPrefix.setNamespaceURI("foo"); - xmlNsPrefix.setPrefix("fooPrefix"); - xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0); - xmlNsPrefix.setNamespaceURI("baz"); - xmlNsPrefix.setPrefix("bazPrefix"); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator(); - - XmlNsAnnotation xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("baz", xmlNsAnnotation.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsAnnotation.getPrefix()); - xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("foo", xmlNsAnnotation.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsAnnotation.getPrefix()); - xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("bar", xmlNsAnnotation.getNamespaceURI()); - assertEquals("barPrefix", xmlNsAnnotation.getPrefix()); - assertFalse(xmlNsPrefixes.hasNext()); - } - - public void testAddXmlNsPrefix2() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - XmlNs xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0); - xmlNsPrefix.setNamespaceURI("bar"); - xmlNsPrefix.setPrefix("barPrefix"); - xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(1); - xmlNsPrefix.setNamespaceURI("foo"); - xmlNsPrefix.setPrefix("fooPrefix"); - xmlNsPrefix = contextXmlSchema.addXmlNsPrefix(0); - xmlNsPrefix.setNamespaceURI("baz"); - xmlNsPrefix.setPrefix("bazPrefix"); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator(); - - XmlNsAnnotation xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("baz", xmlNsAnnotation.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsAnnotation.getPrefix()); - xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("bar", xmlNsAnnotation.getNamespaceURI()); - assertEquals("barPrefix", xmlNsAnnotation.getPrefix()); - xmlNsAnnotation = xmlNsPrefixes.next(); - assertEquals("foo", xmlNsAnnotation.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsAnnotation.getPrefix()); - assertFalse(xmlNsPrefixes.hasNext()); - } - - public void testRemoveXmlNsPrefix() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextXmlSchema.addXmlNsPrefix(0).setNamespaceURI("bar"); - contextXmlSchema.addXmlNsPrefix(1).setNamespaceURI("foo"); - contextXmlSchema.addXmlNsPrefix(2).setNamespaceURI("baz"); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertEquals(3, schemaAnnotation.getXmlnsSize()); - - contextXmlSchema.removeXmlNsPrefix(1); - - ListIterator<XmlNsAnnotation> xmlNsPrefixes = schemaAnnotation.getXmlns().iterator(); - assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI()); - assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI()); - assertFalse(xmlNsPrefixes.hasNext()); - - contextXmlSchema.removeXmlNsPrefix(1); - xmlNsPrefixes = schemaAnnotation.getXmlns().iterator(); - assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI()); - assertFalse(xmlNsPrefixes.hasNext()); - - contextXmlSchema.removeXmlNsPrefix(0); - xmlNsPrefixes = schemaAnnotation.getXmlns().iterator(); - assertFalse(xmlNsPrefixes.hasNext()); - } - - public void testMoveXmlNsPrefix() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - contextXmlSchema.addXmlNsPrefix(0).setNamespaceURI("bar"); - contextXmlSchema.addXmlNsPrefix(1).setNamespaceURI("foo"); - contextXmlSchema.addXmlNsPrefix(2).setNamespaceURI("baz"); - - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - - assertEquals(3, schemaAnnotation.getXmlnsSize()); - - contextXmlSchema.moveXmlNsPrefix(2, 0); - ListIterator<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes().iterator(); - assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI()); - assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI()); - assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI()); - assertFalse(xmlNsPrefixes.hasNext()); - - ListIterator<XmlNsAnnotation> xmlNsAnnotations = schemaAnnotation.getXmlns().iterator(); - assertEquals("foo", xmlNsAnnotations.next().getNamespaceURI()); - assertEquals("baz", xmlNsAnnotations.next().getNamespaceURI()); - assertEquals("bar", xmlNsAnnotations.next().getNamespaceURI()); - - - contextXmlSchema.moveXmlNsPrefix(0, 1); - xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes().iterator(); - assertEquals("baz", xmlNsPrefixes.next().getNamespaceURI()); - assertEquals("foo", xmlNsPrefixes.next().getNamespaceURI()); - assertEquals("bar", xmlNsPrefixes.next().getNamespaceURI()); - assertFalse(xmlNsPrefixes.hasNext()); - - xmlNsAnnotations = schemaAnnotation.getXmlns().iterator(); - assertEquals("baz", xmlNsAnnotations.next().getNamespaceURI()); - assertEquals("foo", xmlNsAnnotations.next().getNamespaceURI()); - assertEquals("bar", xmlNsAnnotations.next().getNamespaceURI()); - } - - public void testSyncXmlNsPrefixes() throws Exception { - this.createPackageInfoWithXmlSchema(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchema contextXmlSchema = contextPackageInfo.getXmlSchema(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - ListIterable<XmlNs> xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes(); - assertFalse(xmlNsPrefixes.iterator().hasNext()); - - //add 3 XmlNs prefixes - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 0, "bar", "barPrefix"); - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 1, "foo", "fooPrefix"); - GenericJavaXmlSchemaTests.this.addXmlNs(declaration, 2, "baz", "bazPrefix"); - } - }); - - xmlNsPrefixes = contextXmlSchema.getXmlNsPrefixes(); - ListIterator<XmlNs> xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - XmlNs xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("bar", xmlNsPref.getNamespaceURI()); - assertEquals("barPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("foo", xmlNsPref.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("baz", xmlNsPref.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.moveXmlNsPrefix(declaration, 2, 0); - } - }); - - xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("foo", xmlNsPref.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("baz", xmlNsPref.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("bar", xmlNsPref.getNamespaceURI()); - assertEquals("barPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.moveXmlNsPrefix(declaration, 0, 1); - } - }); - - xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("baz", xmlNsPref.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("foo", xmlNsPref.getNamespaceURI()); - assertEquals("fooPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("bar", xmlNsPref.getNamespaceURI()); - assertEquals("barPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 1); - } - }); - - xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("baz", xmlNsPref.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsPref.getPrefix()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("bar", xmlNsPref.getNamespaceURI()); - assertEquals("barPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 1); - } - }); - - xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertTrue(xmlNsPrefixesIterator.hasNext()); - xmlNsPref = xmlNsPrefixesIterator.next(); - assertEquals("baz", xmlNsPref.getNamespaceURI()); - assertEquals("bazPrefix", xmlNsPref.getPrefix()); - assertFalse(xmlNsPrefixesIterator.hasNext()); - - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlNsPrefix(declaration, 0); - } - }); - - xmlNsPrefixesIterator = xmlNsPrefixes.iterator(); - assertFalse(xmlNsPrefixesIterator.hasNext()); - } - - protected void addXmlSchemaEnumMemberValuePair(ModifiedDeclaration declaration, String elementName, String value) { - this.addEnumMemberValuePair((MarkerAnnotation) this.getXmlSchemaAnnotation(declaration), elementName, value); - } - - protected void setXmlSchemaEnumMemberValuePair(ModifiedDeclaration declaration, String elementName, String enumValue) { - this.setEnumMemberValuePair((NormalAnnotation) this.getXmlSchemaAnnotation(declaration), elementName, enumValue); - } - - protected void addXmlSchemaMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlSchemaAnnotation(declaration), name, value); - } - - //add another package annotation so that the context model object doesn't get removed when - //removing the XmlSchema annotation. Only "annotated" packages are added to the context model - protected void removeXmlSchemaAnnotation(ModifiedDeclaration declaration) { - this.addMarkerAnnotation(declaration.getDeclaration(), XmlAccessorOrderAnnotation.ANNOTATION_NAME); - this.removeAnnotation(declaration, XmlSchemaAnnotation.ANNOTATION_NAME); - } - - protected Annotation getXmlSchemaAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlSchemaAnnotation.ANNOTATION_NAME); - } - - protected void moveXmlNsPrefix(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - this.moveArrayElement((NormalAnnotation) getXmlSchemaAnnotation(declaration), JAXB.XML_SCHEMA__XMLNS, targetIndex, sourceIndex); - } - - protected void removeXmlNsPrefix(ModifiedDeclaration declaration, int index) { - this.removeArrayElement((NormalAnnotation) getXmlSchemaAnnotation(declaration), JAXB.XML_SCHEMA__XMLNS, index); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java deleted file mode 100644 index c5e96bfb83..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSchemaTypeTests.java +++ /dev/null @@ -1,199 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jpt.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.XmlSchemaType; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; - - -@SuppressWarnings("nls") -public class GenericJavaXmlSchemaTypeTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlSchemaTypeTests(String name) { - super(name); - } - - private ICompilationUnit createPackageInfoWithXmlSchemaType() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaType", - JAXB.XML_SCHEMA_TYPE); - } - - public void testModifyName() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getName()); - - contextXmlSchemaType.setName("foo"); - XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaTypeAnnotation.getName()); - assertEquals("foo", contextXmlSchemaType.getName()); - - //verify the xml schema type annotation is not removed when the name is set to null - contextXmlSchemaType.setName(null); - schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(schemaTypeAnnotation.getName()); - assertNull(contextXmlSchemaType.getName()); - } - - public void testUpdateName() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getName()); - - //add a name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__NAME, "foo"); - } - }); - assertEquals("foo", contextXmlSchemaType.getName()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration); - } - }); - assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext()); - } - - public void testModifyNamespace() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getNamespace()); - - contextXmlSchemaType.setNamespace("foo"); - XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaTypeAnnotation.getNamespace()); - assertEquals("foo", contextXmlSchemaType.getNamespace()); - - //verify the xml schema type annotation is not removed when the namespace is set to null - contextXmlSchemaType.setNamespace(null); - schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(schemaTypeAnnotation.getNamespace()); - assertNull(contextXmlSchemaType.getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getNamespace()); - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__NAMESPACE, "foo"); - } - }); - assertEquals("foo", contextXmlSchemaType.getNamespace()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration); - } - }); - assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext()); - } - - public void testModifyType() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getType()); - - contextXmlSchemaType.setType("foo"); - XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaTypeAnnotation.getType()); - assertEquals("foo", contextXmlSchemaType.getType()); - - //verify the xml schema type annotation is not removed when the type is set to null - contextXmlSchemaType.setType(null); - schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(schemaTypeAnnotation.getType()); - assertNull(contextXmlSchemaType.getType()); - } - - public void testUpdateType() throws Exception { - this.createPackageInfoWithXmlSchemaType(); - JaxbPackageInfo contextPackageInfo = CollectionTools.get(getContextRoot().getPackages(), 0).getPackageInfo(); - XmlSchemaType contextXmlSchemaType = contextPackageInfo.getXmlSchemaTypes().iterator().next(); - JavaResourcePackage resourcePackage = contextPackageInfo.getResourcePackage(); - - assertNull(contextXmlSchemaType.getType()); - - //add a type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.addXmlSchemaTypeTypeMemberValuePair(declaration, JAXB.XML_SCHEMA_TYPE__TYPE, "String"); - } - }); - assertEquals("String", contextXmlSchemaType.getType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTypeTests.this.removeXmlSchemaTypeAnnotation(declaration); - } - }); - assertFalse(contextPackageInfo.getXmlSchemaTypes().iterator().hasNext()); - } - - protected void addXmlSchemaTypeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlSchemaTypeAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected void addXmlSchemaTypeMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlSchemaTypeAnnotation(declaration), name, value); - } - - //add another package annotation so that the context model object doesn't get removed when - //removing the XmlSchemaType annotation. Only "annotated" packages are added to the context model - protected void removeXmlSchemaTypeAnnotation(ModifiedDeclaration declaration) { - this.addMarkerAnnotation(declaration.getDeclaration(), XmlAccessorOrderAnnotation.ANNOTATION_NAME); - this.removeAnnotation(declaration, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - - protected Annotation getXmlSchemaTypeAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java deleted file mode 100644 index 64e2830472..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/JaxbCoreJavaContextModelTests.java +++ /dev/null @@ -1,37 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JaxbCoreJavaContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JaxbCoreJavaContextModelTests.class.getName()); - suite.addTestSuite(GenericJavaElementFactoryMethodTests.class); - suite.addTestSuite(GenericJavaEnumConstantTests.class); - suite.addTestSuite(GenericJavaPackageInfoTests.class); - suite.addTestSuite(GenericJavaPersistentClassTests.class); - suite.addTestSuite(GenericJavaPersistentEnumTests.class); - suite.addTestSuite(GenericJavaRegistryTests.class); - suite.addTestSuite(GenericJavaXmlJavaTypeAdapterTests.class); - suite.addTestSuite(GenericJavaXmlRootElementTests.class); - suite.addTestSuite(GenericJavaXmlSchemaTests.class); - suite.addTestSuite(GenericJavaXmlSchemaTypeTests.class); - return suite; - } - - private JaxbCoreJavaContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java deleted file mode 100644 index a75bf5bb32..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java +++ /dev/null @@ -1,64 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.jaxb.core.JaxbFacet; -import org.eclipse.jpt.jaxb.core.JaxbProject; -import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; -import org.eclipse.jpt.jaxb.core.internal.facet.JaxbFacetInstallConfig; - -/** - * This builds and holds a "JAXB" project. - * Support for adding packages and types. - * - * The JPA project's settings (platform, database connection, etc.) can be - * controlled by building a data model and passing it into the constructor. - */ -@SuppressWarnings("nls") -public class TestJaxbProject extends TestJavaProject { - private final JaxbProject jaxbProject; - - - // ********** builders ********** - - public static TestJaxbProject buildJaxbProject(String baseProjectName, boolean autoBuild, JaxbFacetInstallConfig config) - throws CoreException { - return new TestJaxbProject(baseProjectName, autoBuild, config); - } - - // ********** constructors/initialization ********** - - public TestJaxbProject(String projectName) throws CoreException { - this(projectName, false); - } - - public TestJaxbProject(String projectName, boolean autoBuild) throws CoreException { - this(projectName, autoBuild, null); - } - - public TestJaxbProject(String projectName, boolean autoBuild, JaxbFacetInstallConfig config) throws CoreException { - super(projectName, autoBuild); - String jaxbFacetVersion = config.getProjectFacetVersion().getVersionString(); - this.installFacet(JaxbFacet.ID, jaxbFacetVersion, config); - this.jaxbProject = JptJaxbCorePlugin.getJaxbProject(this.getProject()); -// this.jaxbProject.setUpdater(new SynchronousJpaProjectUpdater(this.jaxbProject)); - } - - - - // ********** public methods ********** - - public JaxbProject getJaxbProject() { - return this.jaxbProject; - } - -} 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 deleted file mode 100644 index 18e284c963..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java +++ /dev/null @@ -1,32 +0,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 - *******************************************************************************/ -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; - - -public class JaxbCoreResourceModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JaxbCoreResourceModelTests.class.getName()); - - suite.addTest(JaxbJavaResourceModelTests.suite()); - 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/JavaResourceModelTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JavaResourceModelTestCase.java deleted file mode 100644 index 20026d4f7f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JavaResourceModelTestCase.java +++ /dev/null @@ -1,197 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.internal.utility.jdt.NullAnnotationEditFormatter; -import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.jaxb.core.AnnotationProvider; -import org.eclipse.jpt.jaxb.core.internal.GenericAnnotationProvider; -import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourcePackageInfoCompilationUnit; -import org.eclipse.jpt.jaxb.core.internal.resource.java.source.SourceTypeCompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.AbstractJavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceCompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackageInfoCompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.NestableAnnotationDefinition; -import org.eclipse.jpt.utility.CommandExecutor; -import org.eclipse.jpt.utility.internal.BitTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.ReflectionTools; -import org.eclipse.jpt.utility.internal.StringTools; - -@SuppressWarnings("nls") -public abstract class JavaResourceModelTestCase - extends AnnotationTestCase { - - private JavaElementChangeListener javaElementChangeListener; - protected JavaResourceCompilationUnit javaResourceCompilationUnit; - - - public JavaResourceModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.javaElementChangeListener = new JavaElementChangeListener(); - JavaCore.addElementChangedListener(this.javaElementChangeListener); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - JavaCore.removeElementChangedListener(this.javaElementChangeListener); - this.javaElementChangeListener = null; - } - - private class JavaElementChangeListener - implements IElementChangedListener { - - JavaElementChangeListener() { - super(); - } - - public void elementChanged(ElementChangedEvent event) { - JavaResourceModelTestCase.this.javaElementChanged(event); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - void javaElementChanged(ElementChangedEvent event) { - if (this.javaResourceCompilationUnit == null) { - return; - } - this.syncWithJavaDelta(event.getDelta()); - } - - /** - * NB: this is copied from GenericJpaProject, so it might need to be - * kept in synch with that code if it changes... yech... - */ - protected void syncWithJavaDelta(IJavaElementDelta delta) { - switch (delta.getElement().getElementType()) { - case IJavaElement.JAVA_MODEL : - case IJavaElement.JAVA_PROJECT : - case IJavaElement.PACKAGE_FRAGMENT_ROOT : - case IJavaElement.PACKAGE_FRAGMENT : - this.syncWithJavaDeltaChildren(delta); - break; - case IJavaElement.COMPILATION_UNIT : - this.javaCompilationUnitChanged(delta); - break; - default : - break; // ignore the elements inside a compilation unit - } - } - - protected void syncWithJavaDeltaChildren(IJavaElementDelta delta) { - for (IJavaElementDelta child : delta.getAffectedChildren()) { - this.syncWithJavaDelta(child); // recurse - } - } - - protected void javaCompilationUnitChanged(IJavaElementDelta delta) { - if (this.deltaIsRelevant(delta)) { - this.javaResourceCompilationUnit.synchronizeWithJavaSource(); - } - } - - protected boolean deltaIsRelevant(IJavaElementDelta delta) { - if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { - return false; - } - return delta.getKind() == IJavaElementDelta.CHANGED; - } - - protected ICompilationUnit createAnnotationAndMembers(String packageName, String annotationName, String annotationBody) throws Exception { - return this.javaProject.createCompilationUnit(packageName, annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - protected ICompilationUnit createEnumAndMembers(String packageName, String enumName, String enumBody) throws Exception { - return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } - - protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) { - JavaResourcePackageInfoCompilationUnit pkgCu = - new SourcePackageInfoCompilationUnit( - cu, - this.buildAnnotationProvider(), - NullAnnotationEditFormatter.instance(), - CommandExecutor.Default.instance()); - this.javaResourceCompilationUnit = pkgCu; - return pkgCu.getPackage(); - } - - protected JavaResourceType buildJavaResourceType(ICompilationUnit cu) { - return (JavaResourceType) this.buildJavaResourceType_(cu); - } - - protected JavaResourceEnum buildJavaResourceEnum(ICompilationUnit cu) { - return (JavaResourceEnum) this.buildJavaResourceType_(cu); - } - - private AbstractJavaResourceType buildJavaResourceType_(ICompilationUnit cu) { - this.javaResourceCompilationUnit = this.buildJavaResourceCompilationUnit(cu); - this.javaResourceCompilationUnit.resolveTypes(); - return this.hackJavaResourceType(); - } - - protected JavaResourceField getField(JavaResourceType type, int index) { - return CollectionTools.get(type.getFields(), index); - } - - protected JavaResourceMethod getMethod(JavaResourceType type, int index) { - return CollectionTools.get(type.getMethods(), index); - } - - protected JavaResourceEnumConstant getEnumConstant(JavaResourceEnum resourceEnum, int index) { - return CollectionTools.get(resourceEnum.getEnumConstants(), index); - } - - protected AbstractJavaResourceType hackJavaResourceType() { - return (AbstractJavaResourceType) ReflectionTools.getFieldValue(this.javaResourceCompilationUnit, "type"); - } - - protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) { - if (this.javaResourceCompilationUnit != null) { - throw new IllegalStateException(); - } - return new SourceTypeCompilationUnit( - cu, - this.buildAnnotationProvider(), - NullAnnotationEditFormatter.instance(), - CommandExecutor.Default.instance()); - } - - protected AnnotationProvider buildAnnotationProvider() { - return new GenericAnnotationProvider(this.annotationDefinitions(), this.nestableAnnotationDefinitions()); - } - - protected abstract AnnotationDefinition[] annotationDefinitions(); - - protected abstract NestableAnnotationDefinition[] nestableAnnotationDefinitions(); -} 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 deleted file mode 100644 index 863e0e0552..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTestCase.java +++ /dev/null @@ -1,33 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.jpt.jaxb.core.internal.jaxb21.GenericJaxb_2_1_PlatformDefinition; -import org.eclipse.jpt.jaxb.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.jaxb.core.resource.java.NestableAnnotationDefinition; - -public class JaxbJavaResourceModelTestCase - extends JavaResourceModelTestCase { - - public JaxbJavaResourceModelTestCase(String name) { - super(name); - } - - - @Override - protected AnnotationDefinition[] annotationDefinitions() { - return GenericJaxb_2_1_PlatformDefinition.instance().getAnnotationDefinitions(); - } - - @Override - protected NestableAnnotationDefinition[] nestableAnnotationDefinitions() { - return GenericJaxb_2_1_PlatformDefinition.instance().getNestableAnnotationDefinitions(); - } -} 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 deleted file mode 100644 index d76311ba11..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/JaxbJavaResourceModelTests.java +++ /dev/null @@ -1,61 +0,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 - ******************************************************************************/ -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(XmlAccessorOrderPackageAnnotationTests.class); - suite.addTestSuite(XmlAccessorOrderTypeAnnotationTests.class); - suite.addTestSuite(XmlAccessorTypePackageAnnotationTests.class); - suite.addTestSuite(XmlAccessorTypeTypeAnnotationTests.class); - suite.addTestSuite(XmlAnyAttributeAnnotationTests.class); - suite.addTestSuite(XmlAnyElementAnnotationTests.class); - suite.addTestSuite(XmlAttachmentRefAnnotationTests.class); - suite.addTestSuite(XmlAttributeAnnotationTests.class); - suite.addTestSuite(XmlElementAnnotationTests.class); - suite.addTestSuite(XmlElementDeclAnnotationTests.class); - suite.addTestSuite(XmlElementRefAnnotationTests.class); - suite.addTestSuite(XmlElementWrapperAnnotationTests.class); - suite.addTestSuite(XmlEnumAnnotationTests.class); - suite.addTestSuite(XmlEnumValueAnnotationTests.class); - suite.addTestSuite(XmlIDAnnotationTests.class); - suite.addTestSuite(XmlIDREFAnnotationTests.class); - suite.addTestSuite(XmlInlineBinaryDataAttributeAnnotationTests.class); - suite.addTestSuite(XmlInlineBinaryDataTypeAnnotationTests.class); - suite.addTestSuite(XmlJavaTypeAdapterPackageAnnotationTests.class); - suite.addTestSuite(XmlJavaTypeAdapterTypeAnnotationTests.class); - suite.addTestSuite(XmlListAnnotationTests.class); - suite.addTestSuite(XmlMimeTypeAnnotationTests.class); - suite.addTestSuite(XmlMixedAnnotationTests.class); - suite.addTestSuite(XmlRegistryAnnotationTests.class); - suite.addTestSuite(XmlRootElementAnnotationTests.class); - suite.addTestSuite(XmlSchemaAnnotationTests.class); - suite.addTestSuite(XmlSchemaTypeAttributeAnnotationTests.class); - suite.addTestSuite(XmlSchemaTypePackageAnnotationTests.class); - suite.addTestSuite(XmlSeeAlsoAnnotationTests.class); - suite.addTestSuite(XmlTransientAttributeAnnotationTests.class); - suite.addTestSuite(XmlTransientTypeAnnotationTests.class); - suite.addTestSuite(XmlTypeAnnotationTests.class); - suite.addTestSuite(XmlValueAnnotationTests.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/XmlAccessorOrderPackageAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorOrderPackageAnnotationTests.java deleted file mode 100644 index 5fde462795..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorOrderPackageAnnotationTests.java +++ /dev/null @@ -1,59 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; - -@SuppressWarnings("nls") -public class XmlAccessorOrderPackageAnnotationTests - extends JaxbJavaResourceModelTestCase { - - public XmlAccessorOrderPackageAnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createPackageInfoWithAccessorOrder() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorOrder(XmlAccessOrder.UNDEFINED)", - JAXB.XML_ACCESS_ORDER, JAXB.XML_ACCESSOR_ORDER); - } - - public void testValue() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithAccessorOrder(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlAccessorOrderAnnotation annotation = - (XmlAccessorOrderAnnotation) resourcePackage.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertTrue(annotation != null); - assertEquals(XmlAccessOrder.UNDEFINED, annotation.getValue()); - - annotation.setValue(XmlAccessOrder.ALPHABETICAL); - assertEquals(XmlAccessOrder.ALPHABETICAL, annotation.getValue()); - assertSourceContains("@XmlAccessorOrder(ALPHABETICAL)", cu); - - annotation.setValue(null); - assertNull(resourcePackage.getAnnotation(JAXB.XML_ACCESSOR_ORDER)); - assertSourceDoesNotContain("@XmlAccessorOrder", cu); - -// TODO uncomment when bug 328400 is addressed -// annotation = (XmlAccessorOrderAnnotation) packageResource.addAnnotation(JAXB.XML_ACCESSOR_ORDER); -// annotation.setValue(XmlAccessOrder.UNDEFINED); -// assertEquals(XmlAccessOrder.UNDEFINED, annotation.getValue()); -// assertSourceContains("@XmlAccessorOrder(UNDEFINED)", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorOrderTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorOrderTypeAnnotationTests.java deleted file mode 100644 index cb39c66a01..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorOrderTypeAnnotationTests.java +++ /dev/null @@ -1,96 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAccessorOrderTypeAnnotationTests - extends JaxbJavaResourceModelTestCase { - - public XmlAccessorOrderTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAccessorOrder() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ACCESSOR_ORDER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlAccessorOrder"); - } - }); - } - - private ICompilationUnit createTestXmlAccessorOrderWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ACCESSOR_ORDER, JAXB.XML_ACCESS_ORDER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlAccessorOrder(value = XmlAccessOrder.ALPHABETICAL)"); - } - }); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorOrder(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorOrderAnnotation xmlAccessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertTrue(xmlAccessorOrderAnnotation != null); - assertNull(xmlAccessorOrderAnnotation.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorOrderWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorOrderAnnotation xmlAccessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertEquals(XmlAccessOrder.ALPHABETICAL, xmlAccessorOrderAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorOrder(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorOrderAnnotation xmlAccessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertEquals(null, xmlAccessorOrderAnnotation.getValue()); - - xmlAccessorOrderAnnotation.setValue(XmlAccessOrder.UNDEFINED); - assertEquals(XmlAccessOrder.UNDEFINED, xmlAccessorOrderAnnotation.getValue()); - - assertSourceContains("@XmlAccessorOrder(UNDEFINED)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorOrderWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorOrderAnnotation xmlAccessorOrderAnnotation = (XmlAccessorOrderAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertEquals(XmlAccessOrder.ALPHABETICAL, xmlAccessorOrderAnnotation.getValue()); - - xmlAccessorOrderAnnotation.setValue(null); - assertNull(xmlAccessorOrderAnnotation.getValue()); - - assertSourceDoesNotContain("@XmlAccessorOrder", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypePackageAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypePackageAnnotationTests.java deleted file mode 100644 index fac334d210..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypePackageAnnotationTests.java +++ /dev/null @@ -1,67 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation; - -@SuppressWarnings("nls") -public class XmlAccessorTypePackageAnnotationTests - extends JaxbJavaResourceModelTestCase { - - public XmlAccessorTypePackageAnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createPackageInfoWithAccessorType() throws CoreException { - return createTestPackageInfo( - "@XmlAccessorType(value = XmlAccessType.PROPERTY)", - JAXB.XML_ACCESS_TYPE, JAXB.XML_ACCESSOR_TYPE); - } - - public void testValue() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithAccessorType(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlAccessorTypeAnnotation annotation = - (XmlAccessorTypeAnnotation) resourcePackage.getAnnotation(JAXB.XML_ACCESSOR_TYPE); - assertTrue(annotation != null); - assertEquals(XmlAccessType.PROPERTY, annotation.getValue()); - - annotation.setValue(XmlAccessType.FIELD); - assertEquals(XmlAccessType.FIELD, annotation.getValue()); - assertSourceContains("@XmlAccessorType(value = FIELD)", cu); - - annotation.setValue(XmlAccessType.NONE); - assertEquals(XmlAccessType.NONE, annotation.getValue()); - assertSourceContains("@XmlAccessorType(value = NONE)", cu); - - annotation.setValue(XmlAccessType.PUBLIC_MEMBER); - assertEquals(XmlAccessType.PUBLIC_MEMBER, annotation.getValue()); - assertSourceContains("@XmlAccessorType(value = PUBLIC_MEMBER)", cu); - - annotation.setValue(null); - assertNull(resourcePackage.getAnnotation(JAXB.XML_ACCESSOR_TYPE)); - assertSourceDoesNotContain("@XmlAccessorType", cu); - -// TODO uncomment when bug 328400 is addressed -// annotation = (XmlAccessorTypeAnnotation) packageResource.addAnnotation(JAXB.XML_ACCESSOR_TYPE); -// annotation.setValue(XmlAccessType.PROPERTY); -// assertEquals(XmlAccessType.PROPERTY, annotation.getValue()); -// assertSourceContains("@XmlAccessorType(PROPERTY)", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeTypeAnnotationTests.java deleted file mode 100644 index 392c4d39a5..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAccessorTypeTypeAnnotationTests.java +++ /dev/null @@ -1,106 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAccessorTypeTypeAnnotationTests - extends JaxbJavaResourceModelTestCase { - - public XmlAccessorTypeTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAccessorType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ACCESSOR_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlAccessorType"); - } - }); - } - - private ICompilationUnit createTestXmlAccessorTypeWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ACCESSOR_TYPE, JAXB.XML_ACCESS_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlAccessorType(value = XmlAccessType.FIELD)"); - } - }); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_TYPE); - assertTrue(xmlAccessorTypeAnnotation != null); - assertNull(xmlAccessorTypeAnnotation.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorTypeWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_TYPE); - assertEquals(XmlAccessType.FIELD, xmlAccessorTypeAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_TYPE); - assertEquals(null, xmlAccessorTypeAnnotation.getValue()); - - xmlAccessorTypeAnnotation.setValue(XmlAccessType.PUBLIC_MEMBER); - assertEquals(XmlAccessType.PUBLIC_MEMBER, xmlAccessorTypeAnnotation.getValue()); - - assertSourceContains("@XmlAccessorType(PUBLIC_MEMBER)", cu); - - xmlAccessorTypeAnnotation.setValue(XmlAccessType.PROPERTY); - assertEquals(XmlAccessType.PROPERTY, xmlAccessorTypeAnnotation.getValue()); - - assertSourceContains("@XmlAccessorType(PROPERTY)", cu); - - xmlAccessorTypeAnnotation.setValue(XmlAccessType.NONE); - assertEquals(XmlAccessType.NONE, xmlAccessorTypeAnnotation.getValue()); - - assertSourceContains("@XmlAccessorType(NONE)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAccessorTypeWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlAccessorTypeAnnotation xmlAccessorTypeAnnotation = (XmlAccessorTypeAnnotation) resourceType.getAnnotation(JAXB.XML_ACCESSOR_TYPE); - assertEquals(XmlAccessType.FIELD, xmlAccessorTypeAnnotation.getValue()); - - xmlAccessorTypeAnnotation.setValue(null); - assertNull(xmlAccessorTypeAnnotation.getValue()); - - assertSourceDoesNotContain("@XmlAccessorType", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyAttributeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyAttributeAnnotationTests.java deleted file mode 100644 index b3dcc09b9f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyAttributeAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyAttributeAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAnyAttributeAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlAnyAttributeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAnyAttribute() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ANY_ATTRIBUTE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyAttribute"); - } - }); - } - - public void testGetXmlAnyAttribute() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyAttribute(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAnyAttributeAnnotation xmlAnyAttributeAnnotation = (XmlAnyAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ATTRIBUTE); - assertTrue(xmlAnyAttributeAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_ANY_ATTRIBUTE); - assertSourceDoesNotContain("@XmlAnyAttribute", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyElementAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyElementAnnotationTests.java deleted file mode 100644 index 770e443f9c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAnyElementAnnotationTests.java +++ /dev/null @@ -1,136 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyElementAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAnyElementAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ANY_ELEMENT_VALUE = "String"; - - public XmlAnyElementAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAnyElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ANY_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyElement"); - } - }); - } - - private ICompilationUnit createTestXmlAnyElementWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ANY_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyElement(" + booleanElement + " = true)"); - } - }); - } - - private ICompilationUnit createTestXmlAnyElementWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ANY_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyElement(value = " + XML_ANY_ELEMENT_VALUE + ".class)"); - } - }); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ELEMENT); - assertTrue(xmlAnyElementAnnotation != null); - assertNull(xmlAnyElementAnnotation.getLax()); - assertNull(xmlAnyElementAnnotation.getValue()); - } - - public void testGetLax() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyElementWithBooleanElement("lax"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ELEMENT); - - assertEquals(Boolean.TRUE, xmlAnyElementAnnotation.getLax()); - } - - public void testSetLax() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ELEMENT); - - assertNotNull(xmlAnyElementAnnotation); - assertNull(xmlAnyElementAnnotation.getLax()); - - xmlAnyElementAnnotation.setLax(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlAnyElementAnnotation.getLax()); - - assertSourceContains("@XmlAnyElement(lax = false)", cu); - - xmlAnyElementAnnotation.setLax(null); - assertSourceContains("@XmlAnyElement", cu); - assertSourceDoesNotContain("lax", cu); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyElementWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ELEMENT); - assertTrue(xmlAnyElementAnnotation != null); - assertEquals(XML_ANY_ELEMENT_VALUE, xmlAnyElementAnnotation.getValue()); - assertEquals("java.lang." + XML_ANY_ELEMENT_VALUE, xmlAnyElementAnnotation.getFullyQualifiedValueClassName()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlAnyElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ANY_ELEMENT); - assertNull(xmlAnyElementAnnotation.getValue()); - xmlAnyElementAnnotation.setValue(XML_ANY_ELEMENT_VALUE); - assertEquals(XML_ANY_ELEMENT_VALUE, xmlAnyElementAnnotation.getValue()); - - assertSourceContains("@XmlAnyElement(" + XML_ANY_ELEMENT_VALUE + ".class)", cu); - - xmlAnyElementAnnotation.setValue(null); - assertNull(xmlAnyElementAnnotation.getValue()); - - assertSourceContains("@XmlAnyElement", cu); - assertSourceDoesNotContain("@XmlAnyElement(value = " + XML_ANY_ELEMENT_VALUE + ".class)", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttachmentRefAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttachmentRefAnnotationTests.java deleted file mode 100644 index fbdb853078..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttachmentRefAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAttachmentRefAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlAttachmentRefAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAttachmentRef() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ATTACHMENT_REF); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttachmentRef"); - } - }); - } - - public void testGetXmlAttachmentRef() throws Exception { - ICompilationUnit cu = this.createTestXmlAttachmentRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTACHMENT_REF); - assertTrue(xmlAttachmentRefAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_ATTACHMENT_REF); - assertSourceDoesNotContain("@XmlAttachmentRef", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttributeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttributeAnnotationTests.java deleted file mode 100644 index 2b893dc537..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlAttributeAnnotationTests.java +++ /dev/null @@ -1,174 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlAttributeAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ATTRIBUTE_NAME = "elementName"; - private static final String XML_ATTRIBUTE_NAMESPACE = "XmlAttributeNamespace"; - - public XmlAttributeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAttribute() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ATTRIBUTE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttribute"); - } - }); - } - - private ICompilationUnit createTestXmlAttributeWithName() throws Exception { - return this.createTestXmlAttributeWithStringElement("name", XML_ATTRIBUTE_NAME); - } - - private ICompilationUnit createTestXmlAttributeWithNamespace() throws Exception { - return this.createTestXmlAttributeWithStringElement("namespace", XML_ATTRIBUTE_NAMESPACE); - } - - private ICompilationUnit createTestXmlAttributeWithStringElement(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ATTRIBUTE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttribute(" + element + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlAttributeWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ATTRIBUTE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttribute(" + booleanElement + " = true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - assertTrue(xmlAttributeAnnotation != null); - assertEquals(XML_ATTRIBUTE_NAME, xmlAttributeAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlAttribute(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - assertTrue(xmlAttributeAnnotation != null); - assertNull(xmlAttributeAnnotation.getName()); - assertNull(xmlAttributeAnnotation.getNamespace()); - assertNull(xmlAttributeAnnotation.getRequired()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlAttribute(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - assertNull(xmlAttributeAnnotation.getName()); - xmlAttributeAnnotation.setName(XML_ATTRIBUTE_NAME); - assertEquals(XML_ATTRIBUTE_NAME, xmlAttributeAnnotation.getName()); - - assertSourceContains("@XmlAttribute(name = \"" + XML_ATTRIBUTE_NAME + "\")", cu); - - xmlAttributeAnnotation.setName(null); - assertNull(xmlAttributeAnnotation.getName()); - - assertSourceContains("@XmlAttribute", cu); - assertSourceDoesNotContain("@XmlAttribute(name = \"" + XML_ATTRIBUTE_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - assertTrue(xmlAttributeAnnotation != null); - assertEquals(XML_ATTRIBUTE_NAMESPACE, xmlAttributeAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlAttribute(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - assertNull(xmlAttributeAnnotation.getNamespace()); - xmlAttributeAnnotation.setNamespace(XML_ATTRIBUTE_NAMESPACE); - assertEquals(XML_ATTRIBUTE_NAMESPACE, xmlAttributeAnnotation.getNamespace()); - - assertSourceContains("@XmlAttribute(namespace = \"" + XML_ATTRIBUTE_NAMESPACE + "\")", cu); - - xmlAttributeAnnotation.setNamespace(null); - assertNull(xmlAttributeAnnotation.getNamespace()); - - assertSourceContains("@XmlAttribute", cu); - assertSourceDoesNotContain("@XmlAttribute(namespace = \"" + XML_ATTRIBUTE_NAMESPACE + "\")", cu); - } - - public void testGetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithBooleanElement("required"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - - assertEquals(Boolean.TRUE, xmlAttributeAnnotation.getRequired()); - } - - public void testSetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlAttribute(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ATTRIBUTE); - - assertNotNull(xmlAttributeAnnotation); - assertNull(xmlAttributeAnnotation.getRequired()); - - xmlAttributeAnnotation.setRequired(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlAttributeAnnotation.getRequired()); - - assertSourceContains("@XmlAttribute(required = false)", cu); - - xmlAttributeAnnotation.setRequired(null); - assertSourceContains("@XmlAttribute", cu); - assertSourceDoesNotContain("required", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java deleted file mode 100644 index 661eb1fe9c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementAnnotationTests.java +++ /dev/null @@ -1,297 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlElementAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ELEMENT_NAME = "elementName"; - private static final String XML_ELEMENT_NAMESPACE = "XmlElementNamespace"; - private static final String XML_ELEMENT_DEFAULT_VALUE = "myDefaultValue"; - private static final String XML_ELEMENT_TYPE = "String"; - - public XmlElementAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElement"); - } - }); - } - - private ICompilationUnit createTestXmlElementWithName() throws Exception { - return this.createTestXmlElementWithStringElement("name", XML_ELEMENT_NAME); - } - - private ICompilationUnit createTestXmlElementWithNamespace() throws Exception { - return this.createTestXmlElementWithStringElement("namespace", XML_ELEMENT_NAMESPACE); - } - - private ICompilationUnit createTestXmlElementWithDefaultValue() throws Exception { - return this.createTestXmlElementWithStringElement("defaultValue", XML_ELEMENT_DEFAULT_VALUE); - } - - private ICompilationUnit createTestXmlElementWithStringElement(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElement(" + element + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlElementWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElement(" + booleanElement + " = true)"); - } - }); - } - - private ICompilationUnit createTestXmlElementWithType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertNull(xmlElementAnnotation.getName()); - assertNull(xmlElementAnnotation.getNamespace()); - assertNull(xmlElementAnnotation.getDefaultValue()); - assertNull(xmlElementAnnotation.getNillable()); - assertNull(xmlElementAnnotation.getRequired()); - assertNull(xmlElementAnnotation.getType()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertNull(xmlElementAnnotation.getName()); - xmlElementAnnotation.setName(XML_ELEMENT_NAME); - assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName()); - - assertSourceContains("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu); - - xmlElementAnnotation.setName(null); - assertNull(xmlElementAnnotation.getName()); - - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertNull(xmlElementAnnotation.getNamespace()); - xmlElementAnnotation.setNamespace(XML_ELEMENT_NAMESPACE); - assertEquals(XML_ELEMENT_NAMESPACE, xmlElementAnnotation.getNamespace()); - - assertSourceContains("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu); - - xmlElementAnnotation.setNamespace(null); - assertNull(xmlElementAnnotation.getNamespace()); - - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("@XmlElement(namespace = \"" + XML_ELEMENT_NAMESPACE + "\")", cu); - } - - public void testGetDefaultValue() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithDefaultValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue()); - } - - public void testSetDefaultValue() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertNull(xmlElementAnnotation.getDefaultValue()); - xmlElementAnnotation.setDefaultValue(XML_ELEMENT_DEFAULT_VALUE); - assertEquals(XML_ELEMENT_DEFAULT_VALUE, xmlElementAnnotation.getDefaultValue()); - - assertSourceContains("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu); - - xmlElementAnnotation.setDefaultValue(null); - assertNull(xmlElementAnnotation.getDefaultValue()); - - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("@XmlElement(defaultValue = \"" + XML_ELEMENT_DEFAULT_VALUE + "\")", cu); - } - - public void testGetNillable() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("nillable"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - - assertEquals(Boolean.TRUE, xmlElementAnnotation.getNillable()); - } - - public void testSetNillable() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - - assertNotNull(xmlElementAnnotation); - assertNull(xmlElementAnnotation.getNillable()); - - xmlElementAnnotation.setNillable(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlElementAnnotation.getNillable()); - - assertSourceContains("@XmlElement(nillable = false)", cu); - - xmlElementAnnotation.setNillable(null); - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("nillable", cu); - } - - public void testGetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithBooleanElement("required"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - - assertEquals(Boolean.TRUE, xmlElementAnnotation.getRequired()); - } - - public void testSetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - - assertNotNull(xmlElementAnnotation); - assertNull(xmlElementAnnotation.getRequired()); - - xmlElementAnnotation.setRequired(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlElementAnnotation.getRequired()); - - assertSourceContains("@XmlElement(required = false)", cu); - - xmlElementAnnotation.setRequired(null); - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("required", cu); - } - - public void testGetType() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType()); - assertEquals("java.lang." + XML_ELEMENT_TYPE, xmlElementAnnotation.getFullyQualifiedTypeName()); - } - - public void testSetType() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertNull(xmlElementAnnotation.getType()); - xmlElementAnnotation.setType(XML_ELEMENT_TYPE); - assertEquals(XML_ELEMENT_TYPE, xmlElementAnnotation.getType()); - - assertSourceContains("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu); - - xmlElementAnnotation.setType(null); - assertNull(xmlElementAnnotation.getType()); - - assertSourceContains("@XmlElement", cu); - assertSourceDoesNotContain("@XmlElement(type = " + XML_ELEMENT_TYPE + ".class", cu); - } - - public void testAddXmlElementAnnotation() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT); - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName()); - - XmlElementAnnotation xmlElementAnnotation2 = (XmlElementAnnotation) resourceAttribute.addAnnotation(1, JAXB.XML_ELEMENT); - xmlElementAnnotation2.setName("Foo"); - assertSourceContains("@XmlElements({ @XmlElement(name = \"" + XML_ELEMENT_NAME + "\"), @XmlElement(name = \"Foo\") })", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementDeclAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementDeclAnnotationTests.java deleted file mode 100644 index db83da1bd4..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementDeclAnnotationTests.java +++ /dev/null @@ -1,280 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlElementDeclAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ELEMENT_DECL_NAME = "elementName"; - private static final String XML_ELEMENT_DECL_NAMESPACE = "XmlElementDeclNamespace"; - private static final String XML_ELEMENT_DECL_DEFAULT_VALUE = "myDefaultValue"; - private static final String XML_ELEMENT_DECL_SCOPE = "XmlElementDecl.GLOBAL"; - - public XmlElementDeclAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlElementDecl() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_DECL); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementDecl"); - } - }); - } - - private ICompilationUnit createTestXmlElementDeclWithName() throws Exception { - return this.createTestXmlElementDeclWithStringElementDecl("name", XML_ELEMENT_DECL_NAME); - } - - private ICompilationUnit createTestXmlElementDeclWithNamespace() throws Exception { - return this.createTestXmlElementDeclWithStringElementDecl("namespace", XML_ELEMENT_DECL_NAMESPACE); - } - - private ICompilationUnit createTestXmlElementDeclWithDefaultValue() throws Exception { - return this.createTestXmlElementDeclWithStringElementDecl("defaultValue", XML_ELEMENT_DECL_DEFAULT_VALUE); - } - - private ICompilationUnit createTestXmlElementDeclWithSubstitutionHeadName() throws Exception { - return this.createTestXmlElementDeclWithStringElementDecl("substitutionHeadName", XML_ELEMENT_DECL_NAME); - } - - private ICompilationUnit createTestXmlElementDeclWithSubstitutionHeadNamespace() throws Exception { - return this.createTestXmlElementDeclWithStringElementDecl("substitutionHeadNamespace", XML_ELEMENT_DECL_NAME); - } - - private ICompilationUnit createTestXmlElementDeclWithStringElementDecl(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_DECL); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementDecl(" + element + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlElementDeclWithScope() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_DECL); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementDecl(scope = " + XML_ELEMENT_DECL_SCOPE + ".class)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertNull(xmlElementDeclAnnotation.getName()); - assertNull(xmlElementDeclAnnotation.getNamespace()); - assertNull(xmlElementDeclAnnotation.getDefaultValue()); - assertNull(xmlElementDeclAnnotation.getScope()); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadName()); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadNamespace()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getName()); - xmlElementDeclAnnotation.setName(XML_ELEMENT_DECL_NAME); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getName()); - - assertSourceContains("@XmlElementDecl(name = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - - xmlElementDeclAnnotation.setName(null); - assertNull(xmlElementDeclAnnotation.getName()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(name = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_NAMESPACE, xmlElementDeclAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getNamespace()); - xmlElementDeclAnnotation.setNamespace(XML_ELEMENT_DECL_NAMESPACE); - assertEquals(XML_ELEMENT_DECL_NAMESPACE, xmlElementDeclAnnotation.getNamespace()); - - assertSourceContains("@XmlElementDecl(namespace = \"" + XML_ELEMENT_DECL_NAMESPACE + "\")", cu); - - xmlElementDeclAnnotation.setNamespace(null); - assertNull(xmlElementDeclAnnotation.getNamespace()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(namespace = \"" + XML_ELEMENT_DECL_NAMESPACE + "\")", cu); - } - - public void testGetDefaultValue() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithDefaultValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_DEFAULT_VALUE, xmlElementDeclAnnotation.getDefaultValue()); - } - - public void testSetDefaultValue() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getDefaultValue()); - xmlElementDeclAnnotation.setDefaultValue(XML_ELEMENT_DECL_DEFAULT_VALUE); - assertEquals(XML_ELEMENT_DECL_DEFAULT_VALUE, xmlElementDeclAnnotation.getDefaultValue()); - - assertSourceContains("@XmlElementDecl(defaultValue = \"" + XML_ELEMENT_DECL_DEFAULT_VALUE + "\")", cu); - - xmlElementDeclAnnotation.setDefaultValue(null); - assertNull(xmlElementDeclAnnotation.getDefaultValue()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(defaultValue = \"" + XML_ELEMENT_DECL_DEFAULT_VALUE + "\")", cu); - } - - public void testGetScope() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithScope(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_SCOPE, xmlElementDeclAnnotation.getScope()); - assertEquals("javax.xml.bind.annotation." + XML_ELEMENT_DECL_SCOPE, xmlElementDeclAnnotation.getFullyQualifiedScopeClassName()); - } - - public void testSetScope() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getScope()); - xmlElementDeclAnnotation.setScope(XML_ELEMENT_DECL_SCOPE); - assertEquals(XML_ELEMENT_DECL_SCOPE, xmlElementDeclAnnotation.getScope()); - - assertSourceContains("@XmlElementDecl(scope = " + XML_ELEMENT_DECL_SCOPE + ".class", cu); - - xmlElementDeclAnnotation.setScope(null); - assertNull(xmlElementDeclAnnotation.getScope()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(scope = " + XML_ELEMENT_DECL_SCOPE + ".class", cu); - } - - public void testGetSubstitutionHeadName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithSubstitutionHeadName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getSubstitutionHeadName()); - } - - public void testSetSubstitutionHeadName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadName()); - xmlElementDeclAnnotation.setSubstitutionHeadName(XML_ELEMENT_DECL_NAME); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getSubstitutionHeadName()); - - assertSourceContains("@XmlElementDecl(substitutionHeadName = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - - xmlElementDeclAnnotation.setSubstitutionHeadName(null); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadName()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(substitutionHeadName = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - } - - public void testGetSubstitutionHeadNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDeclWithSubstitutionHeadNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertTrue(xmlElementDeclAnnotation != null); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getSubstitutionHeadNamespace()); - } - - public void testSetSubstitutionHeadNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementDecl(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = getMethod(resourceType, 0); - - XmlElementDeclAnnotation xmlElementDeclAnnotation = (XmlElementDeclAnnotation) resourceMethod.getAnnotation(JAXB.XML_ELEMENT_DECL); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadNamespace()); - xmlElementDeclAnnotation.setSubstitutionHeadNamespace(XML_ELEMENT_DECL_NAME); - assertEquals(XML_ELEMENT_DECL_NAME, xmlElementDeclAnnotation.getSubstitutionHeadNamespace()); - - assertSourceContains("@XmlElementDecl(substitutionHeadNamespace = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - - xmlElementDeclAnnotation.setSubstitutionHeadNamespace(null); - assertNull(xmlElementDeclAnnotation.getSubstitutionHeadNamespace()); - - assertSourceContains("@XmlElementDecl", cu); - assertSourceDoesNotContain("@XmlElementDecl(substitutionHeadNamespace = \"" + XML_ELEMENT_DECL_NAME + "\")", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java deleted file mode 100644 index 50270200cf..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefAnnotationTests.java +++ /dev/null @@ -1,191 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlElementRefAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ELEMENT_REF_NAME = "elementName"; - private static final String XML_ELEMENT_REF_NAMESPACE = "XmlElementRefNamespace"; - private static final String XML_ELEMENT_REF_TYPE = "String"; - - public XmlElementRefAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlElementRef() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRef"); - } - }); - } - - private ICompilationUnit createTestXmlElementRefWithName() throws Exception { - return this.createTestXmlElementRefWithStringElement("name", XML_ELEMENT_REF_NAME); - } - - private ICompilationUnit createTestXmlElementRefWithNamespace() throws Exception { - return this.createTestXmlElementRefWithStringElement("namespace", XML_ELEMENT_REF_NAMESPACE); - } - - private ICompilationUnit createTestXmlElementRefWithStringElement(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRef(" + element + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlElementRefWithType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertTrue(xmlElementRefAnnotation != null); - assertNull(xmlElementRefAnnotation.getName()); - assertNull(xmlElementRefAnnotation.getNamespace()); - assertNull(xmlElementRefAnnotation.getType()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertNull(xmlElementRefAnnotation.getName()); - xmlElementRefAnnotation.setName(XML_ELEMENT_REF_NAME); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - - assertSourceContains("@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\")", cu); - - xmlElementRefAnnotation.setName(null); - assertNull(xmlElementRefAnnotation.getName()); - - assertSourceContains("@XmlElementRef", cu); - assertSourceDoesNotContain("@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertNull(xmlElementRefAnnotation.getNamespace()); - xmlElementRefAnnotation.setNamespace(XML_ELEMENT_REF_NAMESPACE); - assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace()); - - assertSourceContains("@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\")", cu); - - xmlElementRefAnnotation.setNamespace(null); - assertNull(xmlElementRefAnnotation.getNamespace()); - - assertSourceContains("@XmlElementRef", cu); - assertSourceDoesNotContain("@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\")", cu); - } - - public void testGetType() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType()); - assertEquals("java.lang." + XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getFullyQualifiedTypeName()); - } - - public void testSetType() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertNull(xmlElementRefAnnotation.getType()); - xmlElementRefAnnotation.setType(XML_ELEMENT_REF_TYPE); - assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType()); - - assertSourceContains("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class", cu); - - xmlElementRefAnnotation.setType(null); - assertNull(xmlElementRefAnnotation.getType()); - - assertSourceContains("@XmlElementRef", cu); - assertSourceDoesNotContain("@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class", cu); - } - - public void testAddXmlElementRefAnnotation() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_ELEMENT_REF); - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - - XmlElementRefAnnotation xmlElementRefAnnotation2 = (XmlElementRefAnnotation) resourceAttribute.addAnnotation(1, JAXB.XML_ELEMENT_REF); - xmlElementRefAnnotation2.setName("Foo"); - assertSourceContains("@XmlElementRefs({ @XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\"), @XmlElementRef(name = \"Foo\") })", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementWrapperAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementWrapperAnnotationTests.java deleted file mode 100644 index e40761e9ed..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementWrapperAnnotationTests.java +++ /dev/null @@ -1,203 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlElementWrapperAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ELEMENT_WRAPPER_NAME = "elementName"; - private static final String XML_ELEMENT_WRAPPER_NAMESPACE = "XmlElementWrapperNamespace"; - - public XmlElementWrapperAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlElementWrapper() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_WRAPPER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementWrapper"); - } - }); - } - - private ICompilationUnit createTestXmlElementWrapperWithName() throws Exception { - return this.createTestXmlElementWrapperWithStringElement("name", XML_ELEMENT_WRAPPER_NAME); - } - - private ICompilationUnit createTestXmlElementWrapperWithNamespace() throws Exception { - return this.createTestXmlElementWrapperWithStringElement("namespace", XML_ELEMENT_WRAPPER_NAMESPACE); - } - - private ICompilationUnit createTestXmlElementWrapperWithStringElement(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_WRAPPER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementWrapper(" + element + " = \"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlElementWrapperWithBooleanElement(final String booleanElement) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_WRAPPER); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementWrapper(" + booleanElement + " = true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapperWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - assertTrue(xmlElementWrapperAnnotation != null); - assertEquals(XML_ELEMENT_WRAPPER_NAME, xmlElementWrapperAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapper(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - assertTrue(xmlElementWrapperAnnotation != null); - assertNull(xmlElementWrapperAnnotation.getName()); - assertNull(xmlElementWrapperAnnotation.getNamespace()); - assertNull(xmlElementWrapperAnnotation.getNillable()); - assertNull(xmlElementWrapperAnnotation.getRequired()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapper(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - assertNull(xmlElementWrapperAnnotation.getName()); - xmlElementWrapperAnnotation.setName(XML_ELEMENT_WRAPPER_NAME); - assertEquals(XML_ELEMENT_WRAPPER_NAME, xmlElementWrapperAnnotation.getName()); - - assertSourceContains("@XmlElementWrapper(name = \"" + XML_ELEMENT_WRAPPER_NAME + "\")", cu); - - xmlElementWrapperAnnotation.setName(null); - assertNull(xmlElementWrapperAnnotation.getName()); - - assertSourceContains("@XmlElementWrapper", cu); - assertSourceDoesNotContain("@XmlElementWrapper(name = \"" + XML_ELEMENT_WRAPPER_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapperWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - assertTrue(xmlElementWrapperAnnotation != null); - assertEquals(XML_ELEMENT_WRAPPER_NAMESPACE, xmlElementWrapperAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapper(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - assertNull(xmlElementWrapperAnnotation.getNamespace()); - xmlElementWrapperAnnotation.setNamespace(XML_ELEMENT_WRAPPER_NAMESPACE); - assertEquals(XML_ELEMENT_WRAPPER_NAMESPACE, xmlElementWrapperAnnotation.getNamespace()); - - assertSourceContains("@XmlElementWrapper(namespace = \"" + XML_ELEMENT_WRAPPER_NAMESPACE + "\")", cu); - - xmlElementWrapperAnnotation.setNamespace(null); - assertNull(xmlElementWrapperAnnotation.getNamespace()); - - assertSourceContains("@XmlElementWrapper", cu); - assertSourceDoesNotContain("@XmlElementWrapper(namespace = \"" + XML_ELEMENT_WRAPPER_NAMESPACE + "\")", cu); - } - - public void testGetNillable() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapperWithBooleanElement("nillable"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertEquals(Boolean.TRUE, xmlElementWrapperAnnotation.getNillable()); - } - - public void testSetNillable() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapper(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNotNull(xmlElementWrapperAnnotation); - assertNull(xmlElementWrapperAnnotation.getNillable()); - - xmlElementWrapperAnnotation.setNillable(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlElementWrapperAnnotation.getNillable()); - - assertSourceContains("@XmlElementWrapper(nillable = false)", cu); - - xmlElementWrapperAnnotation.setNillable(null); - assertSourceContains("@XmlElementWrapper", cu); - assertSourceDoesNotContain("nillable", cu); - } - - public void testGetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapperWithBooleanElement("required"); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertEquals(Boolean.TRUE, xmlElementWrapperAnnotation.getRequired()); - } - - public void testSetRequired() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWrapper(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNotNull(xmlElementWrapperAnnotation); - assertNull(xmlElementWrapperAnnotation.getRequired()); - - xmlElementWrapperAnnotation.setRequired(Boolean.FALSE); - assertEquals(Boolean.FALSE, xmlElementWrapperAnnotation.getRequired()); - - assertSourceContains("@XmlElementWrapper(required = false)", cu); - - xmlElementWrapperAnnotation.setRequired(null); - assertSourceContains("@XmlElementWrapper", cu); - assertSourceDoesNotContain("required", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumAnnotationTests.java deleted file mode 100644 index 330403617c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumAnnotationTests.java +++ /dev/null @@ -1,89 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlEnumAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ENUM_JAVA_TYPE = "String"; - - public XmlEnumAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlEnum() throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnum"); - } - }); - } - - private ICompilationUnit createTestXmlEnumWithValue() throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnum(value = " + XML_ENUM_JAVA_TYPE + ".class)"); - } - }); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlEnum(); - JavaResourceEnum resourceEnum = this.buildJavaResourceEnum(cu); - - XmlEnumAnnotation xmlEnumAnnotation = (XmlEnumAnnotation) resourceEnum.getAnnotation(JAXB.XML_ENUM); - assertTrue(xmlEnumAnnotation != null); - assertNull(xmlEnumAnnotation.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlEnumWithValue(); - JavaResourceEnum resourceEnum = this.buildJavaResourceEnum(cu); - - XmlEnumAnnotation xmlEnumAnnotation = (XmlEnumAnnotation) resourceEnum.getAnnotation(JAXB.XML_ENUM); - assertTrue(xmlEnumAnnotation != null); - assertEquals(XML_ENUM_JAVA_TYPE, xmlEnumAnnotation.getValue()); - assertEquals("java.lang." + XML_ENUM_JAVA_TYPE, xmlEnumAnnotation.getFullyQualifiedValueClassName()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlEnum(); - JavaResourceEnum resourceEnum = this.buildJavaResourceEnum(cu); - - XmlEnumAnnotation xmlEnumAnnotation = (XmlEnumAnnotation) resourceEnum.getAnnotation(JAXB.XML_ENUM); - assertNull(xmlEnumAnnotation.getValue()); - xmlEnumAnnotation.setValue(XML_ENUM_JAVA_TYPE); - assertEquals(XML_ENUM_JAVA_TYPE, xmlEnumAnnotation.getValue()); - - assertSourceContains("@XmlEnum(" + XML_ENUM_JAVA_TYPE + ".class)", cu); - - xmlEnumAnnotation.setValue(null); - assertNull(xmlEnumAnnotation.getValue()); - - assertSourceContains("@XmlEnum", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumValueAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumValueAnnotationTests.java deleted file mode 100644 index e376592a8c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlEnumValueAnnotationTests.java +++ /dev/null @@ -1,109 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumValueAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlEnumValueAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ENUM_VALUE_VALUE = "myEnumValue"; - - public XmlEnumValueAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlEnumValue() throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM_VALUE); - } - @Override - public void appendSundayEnumConstantAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnumValue"); - } - }); - } - - private ICompilationUnit createTestXmlEnumValueWithValue() throws Exception { - return this.createTestXmlEnumValueWithStringElement("value", XML_ENUM_VALUE_VALUE); - } - - private ICompilationUnit createTestXmlEnumValueWithStringElement(final String element, final String value) throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ENUM_VALUE); - } - @Override - public void appendSundayEnumConstantAnnotationTo(StringBuilder sb) { - sb.append("@XmlEnumValue(" + element + " = \"" + value + "\")"); - } - }); - } - - public void testGetXmlEnumValue() throws Exception { - ICompilationUnit cu = this.createTestXmlEnumValue(); - JavaResourceEnum resourceEnum = buildJavaResourceEnum(cu); - JavaResourceEnumConstant enumConstant = getEnumConstant(resourceEnum, 0); - - XmlEnumValueAnnotation xmlEnumValueAnnotation = (XmlEnumValueAnnotation) enumConstant.getAnnotation(JAXB.XML_ENUM_VALUE); - assertTrue(xmlEnumValueAnnotation != null); - - enumConstant.removeAnnotation(JAXB.XML_ENUM_VALUE); - assertSourceDoesNotContain("@XmlEnumValue", cu); - } - - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlEnumValueWithValue(); - JavaResourceEnum resourceEnum = buildJavaResourceEnum(cu); - JavaResourceEnumConstant enumConstant = getEnumConstant(resourceEnum, 0); - - XmlEnumValueAnnotation xmlEnumValueAnnotation = (XmlEnumValueAnnotation) enumConstant.getAnnotation(JAXB.XML_ENUM_VALUE); - assertTrue(xmlEnumValueAnnotation != null); - assertEquals(XML_ENUM_VALUE_VALUE, xmlEnumValueAnnotation.getValue()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlEnumValue(); - JavaResourceEnum resourceEnum = buildJavaResourceEnum(cu); - JavaResourceEnumConstant enumConstant = getEnumConstant(resourceEnum, 0); - - XmlEnumValueAnnotation xmlEnumValueAnnotation = (XmlEnumValueAnnotation) enumConstant.getAnnotation(JAXB.XML_ENUM_VALUE); - assertTrue(xmlEnumValueAnnotation != null); - assertNull(xmlEnumValueAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlEnumValue(); - JavaResourceEnum resourceEnum = buildJavaResourceEnum(cu); - JavaResourceEnumConstant enumConstant = getEnumConstant(resourceEnum, 0); - - XmlEnumValueAnnotation xmlEnumValueAnnotation = (XmlEnumValueAnnotation) enumConstant.getAnnotation(JAXB.XML_ENUM_VALUE); - assertNull(xmlEnumValueAnnotation.getValue()); - xmlEnumValueAnnotation.setValue(XML_ENUM_VALUE_VALUE); - assertEquals(XML_ENUM_VALUE_VALUE, xmlEnumValueAnnotation.getValue()); - - assertSourceContains("@XmlEnumValue(\"" + XML_ENUM_VALUE_VALUE + "\")", cu); - - xmlEnumValueAnnotation.setValue(null); - assertNull(xmlEnumValueAnnotation.getValue()); - - assertSourceDoesNotContain("@XmlEnumValue", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDAnnotationTests.java deleted file mode 100644 index b5493ff81e..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlIDAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlIDAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlID() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlID"); - } - }); - } - - public void testGetXmlID() throws Exception { - ICompilationUnit cu = this.createTestXmlID(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ID); - assertTrue(xmlIDAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_ID); - assertSourceDoesNotContain("@XmlID", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDREFAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDREFAnnotationTests.java deleted file mode 100644 index f60ee7df24..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlIDREFAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlIDREFAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlIDREFAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlIDREF() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_IDREF); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlIDREF"); - } - }); - } - - public void testGetXmlIDREF() throws Exception { - ICompilationUnit cu = this.createTestXmlIDREF(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - assertTrue(xmlIDREFAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_IDREF); - assertSourceDoesNotContain("@XmlIDREF", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataAttributeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataAttributeAnnotationTests.java deleted file mode 100644 index 68f2f7cc4f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataAttributeAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlInlineBinaryDataAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlInlineBinaryDataAttributeAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlInlineBinaryDataAttributeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlInlineBinaryData() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_INLINE_BINARY_DATA); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlInlineBinaryData"); - } - }); - } - - public void testGetXmlInlineBinaryData() throws Exception { - ICompilationUnit cu = this.createTestXmlInlineBinaryData(); - JavaResourceType resourceType = this.buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = this.getMethod(resourceType, 0); - - XmlInlineBinaryDataAnnotation xmlInlineBinaryDataAnnotation = (XmlInlineBinaryDataAnnotation) resourceMethod.getAnnotation(JAXB.XML_INLINE_BINARY_DATA); - assertTrue(xmlInlineBinaryDataAnnotation != null); - - resourceMethod.removeAnnotation(JAXB.XML_INLINE_BINARY_DATA); - assertSourceDoesNotContain("@XmlInlineBinaryData", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataTypeAnnotationTests.java deleted file mode 100644 index 41e0989cde..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlInlineBinaryDataTypeAnnotationTests.java +++ /dev/null @@ -1,49 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlInlineBinaryDataAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlInlineBinaryDataTypeAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlInlineBinaryDataTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlInlineBinaryData() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_INLINE_BINARY_DATA); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlInlineBinaryData"); - } - }); - } - - public void testGetXmlInlineBinaryData() throws Exception { - ICompilationUnit cu = this.createTestXmlInlineBinaryData(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlInlineBinaryDataAnnotation xmlInlineBinaryDataAnnotation = (XmlInlineBinaryDataAnnotation) resourceType.getAnnotation(JAXB.XML_INLINE_BINARY_DATA); - assertTrue(xmlInlineBinaryDataAnnotation != null); - - resourceType.removeAnnotation(JAXB.XML_INLINE_BINARY_DATA); - assertSourceDoesNotContain("@XmlInlineBinaryData", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterPackageAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterPackageAnnotationTests.java deleted file mode 100644 index bf7c9d898f..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterPackageAnnotationTests.java +++ /dev/null @@ -1,267 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -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.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; - -@SuppressWarnings("nls") -public class XmlJavaTypeAdapterPackageAnnotationTests - extends JaxbJavaResourceModelTestCase { - - private static final String TEST_CLASS = "TestClass"; - private static final String TEST_CLASS_2 = "TestClass2"; - private static final String FQ_TEST_CLASS = PACKAGE_NAME + "." + TEST_CLASS; - private static final String FQ_TEST_CLASS_2 = PACKAGE_NAME + "." + TEST_CLASS_2; - - - public XmlJavaTypeAdapterPackageAnnotationTests(String name) { - super(name); - } - - - private void createTestClass() throws CoreException { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(TEST_CLASS).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, TEST_CLASS + ".java", sourceWriter); - } - - private void createTestClass2() throws CoreException { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(TEST_CLASS_2).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, TEST_CLASS_2 + ".java", sourceWriter); - } - - private ICompilationUnit createPackageInfoWithJavaTypeAdapter() throws CoreException { - return createTestPackageInfo( - "@XmlJavaTypeAdapter", - JAXB.XML_JAVA_TYPE_ADAPTER); - } - - private ICompilationUnit createPackageInfoWithJavaTypeAdapterAndValue() throws CoreException { - createTestClass(); - return createTestPackageInfo( - "@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", - JAXB.XML_JAVA_TYPE_ADAPTER, FQ_TEST_CLASS); - } - - private ICompilationUnit createPackageInfoWithJavaTypeAdapterAndType() throws CoreException { - createTestClass(); - return createTestPackageInfo( - "@XmlJavaTypeAdapter(type = " + TEST_CLASS + ".class)", - JAXB.XML_JAVA_TYPE_ADAPTER, FQ_TEST_CLASS); - } - - private ICompilationUnit createPackageInfoWithJavaTypeAdapters() throws CoreException { - return createTestPackageInfo( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter,@XmlJavaTypeAdapter})", - JAXB.XML_JAVA_TYPE_ADAPTERS, JAXB.XML_JAVA_TYPE_ADAPTER); - } - - public void testValue() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapterAndValue(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass2(); - - XmlJavaTypeAdapterAnnotation annotation = - (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertTrue(annotation != null); - assertEquals(TEST_CLASS, annotation.getValue()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedValue()); - assertSourceContains("@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", cu); - - annotation.setValue(TEST_CLASS_2); - assertEquals(TEST_CLASS_2, annotation.getValue()); - assertEquals(FQ_TEST_CLASS_2, annotation.getFullyQualifiedValue()); - assertSourceContains("@XmlJavaTypeAdapter(" + TEST_CLASS_2 + ".class)", cu); - - annotation.setValue(null); - assertEquals(null, annotation.getValue()); - assertEquals(null, annotation.getFullyQualifiedValue()); - assertSourceContains("@XmlJavaTypeAdapter", cu); - - annotation.setValue(TEST_CLASS); - assertEquals(TEST_CLASS, annotation.getValue()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedValue()); - assertSourceContains("@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", cu); - } - - public void testType() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapterAndType(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass2(); - - XmlJavaTypeAdapterAnnotation annotation = - (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertTrue(annotation != null); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlJavaTypeAdapter(type = " + TEST_CLASS + ".class)", cu); - - annotation.setType(TEST_CLASS_2); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertEquals(FQ_TEST_CLASS_2, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlJavaTypeAdapter(type = " + TEST_CLASS_2 + ".class)", cu); - - annotation.setType(null); - assertEquals(null, annotation.getType()); - assertEquals(null, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlJavaTypeAdapter", cu); - - annotation.setType(TEST_CLASS); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlJavaTypeAdapter(type = " + TEST_CLASS + ".class)", cu); - } - - public void testTypeWithValue() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapterAndValue(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass2(); - - XmlJavaTypeAdapterAnnotation annotation = - (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertTrue(annotation != null); - assertEquals(TEST_CLASS, annotation.getValue()); - assertSourceContains("@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", cu); - - annotation.setType(TEST_CLASS_2); - assertEquals(TEST_CLASS, annotation.getValue()); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertSourceContains("@XmlJavaTypeAdapter(value = " + TEST_CLASS + ".class, type = " + TEST_CLASS_2 + ".class)", cu); - - annotation.setValue(null); - assertEquals(null, annotation.getValue()); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertSourceContains("@XmlJavaTypeAdapter(type = " + TEST_CLASS_2 + ".class)", cu); - - annotation.setValue(TEST_CLASS); - assertEquals(TEST_CLASS, annotation.getValue()); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertSourceContains("@XmlJavaTypeAdapter(type = " + TEST_CLASS_2 + ".class, value = " + TEST_CLASS + ".class)", cu); - - annotation.setType(null); - assertEquals(TEST_CLASS, annotation.getValue()); - assertEquals(null, annotation.getType()); - assertSourceContains("@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", cu); - } - - public void testContainedWithValue() - throws Exception { - // test contained annotation value setting/updating - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapters(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass(); - - XmlJavaTypeAdapterAnnotation adapterAnnotation = - (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - adapterAnnotation.setValue(TEST_CLASS); - assertEquals(TEST_CLASS, adapterAnnotation.getValue()); - assertEquals(FQ_TEST_CLASS, adapterAnnotation.getFullyQualifiedValue()); - assertSourceContains( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter(" + TEST_CLASS + ".class),@XmlJavaTypeAdapter})", cu); - - adapterAnnotation.setValue(null); - assertNull(adapterAnnotation.getValue()); - assertNull(FQ_TEST_CLASS, adapterAnnotation.getFullyQualifiedValue()); - assertSourceContains( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter,@XmlJavaTypeAdapter})", cu); - } - - public void testContainedWithType() - throws Exception { - // test contained annotation type setting/updating - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapters(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass(); - - XmlJavaTypeAdapterAnnotation adapterAnnotation = - (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(1, JAXB.XML_JAVA_TYPE_ADAPTER); - - adapterAnnotation.setType(TEST_CLASS); - assertEquals(TEST_CLASS, adapterAnnotation.getType()); - assertEquals(FQ_TEST_CLASS, adapterAnnotation.getFullyQualifiedType()); - assertSourceContains( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter,@XmlJavaTypeAdapter(type = " + TEST_CLASS + ".class)})", cu); - - resourcePackage.moveAnnotation(0, 1, JAXB.XML_JAVA_TYPE_ADAPTER); - adapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertEquals(TEST_CLASS, adapterAnnotation.getType()); - assertEquals(FQ_TEST_CLASS, adapterAnnotation.getFullyQualifiedType()); - assertSourceContains( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter(type = " + TEST_CLASS + ".class),@XmlJavaTypeAdapter})", cu); - - adapterAnnotation.setType(null); - assertNull(adapterAnnotation.getType()); - assertNull(FQ_TEST_CLASS, adapterAnnotation.getFullyQualifiedType()); - assertSourceContains( - "@XmlJavaTypeAdapters({@XmlJavaTypeAdapter,@XmlJavaTypeAdapter})", cu); - } - - public void testContained() - throws Exception { - // test adding/removing/moving - - ICompilationUnit cu = createPackageInfoWithJavaTypeAdapter(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - createTestClass(); - createTestClass2(); - - assertEquals(1, resourcePackage.getAnnotationsSize(JAXB.XML_JAVA_TYPE_ADAPTER)); - - resourcePackage.addAnnotation(1, JAXB.XML_JAVA_TYPE_ADAPTER); - assertEquals(2, resourcePackage.getAnnotationsSize(JAXB.XML_JAVA_TYPE_ADAPTER)); - assertSourceContains("@XmlJavaTypeAdapters({ @XmlJavaTypeAdapter, @XmlJavaTypeAdapter })", cu); - - XmlJavaTypeAdapterAnnotation adapterAnnotation1 = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - adapterAnnotation1.setValue(TEST_CLASS); - XmlJavaTypeAdapterAnnotation adapterAnnotation2 = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(1, JAXB.XML_JAVA_TYPE_ADAPTER); - adapterAnnotation2.setValue(TEST_CLASS_2); - assertSourceContains( - "@XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(" + TEST_CLASS - + ".class), @XmlJavaTypeAdapter(" + TEST_CLASS_2 - + ".class) })", cu); - - resourcePackage.moveAnnotation(0, 1, JAXB.XML_JAVA_TYPE_ADAPTER); - assertSourceContains( - "@XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(" + TEST_CLASS_2 - + ".class), @XmlJavaTypeAdapter(" + TEST_CLASS - + ".class) })", cu); - - resourcePackage.removeAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertEquals(1, resourcePackage.getAnnotationsSize(JAXB.XML_JAVA_TYPE_ADAPTER)); - assertSourceContains( - "@XmlJavaTypeAdapter(" + TEST_CLASS + ".class)", cu); - assertSourceDoesNotContain("@XmlJavaTypeAdapters", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterTypeAnnotationTests.java deleted file mode 100644 index d0cecca01d..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlJavaTypeAdapterTypeAnnotationTests.java +++ /dev/null @@ -1,111 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlJavaTypeAdapterTypeAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_JAVA_TYPE_ADAPTER_CLASS = "MyAdapterClass"; - - public XmlJavaTypeAdapterTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlJavaTypeAdapter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_JAVA_TYPE_ADAPTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlJavaTypeAdapter"); - } - }); - } - - private ICompilationUnit createTestXmlJavaTypeAdapterWithValue() throws Exception { - this.createTestAdapterClass(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_JAVA_TYPE_ADAPTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlJavaTypeAdapter(value = " + XML_JAVA_TYPE_ADAPTER_CLASS + ".class)"); - } - }); - } - - private void createTestAdapterClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(XML_JAVA_TYPE_ADAPTER_CLASS).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "MyAdapterClass.java", sourceWriter); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlJavaTypeAdapter(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertTrue(xmlJavaTypeAdapterAnnotation != null); - assertNull(xmlJavaTypeAdapterAnnotation.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlJavaTypeAdapterWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertTrue(xmlJavaTypeAdapterAnnotation != null); - assertEquals(XML_JAVA_TYPE_ADAPTER_CLASS, xmlJavaTypeAdapterAnnotation.getValue()); - assertEquals("test." + XML_JAVA_TYPE_ADAPTER_CLASS, xmlJavaTypeAdapterAnnotation.getFullyQualifiedValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlJavaTypeAdapter(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertNull(xmlJavaTypeAdapterAnnotation.getValue()); - xmlJavaTypeAdapterAnnotation.setValue(XML_JAVA_TYPE_ADAPTER_CLASS); - assertEquals(XML_JAVA_TYPE_ADAPTER_CLASS, xmlJavaTypeAdapterAnnotation.getValue()); - - assertSourceContains("@XmlJavaTypeAdapter(" + XML_JAVA_TYPE_ADAPTER_CLASS + ".class)", cu); - } - - public void testSetValueNull() throws Exception { - ICompilationUnit cu = this.createTestXmlJavaTypeAdapterWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertEquals(XML_JAVA_TYPE_ADAPTER_CLASS, xmlJavaTypeAdapterAnnotation.getValue()); - - xmlJavaTypeAdapterAnnotation.setValue(null); - assertNull(xmlJavaTypeAdapterAnnotation.getValue()); - - assertSourceContains("@XmlJavaTypeAdapter", cu); - assertSourceDoesNotContain("@XmlJavaTypeAdapter(" + XML_JAVA_TYPE_ADAPTER_CLASS + ".class)", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlListAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlListAnnotationTests.java deleted file mode 100644 index 2b55ba5314..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlListAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlListAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlListAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlList() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_LIST); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlList"); - } - }); - } - - public void testGetXmlList() throws Exception { - ICompilationUnit cu = this.createTestXmlList(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(JAXB.XML_LIST); - assertTrue(xmlListAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_LIST); - assertSourceDoesNotContain("@XmlList", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMimeTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMimeTypeAnnotationTests.java deleted file mode 100644 index b597eacc13..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMimeTypeAnnotationTests.java +++ /dev/null @@ -1,108 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlMimeTypeAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlMimeTypeAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_MIME_TYPE_VALUE = "myMimeType"; - - public XmlMimeTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlMimeType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_MIME_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlMimeType"); - } - }); - } - - private ICompilationUnit createTestXmlMimeTypeWithValue() throws Exception { - return this.createTestXmlMimeTypeWithStringElement("value", XML_MIME_TYPE_VALUE); - } - - private ICompilationUnit createTestXmlMimeTypeWithStringElement(final String element, final String value) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_MIME_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlMimeType(" + element + " = \"" + value + "\")"); - } - }); - } - - public void testGetXmlMimeType() throws Exception { - ICompilationUnit cu = this.createTestXmlMimeType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlMimeTypeAnnotation xmlMimeTypeAnnotation = (XmlMimeTypeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_MIME_TYPE); - assertTrue(xmlMimeTypeAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_MIME_TYPE); - assertSourceDoesNotContain("@XmlMimeType", cu); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlMimeTypeWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlMimeTypeAnnotation xmlMimeTypeAnnotation = (XmlMimeTypeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_MIME_TYPE); - assertTrue(xmlMimeTypeAnnotation != null); - assertEquals(XML_MIME_TYPE_VALUE, xmlMimeTypeAnnotation.getValue()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlMimeType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlMimeTypeAnnotation xmlMimeTypeAnnotation = (XmlMimeTypeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_MIME_TYPE); - assertTrue(xmlMimeTypeAnnotation != null); - assertNull(xmlMimeTypeAnnotation.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestXmlMimeType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlMimeTypeAnnotation xmlMimeTypeAnnotation = (XmlMimeTypeAnnotation) resourceAttribute.getAnnotation(JAXB.XML_MIME_TYPE); - assertNull(xmlMimeTypeAnnotation.getValue()); - xmlMimeTypeAnnotation.setValue(XML_MIME_TYPE_VALUE); - assertEquals(XML_MIME_TYPE_VALUE, xmlMimeTypeAnnotation.getValue()); - - assertSourceContains("@XmlMimeType(\"" + XML_MIME_TYPE_VALUE + "\")", cu); - - xmlMimeTypeAnnotation.setValue(null); - assertNull(xmlMimeTypeAnnotation.getValue()); - - assertSourceDoesNotContain("@XmlMimeType", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMixedAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMixedAnnotationTests.java deleted file mode 100644 index f7f1ffc22d..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlMixedAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlMixedAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlMixedAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlMixedAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlMixed() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_MIXED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlMixed"); - } - }); - } - - public void testGetXmlMixed() throws Exception { - ICompilationUnit cu = this.createTestXmlMixed(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlMixedAnnotation xmlMixedAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(JAXB.XML_MIXED); - assertTrue(xmlMixedAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_MIXED); - assertSourceDoesNotContain("@XmlMixed", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java deleted file mode 100644 index 4868727977..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRegistryAnnotationTests.java +++ /dev/null @@ -1,49 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlRegistryAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlRegistryAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlRegistry() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_REGISTRY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRegistry"); - } - }); - } - - public void testGetXmlRegistry() throws Exception { - ICompilationUnit cu = this.createTestXmlRegistry(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRegistryAnnotation xmlRegistryAnnotation = (XmlRegistryAnnotation) resourceType.getAnnotation(JAXB.XML_REGISTRY); - assertTrue(xmlRegistryAnnotation != null); - - resourceType.removeAnnotation(JAXB.XML_REGISTRY); - assertSourceDoesNotContain("@XmlRegistry", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRootElementAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRootElementAnnotationTests.java deleted file mode 100644 index 9295ba8dbf..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlRootElementAnnotationTests.java +++ /dev/null @@ -1,131 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlRootElementAnnotationTests extends JaxbJavaResourceModelTestCase { - - private static final String XML_ROOT_ELEMENT_NAME = "XmlRootElementName"; - private static final String XML_ROOT_ELEMENT_NAMESPACE = "XmlRootElementNamespace"; - - public XmlRootElementAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlRootElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ROOT_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRootElement"); - } - }); - } - - private ICompilationUnit createTestXmlRootElementWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ROOT_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRootElement(name = \"" + XML_ROOT_ELEMENT_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlRootElementWithNamespace() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ROOT_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlRootElement(namespace = \"" + XML_ROOT_ELEMENT_NAMESPACE + "\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlRootElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(JAXB.XML_ROOT_ELEMENT); - assertTrue(xmlRootElementAnnotation != null); - assertEquals(XML_ROOT_ELEMENT_NAME, xmlRootElementAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlRootElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(JAXB.XML_ROOT_ELEMENT); - assertTrue(xmlRootElementAnnotation != null); - assertNull(xmlRootElementAnnotation.getName()); - assertNull(xmlRootElementAnnotation.getNamespace()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlRootElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(JAXB.XML_ROOT_ELEMENT); - assertNull(xmlRootElementAnnotation.getName()); - xmlRootElementAnnotation.setName(XML_ROOT_ELEMENT_NAME); - assertEquals(XML_ROOT_ELEMENT_NAME, xmlRootElementAnnotation.getName()); - - assertSourceContains("@XmlRootElement(name = \"" + XML_ROOT_ELEMENT_NAME + "\")", cu); - - xmlRootElementAnnotation.setName(null); - assertNull(xmlRootElementAnnotation.getName()); - - assertSourceContains("@XmlRootElement", cu); - assertSourceDoesNotContain("@XmlRootElement(name = \"" + XML_ROOT_ELEMENT_NAME + "\")", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlRootElementWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(JAXB.XML_ROOT_ELEMENT); - assertTrue(xmlRootElementAnnotation != null); - assertEquals(XML_ROOT_ELEMENT_NAMESPACE, xmlRootElementAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlRootElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlRootElementAnnotation xmlRootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(JAXB.XML_ROOT_ELEMENT); - assertNull(xmlRootElementAnnotation.getNamespace()); - xmlRootElementAnnotation.setNamespace(XML_ROOT_ELEMENT_NAMESPACE); - assertEquals(XML_ROOT_ELEMENT_NAMESPACE, xmlRootElementAnnotation.getNamespace()); - - assertSourceContains("@XmlRootElement(namespace = \"" + XML_ROOT_ELEMENT_NAMESPACE + "\")", cu); - - xmlRootElementAnnotation.setNamespace(null); - assertNull(xmlRootElementAnnotation.getNamespace()); - - assertSourceContains("@XmlRootElement", cu); - assertSourceDoesNotContain("@XmlRootElement(namespace = \"" + XML_ROOT_ELEMENT_NAMESPACE + "\")", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java deleted file mode 100644 index 492a60976b..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaAnnotationTests.java +++ /dev/null @@ -1,263 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlNsAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlNsForm; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; - -@SuppressWarnings("nls") -public class XmlSchemaAnnotationTests - extends JaxbJavaResourceModelTestCase { - - private static final String TEST_LOCATION = "http://www.eclipse.org/test/schema.xsd"; - - private static final String TEST_NAMESPACE = "http://www.eclipse.org/test/schema"; - - private static final String TEST_PREFIX = "ts"; - - private static final String TEST_NAMESPACE_2 = "http://www.eclipse.org/test/schema2"; - - private static final String TEST_PREFIX_2 = "ts2"; - - - public XmlSchemaAnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createPackageInfoWithSchemaAndAttributeFormDefault() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(attributeFormDefault = XmlNsForm.QUALIFIED)", - JAXB.XML_SCHEMA, JAXB.XML_NS_FORM); - } - - private ICompilationUnit createPackageInfoWithSchemaAndElementFormDefault() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED)", - JAXB.XML_SCHEMA, JAXB.XML_NS_FORM); - } - - private ICompilationUnit createPackageInfoWithSchemaAndLocation() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(location = \"" + TEST_LOCATION + "\")", - JAXB.XML_SCHEMA); - } - - private ICompilationUnit createPackageInfoWithSchemaAndNamespace() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(namespace = \"" + TEST_NAMESPACE + "\")", - JAXB.XML_SCHEMA); - } - - private ICompilationUnit createPackageInfoWithSchemaAndXmlns() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(xmlns = @XmlNs)", - JAXB.XML_SCHEMA, JAXB.XML_NS); - } - - private ICompilationUnit createPackageInfoWithSchemaAndXmlnsWithNamespace() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE + "\"))", - JAXB.XML_SCHEMA, JAXB.XML_NS); - } - - private ICompilationUnit createPackageInfoWithSchemaAndXmlnsWithPrefix() throws CoreException { - return createTestPackageInfo( - "@XmlSchema(xmlns = @XmlNs(prefix = \"" + TEST_PREFIX + "\"))", - JAXB.XML_SCHEMA, JAXB.XML_NS); - } - - public void testAttributeFormDefault() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndAttributeFormDefault(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertTrue(schemaAnnotation != null); - assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertSourceContains("@XmlSchema(attributeFormDefault = XmlNsForm.QUALIFIED)", cu); - - schemaAnnotation.setAttributeFormDefault(XmlNsForm.UNQUALIFIED); - assertEquals(XmlNsForm.UNQUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertSourceContains("@XmlSchema(attributeFormDefault = UNQUALIFIED)", cu); - - schemaAnnotation.setAttributeFormDefault(XmlNsForm.UNSET); - assertEquals(XmlNsForm.UNSET, schemaAnnotation.getAttributeFormDefault()); - assertSourceContains("@XmlSchema(attributeFormDefault = UNSET)", cu); - - schemaAnnotation.setAttributeFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNull(schemaAnnotation); - assertSourceDoesNotContain("@XmlSchema", cu); - - schemaAnnotation = (XmlSchemaAnnotation) packageResource.addAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - schemaAnnotation.setAttributeFormDefault(XmlNsForm.QUALIFIED); - assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getAttributeFormDefault()); - assertSourceContains("@XmlSchema(attributeFormDefault = QUALIFIED)", cu); - } - - public void testElementFormDefault() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndElementFormDefault(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertTrue(schemaAnnotation != null); - assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); - assertSourceContains("@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED)", cu); - - schemaAnnotation.setElementFormDefault(XmlNsForm.UNQUALIFIED); - assertEquals(XmlNsForm.UNQUALIFIED, schemaAnnotation.getElementFormDefault()); - assertSourceContains("@XmlSchema(elementFormDefault = UNQUALIFIED)", cu); - - schemaAnnotation.setElementFormDefault(XmlNsForm.UNSET); - assertEquals(XmlNsForm.UNSET, schemaAnnotation.getElementFormDefault()); - assertSourceContains("@XmlSchema(elementFormDefault = UNSET)", cu); - - schemaAnnotation.setElementFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNull(schemaAnnotation); - assertSourceDoesNotContain("@XmlSchema", cu); - - schemaAnnotation = (XmlSchemaAnnotation) packageResource.addAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - schemaAnnotation.setElementFormDefault(XmlNsForm.QUALIFIED); - assertEquals(XmlNsForm.QUALIFIED, schemaAnnotation.getElementFormDefault()); - assertSourceContains("@XmlSchema(elementFormDefault = QUALIFIED)", cu); - } - - public void testLocation() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndLocation(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNotNull(schemaAnnotation.getLocation()); - - schemaAnnotation.setLocation(null); - schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNull(schemaAnnotation); - assertSourceDoesNotContain("@XmlSchema", cu); - - schemaAnnotation = (XmlSchemaAnnotation) packageResource.addAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - schemaAnnotation.setLocation(TEST_LOCATION); - assertEquals(TEST_LOCATION, schemaAnnotation.getLocation()); - assertSourceContains("@XmlSchema(location = \"" + TEST_LOCATION + "\")", cu); - } - - public void testNamespace() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndNamespace(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNotNull(schemaAnnotation.getNamespace()); - - schemaAnnotation.setNamespace(null); - schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertNull(schemaAnnotation); - assertSourceDoesNotContain("@XmlSchema", cu); - - schemaAnnotation = (XmlSchemaAnnotation) packageResource.addAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - schemaAnnotation.setNamespace(TEST_NAMESPACE); - assertEquals(TEST_NAMESPACE, schemaAnnotation.getNamespace()); - assertSourceContains("@XmlSchema(namespace = \"" + TEST_NAMESPACE + "\")", cu); - } - - public void testXmlnsNamespace() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndXmlnsWithNamespace(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - XmlNsAnnotation xmlnsAnnotation = schemaAnnotation.xmlnsAt(0); - assertNotNull(xmlnsAnnotation.getNamespaceURI()); - - xmlnsAnnotation.setNamespaceURI(null); - assertNull(xmlnsAnnotation.getNamespaceURI()); - assertSourceContains("@XmlSchema(xmlns = @XmlNs)", cu); - - xmlnsAnnotation.setNamespaceURI(TEST_NAMESPACE_2); - assertEquals(TEST_NAMESPACE_2, xmlnsAnnotation.getNamespaceURI()); - assertSourceContains("@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 + "\"))", cu); - } - - public void testXmlnsPrefix() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndXmlnsWithPrefix(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - XmlNsAnnotation xmlnsAnnotation = schemaAnnotation.xmlnsAt(0); - assertNotNull(xmlnsAnnotation.getPrefix()); - - xmlnsAnnotation.setPrefix(null); - assertNull(xmlnsAnnotation.getPrefix()); - assertSourceContains("@XmlSchema(xmlns = @XmlNs)", cu); - - xmlnsAnnotation.setPrefix(TEST_PREFIX_2); - assertEquals(TEST_PREFIX_2, xmlnsAnnotation.getPrefix()); - assertSourceContains("@XmlSchema(xmlns = @XmlNs(prefix = \"" + TEST_PREFIX_2 + "\"))", cu); - } - - public void testXmlns() - throws Exception { - - ICompilationUnit cu = createPackageInfoWithSchemaAndXmlns(); - JavaResourcePackage packageResource = buildJavaResourcePackage(cu); - - XmlSchemaAnnotation schemaAnnotation = (XmlSchemaAnnotation) packageResource.getAnnotation(JAXB.XML_SCHEMA); - assertFalse(CollectionTools.isEmpty(schemaAnnotation.getXmlns())); - assertEquals(1, schemaAnnotation.getXmlnsSize()); - - schemaAnnotation.addXmlns(1); - assertEquals(2, schemaAnnotation.getXmlnsSize()); - assertSourceContains("@XmlSchema(xmlns = {@XmlNs,@XmlNs})", cu); - - XmlNsAnnotation xmlnsAnnotation1 = schemaAnnotation.xmlnsAt(0); - xmlnsAnnotation1.setNamespaceURI(TEST_NAMESPACE); - xmlnsAnnotation1.setPrefix(TEST_PREFIX); - XmlNsAnnotation xmlnsAnnotation2 = schemaAnnotation.xmlnsAt(1); - xmlnsAnnotation2.setNamespaceURI(TEST_NAMESPACE_2); - xmlnsAnnotation2.setPrefix(TEST_PREFIX_2); - assertSourceContains( - "@XmlSchema(xmlns = {@XmlNs(namespaceURI = \"" + TEST_NAMESPACE - + "\", prefix = \"" + TEST_PREFIX - + "\"),@XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 - + "\", prefix = \"" + TEST_PREFIX_2 - + "\")})", cu); - - schemaAnnotation.moveXmlns(0, 1); - assertSourceContains( - "@XmlSchema(xmlns = {@XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 - + "\", prefix = \"" + TEST_PREFIX_2 - + "\"),@XmlNs(namespaceURI = \"" + TEST_NAMESPACE - + "\", prefix = \"" + TEST_PREFIX - + "\")})", cu); - - schemaAnnotation.removeXmlns(1); - assertEquals(1, schemaAnnotation.getXmlnsSize()); - assertSourceContains( - "@XmlSchema(xmlns = @XmlNs(namespaceURI = \"" + TEST_NAMESPACE_2 - + "\", prefix = \"" + TEST_PREFIX_2 - + "\"))", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypeAttributeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypeAttributeAnnotationTests.java deleted file mode 100644 index 1be1012a43..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypeAttributeAnnotationTests.java +++ /dev/null @@ -1,156 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlSchemaTypeAttributeAnnotationTests - extends JaxbJavaResourceModelTestCase { - - private static final String TEST_NAME = "foo"; - private static final String TEST_NAME_2 = "bar"; - - private static final String TEST_NAMESPACE = "http://www.eclipse.org/test/schema"; - private static final String TEST_NAMESPACE_2 = "http://www.eclipse.org/test/schema2"; - - private static final String TEST_CLASS = GregorianCalendar.class.getSimpleName(); - private static final String TEST_CLASS_2 = Date.class.getSimpleName(); - private static final String FQ_TEST_CLASS = GregorianCalendar.class.getName(); - private static final String FQ_TEST_CLASS_2 = Date.class.getName(); - - - public XmlSchemaTypeAttributeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlAttributeWithSchemaTypeAndName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_SCHEMA_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlSchemaType(name = \"" + TEST_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlAttributeWithSchemaTypeAndNamespace() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_SCHEMA_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")"); - } - }); - } - - private ICompilationUnit createTestXmlAttributeWithSchemaTypeAndType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_SCHEMA_TYPE, FQ_TEST_CLASS, FQ_TEST_CLASS_2); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlSchemaType(type = " + TEST_CLASS + ".class)"); - } - }); - } - - public void testName() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithSchemaTypeAndName(); - JavaResourceType resourceType = this.buildJavaResourceType(cu); - JavaResourceField resourceAttribute = this.getField(resourceType, 0); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_NAME, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME + "\")", cu); - - annotation.setName(TEST_NAME_2); - assertEquals(TEST_NAME_2, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME_2 + "\")", cu); - - annotation.setName(null); - assertEquals(null, annotation.getName()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setName(TEST_NAME); - assertEquals(TEST_NAME, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME + "\")", cu); - } - - public void testNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithSchemaTypeAndNamespace(); - JavaResourceType resourceType = this.buildJavaResourceType(cu); - JavaResourceField resourceAttribute = this.getField(resourceType, 0); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_NAMESPACE, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")", cu); - - annotation.setNamespace(TEST_NAMESPACE_2); - assertEquals(TEST_NAMESPACE_2, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE_2 + "\")", cu); - - annotation.setNamespace(null); - assertEquals(null, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setNamespace(TEST_NAMESPACE); - assertEquals(TEST_NAMESPACE, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")", cu); - } - - public void testType() throws Exception { - ICompilationUnit cu = this.createTestXmlAttributeWithSchemaTypeAndType(); - JavaResourceType resourceType = this.buildJavaResourceType(cu); - JavaResourceField resourceAttribute = this.getField(resourceType, 0); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS + ".class)", cu); - - annotation.setType(TEST_CLASS_2); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertEquals(FQ_TEST_CLASS_2, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS_2 + ".class)", cu); - - annotation.setType(null); - assertEquals(null, annotation.getType()); - assertEquals(null, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setType(TEST_CLASS); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS + ".class)", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypePackageAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypePackageAnnotationTests.java deleted file mode 100644 index 03e98ea782..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSchemaTypePackageAnnotationTests.java +++ /dev/null @@ -1,240 +0,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 - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Date; -import java.util.GregorianCalendar; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; - -@SuppressWarnings("nls") -public class XmlSchemaTypePackageAnnotationTests - extends JaxbJavaResourceModelTestCase { - - private static final String TEST_NAME = "foo"; - private static final String TEST_NAME_2 = "bar"; - - private static final String TEST_NAMESPACE = "http://www.eclipse.org/test/schema"; - private static final String TEST_NAMESPACE_2 = "http://www.eclipse.org/test/schema2"; - - private static final String TEST_CLASS = GregorianCalendar.class.getSimpleName(); - private static final String TEST_CLASS_2 = Date.class.getSimpleName(); - private static final String FQ_TEST_CLASS = GregorianCalendar.class.getName(); - private static final String FQ_TEST_CLASS_2 = Date.class.getName(); - - - public XmlSchemaTypePackageAnnotationTests(String name) { - super(name); - } - - - private ICompilationUnit createPackageInfoWithSchemaType() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaType", - JAXB.XML_SCHEMA_TYPE); - } - - private ICompilationUnit createPackageInfoWithSchemaTypeAndName() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaType(name = \"" + TEST_NAME + "\")", - JAXB.XML_SCHEMA_TYPE); - } - - private ICompilationUnit createPackageInfoWithSchemaTypeAndNamespace() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")", - JAXB.XML_SCHEMA_TYPE); - } - - private ICompilationUnit createPackageInfoWithSchemaTypeAndType() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaType(type = " + TEST_CLASS + ".class)", - JAXB.XML_SCHEMA_TYPE, FQ_TEST_CLASS, FQ_TEST_CLASS_2); - } - - private ICompilationUnit createPackageInfoWithSchemaTypes() throws CoreException { - return createTestPackageInfo( - "@XmlSchemaTypes({@XmlSchemaType,@XmlSchemaType})", - JAXB.XML_SCHEMA_TYPES, JAXB.XML_SCHEMA_TYPE, FQ_TEST_CLASS, FQ_TEST_CLASS_2); - } - - public void testName() throws Exception { - ICompilationUnit cu = createPackageInfoWithSchemaTypeAndName(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_NAME, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME + "\")", cu); - - annotation.setName(TEST_NAME_2); - assertEquals(TEST_NAME_2, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME_2 + "\")", cu); - - annotation.setName(null); - assertEquals(null, annotation.getName()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setName(TEST_NAME); - assertEquals(TEST_NAME, annotation.getName()); - assertSourceContains("@XmlSchemaType(name = \"" + TEST_NAME + "\")", cu); - } - - public void testNamespace() throws Exception { - ICompilationUnit cu = createPackageInfoWithSchemaTypeAndNamespace(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_NAMESPACE, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")", cu); - - annotation.setNamespace(TEST_NAMESPACE_2); - assertEquals(TEST_NAMESPACE_2, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE_2 + "\")", cu); - - annotation.setNamespace(null); - assertEquals(null, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setNamespace(TEST_NAMESPACE); - assertEquals(TEST_NAMESPACE, annotation.getNamespace()); - assertSourceContains("@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\")", cu); - } - - public void testType() throws Exception { - ICompilationUnit cu = createPackageInfoWithSchemaTypeAndType(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation annotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - assertTrue(annotation != null); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS + ".class)", cu); - - annotation.setType(TEST_CLASS_2); - assertEquals(TEST_CLASS_2, annotation.getType()); - assertEquals(FQ_TEST_CLASS_2, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS_2 + ".class)", cu); - - annotation.setType(null); - assertEquals(null, annotation.getType()); - assertEquals(null, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType", cu); - - annotation.setType(TEST_CLASS); - assertEquals(TEST_CLASS, annotation.getType()); - assertEquals(FQ_TEST_CLASS, annotation.getFullyQualifiedType()); - assertSourceContains("@XmlSchemaType(type = " + TEST_CLASS + ".class)", cu); - } - - public void testContainedWithName() throws Exception { - // test contained annotation value setting/updating - - ICompilationUnit cu = createPackageInfoWithSchemaTypes(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation containedAnnotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - - containedAnnotation.setName(TEST_NAME); - assertEquals(TEST_NAME, containedAnnotation.getName()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType(name = \"" + TEST_NAME + "\"),@XmlSchemaType})", cu); - - containedAnnotation.setName(null); - assertNull(containedAnnotation.getName()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType,@XmlSchemaType})", cu); - } - - public void testContainedWithNamespace() throws Exception { - // test contained annotation value setting/updating - - ICompilationUnit cu = createPackageInfoWithSchemaTypes(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation containedAnnotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - - containedAnnotation.setNamespace(TEST_NAMESPACE); - assertEquals(TEST_NAMESPACE, containedAnnotation.getNamespace()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType(namespace = \"" + TEST_NAMESPACE + "\"),@XmlSchemaType})", cu); - - containedAnnotation.setNamespace(null); - assertNull(containedAnnotation.getNamespace()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType,@XmlSchemaType})", cu); - } - - public void testContainedWithType()throws Exception { - // test contained annotation type setting/updating - - ICompilationUnit cu = createPackageInfoWithSchemaTypes(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - XmlSchemaTypeAnnotation containedAnnotation = - (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(1, JAXB.XML_SCHEMA_TYPE); - - containedAnnotation.setType(TEST_CLASS); - assertEquals(TEST_CLASS, containedAnnotation.getType()); - assertEquals(FQ_TEST_CLASS, containedAnnotation.getFullyQualifiedType()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType,@XmlSchemaType(type = " + TEST_CLASS + ".class)})", cu); - - containedAnnotation.setType(null); - assertNull(containedAnnotation.getType()); - assertNull(FQ_TEST_CLASS, containedAnnotation.getFullyQualifiedType()); - assertSourceContains( - "@XmlSchemaTypes({@XmlSchemaType,@XmlSchemaType})", cu); - } - - public void testContained() throws Exception { - // test adding/removing/moving - - ICompilationUnit cu = createPackageInfoWithSchemaType(); - JavaResourcePackage resourcePackage = buildJavaResourcePackage(cu); - - assertEquals(1, resourcePackage.getAnnotationsSize(JAXB.XML_SCHEMA_TYPE)); - - resourcePackage.addAnnotation(1, JAXB.XML_SCHEMA_TYPE); - - assertEquals(2, resourcePackage.getAnnotationsSize(JAXB.XML_SCHEMA_TYPE)); - assertSourceContains("@XmlSchemaTypes({ @XmlSchemaType, @XmlSchemaType })", cu); - - XmlSchemaTypeAnnotation containedAnnotation1 = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, JAXB.XML_SCHEMA_TYPE); - containedAnnotation1.setName(TEST_NAME); - XmlSchemaTypeAnnotation containedAnnotation2 = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(1, JAXB.XML_SCHEMA_TYPE); - containedAnnotation2.setName(TEST_NAME_2); - assertSourceContains( - "@XmlSchemaTypes({ @XmlSchemaType(name = \"" + TEST_NAME - + "\"), @XmlSchemaType(name = \"" + TEST_NAME_2 - + "\") })", cu); - - resourcePackage.moveAnnotation(0, 1, JAXB.XML_SCHEMA_TYPE); - assertSourceContains( - "@XmlSchemaTypes({ @XmlSchemaType(name = \"" + TEST_NAME_2 - + "\"), @XmlSchemaType(name = \"" + TEST_NAME - + "\") })", cu); - - resourcePackage.removeAnnotation(1, JAXB.XML_SCHEMA_TYPE); - assertEquals(1, resourcePackage.getAnnotationsSize(JAXB.XML_SCHEMA_TYPE)); - assertSourceContains( - "@XmlSchemaType(name = \"" + TEST_NAME_2 + "\")", cu); - assertSourceDoesNotContain("@XmlSchemaTypes", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java deleted file mode 100644 index a312562667..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlSeeAlsoAnnotationTests.java +++ /dev/null @@ -1,159 +0,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 - ******************************************************************************/ -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.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlSeeAlsoAnnotationTests extends JaxbJavaResourceModelTestCase { - - - public XmlSeeAlsoAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlSeeAlso() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_SEE_ALSO); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlSeeAlso"); - } - }); - } - - private ICompilationUnit createTestXmlSeeAlsoWithValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_SEE_ALSO); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlSeeAlso(value = {Foo.class, Bar.class})"); - } - }); - } - - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlso(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - assertEquals(0, xmlSeeAlsoAnnotation.getClassesSize()); - } - - public void testGetClasses() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - ListIterator<String> classes = xmlSeeAlsoAnnotation.getClasses().iterator(); - assertEquals("Foo", classes.next()); - assertEquals("Bar", classes.next()); - } - - public void testGetClassesSize() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - assertEquals(2, xmlSeeAlsoAnnotation.getClassesSize()); - } - - public void testAddClass() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlso(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - - xmlSeeAlsoAnnotation.addClass("Fooo"); - xmlSeeAlsoAnnotation.addClass("Barrr"); - - assertSourceContains("@XmlSeeAlso({ Fooo.class, Barrr.class })", cu); - } - - public void testAddClassIndex() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlso(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - - xmlSeeAlsoAnnotation.addClass(0, "Fooo"); - xmlSeeAlsoAnnotation.addClass(0, "Barr"); - xmlSeeAlsoAnnotation.addClass(1, "Blah"); - - assertSourceContains("@XmlSeeAlso({ Barr.class, Blah.class, Fooo.class })", cu); - } - - public void testRemoveClass() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - - xmlSeeAlsoAnnotation.removeClass("Foo"); - assertSourceContains("@XmlSeeAlso(value = Bar.class)", cu); - - xmlSeeAlsoAnnotation.removeClass("Bar"); - assertSourceContains("@XmlSeeAlso", cu); - assertSourceDoesNotContain("value", cu); - } - - public void testRemoveClassIndex() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlsoWithValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - - xmlSeeAlsoAnnotation.removeClass(0); - assertSourceContains("@XmlSeeAlso(value = Bar.class)", cu); - - xmlSeeAlsoAnnotation.removeClass(0); - assertSourceContains("@XmlSeeAlso", cu); - assertSourceDoesNotContain("value", cu); - } - - public void testMoveClass() throws Exception { - ICompilationUnit cu = this.createTestXmlSeeAlso(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlSeeAlsoAnnotation xmlSeeAlsoAnnotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertTrue(xmlSeeAlsoAnnotation != null); - - xmlSeeAlsoAnnotation.addClass("Fooo"); - xmlSeeAlsoAnnotation.addClass("Barr"); - xmlSeeAlsoAnnotation.addClass("Blah"); - assertSourceContains("@XmlSeeAlso({ Fooo.class, Barr.class, Blah.class })", cu); - - xmlSeeAlsoAnnotation.moveClass(0, 1); - assertSourceContains("@XmlSeeAlso({ Barr.class, Fooo.class, Blah.class })", cu); - - xmlSeeAlsoAnnotation.moveClass(2, 1); - assertSourceContains("@XmlSeeAlso({ Barr.class, Blah.class, Fooo.class })", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientAttributeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientAttributeAnnotationTests.java deleted file mode 100644 index cc4774e79c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientAttributeAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTransientAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlTransientAttributeAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlTransientAttributeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlTransient() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TRANSIENT); - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@XmlTransient"); - } - }); - } - - public void testGetXmlTransient() throws Exception { - ICompilationUnit cu = this.createTestXmlTransient(); - JavaResourceType resourceType = this.buildJavaResourceType(cu); - JavaResourceMethod resourceMethod = this.getMethod(resourceType, 0); - - XmlTransientAnnotation xmlTransientAnnotation = (XmlTransientAnnotation) resourceMethod.getAnnotation(JAXB.XML_TRANSIENT); - assertTrue(xmlTransientAnnotation != null); - - resourceMethod.removeAnnotation(JAXB.XML_TRANSIENT); - assertSourceDoesNotContain("@XmlTransient", cu); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientTypeAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientTypeAnnotationTests.java deleted file mode 100644 index 4d6ac31190..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTransientTypeAnnotationTests.java +++ /dev/null @@ -1,49 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTransientAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlTransientTypeAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlTransientTypeAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlTransient() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlTransient"); - } - }); - } - - public void testGetXmlTransient() throws Exception { - ICompilationUnit cu = this.createTestXmlTransient(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTransientAnnotation xmlTransientAnnotation = (XmlTransientAnnotation) resourceType.getAnnotation(JAXB.XML_TRANSIENT); - assertTrue(xmlTransientAnnotation != null); - - resourceType.removeAnnotation(JAXB.XML_TRANSIENT); - assertSourceDoesNotContain("@XmlTransient", cu); - } -} 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 deleted file mode 100644 index 3c06252b96..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlTypeAnnotationTests.java +++ /dev/null @@ -1,340 +0,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 - ******************************************************************************/ -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.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -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 { - 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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(JAXB.XML_TYPE); - assertTrue(xmlTypeAnnotation != null); - assertEquals(XML_TYPE_NAME, xmlTypeAnnotation.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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); - - 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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(JAXB.XML_TYPE); - assertTrue(xmlTypeAnnotation != null); - assertEquals(XML_TYPE_NAMESPACE, xmlTypeAnnotation.getNamespace()); - } - - public void testSetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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); - - 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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(JAXB.XML_TYPE); - assertTrue(xmlTypeAnnotation != null); - assertEquals(XML_TYPE_FACTORY_METHOD, xmlTypeAnnotation.getFactoryMethod()); - } - - public void testSetFactoryMethod() throws Exception { - ICompilationUnit cu = this.createTestXmlType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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); - - 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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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); - - 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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(JAXB.XML_TYPE); - assertTrue(xmlTypeAnnotation != null); - assertEquals(2, xmlTypeAnnotation.getPropOrderSize()); - } - - public void testAddProp() throws Exception { - ICompilationUnit cu = this.createTestXmlType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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 testMoveProp() throws Exception { - ICompilationUnit cu = this.createTestXmlType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.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/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlValueAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlValueAnnotationTests.java deleted file mode 100644 index f8986cd0b7..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlValueAnnotationTests.java +++ /dev/null @@ -1,51 +0,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 - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceField; -import org.eclipse.jpt.jaxb.core.resource.java.JavaResourceType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlValueAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class XmlValueAnnotationTests extends JaxbJavaResourceModelTestCase { - - public XmlValueAnnotationTests(String name) { - super(name); - } - - private ICompilationUnit createTestXmlValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_VALUE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlValue"); - } - }); - } - - public void testGetXmlValue() throws Exception { - ICompilationUnit cu = this.createTestXmlValue(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - - XmlValueAnnotation xmlValueAnnotation = (XmlValueAnnotation) resourceAttribute.getAnnotation(JAXB.XML_VALUE); - assertTrue(xmlValueAnnotation != null); - - resourceAttribute.removeAnnotation(JAXB.XML_VALUE); - assertSourceDoesNotContain("@XmlValue", cu); - } -} |