diff options
Diffstat (limited to 'jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests')
69 files changed, 0 insertions, 15105 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 6ce4ff10a5..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/JptJaxbCoreTestsPlugin.java +++ /dev/null @@ -1,57 +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.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.jaxb.core.JaxbProjectManager; -import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; -import org.osgi.framework.BundleContext; - -/** - * configure the core to handle events synchronously when we are - * running tests - */ -@SuppressWarnings("nls") -public class 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 a018d17d59..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbCoreTests.java +++ /dev/null @@ -1,31 +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.addTestSuite(SchemaLibraryTests.class); - 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/JaxbTestCase.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java deleted file mode 100644 index a32117f964..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/JaxbTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal; - -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase; -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.JaxbFacetDataModelProperties; -import org.eclipse.jpt.jaxb.core.internal.facet.JaxbFacetInstallDataModelProvider; -import org.eclipse.jpt.jaxb.core.platform.JaxbPlatformDescription; -import org.eclipse.jpt.jaxb.core.tests.internal.projects.TestJaxbProject; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - - -public class JaxbTestCase - extends AnnotationTestCase { - - protected static final String BASE_PROJECT_NAME = "JaxbTestProject"; - - protected JaxbTestCase(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, IDataModel jaxbConfig) - throws Exception { - return TestJaxbProject.buildJaxbProject(projectName, autoBuild, jaxbConfig); - } - - protected IDataModel buildJaxbFacetInstallConfig() { - IDataModel config = DataModelFactory.createDataModel(new JaxbFacetInstallDataModelProvider()); - config.setProperty(IFacetDataModelProperties.FACET_VERSION, getProjectFacetVersion()); - config.setProperty(JaxbFacetDataModelProperties.PLATFORM, getPlatform()); - return config; - } - - protected JaxbPlatformDescription getPlatform() { - return JptJaxbCorePlugin.getDefaultPlatform(getProjectFacetVersion()); - } - - protected IProjectFacetVersion getProjectFacetVersion() { - return JaxbFacet.VERSION_2_1; - } - - @Override - protected TestJaxbProject getJavaProject() { - return (TestJaxbProject) super.getJavaProject(); - } - - protected JaxbProject getJaxbProject() { - return this.getJavaProject().getJaxbProject(); - } - - protected JavaResourceAttribute getFieldNamed(JavaResourceType resourceType, String attributeName) { - for (JavaResourceAttribute attribute : resourceType.getFields()) { - if (attribute.getName().equals(attributeName)) { - return attribute; - } - } - return null; - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/SchemaLibraryTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/SchemaLibraryTests.java deleted file mode 100644 index 219a879f1a..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/SchemaLibraryTests.java +++ /dev/null @@ -1,122 +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 java.io.ByteArrayInputStream; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.Path; -import org.eclipse.xsd.XSDSchema; - - - -public class SchemaLibraryTests - extends JaxbTestCase { - - public SchemaLibraryTests(String name) { - super(name); - } - - // tests schema for namespace that is set in catalog, but not in project properties - public void testUnsetNamespace() { - String namespace = "http://www.eclipse.org/eclipselink/xsds/persistence/orm"; - - // test initial load - XSDSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test cached load - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test unload/reload - schema.eResource().unload(); - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - } - - // tests schema for registered uri that is set in project properties (namespace not registered in catalog) - public void testSetRegisteredUriUnregisteredNamespace() { - String namespace = "http://java.sun.com/xml/ns/persistence/orm"; - - // set namespace in project properties\ - Map<String, String> schemaLocations = new HashMap<String, String>(); - schemaLocations.put(namespace, "http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"); - getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations); - - // test initial load - XSDSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test cached load - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test unload/reload - schema.eResource().unload(); - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - } - - // tests schema for registerd uri that is set in project properties (namespace already registered in catalog) - public void testSetRegisteredUriRegisteredNamespace() { - String namespace = "http://www.eclipse.org/eclipselink/xsds/persistence/orm"; - - // set namespace in project properties\ - Map<String, String> schemaLocations = new HashMap<String, String>(); - schemaLocations.put(namespace, "http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_1_0.xsd"); - getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations); - - // test initial load - XSDSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test cached load - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test unload/reload - schema.eResource().unload(); - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - } - - // tests schema for unregistered uri that is set in project properties (local file) - public void testSetUnregisterdUri() throws Exception { - IFile schemaFile = getJaxbProject().getProject().getFile(new Path("customer.xsd")); - String contents = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" - + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"" - + " targetNamespace=\"http://www.example.org/customer-example\">" - + "</xs:schema>"; - schemaFile.create(new ByteArrayInputStream(contents.getBytes()), true, null); - - String namespace = "http://www.example.org/customer-example"; - - // set namespace in project properties\ - Map<String, String> schemaLocations = new HashMap<String, String>(); - schemaLocations.put(namespace, "platform:/resource/" + BASE_PROJECT_NAME + "/customer.xsd"); - getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations); - - // test initial load - XSDSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test cached load - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - - // test unload/reload - schema.eResource().unload(); - schema = getJaxbProject().getSchemaLibrary().getSchema(namespace); - assertNotNull(schema); - } -} 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 6249397302..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/GenericContextRootTests.java +++ /dev/null @@ -1,602 +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.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.TypeLiteral; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.ArrayTools; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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; - - -@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 createAnnotatedPersistentClassWithSuperclassNamed(final String superclassName) 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"); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + superclassName); - } - }); - } - - private ICompilationUnit createAnnotatedPersistentClassWithAttributeAndTypeNamed( - final String attributeName, final String typeName) 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"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("public " + typeName + " " + attributeName + ";" + CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createAnnotatedPersistentClassWithAttributeAndElementTypeNamed( - final String attributeName, final String typeName) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>("java.util.List", JAXB.XML_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendNameFieldAnnotationTo(StringBuilder sb) { - sb.append("public List<" + typeName + "> " + attributeName + ";" + CR); - sb.append(CR); - } - }); - } - - 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); - addEnumMemberValuePair(annotation, JAXB.XML_ACCESSOR_TYPE__VALUE, accessType); - } - - protected void removeXmlAccessorTypeAnnotation(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_ACCESSOR_TYPE); - } - - protected void addXmlSeeAlsoAnnotation(final ModifiedDeclaration declaration, String... typeNames) { - Annotation annotation = declaration.getAnnotationNamed(JAXB.XML_SEE_ALSO); - NormalAnnotation normalAnnotation = null; - if (annotation == null) { - normalAnnotation = addNormalAnnotation(declaration.getDeclaration(), JAXB.XML_SEE_ALSO); - } - else if (annotation.isMarkerAnnotation()) { - normalAnnotation = replaceMarkerAnnotation((MarkerAnnotation) annotation); - } - else { - normalAnnotation = (NormalAnnotation) annotation; - } - - Expression arrayInitializer = newArrayInitializer( - declaration.getAst(), - ArrayTools.array( - new TransformationIterable<String, TypeLiteral>(new ArrayIterable<String>(typeNames)) { - @Override - protected TypeLiteral transform(String o) { - return newTypeLiteral(declaration.getAst(), o); - } - }, - new Expression[0])); - addMemberValuePair(normalAnnotation, JAXB.XML_SEE_ALSO__VALUE, arrayInitializer); - } - - public void testGetRegistries() throws Exception { - createAnnotatedRegistry(); - 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 - createUnannotatedClassNamed("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 - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - 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 - createUnannotatedClassNamed("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 - JavaResourceAbstractType 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.createAnnotatedPersistentEnum(); - 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 - createUnannotatedEnumNamed("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 = (JavaResourceEnum) getJaxbProject().getJavaResourceType("test.Foo", JavaResourceAbstractType.Kind.ENUM); - AnnotatedElement annotatedElement = annotatedElement(fooResourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TYPE); - } - }); - - 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_TYPE); - } - }); - - 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 { - createAnnotatedRegistry(); - createUnannotatedClassNamed("Foo"); - JavaResourceAbstractType 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())); - } - - public void testDirectReferencedSuperclass() throws Exception { - String superclassName = "Super" + TYPE_NAME; - String fqSuperclassName = PACKAGE_NAME_ + superclassName; - createUnannotatedClassNamed(superclassName); - - // make sure unannotated superclass is not in context - assertTrue(CollectionTools.isEmpty(getContextRoot().getPersistentClasses())); - - createAnnotatedPersistentClassWithSuperclassNamed(superclassName); - Iterable<JaxbPersistentClass> persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(2, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqSuperclassName)); - - // remove annotated class - both classes removed from context - IFile file = (IFile) getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME).getResource(); - file.delete(true, null); - - persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(0, CollectionTools.size(persistentClasses)); - assertNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNull(getContextRoot().getPersistentClass(fqSuperclassName)); - } - - public void testDirectReferencedAttribute() throws Exception { - String otherClassName = "Other" + TYPE_NAME; - String fqOtherClassName = PACKAGE_NAME_ + otherClassName; - String attributeName = "other"; - createUnannotatedClassNamed(otherClassName); - - // make sure unannotated other class is not in context - assertTrue(CollectionTools.isEmpty(getContextRoot().getPersistentClasses())); - - createAnnotatedPersistentClassWithAttributeAndTypeNamed(attributeName, otherClassName); - JavaResourceType thisType = (JavaResourceType) getJaxbProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceAttribute attribute = getFieldNamed(thisType, attributeName); - AnnotatedElement annotatedAttribute = annotatedElement(attribute); - - Iterable<JaxbPersistentClass> persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(2, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // add an @XmlElement - annotatedAttribute.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT); - } - }); - - persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(2, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // change to @XmlTransient - annotatedAttribute.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_ELEMENT); - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TRANSIENT); - } - }); - - persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(1, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNull(getContextRoot().getPersistentClass(fqOtherClassName)); - } - - public void testDirectReferencedListAttribute() throws Exception { - String otherClassName = "Other" + TYPE_NAME; - String fqOtherClassName = PACKAGE_NAME_ + otherClassName; - String attributeName = "other"; - createUnannotatedClassNamed(otherClassName); - - // make sure unannotated other class is not in context - assertTrue(CollectionTools.isEmpty(getContextRoot().getPersistentClasses())); - - createAnnotatedPersistentClassWithAttributeAndElementTypeNamed(attributeName, otherClassName); - JavaResourceType thisType = (JavaResourceType) getJaxbProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceAttribute attribute = getFieldNamed(thisType, attributeName); - AnnotatedElement annotatedAttribute = annotatedElement(attribute); - - Iterable<JaxbPersistentClass> persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(2, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // add an @XmlElement - annotatedAttribute.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT); - } - }); - - persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(2, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // change to @XmlTransient - annotatedAttribute.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_ELEMENT); - addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_TRANSIENT); - } - }); - - persistentClasses = this.getContextRoot().getPersistentClasses(); - assertEquals(1, CollectionTools.size(persistentClasses)); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNull(getContextRoot().getPersistentClass(fqOtherClassName)); - } - - public void testDirectReferencedSeeAlso() throws Exception { - final String otherClassName = "Other" + TYPE_NAME; - final String fqOtherClassName = PACKAGE_NAME_ + otherClassName; - final String otherClassName2 = "Other" + TYPE_NAME + "2"; - final String fqOtherClassName2 = PACKAGE_NAME_ + otherClassName2; - createUnannotatedClassNamed(otherClassName); - createUnannotatedClassNamed(otherClassName2); - - // make sure unannotated other classes are not in context - assertTrue(CollectionTools.isEmpty(getContextRoot().getPersistentClasses())); - - createAnnotatedPersistentClass(); - JavaResourceType thisType = (JavaResourceType) getJaxbProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME); - AnnotatedElement annotatedType = annotatedElement(thisType); - - // make sure unannotated other classes are not in context - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - - // add an @XmlSeeAlso with one class - annotatedType.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - addXmlSeeAlsoAnnotation(declaration, otherClassName); - } - }); - - assertEquals(2, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // change to @XmlSeeAlso with two classes - annotatedType.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_SEE_ALSO); - addXmlSeeAlsoAnnotation(declaration, otherClassName, otherClassName2); - } - }); - - assertEquals(3, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName2)); - - // remove the @XmlSeeAlso annotation - annotatedType.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - removeAnnotation(declaration, JAXB.XML_SEE_ALSO); - } - }); - - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - } - - public void testJaxbIndex() throws Exception { - final String otherClassName = "Other" + TYPE_NAME; - final String fqOtherClassName = PACKAGE_NAME_ + otherClassName; - final String otherClassName2 = "Other" + TYPE_NAME + "2"; - final String fqOtherClassName2 = PACKAGE_NAME_ + otherClassName2; - createUnannotatedClassNamed(otherClassName); - createUnannotatedClassNamed(otherClassName2); - - // make sure unannotated other classes are not in context - assertTrue(CollectionTools.isEmpty(getContextRoot().getPersistentClasses())); - - createAnnotatedPersistentClass(); - - // make sure unannotated other classes are not in context - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - - // add a jaxb.index with one class - IFile jaxbIndex = getJavaProject().getProject().getFile(new Path("src/test/jaxb.index")); - InputStream stream = new ByteArrayInputStream(otherClassName.getBytes()); - jaxbIndex.create(stream, true, null); - - assertEquals(2, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - - // change to jaxb.index with two classes - jaxbIndex.setContents(new ByteArrayInputStream((otherClassName + CR + otherClassName2).getBytes()), true, false, null); - - assertEquals(3, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName)); - assertNotNull(getContextRoot().getPersistentClass(fqOtherClassName2)); - - // clear the jaxb.index - jaxbIndex.setContents(new ByteArrayInputStream(new byte[0]), true, false, null); - - assertEquals(1, CollectionTools.size(getContextRoot().getPersistentClasses())); - assertNotNull(getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME)); - } -} 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 2b94840f9b..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/JaxbContextModelTestCase.java +++ /dev/null @@ -1,98 +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.jpt.common.core.resource.java.JavaResourceAnnotatedElement; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.JaxbContextRoot; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.tests.internal.JaxbTestCase; - -@SuppressWarnings("nls") -public abstract class JaxbContextModelTestCase - extends JaxbTestCase { - - 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 JaxbContextRoot getContextRoot() { - return this.getJaxbProject().getContextRoot(); - } - - protected AnnotatedElement annotatedElement(JavaResourceAnnotatedElement resource) { - return (AnnotatedElement) ReflectionTools.getFieldValue(resource, "annotatedElement"); - } - - protected ICompilationUnit createUnannotatedPackageInfo(String packageName) throws CoreException { - return createTestPackageInfo(packageName); - } - - protected ICompilationUnit createAnnotatedPersistentClass() 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"); - } - }); - } - - protected ICompilationUnit createUnannotatedClassNamed(String typeName) throws Exception { - return this.createTestType(PACKAGE_NAME, typeName + ".java", typeName, new DefaultAnnotationWriter()); - } - - protected ICompilationUnit createAnnotatedPersistentEnum() throws Exception { - return this.createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - }); - } - - protected ICompilationUnit createUnannotatedEnumNamed(String enumName) throws Exception { - return this.createTestEnum(PACKAGE_NAME, enumName + ".java", enumName, new DefaultEnumAnnotationWriter()); - } - - protected ICompilationUnit createAnnotatedRegistry() 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"); - } - }); - } -} 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/GenericJavaAttributeXmlJavaTypeAdapterTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaAttributeXmlJavaTypeAdapterTests.java deleted file mode 100644 index 2432b98e93..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaAttributeXmlJavaTypeAdapterTests.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -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.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaAttributeXmlJavaTypeAdapterTests extends JaxbContextModelTestCase -{ - - public GenericJavaAttributeXmlJavaTypeAdapterTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlTypeWithXmlJavaTypeAdapter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ATTRIBUTE, JAXB.XML_JAVA_TYPE_ADAPTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").append(CR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttribute").append(CR); - sb.append("@XmlJavaTypeAdapter"); - } - }); - } - - public void testModifyValue() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - XmlAttributeMapping contextAttributeMapping = (XmlAttributeMapping) CollectionTools.get(CollectionTools.get(getContextRoot().getPersistentClasses(), 0).getAttributes(), 0).getMapping(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextAttributeMapping.getXmlJavaTypeAdapter(); - JavaResourceAttribute resourceAttribute = contextAttributeMapping.getJavaResourceAttribute(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - contextXmlJavaTypeAdapter.setValue("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.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) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getValue()); - assertNull(contextXmlJavaTypeAdapter.getValue()); - } - - public void testUpdateValue() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - XmlAttributeMapping contextAttributeMapping = (XmlAttributeMapping) CollectionTools.get(CollectionTools.get(getContextRoot().getPersistentClasses(), 0).getAttributes(), 0).getMapping(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextAttributeMapping.getXmlJavaTypeAdapter(); - JavaResourceAttribute resourceAttribute = contextAttributeMapping.getJavaResourceAttribute(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - //add a value member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaAttributeXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaAttributeXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertNull(contextAttributeMapping.getXmlJavaTypeAdapter()); - } - - public void testModifyType() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - XmlAttributeMapping contextAttributeMapping = (XmlAttributeMapping) CollectionTools.get(CollectionTools.get(getContextRoot().getPersistentClasses(), 0).getAttributes(), 0).getMapping(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextAttributeMapping.getXmlJavaTypeAdapter(); - JavaResourceAttribute resourceAttribute = contextAttributeMapping.getJavaResourceAttribute(); - - assertEquals("int", contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("int", contextXmlJavaTypeAdapter.getDefaultType()); - - contextXmlJavaTypeAdapter.setSpecifiedType("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertEquals("foo", javaTypeAdapterAnnotation.getType()); - assertEquals("foo", contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("int", contextXmlJavaTypeAdapter.getDefaultType()); - - contextXmlJavaTypeAdapter.setSpecifiedType(null); - javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getType()); - assertEquals("int", contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("int", contextXmlJavaTypeAdapter.getDefaultType()); - } - - public void testUpdateType() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - XmlAttributeMapping contextAttributeMapping = (XmlAttributeMapping) CollectionTools.get(CollectionTools.get(getContextRoot().getPersistentClasses(), 0).getAttributes(), 0).getMapping(); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextAttributeMapping.getXmlJavaTypeAdapter(); - JavaResourceAttribute resourceAttribute = contextAttributeMapping.getJavaResourceAttribute(); - - assertEquals("int", contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("int", contextXmlJavaTypeAdapter.getDefaultType()); - - //add a type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaAttributeXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("String", contextXmlJavaTypeAdapter.getType()); - assertEquals("int", contextXmlJavaTypeAdapter.getDefaultType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaAttributeXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertNull(contextAttributeMapping.getXmlJavaTypeAdapter()); - } - - 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); - } - - protected void removeXmlJavaTypeAdapterAnnotation(ModifiedDeclaration declaration) { - 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/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 526fbbf35b..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.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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.XmlElementDeclAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@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 1d93c8c7dd..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.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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.XmlEnumValueAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@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_TYPE); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").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.getValue()); - 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 106a3bf80e..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,794 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.SubListIterableWrapper; -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.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; - - -@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.getValue()); - 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.getValue()); - 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().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().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).getSchemaTypeRef().setSpecifiedName("bar"); - contextPackageInfo.addXmlSchemaType(0).getSchemaTypeRef().setSpecifiedName("foo"); - contextPackageInfo.addXmlSchemaType(0).getSchemaTypeRef().setSpecifiedName("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()); - } - - protected Iterator<XmlSchemaTypeAnnotation> getSchemaTypeAnnotations(JavaResourcePackage resourcePackage) { - return new SubListIterableWrapper<NestableAnnotation, 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).getSchemaTypeRef().setSpecifiedName("bar"); - contextPackageInfo.addXmlSchemaType(1).getSchemaTypeRef().setSpecifiedName("foo"); - contextPackageInfo.addXmlSchemaType(0).getSchemaTypeRef().setSpecifiedName("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).getSchemaTypeRef().setSpecifiedName("bar"); - contextPackageInfo.addXmlSchemaType(1).getSchemaTypeRef().setSpecifiedName("foo"); - contextPackageInfo.addXmlSchemaType(2).getSchemaTypeRef().setSpecifiedName("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).getSchemaTypeRef().setSpecifiedName("bar"); - contextPackageInfo.addXmlSchemaType(1).getSchemaTypeRef().setSpecifiedName("foo"); - contextPackageInfo.addXmlSchemaType(2).getSchemaTypeRef().setSpecifiedName("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().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().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().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getSchemaTypeRef().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().getSchemaTypeRef().getName()); - assertEquals("bar", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("foo", xmlSchemaTypesIterator.next().getSchemaTypeRef().getName()); - assertEquals("baz", xmlSchemaTypesIterator.next().getSchemaTypeRef().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()); - } - - protected Iterator<XmlJavaTypeAdapterAnnotation> getXmlJavaTypeAdapterAnnotations(JavaResourcePackage resourcePackage) { - return new SubListIterableWrapper<NestableAnnotation, 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/GenericJavaPackageXmlJavaTypeAdapterTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageXmlJavaTypeAdapterTests.java deleted file mode 100644 index 0cd9a9acbd..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPackageXmlJavaTypeAdapterTests.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -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.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaPackageXmlJavaTypeAdapterTests extends JaxbContextModelTestCase -{ - - public GenericJavaPackageXmlJavaTypeAdapterTests(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) { - GenericJavaPackageXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageXmlJavaTypeAdapterTests.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()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertNull(contextXmlJavaTypeAdapter.getDefaultType()); - - contextXmlJavaTypeAdapter.setSpecifiedType("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.setSpecifiedType(null); - javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourcePackage.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getType()); - assertNull(contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertNull(contextXmlJavaTypeAdapter.getDefaultType()); - } - - 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()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertNull(contextXmlJavaTypeAdapter.getDefaultType()); - - //add a type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourcePackage); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPackageXmlJavaTypeAdapterTests.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/GenericJavaPersistentAttributeTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java deleted file mode 100644 index 138e99e9f5..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -public class GenericJavaPersistentAttributeTests - extends JaxbContextModelTestCase { - - private static String TEST_CLASS_NAME = "TestClass"; - - public GenericJavaPersistentAttributeTests(String name) { - super(name); - } - - - private void createXmlTypeWithVariousAttributes() throws CoreException { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JAXB.XML_TYPE).append(";").append(CR); - sb.append("import java.util.List;").append(CR); - sb.append(CR); - sb.append("@XmlType").append(CR); - sb.append("public class ").append(TEST_CLASS_NAME).append("<T extends Number> ").append("{").append(CR); - sb.append(" public String string;").append(CR); - sb.append(" public List<String> stringList;").append(CR); - sb.append(" public String[] stringArray;").append(CR); - sb.append(" public String[][] stringDoubleArray;").append(CR); - sb.append(" public T generic;").append(CR); - sb.append(" public List<T> genericList;").append(CR); - sb.append(" public T[] genericArray;").append(CR); - sb.append(" public List<?> wildcardList;").append(CR); - sb.append(" public byte[] byteArray;").append(CR); - sb.append(" public List list;").append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, TEST_CLASS_NAME + ".java", sourceWriter); - } - - - public void testJavaResourceType() throws Exception { - createXmlTypeWithVariousAttributes(); - JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(PACKAGE_NAME_ + TEST_CLASS_NAME); - - // String string - JaxbPersistentAttribute att = CollectionTools.get(persistentClass.getAttributes(), 0); - assertEquals("java.lang.String", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(false, att.isJavaResourceAttributeCollectionType()); - - // List<String> stringList - att = CollectionTools.get(persistentClass.getAttributes(), 1); - assertEquals("java.lang.String", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - - // String[] stringArray - att = CollectionTools.get(persistentClass.getAttributes(), 2); - assertEquals("java.lang.String", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - - // String[][] stringDoubleArray - att = CollectionTools.get(persistentClass.getAttributes(), 3); - assertEquals("java.lang.String[][]", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(false, att.isJavaResourceAttributeCollectionType()); - - // T generic - att = CollectionTools.get(persistentClass.getAttributes(), 4); - assertEquals("java.lang.Number", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(false, att.isJavaResourceAttributeCollectionType()); - - // List<T> genericList - att = CollectionTools.get(persistentClass.getAttributes(), 5); - assertEquals("java.lang.Number", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - - // T[] genericArray - att = CollectionTools.get(persistentClass.getAttributes(), 6); - assertEquals("java.lang.Number", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - - // List<?> wildcardList - att = CollectionTools.get(persistentClass.getAttributes(), 7); - assertEquals("java.lang.Object", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - - // byte[] byteArray - att = CollectionTools.get(persistentClass.getAttributes(), 8); - assertEquals("byte[]", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(false, att.isJavaResourceAttributeCollectionType()); - - // List list - att = CollectionTools.get(persistentClass.getAttributes(), 9); - assertEquals("java.lang.Object", att.getJavaResourceAttributeBaseTypeName()); - assertEquals(true, att.isJavaResourceAttributeCollectionType()); - } -} 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 94aff3c27f..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,2164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.beans.Introspector; -import java.util.Iterator; -import java.util.List; -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.BodyDeclaration; -import org.eclipse.jdt.core.dom.IExtendedModifier; -import org.eclipse.jdt.core.dom.MarkerAnnotation; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMember; -import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.ReflectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.JaxbPackageInfo; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -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.internal.context.java.PropertyAccessor; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTransientAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentClassTests - extends JaxbContextModelTestCase { - - public GenericJavaPersistentClassTests(String name) { - super(name); - } - - - 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); - } - - private void createTestXmlTypeWithFieldAndPublicMemberAccess() 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("import "); - sb.append(JAXB.XML_ATTRIBUTE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TRANSIENT); - sb.append(";"); - sb.append(CR); - sb.append("import java.util.List;"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append(TYPE_NAME).append(" "); - sb.append("{").append(CR); - sb.append(" public int foo;").append(CR); - sb.append(CR).append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestType.java", sourceWriter); - } - - private void createTestXmlTypeWithPropertyAndPublicMemberAccess() 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("import "); - sb.append(JAXB.XML_ATTRIBUTE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TRANSIENT); - sb.append(";"); - sb.append(CR); - sb.append("import java.util.List;"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append(TYPE_NAME).append(" "); - sb.append("{").append(CR); - sb.append(" public int getFoo() {").append(CR); - sb.append(" return 1;").append(CR).append(" }").append(CR); - sb.append(" public void setFoo(int foo) {}").append(CR).append(CR); - sb.append(CR).append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestType.java", sourceWriter); - } - - private void createTestXmlTypeWithPropertyGetterAndPublicMemberAccess() 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("import "); - sb.append(JAXB.XML_ATTRIBUTE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TRANSIENT); - sb.append(";"); - sb.append(CR); - sb.append("import java.util.List;"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append(TYPE_NAME).append(" "); - sb.append("{").append(CR); - sb.append(" public int getFoo() {").append(CR); - sb.append(" return 1;").append(CR).append(" }").append(CR); - sb.append(CR).append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestType.java", sourceWriter); - } - - private void createTestXmlTypeWithPropertyGetterListAndPublicMemberAccess() 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("import "); - sb.append(JAXB.XML_ATTRIBUTE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TRANSIENT); - sb.append(";"); - sb.append(CR); - sb.append("import java.util.List;"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append(TYPE_NAME).append(" "); - sb.append("{").append(CR); - sb.append(" public List<?> getFoo() {").append(CR); - sb.append(" return 1;").append(CR).append(" }").append(CR); - sb.append(CR).append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestType.java", sourceWriter); - } - - private void createTestXmlTypeWithPropertySetterAndPublicMemberAccess() 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("import "); - sb.append(JAXB.XML_ATTRIBUTE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JAXB.XML_TRANSIENT); - sb.append(";"); - sb.append(CR); - sb.append("import java.util.List;"); - sb.append(CR); - sb.append("@XmlType"); - sb.append(CR); - sb.append("public class ").append(TYPE_NAME).append(" "); - sb.append("{").append(CR); - sb.append(" public void setFoo(int foo) {}").append(CR).append(CR); - sb.append(CR).append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestType.java", sourceWriter); - } - - public void testModifyFactoryClass() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - String defaultXmlTypeName = Introspector.decapitalize(TYPE_NAME); - - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getDefaultName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getName()); - - persistentClass.getSchemaTypeRef().setSpecifiedName("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getName()); - - persistentClass.getSchemaTypeRef().setSpecifiedName(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getName()); - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getName()); - - //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.getSchemaTypeRef().setSpecifiedName("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getName()); - } - - public void testUpdateSchemaTypeName() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - String defaultXmlTypeName = Introspector.decapitalize(TYPE_NAME); - - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getDefaultName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getName()); - - //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.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getName()); - - //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.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, persistentClass.getSchemaTypeRef().getName()); - } - - public void testModifyNamespace() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().getDefaultNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().getNamespace()); - - persistentClass.getSchemaTypeRef().setSpecifiedNamespace("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getNamespace()); - - persistentClass.getSchemaTypeRef().setSpecifiedNamespace(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getNamespace()); - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().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.getSchemaTypeRef().setSpecifiedNamespace("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceType.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", persistentClass.getSchemaTypeRef().getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - assertNull(persistentClass.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().getDefaultNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", persistentClass.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", persistentClass.getSchemaTypeRef().getNamespace()); - } - - public void testModifyAccessType() throws Exception { - createXmlTypeWithAccessorType(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.getValue()); - 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); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - 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.createAnnotatedPersistentClass(); - this.createTestSubType(); - JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - JaxbPersistentClass childPersistentClass = getContextRoot().getPersistentClass(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - assertEquals(persistentClass, childPersistentClass.getSuperClass()); - - //test that the superClass is not null even when it is unannotated - AnnotatedElement annotatedElement = this.annotatedElement(persistentClass.getJavaResourceType()); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlTypeAnnotation.ANNOTATION_NAME); - } - }); - assertEquals(persistentClass, childPersistentClass.getSuperClass()); - } - - public void testModifyAccessOrder() throws Exception { - createXmlTypeWithAccessorOrder(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.getValue()); - 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); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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.createAnnotatedPersistentClass(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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().getSchemaElementRef().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 { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType 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().getSchemaElementRef().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()); - } - - - public void testUpdateFieldAttributes() throws Exception { - this.createTestXmlTypeWithFieldAndPublicMemberAccess(); - - JaxbPersistentClass contextClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - //public int foo; - this.publicFieldTest(contextClass); - - //public transient int foo; - this.publicTransientFieldTest(contextClass); - - //public static int foo; - this.publicStaticFieldTest(contextClass); - - //public final int foo; - this.publicFinalFieldTest(contextClass); - - //public static final int foo; - this.publicStaticFinalFieldTest(contextClass); - - //private int foo; - this.privateFieldTest(contextClass); - - // private transient int foo; - this.privateTransientFieldTest(contextClass); - - // @XmlAttribute - // private static int foo; //persistent - this.privateStaticFieldTest(contextClass); - - // @XmlAttribute - // private static final int foo; //persistent - this.privateStaticFinalFieldTest(contextClass); - } - - protected void publicFieldTest(JaxbPersistentClass contextClass) { - //public int foo; PUBLIC_MEMBER access - persistent - assertEquals(1, contextClass.getAttributesSize()); - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - - //add @XmlTransient annotation and test each access type - JavaResourceField resourceField = (JavaResourceField) contextClass.getAttributes().iterator().next().getJavaResourceAttribute(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceField); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlTransientAnnotation.ANNOTATION_NAME); - } - }); - //@XmlTransient - //public int foo; //PROPERTY access - not "persistent", but comes in to our context model because it is "mapped" - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlTransient - //public int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlTransient - //public int foo; //NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlTransient - //public int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlTransientAnnotation.ANNOTATION_NAME); - } - }); - } - - protected void publicTransientFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - - //public transient int foo; PUBLIC_MEMBER access - not persistent - this.addModifiers(resourceField, ModifierKeyword.TRANSIENT_KEYWORD); - assertEquals(0, contextClass.getAttributesSize()); - - //public transient int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public transient int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public transient int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public transient int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - this.removeModifiers(resourceField, ModifierKeyword.TRANSIENT_KEYWORD); - } - - protected void publicStaticFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - - //public static int foo; PUBLIC_MEMBER access - not persistent - this.addModifiers(resourceField, ModifierKeyword.STATIC_KEYWORD); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - this.removeModifiers(resourceField, ModifierKeyword.STATIC_KEYWORD); - } - - protected void publicFinalFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - - //public final int foo; PUBLIC_MEMBER access - persistent - this.addModifiers(resourceField, ModifierKeyword.FINAL_KEYWORD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public final int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public final int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public final int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public final int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - this.removeModifiers(resourceField, ModifierKeyword.FINAL_KEYWORD); - } - - protected void publicStaticFinalFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - - //public static final int foo; PUBLIC_MEMBER access - not persistent - this.addModifiers(resourceField, ModifierKeyword.STATIC_KEYWORD, ModifierKeyword.FINAL_KEYWORD); - assertEquals(0, contextClass.getAttributesSize()); - - //public static final int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public static final int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public static final int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public static final int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - this.removeModifiers(resourceField, ModifierKeyword.STATIC_KEYWORD, ModifierKeyword.FINAL_KEYWORD); - } - - protected void privateFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - removeModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD); - - //private int foo; PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //private int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //private int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //private int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //private int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceField); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //private int foo; //PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int foo; //NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - removeModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - } - - protected void privateTransientFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - removeModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD, ModifierKeyword.TRANSIENT_KEYWORD); - - //private transient int foo; PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //private transient int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //private transient int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //private transient int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //private transient int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceField); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //private transient int foo; //PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private transient int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private transient int foo; //NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private transient int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - removeModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD, ModifierKeyword.TRANSIENT_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - } - - protected void privateStaticFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - removeModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD, ModifierKeyword.STATIC_KEYWORD); - - //private static int foo; PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //private static int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //private static int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //private static int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //private static int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceField); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //private static int foo; //PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static int foo; //NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - removeModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD, ModifierKeyword.STATIC_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - } - - protected void privateStaticFinalFieldTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - JavaResourceField resourceField = (JavaResourceField) attributes.next().getJavaResourceAttribute(); - removeModifiers(resourceField, ModifierKeyword.PUBLIC_KEYWORD); - addModifiers(resourceField, ModifierKeyword.PRIVATE_KEYWORD, ModifierKeyword.STATIC_KEYWORD, ModifierKeyword.FINAL_KEYWORD); - - //private static final int foo; PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //private static final int foo; //PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //private static final int foo; //FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //private static final int foo; //NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //private static final int foo; PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceField); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //private static final int foo; //PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static final int foo; //FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static final int foo; //NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private static final int foo; PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - } - - public void testUpdatePropertyAttributes() throws Exception { - this.createTestXmlTypeWithPropertyAndPublicMemberAccess(); - - JaxbPersistentClass contextClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - //public int getFoo();, public void setFoo(int); - this.publicGetterSetterTest(contextClass); - - //public static int getFoo();, public static void setFoo(int); - this.publicStaticGetterSetterTest(contextClass); - - //private int getFoo();, private void setFoo(int); - this.privateGetterSetterTest(contextClass); - } - - public void testUpdateGetterPropertyAttributes() throws Exception { - this.createTestXmlTypeWithPropertyGetterAndPublicMemberAccess(); - - JaxbPersistentClass contextClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - //public int getFoo(); PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo(); PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo(); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo(); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo(); PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - JavaResourceMethod resourceMethod = contextClass.getJavaResourceType().getMethods().iterator().next(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //public int getFoo(); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo(); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo(); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo(); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - } - - public void testUpdateSetterPropertyAttributes() throws Exception { - this.createTestXmlTypeWithPropertySetterAndPublicMemberAccess(); - - JaxbPersistentClass contextClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - //public void setFoo(int foo); PUBLIC_MEMBER access - not persistent - assertEquals(0, contextClass.getAttributesSize()); - - //public void setFoo(int foo); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public void setFoo(int foo); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public void setFoo(int foo); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public void setFoo(int foo); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - JavaResourceMethod resourceMethod = contextClass.getJavaResourceType().getMethods().iterator().next(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //public void setFoo(int foo);; PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public void setFoo(int foo); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public void setFoo(int foo); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public void setFoo(int foo); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - } - - public void testUpdateGetterListPropertyAttributes() throws Exception { - this.createTestXmlTypeWithPropertyGetterListAndPublicMemberAccess(); - - JaxbPersistentClass contextClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - //public List<?> getFoo(); PUBLIC_MEMBER access - persistent - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public List<?> getFoo(); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public List<?> getFoo(); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public List<?> getFoo(); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public List<?> getFoo(); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - - //add @XmlAttribute annotation and test each access type - JavaResourceMethod resourceMethod = contextClass.getJavaResourceType().getMethods().iterator().next(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //public List<?> getFoo(); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - attributes = contextClass.getAttributes().iterator(); - assertEquals(1, contextClass.getAttributesSize()); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public List<?> getFoo(); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public List<?> getFoo(); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public List<?> getFoo(); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - } - - protected void publicGetterSetterTest(JaxbPersistentClass contextClass) { - //public int getFoo();, public void setFoo(int); PUBLIC_MEMBER access - persistent - assertEquals(1, contextClass.getAttributesSize()); - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public int getFoo();, public void setFoo(int); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //public int getFoo();, public void setFoo(int); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo();, public void setFoo(int); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public int getFoo();, public void setFoo(int); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - - //add @XmlAttribute annotation and test each access type - JavaResourceMethod resourceMethod = (JavaResourceMethod) contextClass.getAttributes().iterator().next().getJavaResourceAttribute(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceMethod); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //public int getFoo();, public void setFoo(int); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo();, public void setFoo(int); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo();, public void setFoo(int); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public int getFoo();, public void setFoo(int); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - } - - protected void publicStaticGetterSetterTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - PropertyAccessor propertyAccessor = (PropertyAccessor) ReflectionTools.getFieldValue(attributes.next(), "accessor"); - JavaResourceMethod resourceGetter = propertyAccessor.getResourceGetterMethod(); - JavaResourceMethod resourceSetter = propertyAccessor.getResourceSetterMethod(); - - //public static int getFoo();, public static void setFoo(int); PUBLIC_MEMBER access - not persistent - this.addModifiers(resourceGetter, ModifierKeyword.STATIC_KEYWORD); - this.addModifiers(resourceSetter, ModifierKeyword.STATIC_KEYWORD); - assertEquals(0, contextClass.getAttributesSize()); - - - //public static int getFoo();, public static void setFoo(int); PROPERTY access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int getFoo();, public static void setFoo(int); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int getFoo();, public static void setFoo(int); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //public static int getFoo();, public static void setFoo(int); PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceGetter); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //public static int getFoo();, public static void setFoo(int); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public static int getFoo();, public static void setFoo(int); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public static int getFoo();, public static void setFoo(int); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //public static int getFoo();, public static void setFoo(int); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - this.removeModifiers(resourceGetter, ModifierKeyword.STATIC_KEYWORD); - this.removeModifiers(resourceSetter, ModifierKeyword.STATIC_KEYWORD); - } - - protected void privateGetterSetterTest(JaxbPersistentClass contextClass) { - Iterator<JaxbPersistentAttribute> attributes = contextClass.getAttributes().iterator(); - PropertyAccessor propertyAccessor = (PropertyAccessor) ReflectionTools.getFieldValue(attributes.next(), "accessor"); - JavaResourceMethod resourceGetter = propertyAccessor.getResourceGetterMethod(); - JavaResourceMethod resourceSetter = propertyAccessor.getResourceSetterMethod(); - - //private int getFoo();, private void setFoo(int); PUBLIC_MEMBER access - not persistent - this.removeModifiers(resourceGetter, ModifierKeyword.PUBLIC_KEYWORD); - this.removeModifiers(resourceSetter, ModifierKeyword.PUBLIC_KEYWORD); - this.addModifiers(resourceGetter, ModifierKeyword.PRIVATE_KEYWORD); - this.addModifiers(resourceSetter, ModifierKeyword.PRIVATE_KEYWORD); - assertEquals(0, contextClass.getAttributesSize()); - - - //private int getFoo();, private void setFoo(int); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //private int getFoo();, private void setFoo(int); FIELD access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(0, contextClass.getAttributesSize()); - - //private int getFoo();, private void setFoo(int); NONE access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(0, contextClass.getAttributesSize()); - - //private int getFoo();, private void setFoo(int); PUBLIC_MEMBER access - not persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(0, contextClass.getAttributesSize()); - - - //add @XmlAttribute annotation and test each access type - AnnotatedElement annotatedElement = this.annotatedElement(resourceGetter); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - //@XmlAttribute - //private int getFoo();, private void setFoo(int); PROPERTY access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PROPERTY); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int getFoo();, private void setFoo(int); FIELD access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__FIELD); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int getFoo();, private void setFoo(int); NONE access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__NONE); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - //@XmlAttribute - //private int getFoo();, private void setFoo(int); PUBLIC_MEMBER access - persistent - this.setAccessTypeInJavaSource(contextClass, JAXB.XML_ACCESS_TYPE__PUBLIC_MEMBER); - assertEquals(1, contextClass.getAttributesSize()); - attributes = contextClass.getAttributes().iterator(); - assertEquals("foo", attributes.next().getName()); - assertFalse(attributes.hasNext()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlAttributeAnnotation.ANNOTATION_NAME); - } - }); - this.removeModifiers(resourceGetter, ModifierKeyword.PRIVATE_KEYWORD); - this.removeModifiers(resourceSetter, ModifierKeyword.PRIVATE_KEYWORD); - this.addModifiers(resourceGetter, ModifierKeyword.PUBLIC_KEYWORD); - this.addModifiers(resourceSetter, ModifierKeyword.PUBLIC_KEYWORD); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(persistentClass.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - persistentClass.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(persistentClass.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - persistentClass.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(persistentClass.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(persistentClass.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(persistentClass.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testModifyXmlSeeAlso() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceType resourceType = persistentClass.getJavaResourceType(); - - XmlSeeAlsoAnnotation annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNull(persistentClass.getXmlSeeAlso()); - assertNull(annotation); - - persistentClass.addXmlSeeAlso(); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNotNull(persistentClass.getXmlSeeAlso()); - assertNotNull(annotation); - - persistentClass.removeXmlSeeAlso(); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNull(persistentClass.getXmlSeeAlso()); - assertNull(annotation); - } - - public void testUpdateXmlSeeAlso() throws Exception { - createAnnotatedPersistentClass(); - - JaxbPersistentClass persistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - JavaResourceType resourceType = persistentClass.getJavaResourceType(); - - XmlSeeAlsoAnnotation annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNull(persistentClass.getXmlSeeAlso()); - assertNull(annotation); - - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_SEE_ALSO); - } - }); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNotNull(persistentClass.getXmlSeeAlso()); - assertNotNull(annotation); - - annotatedElement.edit( - new Member.Editor() { - public void edit( - ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeAnnotation(declaration, JAXB.XML_SEE_ALSO); - } - }); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertNull(persistentClass.getXmlSeeAlso()); - assertNull(annotation); - } - - protected void addModifiers(JavaResourceMember resourceMember, final ModifierKeyword... modifiers) { - AnnotatedElement annotatedElement = this.annotatedElement(resourceMember); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.addModifiers((BodyDeclaration) declaration.getDeclaration(), modifiers); - } - }); - } - - protected void removeModifiers(JavaResourceMember resourceMember, final ModifierKeyword... modifiers) { - AnnotatedElement annotatedElement = this.annotatedElement(resourceMember); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.removeModifiers((BodyDeclaration) declaration.getDeclaration(), modifiers); - } - }); - } - - protected void addModifiers(BodyDeclaration bodyDeclaration, ModifierKeyword... modifiers) { - for (ModifierKeyword modifier : modifiers) { - this.modifiers(bodyDeclaration).add(bodyDeclaration.getAST().newModifier(modifier)); - } - } - - protected void removeModifiers(BodyDeclaration bodyDeclaration, ModifierKeyword... modifierKeywords) { - for (ModifierKeyword modifierKeyWord : modifierKeywords) { - for (Iterator<IExtendedModifier> stream = this.modifiers(bodyDeclaration).iterator(); stream.hasNext();) { - IExtendedModifier modifier = stream.next(); - if (modifier.isModifier()) { - if (((Modifier) modifier).getKeyword() == modifierKeyWord) { - stream.remove(); - break; - } - } - } - } - } - - @SuppressWarnings("unchecked") - protected List<IExtendedModifier> modifiers(BodyDeclaration bodyDeclaration) { - return bodyDeclaration.modifiers(); - } - - protected void setAccessTypeInJavaSource(JaxbPersistentClass contextClass, final String accessType) { - JavaResourceType resourceClass = contextClass.getJavaResourceType(); - AnnotatedElement annotatedElement = this.annotatedElement(resourceClass); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaPersistentClassTests.this.setEnumMemberValuePair(declaration, XmlAccessorTypeAnnotation.ANNOTATION_NAME, accessType); - } - }); - } - -}
\ 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 a6909a1e23..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,740 +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.beans.Introspector; -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.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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.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; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentEnumTests extends JaxbContextModelTestCase -{ - - public GenericJavaPersistentEnumTests(String name) { - super(name); - } - - private ICompilationUnit createEnumWithXmlType() throws Exception { - return createTestEnum(new DefaultEnumAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ENUM); - } - @Override - public void appendEnumAnnotationTo(StringBuilder sb) { - sb.append("@XmlType @XmlEnum"); - } - }); - } - - public void testModifyFactoryClass() throws Exception { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - String defaultXmlTypeName = Introspector.decapitalize(TYPE_NAME); - - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getDefaultName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getName()); - - contextEnum.getSchemaTypeRef().setSpecifiedName("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getName()); - - contextEnum.getSchemaTypeRef().setSpecifiedName(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getName()); - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getName()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set name again, this time starting with no XmlType annotation - contextEnum.getSchemaTypeRef().setSpecifiedName("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getName()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getName()); - } - - public void testUpdateSchemaTypeName() throws Exception { - createEnumWithXmlType(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - String defaultXmlTypeName = Introspector.decapitalize(TYPE_NAME); - - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getDefaultName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getName()); - - //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.getSchemaTypeRef().getSpecifiedName()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getName()); - - //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.getSchemaTypeRef().getSpecifiedName()); - assertEquals(defaultXmlTypeName, contextEnum.getSchemaTypeRef().getName()); - } - - public void testModifyNamespace() throws Exception { - createEnumWithXmlType(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().getDefaultNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().getNamespace()); - - contextEnum.getSchemaTypeRef().setSpecifiedNamespace("foo"); - XmlTypeAnnotation xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getNamespace()); - - contextEnum.getSchemaTypeRef().setSpecifiedNamespace(null); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlTypeAnnotation.getNamespace()); - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().getNamespace()); - - resourceEnum.removeAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - - //set namespace again, this time starting with no XmlType annotation - contextEnum.getSchemaTypeRef().setSpecifiedNamespace("foo"); - xmlTypeAnnotation = (XmlTypeAnnotation) resourceEnum.getAnnotation(XmlTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlTypeAnnotation.getNamespace()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", contextEnum.getSchemaTypeRef().getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createEnumWithXmlType(); - - JaxbPersistentEnum contextEnum = CollectionTools.get(getContextRoot().getPersistentEnums(), 0); - JavaResourceEnum resourceEnum = contextEnum.getJavaResourceType(); - - assertNull(contextEnum.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().getDefaultNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", contextEnum.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("", contextEnum.getSchemaTypeRef().getNamespace()); - } - - public void testGetPropOrder() throws Exception { - this.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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.createEnumWithXmlType(); - 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 { - createEnumWithXmlType(); - - 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().getSchemaElementRef().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 { - createEnumWithXmlType(); - - 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().getSchemaElementRef().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 { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - 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 { - createEnumWithXmlType(); - - 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 5ff255d326..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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.tests.internal.context.JaxbContextModelTestCase; - - -@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/GenericJavaTypeXmlJavaTypeAdapterTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaTypeXmlJavaTypeAdapterTests.java deleted file mode 100644 index 4819c1850c..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaTypeXmlJavaTypeAdapterTests.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -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.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaTypeXmlJavaTypeAdapterTests extends JaxbContextModelTestCase -{ - - public GenericJavaTypeXmlJavaTypeAdapterTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlTypeWithXmlJavaTypeAdapter() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_JAVA_TYPE_ADAPTER); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType").append(CR); - sb.append("@XmlJavaTypeAdapter"); - } - }); - } - - public void testModifyValue() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - JaxbPersistentClass contextPersistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPersistentClass.getXmlJavaTypeAdapter(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - contextXmlJavaTypeAdapter.setValue("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.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) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getValue()); - assertNull(contextXmlJavaTypeAdapter.getValue()); - } - - public void testUpdateValue() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - JaxbPersistentClass contextPersistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPersistentClass.getXmlJavaTypeAdapter(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - - assertNull(contextXmlJavaTypeAdapter.getValue()); - - //add a value member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaTypeXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__VALUE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getValue()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaTypeXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertNull(contextPersistentClass.getXmlJavaTypeAdapter()); - } - - public void testModifyType() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - JaxbPersistentClass contextPersistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPersistentClass.getXmlJavaTypeAdapter(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getDefaultType()); - - contextXmlJavaTypeAdapter.setSpecifiedType("foo"); - XmlJavaTypeAdapterAnnotation javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertEquals("foo", javaTypeAdapterAnnotation.getType()); - assertEquals("foo", contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getDefaultType()); - - contextXmlJavaTypeAdapter.setSpecifiedType(null); - javaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceType.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(javaTypeAdapterAnnotation.getType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getDefaultType()); - } - - public void testUpdateType() throws Exception { - this.createTypeWithXmlTypeWithXmlJavaTypeAdapter(); - JaxbPersistentClass contextPersistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlJavaTypeAdapter contextXmlJavaTypeAdapter = contextPersistentClass.getXmlJavaTypeAdapter(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getType()); - assertNull(contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getDefaultType()); - - //add a type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceType); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaTypeXmlJavaTypeAdapterTests.this.addXmlJavaTypeAdapterTypeMemberValuePair(declaration, JAXB.XML_JAVA_TYPE_ADAPTER__TYPE, "String"); - } - }); - assertEquals("String", contextXmlJavaTypeAdapter.getSpecifiedType()); - assertEquals("String", contextXmlJavaTypeAdapter.getType()); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, contextXmlJavaTypeAdapter.getDefaultType()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaTypeXmlJavaTypeAdapterTests.this.removeXmlJavaTypeAdapterAnnotation(declaration); - } - }); - assertNull(contextPersistentClass.getXmlJavaTypeAdapter()); - } - - 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/GenericJavaXmlAnyAttributeMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAnyAttributeMappingTests.java deleted file mode 100644 index d6e21823e5..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAnyAttributeMappingTests.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.MappingKeys; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAnyAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaXmlAnyAttributeMappingTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlAnyAttributeMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlAnyAttribute() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ANY_ATTRIBUTE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyAttribute"); - } - }); - } - - public void testChangeMappingType() throws Exception { - createTypeWithXmlAnyAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyAttributeMapping xmlAnyAttributeMapping = (XmlAnyAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNotNull(xmlAnyAttributeMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyAttributeAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAttributeMapping); - assertNull(resourceAttribute.getAnnotation(XmlAnyAttributeAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ANY_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - xmlAnyAttributeMapping = (XmlAnyAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAnyAttributeMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyAttributeAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - - persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlElementMapping); - assertNull(resourceAttribute.getAnnotation(XmlAnyAttributeAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ANY_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - xmlAnyAttributeMapping = (XmlAnyAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAnyAttributeMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyAttributeAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAnyAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyAttributeMapping xmlAnyAttributeMapping = (XmlAnyAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - xmlAnyAttributeMapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyAttributeMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - xmlAnyAttributeMapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAnyAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyAttributeMapping xmlAnyAttributeMapping = (XmlAnyAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyAttributeMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyAttributeMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - -}
\ 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/GenericJavaXmlAnyElementMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAnyElementMappingTests.java deleted file mode 100644 index fc99fb45ba..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAnyElementMappingTests.java +++ /dev/null @@ -1,336 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.MappingKeys; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAnyElementMapping; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlMixedAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaXmlAnyElementMappingTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlAnyElementMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlAnyElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ANY_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAnyElement"); - } - }); - } - - public void testChangeMappingType() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNotNull(xmlAnyElementMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAttributeMapping); - assertNull(resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ANY_ELEMENT_ATTRIBUTE_MAPPING_KEY); - xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAnyElementMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - - persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlElementMapping); - assertNull(resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ANY_ELEMENT_ATTRIBUTE_MAPPING_KEY); - xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAnyElementMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - xmlAnyElementMapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyElementMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - xmlAnyElementMapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyElementMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testModifyLax() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(false, xmlAnyElementMapping.isLax()); - - xmlAnyElementMapping.setSpecifiedLax(Boolean.TRUE); - XmlAnyElementAnnotation xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, xmlAnyElementAnnotation.getLax()); - assertEquals(Boolean.TRUE, xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(true, xmlAnyElementMapping.isLax()); - - xmlAnyElementMapping.setSpecifiedLax(null); - xmlAnyElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(false, xmlAnyElementMapping.isLax()); - } - - public void testUpdateLax() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(false, xmlAnyElementMapping.isLax()); - - - //add a nillable member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.addXmlAnyElementMemberValuePair(declaration, JAXB.XML_ANY_ELEMENT__LAX, true); - } - }); - assertEquals(Boolean.TRUE, xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(true, xmlAnyElementMapping.isLax()); - - //remove the lax member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlAnyElementMappingTests.this.getXmlAnyElementAnnotation(declaration); - GenericJavaXmlAnyElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlAnyElementMapping.getSpecifiedLax()); - assertEquals(false, xmlAnyElementMapping.isDefaultLax()); - assertEquals(false, xmlAnyElementMapping.isLax()); - } - - public void testModifyValue() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAnyElementMapping.getSpecifiedValue()); - - xmlAnyElementMapping.setSpecifiedValue("Foo"); - XmlAnyElementAnnotation xmlElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME); - assertEquals("Foo", xmlAnyElementMapping.getSpecifiedValue()); - assertEquals("Foo", xmlAnyElementMapping.getValue()); - - xmlAnyElementMapping.setSpecifiedValue(null); - xmlElementAnnotation = (XmlAnyElementAnnotation) resourceAttribute.getAnnotation(XmlAnyElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getValue()); - assertNull(xmlAnyElementMapping.getSpecifiedValue()); - } - - public void testUpdateValue() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAnyElementMapping.getSpecifiedValue()); - - - //add a Value member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.addXmlAnyElementTypeMemberValuePair(declaration, JAXB.XML_ANY_ELEMENT__VALUE, "Foo"); - } - }); - assertEquals("Foo", xmlAnyElementMapping.getValue()); - - //remove the Value member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlAnyElementMappingTests.this.getXmlAnyElementAnnotation(declaration); - GenericJavaXmlAnyElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlAnyElementMapping.getSpecifiedValue()); - } - - protected void addXmlAnyElementMemberValuePair(ModifiedDeclaration declaration, String name, boolean value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlAnyElementAnnotation(declaration), name, value); - } - - protected void addXmlAnyElementTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlAnyElementAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected Annotation getXmlAnyElementAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlAnyElementAnnotation.ANNOTATION_NAME); - } - - public void testModifyXmlMixed() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlMixedAnnotation xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlMixed()); - assertNull(xmlListAnnotation); - - xmlAnyElementMapping.addXmlMixed(); - xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyElementMapping.getXmlMixed()); - assertNotNull(xmlListAnnotation); - - xmlAnyElementMapping.removeXmlMixed(); - xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlMixed() throws Exception { - createTypeWithXmlAnyElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAnyElementMapping xmlAnyElementMapping = (XmlAnyElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAnyElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlMixedAnnotation xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlMixed()); - assertNull(xmlListAnnotation); - - - //add an XmlMixed annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlMixedAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAnyElementMapping.getXmlMixed()); - assertNotNull(xmlListAnnotation); - - //remove the XmlMixed annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAnyElementMappingTests.this.removeAnnotation(declaration, XmlMixedAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlMixedAnnotation) resourceAttribute.getAnnotation(XmlMixedAnnotation.ANNOTATION_NAME); - assertNull(xmlAnyElementMapping.getXmlMixed()); - assertNull(xmlListAnnotation); - } - -}
\ 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/GenericJavaXmlAttributeMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java deleted file mode 100644 index 206db4d8a2..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlAttributeMappingTests.java +++ /dev/null @@ -1,607 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.MappingKeys; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaXmlAttributeMappingTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlAttributeMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlAttribute() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ATTRIBUTE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlAttribute"); - } - }); - } - - public void testModifyName() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedName()); - assertEquals("id", xmlAttributeMapping.getSchemaComponentRef().getDefaultName()); - assertEquals("id", xmlAttributeMapping.getSchemaComponentRef().getName()); - - xmlAttributeMapping.getSchemaComponentRef().setSpecifiedName("foo"); - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlAttributeAnnotation.getName()); - assertEquals("foo", xmlAttributeMapping.getSchemaComponentRef().getSpecifiedName()); - assertEquals("id", xmlAttributeMapping.getSchemaComponentRef().getDefaultName()); - assertEquals("foo", xmlAttributeMapping.getSchemaComponentRef().getName()); - - xmlAttributeMapping.getSchemaComponentRef().setSpecifiedName(null); - xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeAnnotation.getName()); - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedName()); - } - - public void testUpdateName() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedName()); - - - //add a Name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addXmlAttributeMemberValuePair(declaration, JAXB.XML_ATTRIBUTE__NAME, "foo"); - } - }); - assertEquals("foo", xmlAttributeMapping.getSchemaComponentRef().getName()); - - //remove the Name member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlAttributeAnnotation = (NormalAnnotation) GenericJavaXmlAttributeMappingTests.this.getXmlAttributeAnnotation(declaration); - GenericJavaXmlAttributeMappingTests.this.values(xmlAttributeAnnotation).remove(0); - } - }); - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedName()); - } - - public void testModifyNamespace() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedNamespace()); - - xmlAttributeMapping.getSchemaComponentRef().setSpecifiedNamespace("foo"); - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlAttributeAnnotation.getNamespace()); - assertEquals("foo", xmlAttributeMapping.getSchemaComponentRef().getNamespace()); - - xmlAttributeMapping.getSchemaComponentRef().setSpecifiedNamespace(null); - xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeAnnotation.getNamespace()); - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedNamespace()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addXmlAttributeMemberValuePair(declaration, JAXB.XML_ATTRIBUTE__NAMESPACE, "foo"); - } - }); - assertEquals("foo", xmlAttributeMapping.getSchemaComponentRef().getNamespace()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlAttributeAnnotation = (NormalAnnotation) GenericJavaXmlAttributeMappingTests.this.getXmlAttributeAnnotation(declaration); - GenericJavaXmlAttributeMappingTests.this.values(xmlAttributeAnnotation).remove(0); - } - }); - assertNull(xmlAttributeMapping.getSchemaComponentRef().getSpecifiedNamespace()); - } - - public void testModifyRequired() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(false, xmlAttributeMapping.isRequired()); - - xmlAttributeMapping.setSpecifiedRequired(Boolean.TRUE); - XmlAttributeAnnotation xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, xmlAttributeAnnotation.getRequired()); - assertEquals(Boolean.TRUE, xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(true, xmlAttributeMapping.isRequired()); - - xmlAttributeMapping.setSpecifiedRequired(null); - xmlAttributeAnnotation = (XmlAttributeAnnotation) resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeAnnotation.getName()); - assertNull(xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(false, xmlAttributeMapping.isRequired()); - } - - public void testUpdateRequired() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(false, xmlAttributeMapping.isRequired()); - - - //add a required member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addXmlAttributeMemberValuePair(declaration, JAXB.XML_ATTRIBUTE__REQUIRED, true); - } - }); - assertEquals(Boolean.TRUE, xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(true, xmlAttributeMapping.isRequired()); - - //remove the required member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlAttributeAnnotation = (NormalAnnotation) GenericJavaXmlAttributeMappingTests.this.getXmlAttributeAnnotation(declaration); - GenericJavaXmlAttributeMappingTests.this.values(xmlAttributeAnnotation).remove(0); - } - }); - assertNull(xmlAttributeMapping.getSpecifiedRequired()); - assertEquals(false, xmlAttributeMapping.isDefaultRequired()); - assertEquals(false, xmlAttributeMapping.isRequired()); - } - - public void testChangeMappingType() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNotNull(xmlAttributeMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlElementMapping); - assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - - - persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAttributeMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - xmlAttributeMapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - xmlAttributeMapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testModifyXmlSchemaType() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - - xmlAttributeMapping.addXmlSchemaType(); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlSchemaType()); - assertNotNull(xmlSchemaTypeAnnotation); - - xmlAttributeMapping.removeXmlSchemaType(); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlSchemaType() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - - - //add an XmlSchemaType annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - }); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlSchemaType()); - assertNotNull(xmlSchemaTypeAnnotation); - - //remove the XmlSchemaType annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - }); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - } - - protected void addXmlAttributeMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlAttributeAnnotation(declaration), name, value); - } - - protected void addXmlAttributeMemberValuePair(ModifiedDeclaration declaration, String name, boolean value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlAttributeAnnotation(declaration), name, value); - } - - protected void addXmlAttributeTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlAttributeAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected Annotation getXmlAttributeAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlAttributeAnnotation.ANNOTATION_NAME); - } - - public void testModifyXmlList() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlList()); - assertNull(xmlListAnnotation); - - xmlAttributeMapping.addXmlList(); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlList()); - assertNotNull(xmlListAnnotation); - - xmlAttributeMapping.removeXmlList(); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlList() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlList()); - assertNull(xmlListAnnotation); - - - //add an XmlList annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlListAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlList()); - assertNotNull(xmlListAnnotation); - - //remove the XmlList annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlListAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlList()); - assertNull(xmlListAnnotation); - } - - public void testModifyXmlID() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlID()); - assertNull(xmlIDAnnotation); - - xmlAttributeMapping.addXmlID(); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlID()); - assertNotNull(xmlIDAnnotation); - - xmlAttributeMapping.removeXmlID(); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlID() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlID()); - assertNull(xmlIDAnnotation); - - - //add an XmlID annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDAnnotation.ANNOTATION_NAME); - } - }); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlID()); - assertNotNull(xmlIDAnnotation); - - //remove the XmlID annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlIDAnnotation.ANNOTATION_NAME); - } - }); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlID()); - assertNull(xmlIDAnnotation); - } - - public void testModifyXmlIDREF() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - xmlAttributeMapping.addXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - xmlAttributeMapping.removeXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlIDREF() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - - //add an XmlIDREF annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDREFAnnotation.ANNOTATION_NAME); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - //remove the XmlIDREF annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlIDREFAnnotation.ANNOTATION_NAME); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - } - - public void testModifyXmlAttachmentRef() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - - xmlAttributeMapping.addXmlAttachmentRef(); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlAttachmentRef()); - assertNotNull(xmlAttachmentRefAnnotation); - - xmlAttributeMapping.removeXmlAttachmentRef(); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlAttachmentRef() throws Exception { - createTypeWithXmlAttribute(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlAttributeMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - - - //add an XmlAttachmentRef annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - }); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNotNull(xmlAttributeMapping.getXmlAttachmentRef()); - assertNotNull(xmlAttachmentRefAnnotation); - - //remove the XmlAttachmentRef annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlAttributeMappingTests.this.removeAnnotation(declaration, XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - }); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlAttributeMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - } -}
\ 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/GenericJavaXmlElementMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java deleted file mode 100644 index b8f687588e..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementMappingTests.java +++ /dev/null @@ -1,918 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -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.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.MappingKeys; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlElement; -import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaXmlElementMappingTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlElementMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlElement() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ELEMENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElement"); - } - }); - } - - private void createXmlTypeWithVariousAttributes() throws CoreException { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import ").append(JAXB.XML_TYPE).append(";").append(CR); - sb.append("import java.util.List;").append(CR); - sb.append(CR); - sb.append("@XmlType").append(CR); - sb.append("public class ").append(TYPE_NAME).append("{").append(CR); - sb.append(" public String string;").append(CR); - sb.append(" public List<String> stringList;").append(CR); - sb.append(" public String[] stringArray;").append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, TYPE_NAME + ".java", sourceWriter); - } - - public void testModifyName() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSchemaElementRef().getSpecifiedName()); - assertEquals("id", xmlElement.getSchemaElementRef().getDefaultName()); - assertEquals("id", xmlElement.getSchemaElementRef().getName()); - - xmlElement.getSchemaElementRef().setSpecifiedName("foo"); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlElementAnnotation.getName()); - assertEquals("foo", xmlElement.getSchemaElementRef().getSpecifiedName()); - assertEquals("id", xmlElement.getSchemaElementRef().getDefaultName()); - assertEquals("foo", xmlElement.getSchemaElementRef().getName()); - - xmlElement.getSchemaElementRef().setSpecifiedName(null); - xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getName()); - assertNull(xmlElement.getSchemaElementRef().getSpecifiedName()); - } - - public void testUpdateName() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSchemaElementRef().getSpecifiedName()); - - - //add a Name member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NAME, "foo"); - } - }); - assertEquals("foo", xmlElement.getSchemaElementRef().getName()); - - //remove the Name member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getSchemaElementRef().getSpecifiedName()); - } - - public void testModifyNamespace() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace()); - - xmlElement.getSchemaElementRef().setSpecifiedNamespace("foo"); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlElementAnnotation.getNamespace()); - assertEquals("foo", xmlElement.getSchemaElementRef().getNamespace()); - - xmlElement.getSchemaElementRef().setSpecifiedNamespace(null); - xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getNamespace()); - assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace()); - - - //add a namespace member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NAMESPACE, "foo"); - } - }); - assertEquals("foo", xmlElement.getSchemaElementRef().getNamespace()); - - //remove the namespace member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getSchemaElementRef().getSpecifiedNamespace()); - } - - public void testModifyRequired() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(false, xmlElement.isRequired()); - - xmlElement.setSpecifiedRequired(Boolean.TRUE); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, xmlElementAnnotation.getRequired()); - assertEquals(Boolean.TRUE, xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(true, xmlElement.isRequired()); - - xmlElement.setSpecifiedRequired(null); - xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getName()); - assertNull(xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(false, xmlElement.isRequired()); - } - - public void testUpdateRequired() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(false, xmlElement.isRequired()); - - - //add a required member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__REQUIRED, true); - } - }); - assertEquals(Boolean.TRUE, xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(true, xmlElement.isRequired()); - - //remove the required member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getSpecifiedRequired()); - assertEquals(false, xmlElement.isDefaultRequired()); - assertEquals(false, xmlElement.isRequired()); - } - - public void testModifyNillable() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(false, xmlElement.isNillable()); - - xmlElement.setSpecifiedNillable(Boolean.TRUE); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, xmlElementAnnotation.getNillable()); - assertEquals(Boolean.TRUE, xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(true, xmlElement.isNillable()); - - xmlElement.setSpecifiedNillable(null); - xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getName()); - assertNull(xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(false, xmlElement.isNillable()); - } - - public void testUpdateNillable() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(false, xmlElement.isNillable()); - - - //add a nillable member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__NILLABLE, true); - } - }); - assertEquals(Boolean.TRUE, xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(true, xmlElement.isNillable()); - - //remove the nillable member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getSpecifiedNillable()); - assertEquals(false, xmlElement.isDefaultNillable()); - assertEquals(false, xmlElement.isNillable()); - } - - public void testDefaultNillable() throws Exception { - createXmlTypeWithVariousAttributes(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - - // string - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = persistentAttribute.getJavaResourceAttribute(); - - assertEquals(false, xmlElement.isDefaultNillable()); - - annotatedElement(resourceAttribute).edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT); - } - }); - - assertEquals(false, xmlElement.isDefaultNillable()); - - // string list - persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 1); - xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - xmlElement = xmlElementMapping.getXmlElement(); - resourceAttribute = persistentAttribute.getJavaResourceAttribute(); - - assertEquals(true, xmlElement.isDefaultNillable()); - - annotatedElement(resourceAttribute).edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT); - } - }); - - assertEquals(false, xmlElement.isDefaultNillable()); - - // string array - persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 2); - xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - xmlElement = xmlElementMapping.getXmlElement(); - resourceAttribute = persistentAttribute.getJavaResourceAttribute(); - - assertEquals(true, xmlElement.isDefaultNillable()); - - annotatedElement(resourceAttribute).edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT); - } - }); - - assertEquals(false, xmlElement.isDefaultNillable()); - } - - public void testModifyDefaultValue() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getDefaultValue()); - - xmlElement.setDefaultValue("foo"); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", xmlElementAnnotation.getDefaultValue()); - assertEquals("foo", xmlElement.getDefaultValue()); - - xmlElement.setDefaultValue(null); - xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME); - assertNull(xmlElementAnnotation.getDefaultValue()); - assertNull(xmlElement.getDefaultValue()); - } - - public void testUpdateDefaultValue() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getDefaultValue()); - - - //add a DefaultValue member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementMemberValuePair(declaration, JAXB.XML_ELEMENT__DEFAULT_VALUE, "foo"); - } - }); - assertEquals("foo", xmlElement.getDefaultValue()); - - //remove the DefaultValue member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getDefaultValue()); - } - - public void testModifyType() throws Exception { - createTypeWithXmlElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - - assertNull(xmlElement.getSpecifiedType()); - assertEquals("int", xmlElement.getType()); - assertEquals("int", xmlElement.getDefaultType()); - - xmlElement.setSpecifiedType("Foo"); - assertEquals("Foo", xmlElement.getSpecifiedType()); - assertEquals("Foo", xmlElement.getType()); - - xmlElement.setSpecifiedType(null); - assertNull(xmlElement.getSpecifiedType()); - assertEquals("int", xmlElement.getType()); - } - - public void testUpdateType() throws Exception { - createTypeWithXmlElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - XmlElement xmlElement = xmlElementMapping.getXmlElement(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNull(xmlElement.getSpecifiedType()); - assertEquals("int", xmlElement.getDefaultType()); - assertEquals("int", xmlElement.getType()); - - //add a Type member value pair - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addXmlElementTypeMemberValuePair(declaration, JAXB.XML_ELEMENT__TYPE, "Foo"); - } - }); - assertEquals("Foo", xmlElement.getSpecifiedType()); - assertEquals("Foo", xmlElement.getType()); - - //remove the Type member value pair - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NormalAnnotation xmlElementAnnotation = (NormalAnnotation) GenericJavaXmlElementMappingTests.this.getXmlElementAnnotation(declaration); - GenericJavaXmlElementMappingTests.this.values(xmlElementAnnotation).remove(0); - } - }); - assertNull(xmlElement.getSpecifiedType()); - assertEquals("int", xmlElement.getType()); - } - - public void testChangeMappingType() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNotNull(xmlElementMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAttributeMapping); - assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - - persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY); - xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlElementMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - xmlElementMapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - xmlElementMapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testModifyXmlSchemaType() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - - xmlElementMapping.addXmlSchemaType(); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlSchemaType()); - assertNotNull(xmlSchemaTypeAnnotation); - - xmlElementMapping.removeXmlSchemaType(); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlSchemaType() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlSchemaTypeAnnotation xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - - - //add an XmlSchemaType annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - }); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlSchemaType()); - assertNotNull(xmlSchemaTypeAnnotation); - - //remove the XmlSchemaType annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - } - }); - xmlSchemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourceAttribute.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlSchemaType()); - assertNull(xmlSchemaTypeAnnotation); - } - - protected void addXmlElementMemberValuePair(ModifiedDeclaration declaration, String name, String value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlElementAnnotation(declaration), name, value); - } - - protected void addXmlElementMemberValuePair(ModifiedDeclaration declaration, String name, boolean value) { - this.addMemberValuePair((MarkerAnnotation) this.getXmlElementAnnotation(declaration), name, value); - } - - protected void addXmlElementTypeMemberValuePair(ModifiedDeclaration declaration, String name, String typeName) { - this.addMemberValuePair( - (MarkerAnnotation) this.getXmlElementAnnotation(declaration), - name, - this.newTypeLiteral(declaration.getAst(), typeName)); - } - - protected Annotation getXmlElementAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(XmlElementAnnotation.ANNOTATION_NAME); - } - - - public void testModifyXmlElementWrapper() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - - xmlElementMapping.addXmlElementWrapper(); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlElementWrapper()); - assertNotNull(xmlElementWrapperAnnotation); - - xmlElementMapping.removeXmlElementWrapper(); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlElementWrapper() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - - - //add an XmlElementWrapper annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlElementWrapperAnnotation.ANNOTATION_NAME); - } - }); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlElementWrapper()); - assertNotNull(xmlElementWrapperAnnotation); - - //remove the XmlElementWrapper annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlElementWrapperAnnotation.ANNOTATION_NAME); - } - }); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(XmlElementWrapperAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - } - - public void testModifyXmlList() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlList()); - assertNull(xmlListAnnotation); - - xmlElementMapping.addXmlList(); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlList()); - assertNotNull(xmlListAnnotation); - - xmlElementMapping.removeXmlList(); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlList() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlListAnnotation xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlList()); - assertNull(xmlListAnnotation); - - - //add an XmlList annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlListAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlList()); - assertNotNull(xmlListAnnotation); - - //remove the XmlList annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlListAnnotation.ANNOTATION_NAME); - } - }); - xmlListAnnotation = (XmlListAnnotation) resourceAttribute.getAnnotation(XmlListAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlList()); - assertNull(xmlListAnnotation); - } - - public void testModifyXmlID() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlID()); - assertNull(xmlIDAnnotation); - - xmlElementMapping.addXmlID(); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlID()); - assertNotNull(xmlIDAnnotation); - - xmlElementMapping.removeXmlID(); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlID() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDAnnotation xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlID()); - assertNull(xmlIDAnnotation); - - - //add an XmlID annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDAnnotation.ANNOTATION_NAME); - } - }); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlID()); - assertNotNull(xmlIDAnnotation); - - //remove the XmlID annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlIDAnnotation.ANNOTATION_NAME); - } - }); - xmlIDAnnotation = (XmlIDAnnotation) resourceAttribute.getAnnotation(XmlIDAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlID()); - assertNull(xmlIDAnnotation); - } - - public void testModifyXmlIDREF() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - xmlElementMapping.addXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - xmlElementMapping.removeXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - } - - public void testUpdateXmlIDREF() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - - //add an XmlIDREF annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlIDREFAnnotation.ANNOTATION_NAME); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - //remove the XmlIDREF annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlIDREFAnnotation.ANNOTATION_NAME); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(XmlIDREFAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - } - - public void testModifyXmlAttachmentRef() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - - xmlElementMapping.addXmlAttachmentRef(); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlAttachmentRef()); - assertNotNull(xmlAttachmentRefAnnotation); - - xmlElementMapping.removeXmlAttachmentRef(); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlAttachmentRef() throws Exception { - createTypeWithXmlElement(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlElementMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlAttachmentRefAnnotation xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - - - //add an XmlAttachmentRef annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - }); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNotNull(xmlElementMapping.getXmlAttachmentRef()); - assertNotNull(xmlAttachmentRefAnnotation); - - //remove the XmlAttachmentRef annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementMappingTests.this.removeAnnotation(declaration, XmlAttachmentRefAnnotation.ANNOTATION_NAME); - } - }); - xmlAttachmentRefAnnotation = (XmlAttachmentRefAnnotation) resourceAttribute.getAnnotation(XmlAttachmentRefAnnotation.ANNOTATION_NAME); - assertNull(xmlElementMapping.getXmlAttachmentRef()); - assertNull(xmlAttachmentRefAnnotation); - } - -}
\ 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/GenericJavaXmlElementsMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementsMappingTests.java deleted file mode 100644 index 5492c306fd..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlElementsMappingTests.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlElement; -import org.eclipse.jpt.jaxb.core.context.XmlElementsMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementsAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -public class GenericJavaXmlElementsMappingTests - extends JaxbContextModelTestCase { - - public GenericJavaXmlElementsMappingTests(String name) { - super(name); - } - - - private ICompilationUnit createTypeWithXmlElements() throws Exception { - return this.createTestType( - new DefaultAnnotationWriter() { - - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_ELEMENTS); - } - - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElements"); - } - }); - } - - - // ***** XmlElements ***** - - protected NormalAnnotation newXmlElementAnnotation(AST ast, String name) { - NormalAnnotation annotation = newNormalAnnotation(ast, JAXB.XML_ELEMENT); - addMemberValuePair(annotation, JAXB.XML_ELEMENT__NAME, name); - return annotation; - } - - protected void addXmlElement(ModifiedDeclaration declaration, int index, String name) { - NormalAnnotation arrayElement = newXmlElementAnnotation(declaration.getAst(), name); - addArrayElement(declaration, JAXB.XML_ELEMENTS, index, JAXB.XML_ELEMENTS__VALUE, arrayElement); - } - - protected void moveXmlElement(ModifiedDeclaration declaration, int targetIndex, int sourceIndex) { - moveArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_ELEMENTS), JAXB.XML_ELEMENTS__VALUE, targetIndex, sourceIndex); - } - - protected void removeXmlElement(ModifiedDeclaration declaration, int index) { - removeArrayElement((NormalAnnotation) declaration.getAnnotationNamed(JAXB.XML_ELEMENTS), JAXB.XML_ELEMENTS__VALUE, index); - } - - public void testSyncXmlElements() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - Iterable<XmlElement> xmlElements = mapping.getXmlElements(); - assertTrue(CollectionTools.isEmpty(xmlElements)); - assertEquals(0, mapping.getXmlElementsSize()); - - //add 2 XmlElement annotations - AnnotatedElement annotatedElement = annotatedElement(resourceAttribute); - annotatedElement.edit( - new Member.Editor() { - - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.addXmlElement(declaration, 0, "foo"); - GenericJavaXmlElementsMappingTests.this.addXmlElement(declaration, 1, "bar"); - } - }); - - xmlElements = mapping.getXmlElements(); - - assertFalse(CollectionTools.isEmpty(mapping.getXmlElements())); - assertEquals(2, mapping.getXmlElementsSize()); - assertEquals("foo", CollectionTools.get(xmlElements, 0).getSchemaElementRef().getName()); - assertEquals("bar", CollectionTools.get(xmlElements, 1).getSchemaElementRef().getName()); - - // switch XmlElement annotations - annotatedElement.edit( - new Member.Editor() { - - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.moveXmlElement(declaration, 0, 1); - } - }); - - xmlElements = mapping.getXmlElements(); - - assertFalse(CollectionTools.isEmpty(mapping.getXmlElements())); - assertEquals(2, mapping.getXmlElementsSize()); - assertEquals("bar", CollectionTools.get(xmlElements, 0).getSchemaElementRef().getName()); - assertEquals("foo", CollectionTools.get(xmlElements, 1).getSchemaElementRef().getName()); - - // remove XmlElement annotations - annotatedElement.edit( - new Member.Editor() { - - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.removeXmlElement(declaration, 1); - GenericJavaXmlElementsMappingTests.this.removeXmlElement(declaration, 0); - } - }); - - xmlElements = mapping.getXmlElements(); - - assertTrue(CollectionTools.isEmpty(xmlElements)); - assertEquals(0, mapping.getXmlElementsSize()); - } - - public void testModifyXmlElements() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - XmlElementsAnnotation xmlElementsAnnotation = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - - Iterable<XmlElementAnnotation> xmlElementAnnotations = xmlElementsAnnotation.getXmlElements(); - - assertEquals(0, xmlElementsAnnotation.getXmlElementsSize()); - assertEquals(0, mapping.getXmlElementsSize()); - - mapping.addXmlElement(0).getSchemaElementRef().setSpecifiedName("foo"); - mapping.addXmlElement(1).getSchemaElementRef().setSpecifiedName("baz"); - mapping.addXmlElement(1).getSchemaElementRef().setSpecifiedName("bar"); - - xmlElementAnnotations = xmlElementsAnnotation.getXmlElements(); - - assertEquals(3, xmlElementsAnnotation.getXmlElementsSize()); - assertEquals(3, mapping.getXmlElementsSize()); - assertEquals("foo", CollectionTools.get(xmlElementAnnotations, 0).getName()); - assertEquals("bar", CollectionTools.get(xmlElementAnnotations, 1).getName()); - assertEquals("baz", CollectionTools.get(xmlElementAnnotations, 2).getName()); - - mapping.moveXmlElement(1, 2); - - xmlElementAnnotations = xmlElementsAnnotation.getXmlElements(); - - assertEquals(3, xmlElementsAnnotation.getXmlElementsSize()); - assertEquals(3, mapping.getXmlElementsSize()); - assertEquals("foo", CollectionTools.get(xmlElementAnnotations, 0).getName()); - assertEquals("baz", CollectionTools.get(xmlElementAnnotations, 1).getName()); - assertEquals("bar", CollectionTools.get(xmlElementAnnotations, 2).getName()); - - mapping.removeXmlElement(2); - mapping.removeXmlElement(0); - mapping.removeXmlElement(0); - - assertEquals(0, xmlElementsAnnotation.getXmlElementsSize()); - assertEquals(0, mapping.getXmlElementsSize()); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - assertNull(mapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - mapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - assertNotNull(mapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - mapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - assertNull(mapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - assertNull(mapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - AnnotatedElement annotatedElement = annotatedElement(resourceAttribute); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_JAVA_TYPE_ADAPTER); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - assertNotNull(mapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.removeAnnotation(declaration, JAXB.XML_JAVA_TYPE_ADAPTER); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, JAXB.XML_JAVA_TYPE_ADAPTER); - - assertNull(mapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } - - public void testModifyXmlElementWrapper() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNull(mapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - - mapping.addXmlElementWrapper(); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNotNull(mapping.getXmlElementWrapper()); - assertNotNull(xmlElementWrapperAnnotation); - - mapping.removeXmlElementWrapper(); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNull(mapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - } - - public void testUpdateXmlElementWrapper() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlElementWrapperAnnotation xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNull(mapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - - AnnotatedElement annotatedElement = annotatedElement(resourceAttribute); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_ELEMENT_WRAPPER); - } - }); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNotNull(mapping.getXmlElementWrapper()); - assertNotNull(xmlElementWrapperAnnotation); - - annotatedElement.edit(new Member.Editor() { - public void edit( - ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.removeAnnotation(declaration, JAXB.XML_ELEMENT_WRAPPER); - } - }); - xmlElementWrapperAnnotation = (XmlElementWrapperAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_WRAPPER); - - assertNull(mapping.getXmlElementWrapper()); - assertNull(xmlElementWrapperAnnotation); - } - - public void testModifyXmlIDREF() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNull(mapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - mapping.addXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNotNull(mapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - mapping.removeXmlIDREF(); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNull(mapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - } - - public void testUpdateXmlIDREF() throws Exception { - createTypeWithXmlElements(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlElementsMapping mapping = (XmlElementsMapping) CollectionTools.get(persistentClass.getAttributes(), 0).getMapping(); - JavaResourceAttribute resourceAttribute = mapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlIDREFAnnotation xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNull(mapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - - AnnotatedElement annotatedElement = annotatedElement(resourceAttribute); - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), JAXB.XML_IDREF); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNotNull(mapping.getXmlIDREF()); - assertNotNull(xmlIDREFAnnotation); - - annotatedElement.edit( - new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlElementsMappingTests.this.removeAnnotation(declaration, JAXB.XML_IDREF); - } - }); - xmlIDREFAnnotation = (XmlIDREFAnnotation) resourceAttribute.getAnnotation(JAXB.XML_IDREF); - - assertNull(mapping.getXmlIDREF()); - assertNull(xmlIDREFAnnotation); - } -} 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 192dae92a1..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,166 +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.beans.Introspector; -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.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -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.XmlRootElementAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@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(); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedNamespace()); - assertEquals("", contextRootElement.getSchemaElementRef().getDefaultNamespace()); - assertEquals("", contextRootElement.getSchemaElementRef().getNamespace()); - - contextRootElement.getSchemaElementRef().setSpecifiedNamespace("foo"); - XmlRootElementAnnotation rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", rootElementAnnotation.getNamespace()); - assertEquals("foo", contextRootElement.getSchemaElementRef().getSpecifiedNamespace()); - assertEquals("foo", contextRootElement.getSchemaElementRef().getNamespace()); - - contextRootElement.getSchemaElementRef().setSpecifiedNamespace(null); - rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(rootElementAnnotation.getNamespace()); - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedNamespace()); - assertEquals("", contextRootElement.getSchemaElementRef().getNamespace()); - } - - public void testUpdateNamespace() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedNamespace()); - assertEquals("", contextRootElement.getSchemaElementRef().getDefaultNamespace()); - assertEquals("", contextRootElement.getSchemaElementRef().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.getSchemaElementRef().getSpecifiedNamespace()); - assertEquals("foo", contextRootElement.getSchemaElementRef().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(); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - String defaultName = Introspector.decapitalize(TYPE_NAME); - - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedName()); - assertEquals(defaultName, contextRootElement.getSchemaElementRef().getDefaultName()); - assertEquals(defaultName, contextRootElement.getSchemaElementRef().getName()); - - contextRootElement.getSchemaElementRef().setSpecifiedName("foo"); - XmlRootElementAnnotation rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertEquals("foo", rootElementAnnotation.getName()); - assertEquals("foo", contextRootElement.getSchemaElementRef().getSpecifiedName()); - assertEquals("foo", contextRootElement.getSchemaElementRef().getName()); - - contextRootElement.getSchemaElementRef().setSpecifiedName(null); - rootElementAnnotation = (XmlRootElementAnnotation) resourceType.getAnnotation(XmlRootElementAnnotation.ANNOTATION_NAME); - assertNull(rootElementAnnotation.getName()); - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedName()); - assertEquals(defaultName, contextRootElement.getSchemaElementRef().getName()); - } - - public void testUpdateName() throws Exception { - createTypeWithXmlTypeWithXmlRootElement(); - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - XmlRootElement contextRootElement = persistentClass.getRootElement(); - JavaResourceAbstractType resourceType = persistentClass.getJavaResourceType(); - String defaultName = Introspector.decapitalize(TYPE_NAME); - - assertNull(contextRootElement.getSchemaElementRef().getSpecifiedName()); - assertEquals(defaultName, contextRootElement.getSchemaElementRef().getDefaultName()); - assertEquals(defaultName, contextRootElement.getSchemaElementRef().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.getSchemaElementRef().getSpecifiedName()); - assertEquals("foo", contextRootElement.getSchemaElementRef().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 0fbc619f7f..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,670 +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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; -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.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; - - -@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.getNamespace()); - 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.getLocation()); - 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.getSpecifiedAttributeFormDefault()); - assertEquals(XmlNsForm.UNSET, contextXmlSchema.getAttributeFormDefault()); - - contextXmlSchema.setSpecifiedAttributeFormDefault(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.setSpecifiedAttributeFormDefault(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.setSpecifiedAttributeFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation.getAttributeFormDefault()); - assertNull(contextXmlSchema.getSpecifiedAttributeFormDefault()); - - //set attribute form default again, this time starting with no XmlSchema annotation - contextXmlSchema.setSpecifiedAttributeFormDefault(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.getSpecifiedAttributeFormDefault()); - assertEquals(XmlNsForm.UNSET, 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.getSpecifiedAttributeFormDefault()); - 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.getSpecifiedAttributeFormDefault()); - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getAttributeFormDefault()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertNull(contextXmlSchema.getSpecifiedAttributeFormDefault()); - assertEquals(XmlNsForm.UNSET, 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.getSpecifiedElementFormDefault()); - assertEquals(XmlNsForm.UNSET, contextXmlSchema.getElementFormDefault()); - - contextXmlSchema.setSpecifiedElementFormDefault(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.setSpecifiedElementFormDefault(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.setSpecifiedElementFormDefault(null); - schemaAnnotation = (XmlSchemaAnnotation) resourcePackage.getAnnotation(XmlSchemaAnnotation.ANNOTATION_NAME); - assertNull(schemaAnnotation.getElementFormDefault()); - assertNull(contextXmlSchema.getSpecifiedElementFormDefault()); - - //set element form default again, this time starting with no XmlSchema annotation - contextXmlSchema.setSpecifiedElementFormDefault(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.getSpecifiedElementFormDefault()); - assertEquals(XmlNsForm.UNSET, 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.getSpecifiedElementFormDefault()); - 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.getSpecifiedElementFormDefault()); - assertEquals(XmlNsForm.UNQUALIFIED, contextXmlSchema.getElementFormDefault()); - - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSchemaTests.this.removeXmlSchemaAnnotation(declaration); - } - }); - - contextXmlSchema = contextPackageInfo.getXmlSchema(); - assertNull(contextXmlSchema.getSpecifiedElementFormDefault()); - assertEquals(XmlNsForm.UNSET, 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 74d59c14b5..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,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -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.XmlAccessorOrderAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; -import org.eclipse.xsd.util.XSDUtil; - - -@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.getSchemaTypeRef().getName()); - - contextXmlSchemaType.getSchemaTypeRef().setSpecifiedName("foo"); - XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaTypeAnnotation.getName()); - assertEquals("foo", contextXmlSchemaType.getSchemaTypeRef().getName()); - - //verify the xml schema type annotation is not removed when the name is set to null - contextXmlSchemaType.getSchemaTypeRef().setSpecifiedName(null); - schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(schemaTypeAnnotation.getName()); - assertNull(contextXmlSchemaType.getSchemaTypeRef().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.getSchemaTypeRef().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.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001, contextXmlSchemaType.getSchemaTypeRef().getDefaultNamespace()); - assertEquals(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001, contextXmlSchemaType.getSchemaTypeRef().getNamespace()); - - contextXmlSchemaType.getSchemaTypeRef().setSpecifiedNamespace("foo"); - XmlSchemaTypeAnnotation schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertEquals("foo", schemaTypeAnnotation.getNamespace()); - assertEquals("foo", contextXmlSchemaType.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", contextXmlSchemaType.getSchemaTypeRef().getNamespace()); - - //verify the xml schema type annotation is not removed when the namespace is set to null - contextXmlSchemaType.getSchemaTypeRef().setSpecifiedNamespace(null); - schemaTypeAnnotation = (XmlSchemaTypeAnnotation) resourcePackage.getAnnotation(0, XmlSchemaTypeAnnotation.ANNOTATION_NAME); - assertNull(schemaTypeAnnotation.getNamespace()); - assertNull(contextXmlSchemaType.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001, contextXmlSchemaType.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001, contextXmlSchemaType.getSchemaTypeRef().getDefaultNamespace()); - assertEquals(XSDUtil.SCHEMA_FOR_SCHEMA_URI_2001, contextXmlSchemaType.getSchemaTypeRef().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.getSchemaTypeRef().getSpecifiedNamespace()); - assertEquals("foo", contextXmlSchemaType.getSchemaTypeRef().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/GenericJavaXmlSeeAlsoTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSeeAlsoTests.java deleted file mode 100644 index 2f20f7df59..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlSeeAlsoTests.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.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.NormalAnnotation; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlSeeAlso; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -public class GenericJavaXmlSeeAlsoTests - extends JaxbContextModelTestCase { - - public GenericJavaXmlSeeAlsoTests(String name) { - super(name); - } - - - private ICompilationUnit createAnnotatedPersistentClassWithXmlSeeAlso() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_SEE_ALSO); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType" + CR); - sb.append("@XmlSeeAlso"); - } - }); - } - - public void testModifyClasses() throws Exception { - createAnnotatedPersistentClassWithXmlSeeAlso(); - JaxbPersistentClass contextPersistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - XmlSeeAlso contextXmlSeeAlso = contextPersistentClass.getXmlSeeAlso(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - - assertEquals(0, contextXmlSeeAlso.getClassesSize()); - - // add a class - contextXmlSeeAlso.addClass(0, "foo"); - XmlSeeAlsoAnnotation annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertEquals(1, annotation.getClassesSize()); - assertTrue(CollectionTools.contains(annotation.getClasses(), "foo")); - assertFalse(CollectionTools.contains(annotation.getClasses(), "bar")); - - // add another - contextXmlSeeAlso.addClass(0, "bar"); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertEquals(2, annotation.getClassesSize()); - assertTrue(CollectionTools.contains(annotation.getClasses(), "foo")); - assertTrue(CollectionTools.contains(annotation.getClasses(), "bar")); - - // remove one - contextXmlSeeAlso.removeClass(1); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertEquals(1, annotation.getClassesSize()); - assertFalse(CollectionTools.contains(annotation.getClasses(), "foo")); - assertTrue(CollectionTools.contains(annotation.getClasses(), "bar")); - - // remove the other - contextXmlSeeAlso.removeClass(0); - annotation = (XmlSeeAlsoAnnotation) resourceType.getAnnotation(JAXB.XML_SEE_ALSO); - assertEquals(0, annotation.getClassesSize()); - assertFalse(CollectionTools.contains(annotation.getClasses(), "bar")); - assertFalse(CollectionTools.contains(annotation.getClasses(), "foo")); - } - - public void testUpdateClasses() throws Exception { - createAnnotatedPersistentClassWithXmlSeeAlso(); - JaxbPersistentClass contextPersistentClass = getContextRoot().getPersistentClass(FULLY_QUALIFIED_TYPE_NAME); - XmlSeeAlso contextXmlSeeAlso = contextPersistentClass.getXmlSeeAlso(); - JavaResourceType resourceType = contextPersistentClass.getJavaResourceType(); - AnnotatedElement annotatedElement = annotatedElement(resourceType); - - assertEquals(0, contextXmlSeeAlso.getClassesSize()); - - // add a class - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSeeAlsoTests.this.addClass(declaration, 0, "foo"); - } - }); - assertEquals(1, contextXmlSeeAlso.getClassesSize()); - assertTrue(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "foo")); - assertFalse(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "bar")); - - // add another - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSeeAlsoTests.this.addClass(declaration, 0, "bar"); - } - }); - assertEquals(2, contextXmlSeeAlso.getClassesSize()); - assertTrue(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "foo")); - assertTrue(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "bar")); - - // remove one - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSeeAlsoTests.this.removeClass(declaration, 1); - } - }); - assertEquals(1, contextXmlSeeAlso.getClassesSize()); - assertFalse(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "foo")); - assertTrue(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "bar")); - - // remove the other - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlSeeAlsoTests.this.removeClass(declaration, 0); - } - }); - assertEquals(0, contextXmlSeeAlso.getClassesSize()); - assertFalse(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "bar")); - assertFalse(CollectionTools.contains(contextXmlSeeAlso.getClasses(), "foo")); - } - - protected void addClass(ModifiedDeclaration declaration, int index, String clazz) { - addArrayElement(declaration, JAXB.XML_SEE_ALSO, index, JAXB.XML_SEE_ALSO__VALUE, newTypeLiteral(declaration.getAst(), clazz)); - } - - protected void removeClass(ModifiedDeclaration declaration, int index) { - removeArrayElement((NormalAnnotation) getXmlSeeAlsoAnnotation(declaration), JAXB.XML_SEE_ALSO__VALUE, index); - } - - protected Annotation getXmlSeeAlsoAnnotation(ModifiedDeclaration declaration) { - return declaration.getAnnotationNamed(JAXB.XML_SEE_ALSO); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlValueMappingTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlValueMappingTests.java deleted file mode 100644 index 8f748f295d..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/context/java/GenericJavaXmlValueMappingTests.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.utility.jdt.AnnotatedElement; -import org.eclipse.jpt.common.core.utility.jdt.Member; -import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.MappingKeys; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentAttribute; -import org.eclipse.jpt.jaxb.core.context.JaxbPersistentClass; -import org.eclipse.jpt.jaxb.core.context.XmlAttributeMapping; -import org.eclipse.jpt.jaxb.core.context.XmlElementMapping; -import org.eclipse.jpt.jaxb.core.context.XmlValueMapping; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlValueAnnotation; -import org.eclipse.jpt.jaxb.core.tests.internal.context.JaxbContextModelTestCase; - - -@SuppressWarnings("nls") -public class GenericJavaXmlValueMappingTests extends JaxbContextModelTestCase -{ - - public GenericJavaXmlValueMappingTests(String name) { - super(name); - } - - private ICompilationUnit createTypeWithXmlValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_TYPE, JAXB.XML_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@XmlType"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlValue"); - } - }); - } - - public void testChangeMappingType() throws Exception { - createTypeWithXmlValue(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlValueMapping xmlValueMapping = (XmlValueMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlValueMapping.getPersistentAttribute().getJavaResourceAttribute(); - - assertNotNull(xmlValueMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlValueAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_ATTRIBUTE_ATTRIBUTE_MAPPING_KEY); - XmlAttributeMapping xmlAttributeMapping = (XmlAttributeMapping) persistentAttribute.getMapping(); - assertNotNull(xmlAttributeMapping); - assertNull(resourceAttribute.getAnnotation(XmlValueAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_VALUE_ATTRIBUTE_MAPPING_KEY); - xmlValueMapping = (XmlValueMapping) persistentAttribute.getMapping(); - assertNotNull(xmlValueMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlValueAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlAttributeAnnotation.ANNOTATION_NAME)); - - - persistentAttribute.setMappingKey(MappingKeys.XML_ELEMENT_ATTRIBUTE_MAPPING_KEY); - XmlElementMapping xmlElementMapping = (XmlElementMapping) persistentAttribute.getMapping(); - assertNotNull(xmlElementMapping); - assertNull(resourceAttribute.getAnnotation(XmlValueAnnotation.ANNOTATION_NAME)); - assertNotNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - - persistentAttribute.setMappingKey(MappingKeys.XML_VALUE_ATTRIBUTE_MAPPING_KEY); - xmlValueMapping = (XmlValueMapping) persistentAttribute.getMapping(); - assertNotNull(xmlValueMapping); - assertNotNull(resourceAttribute.getAnnotation(XmlValueAnnotation.ANNOTATION_NAME)); - assertNull(resourceAttribute.getAnnotation(XmlElementAnnotation.ANNOTATION_NAME)); - } - - public void testModifyXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlValue(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlValueMapping xmlValueMapping = (XmlValueMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlValueMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlValueMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - xmlValueMapping.addXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlValueMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - xmlValueMapping.removeXmlJavaTypeAdapter(); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - - public void testUpdateXmlJavaTypeAdapter() throws Exception { - createTypeWithXmlValue(); - - JaxbPersistentClass persistentClass = CollectionTools.get(getContextRoot().getPersistentClasses(), 0); - JaxbPersistentAttribute persistentAttribute = CollectionTools.get(persistentClass.getAttributes(), 0); - XmlValueMapping xmlValueMapping = (XmlValueMapping) persistentAttribute.getMapping(); - JavaResourceAttribute resourceAttribute = xmlValueMapping.getPersistentAttribute().getJavaResourceAttribute(); - - XmlJavaTypeAdapterAnnotation xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlValueMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - - - //add an XmlJavaTypeAdapter annotation - AnnotatedElement annotatedElement = this.annotatedElement(resourceAttribute); - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlValueMappingTests.this.addMarkerAnnotation(declaration.getDeclaration(), XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNotNull(xmlValueMapping.getXmlJavaTypeAdapter()); - assertNotNull(xmlJavaTypeAdapterAnnotation); - - //remove the XmlJavaTypeAdapter annotation - annotatedElement.edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - GenericJavaXmlValueMappingTests.this.removeAnnotation(declaration, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - } - }); - xmlJavaTypeAdapterAnnotation = (XmlJavaTypeAdapterAnnotation) resourceAttribute.getAnnotation(0, XmlJavaTypeAdapterAnnotation.ANNOTATION_NAME); - assertNull(xmlValueMapping.getXmlJavaTypeAdapter()); - assertNull(xmlJavaTypeAdapterAnnotation); - } -}
\ 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/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 cf42f29d5d..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,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.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(GenericJavaPersistentAttributeTests.class); - suite.addTestSuite(GenericJavaPersistentClassTests.class); - suite.addTestSuite(GenericJavaPersistentEnumTests.class); - suite.addTestSuite(GenericJavaRegistryTests.class); - suite.addTestSuite(GenericJavaXmlAnyAttributeMappingTests.class); - suite.addTestSuite(GenericJavaXmlAnyElementMappingTests.class); - suite.addTestSuite(GenericJavaXmlAttributeMappingTests.class); - suite.addTestSuite(GenericJavaXmlElementMappingTests.class); - suite.addTestSuite(GenericJavaXmlElementsMappingTests.class); - suite.addTestSuite(GenericJavaPackageXmlJavaTypeAdapterTests.class); - suite.addTestSuite(GenericJavaTypeXmlJavaTypeAdapterTests.class); - suite.addTestSuite(GenericJavaAttributeXmlJavaTypeAdapterTests.class); - suite.addTestSuite(GenericJavaXmlRootElementTests.class); - suite.addTestSuite(GenericJavaXmlSchemaTests.class); - suite.addTestSuite(GenericJavaXmlSchemaTypeTests.class); - suite.addTestSuite(GenericJavaXmlSeeAlsoTests.class); - suite.addTestSuite(GenericJavaXmlValueMappingTests.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 f40d96cb14..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/projects/TestJaxbProject.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.common.utility.Command; -import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackSynchronousSynchronizer; -import org.eclipse.jpt.common.utility.internal.synchronizers.SynchronousSynchronizer; -import org.eclipse.jpt.common.utility.synchronizers.CallbackSynchronizer; -import org.eclipse.jpt.common.utility.synchronizers.Synchronizer; -import org.eclipse.jpt.jaxb.core.JaxbFacet; -import org.eclipse.jpt.jaxb.core.JaxbProject; -import org.eclipse.jpt.jaxb.core.JptJaxbCorePlugin; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -/** - * 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. - */ -public class TestJaxbProject - extends TestJavaProject { - - private final JaxbProject jaxbProject; - - - // ********** builders ********** - - public static TestJaxbProject buildJaxbProject( - String baseProjectName, boolean autoBuild, IDataModel 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, IDataModel config) throws CoreException { - super(projectName, autoBuild); - String jaxbFacetVersion = - ((IProjectFacetVersion) config.getProperty(IFacetDataModelProperties.FACET_VERSION)).getVersionString(); - this.installFacet(JaxbFacet.ID, jaxbFacetVersion, config); - this.jaxbProject = JptJaxbCorePlugin.getJaxbProject(this.getProject()); - this.jaxbProject.setContextModelSynchronizer(this.buildSynchronousContextModelSynchronizer()); - this.jaxbProject.setUpdateSynchronizer(this.buildSynchronousUpdateSynchronizer()); - } - - protected Synchronizer buildSynchronousContextModelSynchronizer() { - return new SynchronousSynchronizer(this.buildSynchronousContextModelSynchronizerCommand()); - } - - protected Command buildSynchronousContextModelSynchronizerCommand() { - return new SynchronousContextModelSynchronizerCommand(); - } - - protected class SynchronousContextModelSynchronizerCommand implements Command { - public void execute() { - TestJaxbProject.this.jaxbProject.synchronizeContextModel(new NullProgressMonitor()); - } - } - - protected CallbackSynchronizer buildSynchronousUpdateSynchronizer() { - return new CallbackSynchronousSynchronizer(this.buildSynchronousUpdateSynchronizerCommand()); - } - - protected Command buildSynchronousUpdateSynchronizerCommand() { - return new SynchronousUpdateSynchronizerCommand(); - } - - protected class SynchronousUpdateSynchronizerCommand implements Command { - public void execute() { - TestJaxbProject.this.jaxbProject.update(new NullProgressMonitor()); - } - } - - - // ********** 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 123ed57146..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbCoreResourceModelTests.java +++ /dev/null @@ -1,34 +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.addTestSuite(JaxbIndexResourceTests.class); - suite.addTestSuite(JaxbPropertiesResourceTests.class); - 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/JaxbIndexResourceTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbIndexResourceTests.java deleted file mode 100644 index e066113983..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbIndexResourceTests.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable; -import org.eclipse.jpt.jaxb.core.internal.resource.jaxbindex.JaxbIndexResourceModelProvider; -import org.eclipse.jpt.jaxb.core.resource.jaxbindex.JaxbIndexResource; - - -public class JaxbIndexResourceTests - extends AnnotationTestCase { - - private static String JAXB_INDEX = "jaxb.index"; - - - public JaxbIndexResourceTests(String name) { - super(name); - } - - - private IFile createJaxbIndex(IPath projectRelativePath, String... classNames) throws Exception { - IFolder folder = getJavaProject().getProject().getFolder(projectRelativePath); - if (! folder.exists()) { - folder.create(true, false, null); - } - IFile jaxbIndex = getJavaProject().getProject().getFile(projectRelativePath.append(new Path(JAXB_INDEX))); - InputStream stream = inputStream(classNames); - jaxbIndex.create(stream, true, null); - return jaxbIndex; - } - - private void setClassNames(IFile jaxbIndex, String... classNames) throws Exception { - jaxbIndex.setContents(inputStream(classNames), true, false, null); - } - - private InputStream inputStream(String... classNames) { - StringBuffer sb = new StringBuffer(); - for (String className : classNames) { - sb.append(className + CR); - } - return new ByteArrayInputStream(sb.toString().getBytes()); - } - - public void testUpdateClasses() throws Exception { - IFile jaxbIndex = createJaxbIndex(new Path("src/test"), "foo", "bar"); - JaxbIndexResource resource = JaxbIndexResourceModelProvider.instance().buildResourceModel(jaxbIndex); - - assertTrue(CollectionTools.elementsAreEqual( - resource.getFullyQualifiedClassNames(), - new ArrayIterable<String>(new String[] {"test.foo", "test.bar"}))); - - setClassNames(jaxbIndex, "foo", "bar", "baz"); - - assertTrue(CollectionTools.elementsAreEqual( - resource.getFullyQualifiedClassNames(), - new ArrayIterable<String>(new String[] {"test.foo", "test.bar", "test.baz"}))); - - setClassNames(jaxbIndex); - - assertTrue(CollectionTools.isEmpty(resource.getFullyQualifiedClassNames())); - - jaxbIndex = createJaxbIndex(new Path("src"), "foo", "bar"); - resource = JaxbIndexResourceModelProvider.instance().buildResourceModel(jaxbIndex); - - assertTrue(CollectionTools.elementsAreEqual( - resource.getFullyQualifiedClassNames(), - new ArrayIterable<String>(new String[] {"foo", "bar"}))); - - setClassNames(jaxbIndex, "foo", "bar", "baz"); - - assertTrue(CollectionTools.elementsAreEqual( - resource.getFullyQualifiedClassNames(), - new ArrayIterable<String>(new String[] {"foo", "bar", "baz"}))); - - setClassNames(jaxbIndex); - - assertTrue(CollectionTools.isEmpty(resource.getFullyQualifiedClassNames())); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbPropertiesResourceTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbPropertiesResourceTests.java deleted file mode 100644 index bc0684fc7a..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/JaxbPropertiesResourceTests.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.jaxb.core.internal.resource.jaxbprops.JaxbPropertiesResourceModelProvider; -import org.eclipse.jpt.jaxb.core.resource.jaxbprops.JaxbPropertiesResource; - - -public class JaxbPropertiesResourceTests - extends AnnotationTestCase { - - private static String JAXB_PROPERTIES = "jaxb.properties"; - - - public JaxbPropertiesResourceTests(String name) { - super(name); - } - - - private IFile createJaxbProperties(IPath projectRelativePath, String[] ... propertyValuePairs) throws Exception { - IFolder folder = getJavaProject().getProject().getFolder(projectRelativePath); - if (! folder.exists()) { - folder.create(true, false, null); - } - IFile jaxbProperties = getJavaProject().getProject().getFile(projectRelativePath.append(new Path(JAXB_PROPERTIES))); - InputStream stream = inputStream(propertyValuePairs); - jaxbProperties.create(stream, true, null); - return jaxbProperties; - } - - private void setProperties(IFile jaxbProperties, String[] ... propertyValuePairs) throws Exception { - jaxbProperties.setContents(inputStream(propertyValuePairs), true, false, null); - } - - private InputStream inputStream(String[] ... propertyValuePairs) { - StringBuffer sb = new StringBuffer(); - for (String[] propertyValuePair : propertyValuePairs) { - sb.append(propertyValuePair[0] + "=" + propertyValuePair[1] + CR); - } - return new ByteArrayInputStream(sb.toString().getBytes()); - } - - public void testUpdateProperties() throws Exception { - IFile jaxbProperties = createJaxbProperties(new Path("src/test"), new String[] {"foo", "fooProp"}, new String[] {"bar", "barProp"}); - JaxbPropertiesResource resource = JaxbPropertiesResourceModelProvider.instance().buildResourceModel(jaxbProperties); - - assertEquals(resource.getProperty("foo"), "fooProp"); - assertEquals(resource.getProperty("bar"), "barProp"); - - setProperties(jaxbProperties, new String[] {"foo", "fooProp2"}, new String[] {"baz", "bazProp"}); - - assertEquals(resource.getProperty("foo"), "fooProp2"); - assertNull(resource.getProperty("bar")); - assertEquals(resource.getProperty("baz"), "bazProp"); - - setProperties(jaxbProperties); - - assertNull(resource.getProperty("foo")); - assertNull(resource.getProperty("bar")); - assertNull(resource.getProperty("baz")); - } -} 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 b75e22c6e5..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,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition; -import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition; -import org.eclipse.jpt.common.core.tests.internal.resource.java.JavaResourceModelTestCase; -import org.eclipse.jpt.jaxb.core.internal.jaxb21.GenericJaxb_2_1_PlatformDefinition; - -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 e3864f284e..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,63 +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(XmlElementRefsAnnotationTests.class); - suite.addTestSuite(XmlElementsAnnotationTests.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 32cb73c062..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,60 +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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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); - assertNotNull(annotation); - assertEquals(XmlAccessOrder.UNDEFINED, annotation.getValue()); - - annotation.setValue(XmlAccessOrder.ALPHABETICAL); - assertEquals(XmlAccessOrder.ALPHABETICAL, annotation.getValue()); - assertSourceContains("@XmlAccessorOrder(ALPHABETICAL)", cu); - - annotation.setValue(null); - annotation = (XmlAccessorOrderAnnotation) resourcePackage.getAnnotation(JAXB.XML_ACCESSOR_ORDER); - assertNull(annotation.getValue()); - 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 1518c916ef..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,94 +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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessOrder; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorOrderAnnotation; - -@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()); - } -} 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 fc3e737548..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,66 +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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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); - 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 4c7c4f32b7..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessType; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAccessorTypeAnnotation; - -@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 1758e19fb9..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyAttributeAnnotation; - -@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 3ae8713f60..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAnyElementAnnotation; - -@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 9f10d0714c..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttachmentRefAnnotation; - -@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 d2527290f6..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlAttributeAnnotation; - -@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 12589383e8..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,305 +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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; - -@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 testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(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 testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT); - - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = (XmlElementAnnotation) resourceAttribute.getAnnotation(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(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(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(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(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(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(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(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(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(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(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); - } -} 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 a782a0b072..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.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementDeclAnnotation; - -@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 3865979b82..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,192 +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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation; - -@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 testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF); - - assertTrue(xmlElementRefAnnotation != null); - assertNull(xmlElementRefAnnotation.getName()); - assertNull(xmlElementRefAnnotation.getNamespace()); - assertNull(xmlElementRefAnnotation.getType()); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF); - - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = (XmlElementRefAnnotation) resourceAttribute.getAnnotation(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(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(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(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(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); - } -} diff --git a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java deleted file mode 100644 index 835c30641e..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementRefsAnnotationTests.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementRefsAnnotation; - - -public class XmlElementRefsAnnotationTests - 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 XmlElementRefsAnnotationTests(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, JAXB.XML_ELEMENT_REFS); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRefs(@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, JAXB.XML_ELEMENT_REFS); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRefs(@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, JAXB.XML_ELEMENT_REFS); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRefs(@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class))"); - } - }); - } - - private ICompilationUnit createTestXmlElementRefWithAll() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENT_REF, JAXB.XML_ELEMENT_REFS); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElementRefs(@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\", type = " + XML_ELEMENT_REF_TYPE + ".class))"); - } - }); - } - - - private XmlElementRefAnnotation getXmlElementRefAnnotation(JavaResourceAttribute resourceAttribute) { - XmlElementRefsAnnotation refsAnnotation - = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS); - return refsAnnotation.xmlElementRefAt(0); - } - - private XmlElementRefAnnotation addXmlElementRefAnnotation(int index, JavaResourceAttribute resourceAttribute) { - XmlElementRefsAnnotation refsAnnotation - = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS); - return refsAnnotation.addXmlElementRef(index); - } - - private void removeXmlElementRefAnnotation(int index, JavaResourceAttribute resourceAttribute) { - XmlElementRefsAnnotation refsAnnotation - = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS); - refsAnnotation.removeXmlElementRef(index); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute); - - assertTrue(xmlElementRefAnnotation != null); - assertNull(xmlElementRefAnnotation.getName()); - assertNull(xmlElementRefAnnotation.getNamespace()); - assertNull(xmlElementRefAnnotation.getType()); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute); - - assertTrue(xmlElementRefAnnotation != null); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRef(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute); - - assertNull(xmlElementRefAnnotation.getName()); - - xmlElementRefAnnotation.setName(XML_ELEMENT_REF_NAME); - assertEquals(XML_ELEMENT_REF_NAME, xmlElementRefAnnotation.getName()); - - assertSourceContains("@XmlElementRefs(@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME + "\"))", cu); - - xmlElementRefAnnotation.setName(null); - assertNull(xmlElementRefAnnotation.getName()); - - assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu); - } - - public void testGetNamespace() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithNamespace(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute); - - 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 = getXmlElementRefAnnotation(resourceAttribute); - - assertNull(xmlElementRefAnnotation.getNamespace()); - - xmlElementRefAnnotation.setNamespace(XML_ELEMENT_REF_NAMESPACE); - - assertEquals(XML_ELEMENT_REF_NAMESPACE, xmlElementRefAnnotation.getNamespace()); - assertSourceContains("@XmlElementRefs(@XmlElementRef(namespace = \"" + XML_ELEMENT_REF_NAMESPACE + "\"))", cu); - - xmlElementRefAnnotation.setNamespace(null); - - assertNull(xmlElementRefAnnotation.getNamespace()); - assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu); - } - - public void testGetType() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithType(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementRefAnnotation xmlElementRefAnnotation = getXmlElementRefAnnotation(resourceAttribute); - - 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 = getXmlElementRefAnnotation(resourceAttribute); - - assertNull(xmlElementRefAnnotation.getType()); - - xmlElementRefAnnotation.setType(XML_ELEMENT_REF_TYPE); - - assertEquals(XML_ELEMENT_REF_TYPE, xmlElementRefAnnotation.getType()); - assertSourceContains("@XmlElementRefs(@XmlElementRef(type = " + XML_ELEMENT_REF_TYPE + ".class))", cu); - - xmlElementRefAnnotation.setType(null); - - assertNull(xmlElementRefAnnotation.getType()); - assertSourceContains("@XmlElementRefs(@XmlElementRef)", cu); - } - - public void testAddXmlElementRef() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithAll(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementRefAnnotation(1, resourceAttribute); - XmlElementRefsAnnotation refsAnnotation = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS); - - assertSourceContains( - "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME - + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE - + "\", type = " + XML_ELEMENT_REF_TYPE - + ".class),@XmlElementRef})", cu); - assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF)); - assertNotNull(refsAnnotation); - assertEquals(2, refsAnnotation.getXmlElementRefsSize()); - } - - public void testAddXmlElementRefToBeginningOfList() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithAll(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementRefAnnotation(1, resourceAttribute); - XmlElementRefsAnnotation refsAnnotation = (XmlElementRefsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REFS); - - assertSourceContains( - "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME - + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE - + "\", type = " + XML_ELEMENT_REF_TYPE - + ".class),@XmlElementRef})", cu); - - addXmlElementRefAnnotation(0, resourceAttribute); - - assertSourceContains( - "@XmlElementRefs({@XmlElementRef,@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME - + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE - + "\", type = " + XML_ELEMENT_REF_TYPE - + ".class), @XmlElementRef})", cu); - - assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT_REF)); - assertNotNull(refsAnnotation); - assertEquals(3, refsAnnotation.getXmlElementRefsSize()); - } - - public void testRemoveXmlElementRef() throws Exception { - ICompilationUnit cu = this.createTestXmlElementRefWithAll(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementRefAnnotation(1, resourceAttribute); - - assertSourceContains( - "@XmlElementRefs({@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME - + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE - + "\", type = " + XML_ELEMENT_REF_TYPE - + ".class),@XmlElementRef})", cu); - - removeXmlElementRefAnnotation(1, resourceAttribute); - - assertSourceContains( - "@XmlElementRef(name = \"" + XML_ELEMENT_REF_NAME - + "\", namespace = \"" + XML_ELEMENT_REF_NAMESPACE - + "\", type = " + XML_ELEMENT_REF_TYPE - + ".class)", cu); - } -}
\ 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/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 638c375733..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementWrapperAnnotation; - -@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/XmlElementsAnnotationTests.java b/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java deleted file mode 100644 index db85a0cf63..0000000000 --- a/jaxb/tests/org.eclipse.jpt.jaxb.core.tests/src/org/eclipse/jpt/jaxb/core/tests/internal/resource/java/XmlElementsAnnotationTests.java +++ /dev/null @@ -1,380 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.jaxb.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute; -import org.eclipse.jpt.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementAnnotation; -import org.eclipse.jpt.jaxb.core.resource.java.XmlElementsAnnotation; - - -public class XmlElementsAnnotationTests - 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 XmlElementsAnnotationTests(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_ELEMENTS, JAXB.XML_ELEMENT); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElements(@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_ELEMENTS, JAXB.XML_ELEMENT); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElements(@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_ELEMENTS, JAXB.XML_ELEMENT); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElements(@XmlElement(" + booleanElement + " = true))"); - } - }); - } - - private ICompilationUnit createTestXmlElementWithType() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JAXB.XML_ELEMENTS, JAXB.XML_ELEMENT); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@XmlElements(@XmlElement(type = " + XML_ELEMENT_TYPE + ".class))"); - } - }); - } - - - private XmlElementAnnotation getXmlElementAnnotation(JavaResourceAttribute resourceAttribute) { - XmlElementsAnnotation annotation - = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - return annotation.xmlElementAt(0); - } - - private XmlElementAnnotation addXmlElementAnnotation(int index, JavaResourceAttribute resourceAttribute) { - XmlElementsAnnotation annotation - = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - return annotation.addXmlElement(index); - } - - private void removeXmlElementAnnotation(int index, JavaResourceAttribute resourceAttribute) { - XmlElementsAnnotation annotation - = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - annotation.removeXmlElement(index); - } - - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute); - - assertTrue(xmlElementAnnotation != null); - assertNull(xmlElementAnnotation.getName()); - assertNull(xmlElementAnnotation.getNamespace()); - assertNull(xmlElementAnnotation.getDefaultValue()); - assertNull(xmlElementAnnotation.getNillable()); - assertNull(xmlElementAnnotation.getRequired()); - assertNull(xmlElementAnnotation.getType()); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute); - - assertTrue(xmlElementAnnotation != null); - assertEquals(XML_ELEMENT_NAME, xmlElementAnnotation.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestXmlElement(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - XmlElementAnnotation xmlElementAnnotation = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 = getXmlElementAnnotation(resourceAttribute); - - 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 testAddXmlElement() throws Exception { - ICompilationUnit cu = createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementAnnotation(1, resourceAttribute); - XmlElementsAnnotation annotation = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - - assertSourceContains( - "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})", - cu); - assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT)); - assertNotNull(annotation); - assertEquals(2, annotation.getXmlElementsSize()); - } - - public void testAddXmlElementToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementAnnotation(1, resourceAttribute); - XmlElementsAnnotation annotation = (XmlElementsAnnotation) resourceAttribute.getAnnotation(JAXB.XML_ELEMENTS); - - assertSourceContains( - "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})", - cu); - - addXmlElementAnnotation(0, resourceAttribute); - - assertSourceContains( - "@XmlElements({@XmlElement,@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"), @XmlElement})", - cu); - - assertNull(resourceAttribute.getAnnotation(JAXB.XML_ELEMENT)); - assertNotNull(annotation); - assertEquals(3, annotation.getXmlElementsSize()); - } - - public void testRemoveXmlElement() throws Exception { - ICompilationUnit cu = createTestXmlElementWithName(); - JavaResourceType resourceType = buildJavaResourceType(cu); - JavaResourceField resourceAttribute = getField(resourceType, 0); - addXmlElementAnnotation(1, resourceAttribute); - - assertSourceContains( - "@XmlElements({@XmlElement(name = \"" + XML_ELEMENT_NAME + "\"),@XmlElement})", - cu); - - removeXmlElementAnnotation(1, resourceAttribute); - - assertSourceContains( - "@XmlElement(name = \"" + XML_ELEMENT_NAME + "\")", - cu); - } -}
\ 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/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 02d0d62311..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.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumAnnotation; - -@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 4629e37f00..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.common.core.resource.java.JavaResourceEnum; -import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlEnumValueAnnotation; - -@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 3c13c6e554..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDAnnotation; - -@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 48aacb46ce..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlIDREFAnnotation; - -@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 47ad282afd..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.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlInlineBinaryDataAnnotation; - -@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 1ed94cbb14..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlInlineBinaryDataAnnotation; - -@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 adeab40f26..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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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 760feb054c..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlJavaTypeAdapterAnnotation; - -@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 c21a90420d..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlListAnnotation; - -@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 510878c149..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlMimeTypeAnnotation; - -@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 fe9e868763..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlMixedAnnotation; - -@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 2e7b36bb2e..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRegistryAnnotation; - -@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 adb6360444..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlRootElementAnnotation; - -@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 1128885d56..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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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; - -@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.getAttributeFormDefault()); - 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.getElementFormDefault()); - 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.getLocation()); - 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.getNamespace()); - 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 adebaa97b8..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSchemaTypeAnnotation; - -@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 5e358517c3..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.common.core.resource.java.JavaResourcePackage; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -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 a00b7b6718..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,144 +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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlSeeAlsoAnnotation; - -@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(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 656a5947ed..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.common.core.resource.java.JavaResourceMethod; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTransientAnnotation; - -@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 6a768654ed..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTransientAnnotation; - -@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 6995ed4d5c..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.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlTypeAnnotation; - -@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 eb635a316f..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.common.core.resource.java.JavaResourceField; -import org.eclipse.jpt.common.core.resource.java.JavaResourceType; -import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator; -import org.eclipse.jpt.jaxb.core.resource.java.JAXB; -import org.eclipse.jpt.jaxb.core.resource.java.XmlValueAnnotation; - -@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); - } -} |