diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests')
216 files changed, 0 insertions, 96388 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.classpath b/jpa/tests/org.eclipse.jpt.core.tests/.classpath deleted file mode 100644 index 3c0b3a6a9e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.classpath +++ /dev/null @@ -1,14 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> - <accessrules> - <accessrule kind="accessible" pattern="org/eclipse/wst/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jst/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jpt/core/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/> - </accessrules> - </classpathentry> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore deleted file mode 100644 index c4ba612bad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -bin -@dot -temp.folder -build.xml -javaCompiler...args
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.project b/jpa/tests/org.eclipse.jpt.core.tests/.project deleted file mode 100644 index 08395a8e86..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jpt.core.tests</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index eb348782fa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:10:55 EST 2008 -eclipse.preferences.version=1 -encoding/<project>=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs b/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index a2f6604d54..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,7 +0,0 @@ -#Sun May 27 14:58:31 EDT 2007 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF deleted file mode 100644 index fb6487882c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,44 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.core.tests;singleton:=true -Bundle-Version: 2.3.2.qualifier -Bundle-Localization: plugin -Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)", - org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)", - org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)", - org.eclipse.jem.util;bundle-version="[2.0.100,3.0.0)", - org.eclipse.jpt.core;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.core.tests.extension.resource;bundle-version="[2.0.0,3.0.0)", - org.eclipse.jpt.db;bundle-version="[1.2.0,2.0.0)", - org.eclipse.jpt.utility;bundle-version="[1.2.0,2.0.0)", - org.eclipse.jpt.utility.tests;bundle-version="[1.2.0,2.0.0)", - org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,1.3.0)", - org.eclipse.wst.common.modulecore;bundle-version="[1.1.200,2.0.0)", - org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)", - org.junit;bundle-version="3.8.0" -Export-Package: org.eclipse.jpt.core.tests, - org.eclipse.jpt.core.tests.internal;x-friends:="org.eclipse.jpt.ui.tests", - org.eclipse.jpt.core.tests.internal.context;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.orm;x-internal:=true, - org.eclipse.jpt.core.tests.internal.context.persistence;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.orm;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.context.persistence;x-internal:=true, - org.eclipse.jpt.core.tests.internal.jpa2.resource.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.model;x-internal:=true, - org.eclipse.jpt.core.tests.internal.platform;x-internal:=true, - org.eclipse.jpt.core.tests.internal.projects;x-friends:="org.eclipse.jpt.ui.tests", - org.eclipse.jpt.core.tests.internal.resource;x-internal:=true, - org.eclipse.jpt.core.tests.internal.resource.java;x-internal:=true, - org.eclipse.jpt.core.tests.internal.utility.jdt;x-internal:=true -Bundle-Activator: org.eclipse.jpt.core.tests.JptCoreTestsPlugin -Bundle-ActivationPolicy: lazy diff --git a/jpa/tests/org.eclipse.jpt.core.tests/about.html b/jpa/tests/org.eclipse.jpt.core.tests/about.html deleted file mode 100644 index be534ba44f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/about.html +++ /dev/null @@ -1,34 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> -<HTML> - -<head> -<title>About</title> -<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1"> -</head> - -<BODY lang="EN-US"> - -<H3>About This Content</H3> - -<P>May 02, 2008</P> - -<H3>License</H3> - -<P>The Eclipse Foundation makes available all content in this plug-in -("Content"). Unless otherwise indicated below, the Content is provided to you -under the terms and conditions of the Eclipse Public License Version 1.0 -("EPL"). A copy of the EPL is available at -<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>. -For purposes of the EPL, "Program" will mean the Content.</P> - -<P>If you did not receive this Content directly from the Eclipse Foundation, the -Content is being redistributed by another party ("Redistributor") and different -terms and conditions may apply to your use of any object code in the Content. -Check the Redistributor's license that was provided with the Content. If no such -license exists, contact the Redistributor. Unless otherwise indicated below, the -terms and conditions of the EPL still apply to any source code in the Content -and such source code may be obtained at -<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P> - -</BODY> -</HTML> diff --git a/jpa/tests/org.eclipse.jpt.core.tests/build.properties b/jpa/tests/org.eclipse.jpt.core.tests/build.properties deleted file mode 100644 index 96de1ee6d2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/build.properties +++ /dev/null @@ -1,18 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 2008 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ -javacSource = 1.5 -javacTarget = 1.5 -bin.includes = .,\ - META-INF/,\ - about.html,\ - test.xml,\ - plugin.properties -source.. = src/ -output.. = bin/ diff --git a/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties deleted file mode 100644 index 113453a4d6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/plugin.properties +++ /dev/null @@ -1,23 +0,0 @@ -################################################################################ -# Copyright (c) 2006, 2009 Oracle. All rights reserved. -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License v1.0, which accompanies this distribution -# and is available at http://www.eclipse.org/legal/epl-v10.html. -# -# Contributors: -# Oracle - initial API and implementation -################################################################################ -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Dali Java Persistence Tools - Core Tests -providerName=Eclipse Web Tools Platform diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java deleted file mode 100644 index 4d6ed067f6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/JptCoreTestsPlugin.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 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.core.tests; - -import org.eclipse.core.runtime.Plugin; -import org.eclipse.jpt.core.JpaProjectManager; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.utility.internal.ReflectionTools; -import org.osgi.framework.BundleContext; - -/** - * configure the core to handle events synchronously when we are - * running tests - */ -@SuppressWarnings("nls") -public class JptCoreTestsPlugin extends Plugin { - - private static JptCoreTestsPlugin INSTANCE; - - public static JptCoreTestsPlugin instance() { - return INSTANCE; - } - - - // ********** plug-in implementation ********** - - public JptCoreTestsPlugin() { - super(); - if (INSTANCE != null) { - throw new IllegalStateException(); - } - // this convention is *wack*... ~bjv - INSTANCE = this; - } - - - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - JpaProjectManager jpaProjectManager = JptCorePlugin.getJpaProjectManager(); - ReflectionTools.executeMethod(jpaProjectManager, "handleEventsSynchronously"); - ReflectionTools.executeStaticMethod(JptCorePlugin.class, "doNotFlushPreferences"); - } - - @Override - public void stop(BundleContext context) throws Exception { - super.stop(context); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java deleted file mode 100644 index 72c9ad75ac..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/MiscTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.core.tests; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.ILock; -import org.eclipse.core.runtime.jobs.Job; - -@SuppressWarnings("nls") -public class MiscTests extends TestCase { - - public MiscTests(String name) { - super(name); - } - - /* - * - */ - public void testJobsAndLocks() throws Exception { - ILock lock = Job.getJobManager().newLock(); - Job testJob = new TestJob(lock); - testJob.schedule(); - } - - class TestJob extends Job { - private final ILock lock; - TestJob(ILock lock) { - super("test job"); - this.lock = lock; - } - @Override - protected IStatus run(IProgressMonitor monitor) { - this.run(); - return Status.OK_STATUS; - } - private void run() { - try { - this.lock.acquire(); - MiscTests.sleep(100); - } finally { - this.lock.release(); - } - } - } - - static void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java deleted file mode 100644 index 0dab6a33a8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2010 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal; - -import java.io.File; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.context.JptCoreContextModelTests; -import org.eclipse.jpt.core.tests.internal.model.JptCoreModelTests; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.core.tests.internal.resource.JptCoreResourceModelTests; -import org.eclipse.jpt.core.tests.internal.utility.jdt.JptCoreUtilityJdtTests; - -/** - * decentralize test creation code - * - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path> - */ -@SuppressWarnings("nls") -public class JptCoreTests { - private static final String JPA_JAR_PROPERTY = TestJpaProject.JPA_JAR_NAME_SYSTEM_PROPERTY; - - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreTests.class.getPackage().getName()); - suite.addTest(JptCoreUtilityJdtTests.suite()); - suite.addTest(JptCoreModelTests.suite()); - suite.addTest(JptCoreResourceModelTests.suite()); - suite.addTest(JptCoreContextModelTests.suite()); - return suite; - } - - public static boolean requiredJarsExists() { - return jpaJarPropertyExists() && jpaJarFileExists(); - } - - public static boolean jpaJarPropertyExists() { - return getSystemProperty(JPA_JAR_PROPERTY) != null; - } - - public static boolean jpaJarFileExists() { - return (new File(getSystemProperty(JPA_JAR_PROPERTY))).exists(); - } - - public static String buildMissingJarErrorMessage() { - if( ! jpaJarPropertyExists()) { - return errorMissingProperty(JPA_JAR_PROPERTY); - } - return errorJarFileDoesNotExist(getSystemProperty(JPA_JAR_PROPERTY)); - } - - /*********** private **********/ - private static String errorMissingProperty(String propertyName) { - return "missing Java system property: \"" + propertyName + "\""; - } - - private static String errorJarFileDoesNotExist(String propertyValue) { - return "JAR file doesn't exist: \"" + propertyValue + "\""; - } - - private static String getSystemProperty(String propertyName) { - return System.getProperty(propertyName); - } - - private JptCoreTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java deleted file mode 100644 index b49982ead1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java +++ /dev/null @@ -1,199 +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.core.tests.internal.context; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.MappingFile; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.GenericJpaPlatformProvider; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase; -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.internal.emfworkbench.WorkbenchResourceHelper; - -@SuppressWarnings("nls") -public abstract class ContextModelTestCase extends AnnotationTestCase -{ - protected static final String BASE_PROJECT_NAME = "ContextModelTestProject"; - - protected JpaXmlResource persistenceXmlResource; - - protected JpaXmlResource ormXmlResource; - - - protected ContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.persistenceXmlResource = getJpaProject().getPersistenceXmlResource(); - this.ormXmlResource = getJpaProject().getDefaultOrmXmlResource(); - this.waitForWorkspaceJobsToFinish(); - } - - @Override - protected void tearDown() throws Exception { - this.persistenceXmlResource = null; - this.ormXmlResource = null; - JptCorePlugin.getWorkspacePreferences().clear(); - this.waitForWorkspaceJobsToFinish(); - super.tearDown(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return buildJpaProject(BASE_PROJECT_NAME, autoBuild, buildJpaConfigDataModel()); - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) - throws Exception { - return TestJpaProject.buildJpaProject(projectName, autoBuild, jpaConfig); - } - - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); - // default facet version is 2.0 - most tests use 1.0 - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JptCorePlugin.JPA_FACET_VERSION_1_0); - // most tests use the basic generic platform - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM_ID, GenericJpaPlatformProvider.ID); - // most tests do use an orm.xml - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - protected JpaProject getJpaProject() { - return getJavaProject().getJpaProject(); - } - - protected void waitForWorkspaceJobsToFinish() throws InterruptedException { - // This job will not start running until all the other workspace jobs are done - Job waitJob = new Job("Wait job") { - @Override - protected IStatus run(IProgressMonitor monitor) { - return Status.OK_STATUS; - } - }; - waitJob.setRule(ResourcesPlugin.getWorkspace().getRoot()); - waitJob.schedule(); - waitJob.join(); - } - - protected JpaXmlResource getPersistenceXmlResource() { - return this.persistenceXmlResource; - } - - protected JpaXmlResource getOrmXmlResource() { - return this.ormXmlResource; - } - - protected XmlEntityMappings getXmlEntityMappings() { - return (XmlEntityMappings) getOrmXmlResource().getRootObject(); - } - - protected XmlPersistence getXmlPersistence() { - return (XmlPersistence) getPersistenceXmlResource().getRootObject(); - } - - protected EntityMappings getEntityMappings() { - MappingFile mappingFile = getPersistenceUnit().mappingFileRefs().next().getMappingFile(); - return (mappingFile == null) ? null : (EntityMappings) mappingFile.getRoot(); - } - - protected XmlPersistenceUnit getXmlPersistenceUnit() { - return getXmlPersistence().getPersistenceUnits().get(0); - } - - protected PersistenceUnit getPersistenceUnit() { - return getRootContextNode().getPersistenceXml().getPersistence().persistenceUnits().next(); - } - - protected ClassRef getSpecifiedClassRef() { - return getPersistenceUnit().specifiedClassRefs().next(); - } - - protected JavaPersistentType getJavaPersistentType() { - return getSpecifiedClassRef().getJavaPersistentType(); - } - - protected JavaEntity getJavaEntity() { - return (JavaEntity) getJavaPersistentType().getMapping(); - } - - protected void addXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass(className); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - } - - protected void removeXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - XmlJavaClassRef xmlJavaClassRefToRemove = null; - for (XmlJavaClassRef xmlJavaClassRef : xmlPersistenceUnit.getClasses()) { - if (xmlJavaClassRef.getJavaClass().equals(className)) { - xmlJavaClassRefToRemove = xmlJavaClassRef; - } - } - if (xmlJavaClassRefToRemove == null) { - throw new IllegalArgumentException(); - } - xmlPersistenceUnit.getClasses().remove(xmlJavaClassRefToRemove); - } - - protected void addXmlMappingFileRef(String fileName) { - XmlPersistenceUnit xmlPersistenceUnit = getXmlPersistenceUnit(); - - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName(fileName); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - } - - protected JpaRootContextNode getRootContextNode() { - return getJavaProject().getJpaProject().getRootContextNode(); - } - - @Override - protected TestJpaProject getJavaProject() { - return (TestJpaProject) super.getJavaProject(); - } - - protected void deleteResource(Resource resource) throws CoreException { - WorkbenchResourceHelper.deleteResource(resource); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java deleted file mode 100644 index 25819715cf..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java +++ /dev/null @@ -1,411 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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.core.tests.internal.context; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JpaFileTests extends ContextModelTestCase -{ - public JpaFileTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - public void testGetRootStructureNode() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //verify the mapping file reference "wins" as the root structure node when both - //persistence.xml <class> tag and mapping file <entity> tag exist for a particulary java class - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(ormPersistentType); - - assertEquals(getJavaEntity().getPersistentType(), javaJpaFile.rootStructureNodes().next()); - - ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - public void testEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testImpliedEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertNull(getPersistenceUnit().getImpliedMappingFileRef()); - - getXmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(getPersistenceUnit().getImpliedMappingFileRef()); - assertEquals(getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot(), ormXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) ormXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testEntityMappingsRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = getOrmXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - getOrmXmlResource().getContents().remove(getOrmXmlResource().getRootObject()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdatePersistenceRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateJavaRootStructureNodePersistenceRemoved() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - JpaXmlResource resource = (JpaXmlResource) persistenceXmlJpaFile.getResourceModel(); - resource.getContents().remove(resource.getRootObject()); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testPersistenceRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = getPersistenceXmlResource().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - getRootContextNode().getPersistenceXml().getPersistence(); - assertEquals(getRootContextNode().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceXmlRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateJavaRootStructureNodePersistenceXmlRemoved() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - getPersistenceXmlResource().getContents().remove(getXmlPersistence()); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType); - - - getEntityMappings().removePersistentType(0); - - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof OrmPersistentType); - - getXmlEntityMappings().getEntities().remove(0); - - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - } - - public void testJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - - getEntityMappings().getPersistenceUnit().removeSpecifiedClassRef(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception { - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - JavaPersistentType javaPersistentType = getJavaPersistentType(); - Iterator<JpaStructureNode> rootStructureNodes = javaJpaFile.rootStructureNodes(); - JpaStructureNode rootStructureNode = rootStructureNodes.next(); - assertEquals(javaPersistentType, rootStructureNode); - assertEquals(getEntityMappings().getPersistenceUnit().specifiedClassRefs().next(), rootStructureNode.getParent()); - assertFalse(rootStructureNodes.hasNext()); - - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testImpliedJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - getJpaProject().setDiscoversAnnotatedClasses(true); - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = getPersistenceUnit().impliedClassRefs().next().getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - javaPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testJavaRootStructureNodesEntityMappingsRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getOrmXmlResource().getContents().remove(getXmlEntityMappings()); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getXmlPersistence().getPersistenceUnits().remove(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getJpaProject().getRootContextNode().getPersistenceXml().getPersistence().removePersistenceUnit(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesOrmPersistentTypeRemoved() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesOrmTypeMappingMorphed() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - javaPersistentType = getEntityMappings().getPersistentTypes().iterator().next().getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - getEntityMappings().removePersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getEntityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testUpdateOrmJavaRootStructureNodeMappingFileRefChanged() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - - ormPersistentType = ((EntityMappings) getPersistenceUnit().getImpliedMappingFileRef().getMappingFile().getRoot()).getPersistentTypes().iterator().next(); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - IFile file = getPersistenceXmlResource().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertEquals(1, ormXmlJpaFile.rootStructureNodesSize()); - } - - public void testUpdateJavaRootStructureNodeMappingFileRefChanged() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - MappingFileRef mappingFileRef = getPersistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - assertEquals(getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - - public void testUpdateJavaRootStrucutreNodeDeleteOrmResource() throws Exception { - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - - deleteResource(getOrmXmlResource()); - - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - //TODO test rootStructureNodes with a static inner class -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java deleted file mode 100644 index 583b0a323e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaProjectTests.java +++ /dev/null @@ -1,167 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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.core.tests.internal.context; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.GenericJpaPlatformProvider; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProvider; -import org.eclipse.jpt.core.internal.operations.JpaFileCreationDataModelProperties; -import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; -import org.eclipse.jpt.core.internal.operations.PersistenceFileCreationDataModelProvider; -import org.eclipse.jpt.core.resource.xml.JpaXmlResource; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -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; - -@SuppressWarnings("nls") -public class JpaProjectTests extends TestCase -{ - static final String BASE_PROJECT_NAME = JpaProjectTests.class.getSimpleName(); - - TestJpaProject jpaProject; - - - public JpaProjectTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false, buildJpaConfigDataModel()); // false = no auto-build - } - - protected IDataModel buildJpaConfigDataModel() { - IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider()); - dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, JptCorePlugin.JPA_FACET_VERSION_1_0); - dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM_ID, GenericJpaPlatformProvider.ID); - dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE); - return dataModel; - } - - @Override - protected void tearDown() throws Exception { - this.jpaProject.getProject().delete(true, true, null); - this.jpaProject = null; - super.tearDown(); - } - - protected JpaProject getJpaProject() { - return this.jpaProject.getJpaProject(); - } - - public void testGetPersistenceXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getPersistenceXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the persistence.xml file and verify it is not returned from getPersistenceXmlResource() - resource.delete(null); - resource = this.getJpaProject().getPersistenceXmlResource(); - assertNull(resource); - - //add the persistence.xml file back - createPersistenceXmlFile(); - resource = this.getJpaProject().getPersistenceXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/persistence.xml", resource.getFile().getProjectRelativePath().toString()); - } - - private void createPersistenceXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new PersistenceFileCreationDataModelProvider()); - config.setProperty(JpaFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName()); - config.getDefaultOperation().execute(null, null); - } - - public void testGetDefaultOrmXmlResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() - resource.delete(null); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNull(resource); - - //add the default orm.xml file back - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getDefaultOrmXmlResource(); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - private void createDefaultOrmXmlFile() throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JpaFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName()); - config.getDefaultOperation().execute(null, null); - } - - private void createOrmXmlFile(String filePath) throws Exception { - IDataModel config = - DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); - config.setProperty(JpaFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName()); - config.setProperty(JpaFileCreationDataModelProperties.FILE_PATH, filePath); - config.getDefaultOperation().execute(null, null); - } - - public void testGetMappingFileResource() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - assertNull(resource); - - //add the orm.xml file back - createDefaultOrmXmlFile(); - resource = this.getJpaProject().getMappingFileXmlResource(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); - } - - public void testGetMappingFileResourceDifferentlyName() throws Exception { - JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); - assertNull(resource); - - //create the orm2.xml file - createOrmXmlFile("META-INF/orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - - //delete the orm2.xml file and verify it is not returned from getMappingFileResource() - resource.delete(null); - resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); - assertNull(resource); - - //add the orm2.xml file back - createOrmXmlFile("META-INF/orm2.xml"); - resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); - assertNotNull(resource); - assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); - assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java deleted file mode 100644 index 167c4a87cd..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java +++ /dev/null @@ -1,53 +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.core.tests.internal.context; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.JptCoreTests; -import org.eclipse.jpt.core.tests.internal.context.java.JptCoreContextJavaModelTests; -import org.eclipse.jpt.core.tests.internal.context.orm.JptCoreOrmContextModelTests; -import org.eclipse.jpt.core.tests.internal.context.persistence.JptCorePersistenceContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.java.Generic2_0JavaContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.orm.Generic2_0OrmContextModelTests; -import org.eclipse.jpt.core.tests.internal.jpa2.context.persistence.Generic2_0PersistenceContextModelTests; - -/** - * Required Java system property: - * -Dorg.eclipse.jpt.jpa.jar=<jpa.jar path> - */ -public class JptCoreContextModelTests extends TestCase -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptCoreContextModelTests.class.getName()); - - if(JptCoreTests.requiredJarsExists()) { - suite.addTestSuite(JpaProjectTests.class); - suite.addTestSuite(JpaFileTests.class); - suite.addTest(JptCorePersistenceContextModelTests.suite()); - suite.addTest(JptCoreOrmContextModelTests.suite()); - suite.addTest(JptCoreContextJavaModelTests.suite()); - suite.addTest(Generic2_0JavaContextModelTests.suite()); - suite.addTest(Generic2_0OrmContextModelTests.suite()); - suite.addTest(Generic2_0PersistenceContextModelTests.suite()); - } - else { - suite.addTest(TestSuite.warning(JptCoreTests.buildMissingJarErrorMessage())); - } - return suite; - } - - private JptCoreContextModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java deleted file mode 100644 index a729eebd40..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentAttributeTests.java +++ /dev/null @@ -1,236 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class GenericJavaPersistentAttributeTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public GenericJavaPersistentAttributeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals("id", persistentAttribute.getName()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getMapping() instanceof JavaIdMapping); - - persistentAttribute.setSpecifiedMappingKey(null); - assertTrue(persistentAttribute.getMapping() instanceof JavaBasicMapping); - } - - public void testGetSpecifiedMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaIdMapping); - - persistentAttribute.setSpecifiedMappingKey(null); - assertNull(persistentAttribute.getSpecifiedMapping()); - } - - public void testGetSpecifiedMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertNotNull(persistentAttribute.getMapping()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(null); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testDefaultMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - } - - public void testSetSpecifiedMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - assertTrue(persistentAttribute.getSpecifiedMapping() instanceof JavaEmbeddedMapping); - } - - public void testSetSpecifiedMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - - assertNull(persistentAttribute.getSpecifiedMapping()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(EmbeddedAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.setPrimaryAnnotation(BasicAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getSpecifiedMapping().getKey()); - } - - public void testGetAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.FIELD, persistentAttribute.getAccess()); - assertEquals(AccessType.FIELD, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } - - public void testGetAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertEquals(AccessType.PROPERTY, persistentAttribute.getAccess()); - assertEquals(AccessType.PROPERTY, persistentAttribute.getDefaultAccess()); - assertEquals(null, persistentAttribute.getSpecifiedAccess()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java deleted file mode 100644 index 33c2f55a3b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java +++ /dev/null @@ -1,757 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -@SuppressWarnings("nls") -public class GenericJavaPersistentTypeTests extends ContextModelTestCase -{ - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - private ICompilationUnit createTestEntityAnnotatedFieldAndMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubType() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - }); - } - - private ICompilationUnit createTestSubTypeWithFieldAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeWithMethodAnnotation() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestSubTypeNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild.java", "AnnotationTestTypeChild", new DefaultAnnotationWriter() { - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends " + TYPE_NAME + " "); - } - }); - } - - private ICompilationUnit createTestSubTypePersistentExtendsNonPersistent() throws Exception { - return this.createTestType(PACKAGE_NAME, "AnnotationTestTypeChild2.java", "AnnotationTestTypeChild2", new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendExtendsImplementsTo(StringBuilder sb) { - sb.append("extends AnnotationTestTypeChild "); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public GenericJavaPersistentTypeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, getJavaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance2() throws Exception { - createTestEntityAnnotatedField(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessInheritance3() throws Exception { - createTestEntityAnnotatedField(); - createTestSubTypeWithMethodAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessInheritance4() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inherited class having annotations set wins over the default access set on persistence-unit-defaults - public void testAccessInheritancePersistenceUnitDefaultAccess() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef classRef = classRefs.next(); - JavaPersistentType javaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(PACKAGE_NAME + ".AnnotationTestTypeChild", javaPersistentType.getName()); - - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlNoAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is field - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is property - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - - ormPersistentType.setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, java has field annotations so the access should be field - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated - OrmPersistentType entityPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testSuperPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testSuperPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //super is not added to the persistenceUnit, but it should still be found - //as the superPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getSuperPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testSuperPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getSuperPersistentType()); - assertNull(rootJavaPersistentType.getSuperPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testInheritanceHierarchy2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType childJavaPersistentType = classRefs.next().getJavaPersistentType(); - JavaPersistentType rootJavaPersistentType = classRefs.next().getJavaPersistentType(); - - Iterator<PersistentType> inheritanceHierarchy = childJavaPersistentType.inheritanceHierarchy(); - - assertEquals(childJavaPersistentType, inheritanceHierarchy.next()); - assertEquals(rootJavaPersistentType, inheritanceHierarchy.next()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EmbeddableAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setPrimaryAnnotation(EntityAnnotation.ANNOTATION_NAME, EmptyIterable.<String>instance()); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, getJavaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaPersistentType().isMapped()); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(getJavaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertEquals("name", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributesSize() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(1, getJavaPersistentType().attributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, getJavaPersistentType().attributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(getJavaPersistentType().getAttributeNamed("name")); - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = getJavaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(getJavaPersistentType().getAttributeNamed("foo")); - } - - public void testRenameAttribute() throws Exception { - ICompilationUnit testType = createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<JavaPersistentAttribute> attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute idAttribute = attributes.next(); - JavaPersistentAttribute nameAttribute = attributes.next(); - - - assertEquals("id", idAttribute.getName()); - assertEquals("name", nameAttribute.getName()); - - IField idField = testType.findPrimaryType().getField("id"); - idField.rename("id2", false, null); - - attributes = getJavaPersistentType().attributes(); - JavaPersistentAttribute nameAttribute2 = attributes.next(); - JavaPersistentAttribute id2Attribute = attributes.next(); - - assertNotSame(idAttribute, id2Attribute); - assertEquals("id2", id2Attribute.getName()); - assertEquals(nameAttribute, nameAttribute2); - assertEquals("name", nameAttribute2.getName()); - assertFalse(attributes.hasNext()); - } - - public void testSuperPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = getJavaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getSuperPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getSuperPersistentType().getName()); - } - - private void createTestGenericEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 "); - sb.append("extends Entity2<Integer> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericMappedSuperclass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.MAPPED_SUPERCLASS); - sb.append(";"); - sb.append(CR); - sb.append("@MappedSuperclass"); - sb.append(CR); - sb.append("public class Entity2<K> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity2.java", sourceWriter); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java deleted file mode 100644 index fa217070aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java +++ /dev/null @@ -1,442 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAssociationOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaAssociationOverrideTests extends ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - sb.append(CR); - sb.append(" private AnnotationTestTypeChild address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - 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); - } - - - - public JavaAssociationOverrideTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.associationOverrides().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, overrideContainer.specifiedAssociationOverridesSize()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, overrideContainer.specifiedAssociationOverridesSize()); - javaAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - assertFalse(overrideContainer.specifiedAssociationOverrides().hasNext()); - assertFalse(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).hasNext()); - } - - public void testModifyName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(overrideContainer.associationOverrides().hasNext()); - - //set name in the context model, verify resource model modified - javaAssociationOverride.setName("foo"); - assertEquals("foo", javaAssociationOverride.getName()); - assertEquals("foo", associationOverrideResource.getName()); - - //set name to null in the context model - javaAssociationOverride.setName(null); - assertNull(javaAssociationOverride.getName()); - associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - assertNull(associationOverrideResource.getName()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JavaJoinColumn joinColumn = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.joinColumnAt(0).getName()); - - JavaJoinColumn joinColumn2 = joiningStrategy.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(1).getName()); - - JavaJoinColumn joinColumn3 = joiningStrategy.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - AssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(3, associationOverrideResource.joinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.joinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.joinColumnsSize()); - - joiningStrategy.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - joiningStrategy.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joiningStrategy.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joiningStrategy.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(4, associationOverrideResource.joinColumnsSize()); - - - joiningStrategy.moveSpecifiedJoinColumn(2, 0); - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - - joiningStrategy.moveSpecifiedJoinColumn(0, 1); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaAssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - JavaAssociationOverride javaAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - JavaJoinColumnJoiningStrategy joiningStrategy = javaAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - ListIterator<JavaJoinColumn> joinColumns = joiningStrategy.specifiedJoinColumns(); - JoinColumn joinColumn = joinColumns.next(); - assertEquals("address_id", joinColumn.getSpecifiedName()); - assertEquals("id", joinColumn.getSpecifiedReferencedColumnName()); - - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("address_id", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - joinColumns = joiningStrategy.specifiedJoinColumns(); - assertEquals("address_id", joinColumns.next().getName()); - - associationOverrideResource.removeJoinColumn(0); - getJpaProject().synchronizeContextModel(); - assertFalse(joiningStrategy.specifiedJoinColumns().hasNext()); - } - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("FOO", associationOverrideResource.getName()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AssociationOverrideContainer overrideContainer = entity.getAssociationOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertTrue(associationOverride.isVirtual()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java deleted file mode 100644 index 33922cda5c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java +++ /dev/null @@ -1,258 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaAttributeOverrideTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE_NAME"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "MY_ATTRIBUTE_OVERRIDE_COLUMN_NAME"; - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - }); - } - - private ICompilationUnit createTestEntityWithAttributeOverride() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - 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); - } - - - - public JavaAttributeOverrideTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - attributeOverrideResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals("FOO", specifiedAttributeOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - specifiedAttributeOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getName()); - } - - public void testColumnGetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - columnResource.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - - column = overrideContainer.specifiedAttributeOverrides().next().getColumn(); - assertEquals("FOO", column.getName()); - } - - public void testColumnSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - column.setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - - assertEquals("FOO", columnResource.getName()); - - column.setSpecifiedName(null); - - attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - assertNull(attributeOverrideResource.getColumn()); - assertNotNull(specifiedAttributeOverride.getColumn()); - } - - public void testColumnDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedName("FOO"); - - attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("FOO", attributeOverride.getColumn().getDefaultName()); - } - - public void testColumnDefaultTableName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("AnnotationTestTypeChild", attributeOverride.getColumn().getDefaultTable()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(getPersistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedTable("BAR"); - - attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - - public void testDefaultName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - AttributeOverrideContainer overrideContainer = entity.getAttributeOverrideContainer(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertTrue(attributeOverride.isVirtual()); - } - - public void testSetColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - AttributeOverride attributeOverride = overrideContainer.virtualAttributeOverrides().next(); - attributeOverride = attributeOverride.setVirtual(false); - attributeOverride.getColumn().setSpecifiedName("FOO"); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getColumn().getName()); - assertEquals("FOO", overrideContainer.specifiedAttributeOverrides().next().getColumn().getSpecifiedName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java deleted file mode 100644 index 5554e65e83..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java +++ /dev/null @@ -1,995 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.EnumType; -import org.eclipse.jpt.core.context.EnumeratedConverter; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.LobAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaBasicMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithBasicMappingFetchOptionalSpecified() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.EAGER, optional=false)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithLob() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.LOB); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Lob").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithEnumerated() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated(EnumType.STRING)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaBasicMappingTests(String name) { - super(name); - } - - public void testDefaultBasicGetDefaultFetch() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testSpecifiedBasicGetDefaultFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(FetchType.EAGER, basicMapping.getDefaultFetch()); - } - - public void testGetFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, basicMapping.getFetch()); - } - - public void testGetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedFetch()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - getJpaProject().synchronizeContextModel(); - - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - } - - public void testGetSpecifiedFetch2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(FetchType.EAGER, basicMapping.getSpecifiedFetch()); - } - - public void testSetSpecifiedFetch() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedFetch2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - createOrmXmlFile(); - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableProperties().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - protected void createOrmXmlFile() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - getPersistenceXmlResource().save(null); - } - - public void testSetBasicToDefault() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertFalse(basicMapping.isDefault()); - - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNotSame(basicMapping, persistentAttribute.getMapping()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.isDefault()); - assertEquals("FOO", basicMapping.getColumn().getSpecifiedName()); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToDefaultBasic() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.ENUMERATED_CONVERTER); - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(EnumType.STRING, ((EnumeratedConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getEnumType()); - - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((IdMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToVersion() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbedded() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToEmbeddedId() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToTransient() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToOneToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IOneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - public void testBasicMorphToManyToOne() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testBasicMorphToManyToMany() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - -//TODO assertEquals(FetchType.EAGER, ((IManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultBasicGetDefaultOptional() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testSpecifiedBasicGetDefaultOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(true, basicMapping.isDefaultOptional()); - } - - public void testGetOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(true, basicMapping.isOptional()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(true, basicMapping.isOptional()); - } - - public void testGetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testGetSpecifiedOptional2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testSetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - - basicMapping.setSpecifiedOptional(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.FALSE, basic.getOptional()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedOptional2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - - assertEquals(Boolean.TRUE, basic.getOptional()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - - public void testGetSpecifiedOptionalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - - basic.setOptional(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - - basic.setOptional(Boolean.FALSE); - attributeResource.setPrimaryAnnotation(null, EmptyIterable.<String>instance()); - getJpaProject().synchronizeContextModel(); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertEquals(true, ((BasicMapping) persistentAttribute.getMapping()).isOptional()); - } - - - public void testIsLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testIsLob2() throws Exception { - createTestEntityWithLob(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testSetLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - basicMapping.setConverter(Converter.LOB_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - } - - public void testIsLobUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertTrue(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - - attributeResource.removeAnnotation(LobAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertFalse(basicMapping.getConverter().getType() == Converter.LOB_CONVERTER); - } - - public void testDefaultBasicGetDefaultConverter() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - } - - public void testSpecifiedBasicGetDefaultConverter() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - } - - public void testGetEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumeratedAnnotation = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.ORDINAL, ((EnumeratedConverter) basicMapping.getConverter()).getDefaultEnumType()); - - enumeratedAnnotation.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testGetSpecifiedEnumerated() throws Exception { - createTestEntityWithEnumerated(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - } - - public void testSetSpecifiedEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - basicMapping.setConverter(Converter.ENUMERATED_CONVERTER); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertNotNull(enumerated); - assertEquals(null, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.java.EnumType.STRING, enumerated.getValue()); - - ((EnumeratedConverter) basicMapping.getConverter()).setSpecifiedEnumType(null); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(enumerated.getValue()); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testGetSpecifiedEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertTrue(basicMapping.getConverter().getType() == Converter.NO_CONVERTER); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - getJpaProject().synchronizeContextModel(); - - assertEquals(EnumType.STRING, ((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - - enumerated.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNotNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(((EnumeratedConverter) basicMapping.getConverter()).getSpecifiedEnumType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - - basicMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) basicMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - basicMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.TEMPORAL_CONVERTER, basicMapping.getConverter().getType()); - assertEquals(TemporalType.DATE, ((TemporalConverter) basicMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.NO_CONVERTER, basicMapping.getConverter().getType()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - assertEquals("id", basicMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java deleted file mode 100644 index 97f3d018cb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaCascadeTests.java +++ /dev/null @@ -1,321 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaCascade; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaCascadeTests - extends ContextModelTestCase -{ - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - - public JavaCascadeTests(String name) { - super(name); - } - - - public void testUpdateCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the resource model, verify context model updated - annotation.setCascadeAll(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the resource model - annotation.setCascadeAll(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testModifyCascadeAll() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isAll()); - assertFalse(annotation.isCascadeAll()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertTrue(annotation.isCascadeAll()); - assertTrue(cascade.isAll()); - - //set all to false in the context model - cascade.setAll(false); - assertFalse(annotation.isCascadeAll()); - assertFalse(cascade.isAll()); - } - - public void testUpdateCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the resource model, verify context model updated - annotation.setCascadePersist(true); - getJpaProject().update(); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the resource model - annotation.setCascadePersist(false); - getJpaProject().update(); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testModifyCascadePersist() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isPersist()); - assertFalse(annotation.isCascadePersist()); - - //set persist in the context model, verify resource model updated - cascade.setPersist(true); - assertTrue(annotation.isCascadePersist()); - assertTrue(cascade.isPersist()); - - //set persist to false in the context model - cascade.setPersist(false); - assertFalse(annotation.isCascadePersist()); - assertFalse(cascade.isPersist()); - } - - public void testUpdateCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the resource model, verify context model updated - annotation.setCascadeMerge(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the resource model - annotation.setCascadeMerge(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isMerge()); - assertFalse(annotation.isCascadeMerge()); - - //set merge in the context model, verify resource model updated - cascade.setMerge(true); - assertTrue(annotation.isCascadeMerge()); - assertTrue(cascade.isMerge()); - - //set merge to false in the context model - cascade.setMerge(false); - assertFalse(annotation.isCascadeMerge()); - assertFalse(cascade.isMerge()); - } - - public void testUpdateCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the resource model, verify context model updated - annotation.setCascadeRemove(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the resource model - annotation.setCascadeRemove(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRemove()); - assertFalse(annotation.isCascadeRemove()); - - //set remove in the context model, verify resource model updated - cascade.setRemove(true); - assertTrue(annotation.isCascadeRemove()); - assertTrue(cascade.isRemove()); - - //set remove to false in the context model - cascade.setRemove(false); - assertFalse(annotation.isCascadeRemove()); - assertFalse(cascade.isRemove()); - } - - public void testUpdateCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the resource model, verify context model updated - annotation.setCascadeRefresh(true); - getJpaProject().update(); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the resource model - annotation.setCascadeRefresh(false); - getJpaProject().update(); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - OneToOneAnnotation annotation = (OneToOneAnnotation) attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - JavaOneToOneMapping mapping = (JavaOneToOneMapping) persistentAttribute.getMapping(); - JavaCascade cascade = mapping.getCascade(); - - assertFalse(cascade.isRefresh()); - assertFalse(annotation.isCascadeRefresh()); - - //set refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertTrue(annotation.isCascadeRefresh()); - assertTrue(cascade.isRefresh()); - - //set refresh to false in the context model - cascade.setRefresh(false); - assertFalse(annotation.isCascadeRefresh()); - assertFalse(cascade.isRefresh()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java deleted file mode 100644 index 78d419cdd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java +++ /dev/null @@ -1,836 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.BaseColumn; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaColumnTests extends ContextModelTestCase -{ - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDefaultBasicColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnTableSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(table=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithBasicColumnColumnDefinitionSet() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - sb.append("@Column(columnDefinition=\"" + COLUMN_DEFINITION + "\")"); - } - }); - } - - public JavaColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(basicMapping.getPersistentAttribute().getName(), basicMapping.getColumn().getDefaultName()); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - - basicMapping.getColumn().setSpecifiedName("foo"); - assertEquals("id", basicMapping.getColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals("id", basicMapping.getColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName(null); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetNameUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - - column.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - - - - - - - - - - - - - public void testGetSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetSpecifiedTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetDefaultTableSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(((Entity) basicMapping.getTypeMapping()).getName(), basicMapping.getColumn().getDefaultTable()); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetDefaultTable() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - - basicMapping.getColumn().setSpecifiedTable("foo"); - assertEquals(TYPE_NAME, basicMapping.getColumn().getDefaultTable()); - } - - public void testGetTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getTable()); - } - - public void testSetSpecifiedTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getTable()); - } - - public void testSetSpecifiedTableNull() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable(null); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetTableUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setTable("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - assertEquals("foo", basicMapping.getColumn().getTable()); - - column.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_DEFINITION, basicMapping.getColumn().getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - basicMapping.getColumn().setColumnDefinition(null); - assertNull(column.getColumnDefinition()); - } - - public void testGetColumnDefinitionUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setColumnDefinition("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals("foo", basicMapping.getColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - assertNull(basicMapping.getColumn().getColumnDefinition()); - - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedLength()); - assertEquals(66, basicMapping.getColumn().getLength()); - - column.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getLength()); - - basicMapping.getColumn().setSpecifiedLength(null); - - assertNull(column.getLength()); - } - - public void testGetPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getPrecision()); - } - - public void testGetDefaultPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getDefaultPrecision()); - } - - public void testGetSpecifiedPrecision() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setPrecision(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedPrecision()); - assertEquals(66, basicMapping.getColumn().getPrecision()); - - column.setPrecision(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - } - - public void testSetSpecifiedPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(null); - - assertNull(column.getPrecision()); - } - - public void testGetScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - assertEquals(55, basicMapping.getColumn().getScale()); - } - - public void testGetDefaultScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getDefaultScale()); - } - - public void testGetSpecifiedScale() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setScale(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedScale()); - assertEquals(66, basicMapping.getColumn().getScale()); - - column.setScale(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedScale()); - } - - public void testSetSpecifiedScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(100), column.getScale()); - - basicMapping.getColumn().setSpecifiedScale(null); - - assertNull(column.getScale()); - } - - public void testGetUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUnique()); - } - - public void testGetDefaultUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().isDefaultUnique()); - } - - public void testGetSpecifiedUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUnique()); - assertEquals(true, basicMapping.getColumn().isUnique()); - - column.setUnique(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - } - - public void testSetSpecifiedUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - basicMapping.getColumn().setSpecifiedUnique(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getUnique()); - - basicMapping.getColumn().setSpecifiedUnique(null); - - assertNull(column.getUnique()); - } - - public void testGetInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isInsertable()); - } - - public void testGetDefaultInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().isDefaultInsertable()); - } - - public void testGetSpecifiedInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setInsertable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedInsertable()); - assertEquals(true, basicMapping.getColumn().isInsertable()); - - column.setInsertable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - } - - public void testSetSpecifiedInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(null); - - assertNull(column.getInsertable()); - } - - public void testGetNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isNullable()); - } - - public void testGetDefaultNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().isDefaultNullable()); - } - - public void testGetSpecifiedNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setNullable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedNullable()); - assertEquals(true, basicMapping.getColumn().isNullable()); - - column.setNullable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - } - - public void testSetSpecifiedNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getNullable()); - - basicMapping.getColumn().setSpecifiedNullable(null); - - assertNull(column.getNullable()); - } - - public void testGetUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - } - - public void testGetDefaultUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().isDefaultUpdatable()); - } - - public void testGetSpecifiedUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUpdatable(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUpdatable()); - assertEquals(true, basicMapping.getColumn().isUpdatable()); - - column.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - } - - public void testSetSpecifiedUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) getJavaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.FALSE, column.getUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(null); - - assertNull(column.getUpdatable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java deleted file mode 100644 index 686a032f63..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java +++ /dev/null @@ -1,459 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaDiscriminatorColumnTests extends ContextModelTestCase -{ - private static final String DISCRIMINATOR_COLUMN_NAME = "MY_DISCRIMINATOR_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorColumn() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorColumn(name=\"" + DISCRIMINATOR_COLUMN_NAME + "\")"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - 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); - } - - - public JavaDiscriminatorColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getName()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("DTYPE", getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, getJavaEntity().getDiscriminatorColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", discriminatorColumn.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNull(discriminatorColumn); - } - - public void testGetDefaultDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - } - - public void testGetDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorType.STRING, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR); - getJpaProject().synchronizeContextModel(); - - assertEquals(DiscriminatorType.CHAR, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - } - - public void testSetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR, discriminatorColumn.getDiscriminatorType()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetDiscriminatorTypeUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.INTEGER); - getJpaProject().synchronizeContextModel(); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(DiscriminatorType.INTEGER, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - column.setDiscriminatorType(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(null, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, getJavaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(55, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setLength(Integer.valueOf(66)); - getJpaProject().synchronizeContextModel(); - - assertEquals(Integer.valueOf(66), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(66, getJavaEntity().getDiscriminatorColumn().getLength()); - discriminatorColumn.setName(null); - discriminatorColumn.setLength(null); - getJpaProject().synchronizeContextModel(); - - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(100), discriminatorColumn.getLength()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedName(null); - getJavaEntity().getDiscriminatorColumn().setSpecifiedLength(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetLengthUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setLength(Integer.valueOf(78)); - getJpaProject().synchronizeContextModel(); - assertEquals(Integer.valueOf(78), getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(78, getJavaEntity().getDiscriminatorColumn().getLength()); - - column.setLength(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(0, getJavaEntity().getDiscriminatorColumn().getLength()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, getJavaEntity().getDiscriminatorColumn().getLength()); - } - - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - getJpaProject().synchronizeContextModel(); - - assertEquals(COLUMN_DEFINITION, getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getColumnDefinition()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - getJavaEntity().getDiscriminatorColumn().setColumnDefinition(null); - column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testDefaults() throws Exception { - createTestAbstractEntity(); - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + "." + "AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - JavaEntity childEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - - //test defaults with single-table inheritance, no specified discriminator column set - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - - //test defaults with single-table inheritance, specified discriminator column set on root - abstractEntity.getDiscriminatorColumn().setSpecifiedName("DTYPE2"); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(5)); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - assertEquals(InheritanceType.SINGLE_TABLE, abstractEntity.getDefaultInheritanceStrategy()); - assertEquals(DiscriminatorColumn.DEFAULT_NAME, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals("DTYPE2", abstractEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(Integer.valueOf(5), abstractEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(DiscriminatorType.CHAR, abstractEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - assertEquals("DTYPE2", childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(5, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(DiscriminatorType.CHAR, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - //test defaults with table-per-class inheritance, discriminator column does not apply - abstractEntity.getDiscriminatorColumn().setSpecifiedName(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedLength(null); - abstractEntity.getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - abstractEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getInheritanceStrategy()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, abstractEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(0, childEntity.getDiscriminatorColumn().getDefaultLength()); - assertEquals(null, childEntity.getDiscriminatorColumn().getDefaultDiscriminatorType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java deleted file mode 100644 index 9885cce9ad..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.EmbeddableAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddableTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEmbeddable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Embeddable"); - } - }); - } - - - public JavaEmbeddableTests(String name) { - super(name); - } - - public void testMorphToEntity() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testEmbeddable() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = embeddable.overridableAttributeNames(); - assertEquals(overridableAttributeNames.next(), "id"); - assertEquals(overridableAttributeNames.next(), "name"); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(embeddable.tableNameIsInvalid("FOO")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(embeddable.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertFalse(embeddable.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - - public void testAssociatedTables() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTablesIncludingInherited().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTableNamesIncludingInherited().hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) getJavaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java deleted file mode 100644 index 8618c20fa5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java +++ /dev/null @@ -1,658 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddedIdMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId").append(CR); - sb.append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME +" myEmbeddedId;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - - public JavaEmbeddedIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualAttributeOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedIdMapping embeddedIdMapping = (JavaEmbeddedIdMapping) getJavaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedIdMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java deleted file mode 100644 index 8d859abc8b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java +++ /dev/null @@ -1,863 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverrideContainer; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.jpa1.context.java.GenericJavaNullAttributeMapping; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEmbeddedMappingTests extends ContextModelTestCase -{ - - public static final String EMBEDDABLE_TYPE_NAME = "MyEmbeddable"; - public static final String FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME = PACKAGE_NAME + "." + EMBEDDABLE_TYPE_NAME; - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded").append(CR); - sb.append(" private " + EMBEDDABLE_TYPE_NAME + " myEmbedded;").append(CR); - sb.append(CR); - } - }); - } - - private void createEmbeddableType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append(EMBEDDABLE_TYPE_NAME).append(" {"); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" "); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, EMBEDDABLE_TYPE_NAME + ".java", sourceWriter); - } - - private void createTestEntityCustomer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class ").append("Customer").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private String id;").append(CR); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Customer.java", sourceWriter); - } - - private void createTestEmbeddableAddress() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDED); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String street;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" @Embedded").append(CR); - sb.append(" private ZipCode zipCode;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private void createTestEmbeddableZipCode() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class ").append("ZipCode").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" private String zip;").append(CR); - sb.append(CR); - sb.append(" private String plusfour;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "ZipCode.java", sourceWriter); - } - - - public JavaEmbeddedMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).getAttributeOverrideContainer().attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof GenericJavaNullAttributeMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - public void testDefaultEmbeddedMappingGenericEmbeddable() throws Exception { - createTestEntityWithDefaultEmbeddedMapping(); - createTestGenericEmbeddable(); - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Embeddable1"); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertNotNull(persistentAttribute.getMapping()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getDefaultMappingKey()); - assertTrue(persistentAttribute.getMapping().isDefault()); - } - - private void createTestEntityWithDefaultEmbeddedMapping() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Entity1 { ").append(CR); - sb.append("private Embeddable1<Integer> myEmbeddable;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Entity1.java", sourceWriter); - } - - private void createTestGenericEmbeddable() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.EMBEDDABLE); - sb.append(";"); - sb.append(CR); - sb.append("@Embeddable"); - sb.append(CR); - sb.append("public class Embeddable1<T> {}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Embeddable1.java", sourceWriter); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - assertNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - JavaEmbeddedMapping embeddedMapping = (JavaEmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - JavaAttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = attributeOverrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - Embeddable embeddable = (Embeddable) classRefs.next().getJavaPersistentType().getMapping(); - - BasicMapping cityMapping = (BasicMapping) embeddable.getPersistentType().getAttributeNamed("city").getMapping(); - cityMapping.getColumn().setSpecifiedName("FOO"); - cityMapping.getColumn().setSpecifiedTable("BAR"); - cityMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - cityMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - cityMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - cityMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - cityMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - cityMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(false, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(5, defaultAttributeOverride.getColumn().getLength()); - assertEquals(6, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(7, defaultAttributeOverride.getColumn().getScale()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - cityMapping.getColumn().setColumnDefinition(null); - cityMapping.getColumn().setSpecifiedInsertable(null); - cityMapping.getColumn().setSpecifiedUpdatable(null); - cityMapping.getColumn().setSpecifiedUnique(null); - cityMapping.getColumn().setSpecifiedNullable(null); - cityMapping.getColumn().setSpecifiedLength(null); - cityMapping.getColumn().setSpecifiedPrecision(null); - cityMapping.getColumn().setSpecifiedScale(null); - defaultAttributeOverride = attributeOverrideContainer.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - assertEquals(null, defaultAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, defaultAttributeOverride.getColumn().isInsertable()); - assertEquals(true, defaultAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, defaultAttributeOverride.getColumn().isUnique()); - assertEquals(true, defaultAttributeOverride.getColumn().isNullable()); - assertEquals(255, defaultAttributeOverride.getColumn().getLength()); - assertEquals(0, defaultAttributeOverride.getColumn().getPrecision()); - assertEquals(0, defaultAttributeOverride.getColumn().getScale()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(0, attributeOverrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(4, attributeOverrideContainer.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - getJpaProject().synchronizeContextModel(); - assertEquals(0, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", attributeOverrideContainer.virtualAttributeOverrides().next().getName()); - assertEquals(1, attributeOverrideContainer.virtualAttributeOverridesSize()); - - attributeOverrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, attributeOverrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - ListIterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) getJavaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - attributeOverrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - attributeResource.moveAnnotation(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<NestableAnnotation> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - //1.0 projects do not support dot-notation, this tests to make sure that support does not exist - public void testNestedVirtualAttributeOverrides() throws Exception { - createTestEntityCustomer(); - createTestEmbeddableAddress(); - createTestEmbeddableZipCode(); - - addXmlClassRef(PACKAGE_NAME + ".Customer"); - addXmlClassRef(PACKAGE_NAME + ".Address"); - addXmlClassRef(PACKAGE_NAME + ".ZipCode"); - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - PersistentType customerPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping(); - AttributeOverrideContainer attributeOverrideContainer = embeddedMapping.getAttributeOverrideContainer(); - - assertEquals(3, attributeOverrideContainer.virtualAttributeOverridesSize()); - ListIterator<AttributeOverride> virtualAttributeOverrides = attributeOverrideContainer.virtualAttributeOverrides(); - AttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("street", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", virtualAttributeOverride.getName()); - assertEquals(false, virtualAttributeOverrides.hasNext()); - - - PersistentType addressPersistentType = specifiedClassRefs.next().getJavaPersistentType(); - EmbeddedMapping nestedEmbeddedMapping = (EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping(); - AttributeOverrideContainer nestedAttributeOverrideContainer = nestedEmbeddedMapping.getAttributeOverrideContainer(); - assertEquals(2, nestedAttributeOverrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverrides = nestedAttributeOverrideContainer.virtualAttributeOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", virtualAttributeOverride.getName()); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("plusfour", virtualAttributeOverride.getName()); - - PersistentType zipCodePersistentType = specifiedClassRefs.next().getJavaPersistentType(); - BasicMapping plusFourMapping = (BasicMapping) zipCodePersistentType.getAttributeNamed("plusfour").getMapping(); - plusFourMapping.getColumn().setSpecifiedName("BLAH"); - plusFourMapping.getColumn().setSpecifiedTable("BLAH_TABLE"); - plusFourMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - plusFourMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - plusFourMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - plusFourMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - plusFourMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - plusFourMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - //check the nested embedded (Address.zipCode) attribute override to verify it is getting settings from the specified column on Zipcode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) addressPersistentType.getAttributeNamed("zipCode").getMapping()).getAttributeOverrideContainer().getAttributeOverrideNamed("plusfour"); - assertEquals("plusfour", virtualAttributeOverride.getName()); - assertEquals("BLAH", virtualAttributeOverride.getColumn().getName()); - assertEquals("BLAH_TABLE", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEFINITION", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - //check the top-level embedded (Customer.address) attribute override to verify there is no attribute override named zipCode.plusfour - virtualAttributeOverride = ((EmbeddedMapping) customerPersistentType.getAttributeNamed("address").getMapping()).getAttributeOverrideContainer().getAttributeOverrideNamed("zipCode.plusfour"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java deleted file mode 100644 index 70952952a4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java +++ /dev/null @@ -1,3409 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.AssociationOverride; -import org.eclipse.jpt.core.context.AssociationOverrideContainer; -import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.AttributeOverrideContainer; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.DiscriminatorType; -import org.eclipse.jpt.core.context.Embeddable; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.InheritanceType; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.MappedSuperclass; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.java.JavaAssociationOverride; -import org.eclipse.jpt.core.context.java.JavaAttributeOverride; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaNamedNativeQuery; -import org.eclipse.jpt.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.internal.context.java.JavaNullTypeMapping; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.NestableAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnsAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaEntityTests extends ContextModelTestCase -{ - private static final String ENTITY_NAME = "entityName"; - private static final String TABLE_NAME = "MY_TABLE"; - private static final String DISCRIMINATOR_VALUE = "MY_DISCRIMINATOR_VALUE"; - protected static final String SUB_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_SUB_TYPE_NAME = PACKAGE_NAME + "." + SUB_TYPE_NAME; - - - public JavaEntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - }); - } - - private ICompilationUnit createTestEntityInvalidNamedQueries() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.NAMED_QUERIES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@NamedQueries(value={@NamedQuery(query=\"asdf\", name=\"foo\"), @NamedQuer})"); - } - }); - } - - private void createTestAbstractEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - private ICompilationUnit createTestEntityAnnotationOnProperty() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>( - JPA.MAPPED_SUPERCLASS, - JPA.BASIC, - JPA.VERSION, - JPA.TRANSIENT, - JPA.EMBEDDED, - JPA.EMBEDDED_ID, - JPA.ONE_TO_ONE, - JPA.ONE_TO_MANY, - JPA.MANY_TO_ONE, - JPA.MANY_TO_MANY, - JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @Basic"); - sb.append(CR); - sb.append(" private int basic;").append(CR); - sb.append(CR); - sb.append(" @Version"); - sb.append(CR); - sb.append(" private int version;").append(CR); - sb.append(CR); - sb.append(" @Transient"); - sb.append(CR); - sb.append(" private int transient;").append(CR); - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" private int embedded;").append(CR); - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" private int embeddedId;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private " + SUB_TYPE_NAME + " oneToOne;").append(CR); - sb.append(CR); - sb.append(" @OneToMany"); - sb.append(CR); - sb.append(" private int oneToMany;").append(CR); - sb.append(CR); - sb.append(" @ManyToOne"); - sb.append(CR); - sb.append(" private int manyToOne;").append(CR); - sb.append(CR); - sb.append(" @ManyToMany"); - sb.append(CR); - sb.append(" private int manyToMany;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private ICompilationUnit createTestAbstractEntityTablePerClass() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)"); - sb.append("abstract"); - } - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("private String foo;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address2;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityWithName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity(name=\"" + ENTITY_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private void createTestSubType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("@Entity"); - 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 createTestEntityWithInheritance() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithDiscriminatorValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@DiscriminatorValue(value=\"" + DISCRIMINATOR_VALUE + "\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"foo\"), @SecondaryTable(name=\"bar\")})"); - } - }); - } - - private ICompilationUnit createAbstractTestEntity() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)").append(CR); - sb.append("abstract"); - } - }); - } - - private void createTestIdClass() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append("TestTypeId").append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "TestTypeId.java", sourceWriter); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof MappedSuperclass); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof Embeddable); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = (JavaEntity) getJavaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedDiscriminatorValue("asdf"); - entity.getDiscriminatorColumn().setSpecifiedName("BAR"); - entity.getGeneratorContainer().addTableGenerator(); - entity.getGeneratorContainer().addSequenceGenerator(); - entity.getIdClassReference().setSpecifiedIdClassName("myIdClass"); - entity.getQueryContainer().addNamedNativeQuery(0); - entity.getQueryContainer().addNamedQuery(0); - - getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(getJavaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - assertNull(typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SecondaryTableAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(DiscriminatorColumnAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME)); - } - - public void testAccessNoAnnotations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - } - - public void testAccessAnnotationsOnSuper() throws Exception { - createTestEntityAnnotationOnProperty(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - JavaPersistentType childPersistentType = getJavaPersistentType(); - PersistentType superPersistentType = childPersistentType.getSuperPersistentType(); - - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((IdMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - typeResource.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((BasicMapping) superPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - assertEquals(AccessType.FIELD, superPersistentType.getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, superPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //only parent specified in orm.xml, i think this outcome is right?? - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - OrmPersistentType childOrmPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - removeXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - //both parent and child specified in orm.xml - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.FIELD, childOrmPersistentType.getJavaPersistentType().getAccess()); - } - - public void testAccessWithXmlSettings() throws Exception { - createTestEntityAnnotationOnProperty(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - getXmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - typeResource.persistableProperties().next().removeAnnotation(JPA.ID); - getJpaProject().synchronizeContextModel(); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - ((BasicMapping) getJavaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(AccessType.FIELD, getJavaPersistentType().getAccess()); - - getEntityMappings().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - getEntityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, getJavaPersistentType().getAccess()); - - OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - //now class is specified in orm.xml, so entityMappings access setting wins over persistence-unit-defaults - assertEquals(AccessType.FIELD, ormPersistentType.getJavaPersistentType().getAccess()); - - ormPersistentType.setSpecifiedAccess(AccessType.PROPERTY); - - //accessType should be PROPERTY now, java gets the access from xml entity if it is specified - assertEquals(AccessType.PROPERTY, ormPersistentType.getJavaPersistentType().getAccess()); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, getJavaEntity().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("foo", ((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().setSpecifiedName(null); - - assertNull(getJavaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(((EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME)).getName()); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - EntityAnnotation entity = (EntityAnnotation) typeResource.getAnnotation(EntityAnnotation.ANNOTATION_NAME); - entity.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedName()); - } - - public void testGetTableName() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithName(); - - assertEquals(ENTITY_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testGetTableName3() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - } - - public void testSetTableNameWithNullTable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = getJavaEntity().getTable(); - assertEquals(TYPE_NAME, table.getName()); - assertSourceDoesNotContain("@Table", cu); - - table.setSpecifiedName(TABLE_NAME); - assertSourceContains("@Table(name = \"" + TABLE_NAME + "\")", cu); - - assertEquals(TABLE_NAME, getJavaEntity().getPrimaryTableName()); - assertEquals(TABLE_NAME, table.getName()); - - table.setSpecifiedCatalog(TABLE_NAME); - } - - public void testGetInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getInheritanceStrategy()); - } - - public void testGetDefaultInheritanceStrategy() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertNotSame(childEntity, rootEntity); - assertEquals(InheritanceType.SINGLE_TABLE, childEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - rootEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.SINGLE_TABLE, rootEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childEntity.getInheritanceStrategy()); - assertNull(childEntity.getSpecifiedInheritanceStrategy()); - } - - public void testGetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - - inheritance.setStrategy(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED); - getJpaProject().synchronizeContextModel(); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - inheritance.setStrategy(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedInheritanceStrategy()); - } - - public void testSetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(InheritanceType.TABLE_PER_CLASS, getJavaEntity().getSpecifiedInheritanceStrategy()); - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - assertEquals(InheritanceType.JOINED, getJavaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - assertEquals(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED, inheritance.getStrategy()); - - } - - public void testGetDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getDiscriminatorValue()); - } - - public void testGetDefaultDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(null, getJavaEntity().getDefaultDiscriminatorValue()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - assertEquals(getJavaEntity().getName(), getJavaEntity().getDefaultDiscriminatorValue()); - - getJavaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - assertNull(getJavaEntity().getDefaultDiscriminatorValue()); - } - - public void testGetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - - discriminatorValue.setValue("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - discriminatorValue.setValue(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getSpecifiedDiscriminatorValue()); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - } - - public void testSetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DISCRIMINATOR_VALUE, getJavaEntity().getSpecifiedDiscriminatorValue()); - - getJavaEntity().setSpecifiedDiscriminatorValue("foo"); - - assertEquals("foo", getJavaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - assertEquals("foo", discriminatorValue.getValue()); - } - - public void testSecondaryTables() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - - assertTrue(secondaryTables.hasNext()); - assertEquals("foo", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.secondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.secondaryTablesSize()); - } - - public void testSpecifiedSecondaryTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaSecondaryTable> specifiedSecondaryTables = getJavaEntity().specifiedSecondaryTables(); - - assertTrue(specifiedSecondaryTables.hasNext()); - assertEquals("foo", specifiedSecondaryTables.next().getName()); - assertEquals("bar", specifiedSecondaryTables.next().getName()); - assertFalse(specifiedSecondaryTables.hasNext()); - } - - public void testSpecifiedSecondaryTablesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.specifiedSecondaryTablesSize()); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.specifiedSecondaryTablesSize()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTable2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> secondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertFalse(secondaryTables.hasNext()); - } - - public void testAddSpecifiedSecondaryTablePreservePkJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable specifiedSecondaryTable = getJavaEntity().addSpecifiedSecondaryTable(0); - specifiedSecondaryTable.setSpecifiedName("FOO"); - specifiedSecondaryTable.setSpecifiedCatalog("CATALOG"); - specifiedSecondaryTable.setSpecifiedSchema("SCHEMA"); - specifiedSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("PK_NAME"); - - //add another specified secondary table, pkJoinColumns from first should be saved. - SecondaryTable specifiedSecondaryTable2 = getJavaEntity().addSpecifiedSecondaryTable(1); - specifiedSecondaryTable2.setSpecifiedName("BAR"); - - - Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - SecondaryTable secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable); - assertEquals("FOO", secondaryTable.getName()); - assertEquals("CATALOG", secondaryTable.getCatalog()); - assertEquals("SCHEMA", secondaryTable.getSchema()); - assertEquals(1, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - PrimaryKeyJoinColumn pkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertEquals("PK_NAME", pkJoinColumn.getName()); - - secondaryTable = secondaryTables.next(); - assertEquals(secondaryTable, specifiedSecondaryTable2); - assertEquals("BAR", secondaryTable.getName()); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedSecondaryTable(1); - - Iterator<NestableAnnotation> secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - Iterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(1); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - getJavaEntity().removeSpecifiedSecondaryTable(0); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertFalse(secondaryTableResources.hasNext()); - secondaryTables = getJavaEntity().secondaryTables(); - assertFalse(secondaryTables.hasNext()); - - assertNull(typeResource.getAnnotation(SecondaryTablesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - entity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - Iterator<NestableAnnotation> javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaSecondaryTables)); - - - entity.moveSpecifiedSecondaryTable(2, 0); - ListIterator<SecondaryTable> secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - - - entity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - - javaSecondaryTables = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) javaSecondaryTables.next()).getName()); - } - - public void testUpdateSpecifiedSecondaryTables() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((SecondaryTableAnnotation) typeResource.addAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((SecondaryTableAnnotation) typeResource.addAnnotation(2, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<SecondaryTable> secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(2, 0, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.moveAnnotation(0, 1, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(1, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - secondaryTables = entity.specifiedSecondaryTables(); - assertFalse(secondaryTables.hasNext()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(getJavaEntity().associatedTables())); - Iterator<Table> associatedTables = getJavaEntity().associatedTables(); - Table table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.associatedTablesIncludingInherited())); - Iterator<Table> associatedTables = rootEntity.associatedTablesIncludingInherited(); - Table table1 = associatedTables.next(); - SecondaryTable table2 = (SecondaryTable) associatedTables.next(); - SecondaryTable table3 = (SecondaryTable) associatedTables.next(); - assertEquals(TYPE_NAME, table1.getName()); - assertEquals("foo", table2.getName()); - assertEquals("bar", table3.getName()); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.associatedTablesIncludingInherited())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEntityWithSecondaryTables(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity childEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - Entity rootEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - - assertEquals(3, CollectionTools.size(rootEntity.associatedTableNamesIncludingInherited())); - Iterator<String> associatedTables = rootEntity.associatedTableNamesIncludingInherited(); - String table1 = associatedTables.next(); - String table2 = associatedTables.next(); - String table3 = associatedTables.next(); - assertEquals(TYPE_NAME, table1); - assertEquals("foo", table2); - assertEquals("bar", table3); - - //TODO probably want this to be 3, since in this case the child descriptor really uses the - //parent table because it is single table inheritance strategy. Not sure yet how to deal with this. - assertEquals(4, CollectionTools.size(childEntity.associatedTableNamesIncludingInherited())); - } - - public void testAddSecondaryTableToResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getSpecifiedName()); - assertEquals("FOO", getJavaEntity().secondaryTables().next().getName()); - - SecondaryTableAnnotation secondaryTable2 = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable2.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, getJavaEntity().secondaryTablesSize()); - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - - SecondaryTableAnnotation secondaryTable3 = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable3.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals("BAZ", secondaryTables.next().getSpecifiedName()); - assertEquals("FOO", secondaryTables.next().getSpecifiedName()); - assertEquals("BAR", secondaryTables.next().getSpecifiedName()); - } - - public void testRemoveSecondaryTableFromResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("baz"); - ListIterator<JavaSecondaryTable> secondaryTables = getJavaEntity().secondaryTables(); - - assertEquals(3, getJavaEntity().secondaryTablesSize()); - assertEquals("foo", secondaryTables.next().getSpecifiedName()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(2, getJavaEntity().secondaryTablesSize()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(1, getJavaEntity().secondaryTablesSize()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - getJpaProject().synchronizeContextModel(); - - secondaryTables = getJavaEntity().secondaryTables(); - assertEquals(0, getJavaEntity().secondaryTablesSize()); - assertFalse(secondaryTables.hasNext()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getSequenceGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getSequenceGenerator()); - assertNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(0, getJavaEntity().getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertEquals(2, typeResource.annotationsSize()); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - - getJavaEntity().getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, getJavaEntity().getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - getJavaEntity().getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - - assertNull(getJavaEntity().getGeneratorContainer().getTableGenerator()); - assertNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - getJavaEntity().getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetDiscriminatorColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - column.setName(null); - getJpaProject().synchronizeContextModel(); - - assertNull(getJavaEntity().getDiscriminatorColumn().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - getJpaProject().synchronizeContextModel(); - - assertNotNull(getJavaEntity().getDiscriminatorColumn()); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - pkJoinColumn.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - getJpaProject().synchronizeContextModel(); - specifiedPkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, getJavaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //just the default pkJoinColumn, so 1 - assertEquals(1, getJavaEntity().primaryKeyJoinColumnsSize()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, getJavaEntity().primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - Iterator<NestableAnnotation> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME))); - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator<NestableAnnotation> pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator<JavaPrimaryKeyJoinColumn> pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - getJavaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = getJavaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - entity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - entity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<NestableAnnotation> javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaPrimaryKeyJoinColumns)); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - - - entity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) javaPrimaryKeyJoinColumns.next()).getName()); - } - - public void testUpdateSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(2, 0, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.moveAnnotation(0, 1, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(getJavaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual()); - - getJavaEntity().addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = getJavaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(getJavaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertFalse(getJavaEntity().tableNameIsInvalid(TYPE_NAME)); - assertTrue(getJavaEntity().tableNameIsInvalid("FOO")); - - getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - - assertFalse(getJavaEntity().tableNameIsInvalid("BAR")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) getJavaPersistentType().getMapping(); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(entity.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testOverridableAttributes() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributes.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributes = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - - - getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - overridableAttributeNames = getJavaEntity().overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAttributes = abstractEntity.allOverridableAttributeNames(); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertEquals("foo", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAssociationsTablePerClass() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity abstractEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - overridableAssociations = abstractEntity.allOverridableAssociationNames(); - assertEquals("address", overridableAssociations.next()); - assertEquals("address2", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributes = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributes.next()); - assertEquals("basic", overridableAttributes.next()); - assertEquals("id", overridableAttributes.next()); - assertEquals("name", overridableAttributes.next()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = getJavaEntity().allOverridableAttributeNames(); - assertEquals("foo", overridableAttributeNames.next()); - assertEquals("basic", overridableAttributeNames.next()); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAttributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testVirtualAttributeOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - AttributeOverride virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) getJavaPersistentType().getMapping(); - - BasicMapping fooMapping = (BasicMapping) mappedSuperclass.getPersistentType().getAttributeNamed("foo").getMapping(); - fooMapping.getColumn().setSpecifiedName("FOO"); - fooMapping.getColumn().setSpecifiedTable("BAR"); - fooMapping.getColumn().setColumnDefinition("COLUMN_DEF"); - fooMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - fooMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - fooMapping.getColumn().setSpecifiedLength(Integer.valueOf(5)); - fooMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(6)); - fooMapping.getColumn().setSpecifiedScale(Integer.valueOf(7)); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - assertEquals("COLUMN_DEF", virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(false, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(false, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(5, virtualAttributeOverride.getColumn().getLength()); - assertEquals(6, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(7, virtualAttributeOverride.getColumn().getScale()); - - fooMapping.getColumn().setSpecifiedName(null); - fooMapping.getColumn().setSpecifiedTable(null); - fooMapping.getColumn().setColumnDefinition(null); - fooMapping.getColumn().setSpecifiedInsertable(null); - fooMapping.getColumn().setSpecifiedUpdatable(null); - fooMapping.getColumn().setSpecifiedUnique(null); - fooMapping.getColumn().setSpecifiedNullable(null); - fooMapping.getColumn().setSpecifiedLength(null); - fooMapping.getColumn().setSpecifiedPrecision(null); - fooMapping.getColumn().setSpecifiedScale(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertEquals("foo", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - assertEquals(null, virtualAttributeOverride.getColumn().getColumnDefinition()); - assertEquals(true, virtualAttributeOverride.getColumn().isInsertable()); - assertEquals(true, virtualAttributeOverride.getColumn().isUpdatable()); - assertEquals(false, virtualAttributeOverride.getColumn().isUnique()); - assertEquals(true, virtualAttributeOverride.getColumn().isNullable()); - assertEquals(255, virtualAttributeOverride.getColumn().getLength()); - assertEquals(0, virtualAttributeOverride.getColumn().getPrecision()); - assertEquals(0, virtualAttributeOverride.getColumn().getScale()); - - virtualAttributeOverride = virtualAttributeOverride.setVirtual(false); - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testVirtualAttributeOverridesEntityHierachy() throws Exception { - createTestAbstractEntityTablePerClass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AttributeOverrideContainer overrideContainer = javaEntity.getAttributeOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - AttributeOverride virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - JavaEntity superclass = (JavaEntity) getJavaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) superclass.getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("FOO", virtualAttributeOverride.getColumn().getName()); - assertEquals("BAR", virtualAttributeOverride.getColumn().getTable()); - - idMapping.getColumn().setSpecifiedName(null); - idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - virtualAttributeOverride = overrideContainer.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride = virtualAttributeOverride.setVirtual(false); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - assertEquals(0, overrideContainer.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedAttributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(3, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(1, overrideContainer.virtualAttributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(0, overrideContainer.virtualAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - assertEquals(4, overrideContainer.attributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(4, overrideContainer.attributeOverridesSize()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(4, overrideContainer.attributeOverridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(5, overrideContainer.attributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - - Iterator<NestableAnnotation> attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator<JavaAttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - overrideContainer.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(attributeOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator<NestableAnnotation> javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - overrideContainer.moveSpecifiedAttributeOverride(2, 0); - ListIterator<AttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("id", attributeOverrides.next().getName()); - assertEquals("basic", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("id", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("basic", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) javaAttributeOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AttributeOverrideAnnotation) typeResource.addAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AttributeOverrideAnnotation) typeResource.addAnnotation(2, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<AttributeOverride> attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - attributeOverrides = overrideContainer.specifiedAttributeOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverrideContainer overrideContainer = getJavaEntity().getAttributeOverrideContainer(); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - AttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - overrideContainer.virtualAttributeOverrides().next().setVirtual(false); - AttributeOverride specifiedAttributeOverride = overrideContainer.specifiedAttributeOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = overrideContainer.virtualAttributeOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("basic", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociationNames.next()); - assertEquals("manyToOne", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociations = getJavaEntity().allOverridableAssociationNames(); - assertEquals("oneToOne", overridableAssociations.next()); - assertEquals("manyToOne", overridableAssociations.next()); - assertFalse(overridableAssociations.hasNext()); - } -// -// public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { -// createTestMappedSuperclass(); -// createTestSubType(); -// addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); -// getEntityMappings().addPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// -// Iterator<RelationshipMapping> overridableAssociations = getJavaEntity().allOverridableAssociations(); -// assertEquals("oneToOne", overridableAssociations.next().getName()); -// assertEquals("manyToOne", overridableAssociations.next().getName()); -// assertFalse(overridableAssociations.hasNext()); -// } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - typeResource.moveAnnotation(1, 0, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - getJpaProject().synchronizeContextModel(); - specifiedAssociationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testVirtualAssociationOverrideDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - AssociationOverrideContainer overrideContainer = javaEntity.getAssociationOverrideContainer(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - AssociationOverride virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - JoinColumnJoiningStrategy joiningStrategy = virtualAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - JoinColumn virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("oneToOne_id", virtualJoinColumn.getName()); - assertEquals("id", virtualJoinColumn.getReferencedColumnName()); - assertEquals(SUB_TYPE_NAME, virtualJoinColumn.getTable()); - assertEquals(null, virtualJoinColumn.getColumnDefinition()); - assertEquals(true, virtualJoinColumn.isInsertable()); - assertEquals(true, virtualJoinColumn.isUpdatable()); - assertEquals(false, virtualJoinColumn.isUnique()); - assertEquals(true, virtualJoinColumn.isNullable()); - - - OneToOneMapping oneToOneMapping = (OneToOneMapping) getJavaPersistentType().getAttributeNamed("oneToOne").getMapping(); - JoinColumn joinColumn = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("MY_JOIN_COLUMN"); - joinColumn.setSpecifiedReferencedColumnName("MY_REFERENCE_COLUMN"); - joinColumn.setSpecifiedTable("BAR"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - joiningStrategy = virtualAssociationOverride.getRelationshipReference().getJoinColumnJoiningStrategy(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertEquals(1, joiningStrategy.joinColumnsSize()); - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - virtualJoinColumn = joiningStrategy.joinColumns().next(); - assertEquals("MY_JOIN_COLUMN", virtualJoinColumn.getName()); - assertEquals("MY_REFERENCE_COLUMN", virtualJoinColumn.getReferencedColumnName()); - assertEquals("BAR", virtualJoinColumn.getTable()); - assertEquals("COLUMN_DEF", virtualJoinColumn.getColumnDefinition()); - assertEquals(false, virtualJoinColumn.isInsertable()); - assertEquals(false, virtualJoinColumn.isUpdatable()); - assertEquals(true, virtualJoinColumn.isUnique()); - assertEquals(false, virtualJoinColumn.isNullable()); - - assertEquals("MY_JOIN_COLUMN", joiningStrategy.joinColumns().next().getName()); - - - - - - - //idMapping.getColumn().setSpecifiedName(null); - //idMapping.getColumn().setSpecifiedTable(null); - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - virtualAssociationOverride = overrideContainer.virtualAssociationOverrides().next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - - virtualAssociationOverride = virtualAssociationOverride.setVirtual(false); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - - -// //TODO joinColumns for default association overrides -//// IJoinColumn defaultJoinColumn = defaultAssociationOverride.joinColumns().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// -//// IMappedSuperclass mappedSuperclass = (IMappedSuperclass) javaPersistentType().getMapping(); -//// -//// IOneToOneMapping addressMapping = (IOneToOneMapping) mappedSuperclass.persistentType().attributeNamed("address").getMapping(); -//// IJoinColumn joinColumn = addressMapping.addSpecifiedJoinColumn(0); -//// joinColumn.setSpecifiedName("FOO"); -//// joinColumn.setSpecifiedReferencedColumnName("BAR"); -//// joinColumn.setSpecifiedTable("BAZ"); -//// -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// assertEquals(1, CollectionTools.size(javaEntity.defaultAssociationOverrides())); -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultAssociationOverride.getName()); -//// assertEquals("FOO", defaultJoinColumn.getName()); -//// assertEquals("BAR", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals("BAZ", defaultJoinColumn.getTable()); -//// -//// joinColumn.setSpecifiedName(null); -//// joinColumn.setSpecifiedReferencedColumnName(null); -//// joinColumn.setSpecifiedTable(null); -//// assertEquals(SUB_TYPE_NAME, typeResource.getName()); -//// assertNull(typeResource.annotation(AssociationOverride.ANNOTATION_NAME)); -//// assertNull(typeResource.annotation(AssociationOverrides.ANNOTATION_NAME)); -//// -//// defaultAssociationOverride = javaEntity.defaultAssociationOverrides().next(); -//// assertEquals("address", defaultJoinColumn.getName()); -//// assertEquals("address", defaultJoinColumn.getReferencedColumnName()); -//// assertEquals(SUB_TYPE_NAME, defaultJoinColumn.getTable()); -//// -//// javaEntity.addSpecifiedAssociationOverride(0).setName("address"); -//// assertEquals(0, CollectionTools.size(javaEntity.defaultAssociationOverrides())); - - } - - public void testSpecifiedAssociationOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - assertEquals(0, overrideContainer.specifiedAssociationOverridesSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - //add an annotation to the resource model and verify the context model is updated - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("FOO"); - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(2, overrideContainer.specifiedAssociationOverridesSize()); - } - - public void testVirtualAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.virtualAssociationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(1, overrideContainer.virtualAssociationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(0, overrideContainer.virtualAssociationOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - - assertEquals(2, overrideContainer.associationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.associationOverridesSize()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, overrideContainer.associationOverridesSize()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - getJpaProject().synchronizeContextModel(); - assertEquals(3, overrideContainer.associationOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtual2() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<NestableAnnotation> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideSetVirtualTrue() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - overrideContainer.specifiedAssociationOverrides().next().setVirtual(true); - - Iterator<NestableAnnotation> associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator<JavaAssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - overrideContainer.specifiedAssociationOverrides().next().setVirtual(true); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(associationOverrides.hasNext()); - - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_SUB_TYPE_NAME); - - Iterator<NestableAnnotation> javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - overrideContainer.moveSpecifiedAssociationOverride(1, 0); - ListIterator<AssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("manyToOne", associationOverrides.next().getName()); - assertEquals("oneToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - - - overrideContainer.moveSpecifiedAssociationOverride(0, 1); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("oneToOne", associationOverrides.next().getName()); - assertEquals("manyToOne", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("oneToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - assertEquals("manyToOne", ((AssociationOverrideAnnotation) javaAssociationOverrides.next()).getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - ((AssociationOverrideAnnotation) typeResource.addAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((AssociationOverrideAnnotation) typeResource.addAnnotation(2, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - - ListIterator<AssociationOverride> associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.moveAnnotation(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - associationOverrides = overrideContainer.specifiedAssociationOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverrideContainer overrideContainer = getJavaEntity().getAssociationOverrideContainer(); - ListIterator<JavaAssociationOverride> virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - AssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("oneToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - overrideContainer.virtualAssociationOverrides().next().setVirtual(false); - AssociationOverride specifiedAssociationOverride = overrideContainer.specifiedAssociationOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = overrideContainer.virtualAssociationOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("manyToOne", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testAddNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedQuery namedQuery1 = entity.getQueryContainer().addNamedQuery(0); - namedQuery1.setName("FOO"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery2 = entity.getQueryContainer().addNamedQuery(0); - namedQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedQuery namedQuery3 = entity.getQueryContainer().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery1, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("foo"); - } - - public void testInvalidNamedQueries() throws Exception { - createTestEntityInvalidNamedQueries(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - assertEquals(2, entity.getQueryContainer().namedQueriesSize()); - } - - public void testRemoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedQuery(0); - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testAddNamedNativeQueryWithNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - - - NamedNativeQueryAnnotation nativeQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - nativeQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedNativeQueriesSize()); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testAddNamedQueryWithNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - getJpaProject().synchronizeContextModel(); - - assertEquals(1, entity.getQueryContainer().namedQueriesSize()); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - } - - public void testMoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.getQueryContainer().moveNamedQuery(2, 0); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedQuery(0, 1); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator<JavaNamedQuery> namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedQueriesSize()); - - ((NamedQueryAnnotation) typeResource.addAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedQueryAnnotation) typeResource.addAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedQueryAnnotation) typeResource.addAnnotation(2, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedQueriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - NamedNativeQuery namedNativeQuery = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery2 = entity.getQueryContainer().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - NamedNativeQuery namedNativeQuery3 = entity.getQueryContainer().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedQueries.next()); - assertEquals(namedNativeQuery3, namedQueries.next()); - assertEquals(namedNativeQuery, namedQueries.next()); - - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(1, CollectionTools.size(javaNamedQueries)); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - entity.getQueryContainer().removeNamedNativeQuery(0); - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(0, CollectionTools.size(javaNamedQueries)); - } - - public void testMoveNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - entity.getQueryContainer().addNamedNativeQuery(0).setName("FOO"); - entity.getQueryContainer().addNamedNativeQuery(1).setName("BAR"); - entity.getQueryContainer().addNamedNativeQuery(2).setName("BAZ"); - - Iterator<NestableAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.getQueryContainer().moveNamedNativeQuery(2, 0); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - - - entity.getQueryContainer().moveNamedNativeQuery(0, 1); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("BAR", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - assertEquals("FOO", ((NamedNativeQueryAnnotation) javaNamedQueries.next()).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - getJpaProject().synchronizeContextModel(); - ListIterator<JavaNamedNativeQuery> namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, entity.getPersistenceUnit().queriesSize()); - - typeResource.moveAnnotation(2, 0, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.moveAnnotation(0, 1, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, entity.getPersistenceUnit().queriesSize()); - - typeResource.removeAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - namedQueries = entity.getQueryContainer().namedNativeQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, entity.getPersistenceUnit().queriesSize()); - } - - public void testNamedNativeQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaEntity entity = getJavaEntity(); - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.getQueryContainer().namedNativeQueriesSize()); - - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((NamedNativeQueryAnnotation) typeResource.addAnnotation(2, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - getJpaProject().synchronizeContextModel(); - assertEquals(3, entity.getQueryContainer().namedNativeQueriesSize()); - } - - public void testUpdateIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - // test setting id class name to nonexistent class. test class name is set, but class is null - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - idClass.setValue(nonExistentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - // test setting id class name to existent class. test class name is set and class is not null - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - idClass.setValue(existentIdClassName); - getJpaProject().synchronizeContextModel(); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClass.setValue(null); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - //reset @IdClass value and then remove @IdClass - idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClass.setValue(existentIdClassName); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testModifyIdClass() throws Exception { - createTestEntity(); - createTestIdClass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String nonExistentIdClassName = PACKAGE_NAME + ".Foo"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(nonExistentIdClassName); - assertEquals(nonExistentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(nonExistentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - - String existentIdClassName = PACKAGE_NAME + ".TestTypeId"; - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(existentIdClassName); - assertEquals(existentIdClassName, ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals(existentIdClassName, getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNotNull(getJavaEntity().getIdClassReference().getIdClass()); - - getJavaEntity().getIdClassReference().setSpecifiedIdClassName(null); - assertNull(getJavaEntity().getIdClassReference().getSpecifiedIdClassName()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - assertNull(getJavaEntity().getIdClassReference().getIdClass()); - } - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<ClassRef> classRefs = getPersistenceUnit().specifiedClassRefs(); - JavaPersistentType entityPersistentType = classRefs.next().getJavaPersistentType(); - JavaEntity javaEntity = (JavaEntity) entityPersistentType.getMapping(); - JavaPersistentType mappedSuperclassPersistentType = classRefs.next().getJavaPersistentType(); - - assertEquals("id", javaEntity.getPrimaryKeyColumnName()); - - ((JavaIdMapping) mappedSuperclassPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", javaEntity.getPrimaryKeyColumnName()); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = javaEntity.getAttributeOverrideContainer().virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next(); - JavaAttributeOverride javaAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", javaAttributeOverride.getName()); - - javaAttributeOverride = javaAttributeOverride.setVirtual(false); - javaAttributeOverride.getColumn().setSpecifiedName("ID"); - assertEquals("ID", javaEntity.getPrimaryKeyColumnName()); - } - - public void testDiscriminatorValueIsUndefinedConcreteClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertFalse(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testDiscriminatorValueIsUndefinedAbstractClass() throws Exception { - createTestAbstractEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - - createTestSubType(); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertTrue(getJavaEntity().discriminatorValueIsUndefined()); - } - - public void testSpecifiedDiscriminatorColumnIsAllowed() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - //table-per-class, no discriminator column allowed - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertFalse(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - - - //single-table, discriminator column allowed on root entity - abstractEntity.setSpecifiedInheritanceStrategy(null); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertTrue(abstractEntity.specifiedDiscriminatorColumnIsAllowed()); - } - - public void testAbstractEntityGetDefaultDiscriminatorColumnNameTablePerClassInheritance() throws Exception { - createAbstractTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<ClassRef> specifiedClassRefs = getPersistenceUnit().specifiedClassRefs(); - Entity concreteEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals("AnnotationTestTypeChild", concreteEntity.getName()); - - Entity abstractEntity = (Entity) specifiedClassRefs.next().getJavaPersistentType().getMapping(); - assertEquals(TYPE_NAME, abstractEntity.getName()); - - - assertEquals(InheritanceType.TABLE_PER_CLASS, abstractEntity.getSpecifiedInheritanceStrategy()); - assertEquals(null, concreteEntity.getSpecifiedInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, concreteEntity.getDefaultInheritanceStrategy()); - - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertFalse(concreteEntity.specifiedDiscriminatorColumnIsAllowed()); - assertEquals(null, abstractEntity.getDiscriminatorColumn().getDefaultName()); - assertEquals(null, concreteEntity.getDiscriminatorColumn().getDefaultName()); - - assertTrue(abstractEntity.discriminatorValueIsUndefined()); - assertEquals(null, abstractEntity.getDefaultDiscriminatorValue()); - assertTrue(concreteEntity.discriminatorValueIsUndefined()); - assertEquals(null, concreteEntity.getDefaultDiscriminatorValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java deleted file mode 100644 index a198b737a1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java +++ /dev/null @@ -1,149 +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.core.tests.internal.context.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.GeneratedValue; -import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaGeneratedValueTests extends ContextModelTestCase -{ - private static final String GENERATOR = "MY_GENERATOR"; - - private ICompilationUnit createTestEntityWithGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.GENERATED_VALUE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue(generator=\"" + GENERATOR + "\")"); - } - }); - } - - public JavaGeneratedValueTests(String name) { - super(name); - } - - public void testGetGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setGenerator("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - } - - public void testSetSpecifiedGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator("foo"); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals("foo", generatedValue.getGenerator()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator(null); - - assertNotNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertNotNull(generatedValue); - } - - public void testGetStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setStrategy(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY); - getJpaProject().synchronizeContextModel(); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getDefaultStrategy()); - } - - public void testSetSpecifiedStrategy() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) getJavaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(GenerationType.IDENTITY); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - assertEquals(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY, generatedValue.getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(null); - - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertNotNull(generatedValue); - assertNull(generatedValue.getStrategy()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java deleted file mode 100644 index c06b8b4f93..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java +++ /dev/null @@ -1,717 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.Converter; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.ManyToManyMapping; -import org.eclipse.jpt.core.context.ManyToOneMapping; -import org.eclipse.jpt.core.context.OneToManyMapping; -import org.eclipse.jpt.core.context.OneToOneMapping; -import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TemporalConverter; -import org.eclipse.jpt.core.context.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaIdMappingTests extends ContextModelTestCase -{ - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdMappingGeneratedValue() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.GENERATED_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@GeneratedValue").append(CR); - } - }); - } - - public JavaIdMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((BasicMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((TemporalConverter) ((VersionMapping) persistentAttribute.getMapping()).getConverter()).getTemporalType()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.getGeneratorContainer().addTableGenerator(); - idMapping.getGeneratorContainer().addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - assertNull(attributeResource.getAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(GeneratedValueAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(TemporalType.TIMESTAMP, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - - idMapping.setConverter(Converter.TEMPORAL_CONVERTER); - ((TemporalConverter) idMapping.getConverter()).setTemporalType(TemporalType.TIME); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - idMapping.setConverter(Converter.NO_CONVERTER); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - getJpaProject().synchronizeContextModel(); - - assertEquals(TemporalType.DATE, ((TemporalConverter) idMapping.getConverter()).getTemporalType()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - - assertEquals(Converter.NO_CONVERTER, idMapping.getConverter().getType()); - assertFalse(idMapping.isDefault()); - assertSame(idMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getColumn().getSpecifiedName()); - assertEquals("id", idMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - getJpaProject().synchronizeContextModel(); - - assertEquals("foo", idMapping.getColumn().getSpecifiedName()); - assertEquals("foo", idMapping.getColumn().getName()); - assertEquals("id", idMapping.getColumn().getDefaultName()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - getJpaProject().synchronizeContextModel(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertEquals(2, attributeResource.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getSequenceGenerator().setName("foo"); - getJpaProject().synchronizeContextModel(); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - idMapping.getGeneratorContainer().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeSequenceGenerator(); - - assertNull(idMapping.getGeneratorContainer().getSequenceGenerator()); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(0, idMapping.getPersistenceUnit().generatorsSize()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertEquals(2, attributeResource.annotationsSize()); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - - idMapping.getGeneratorContainer().getTableGenerator().setName("foo"); - assertEquals(1, idMapping.getPersistenceUnit().generatorsSize()); - } - - public void testAddTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - - idMapping.getGeneratorContainer().addTableGenerator(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(idMapping.getGeneratorContainer().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - getJpaProject().synchronizeContextModel(); - - - idMapping.getGeneratorContainer().removeTableGenerator(); - - assertNull(idMapping.getGeneratorContainer().getTableGenerator()); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - idMapping.getGeneratorContainer().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testGetGeneratedValue2() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithIdMappingGeneratedValue(); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(2, attributeResource.annotationsSize()); - } - - public void testAddGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - idMapping.addGeneratedValue(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - assertNotNull(idMapping.getGeneratedValue()); - - //try adding another generated value, should get an IllegalStateException - try { - idMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = getJavaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - getJpaProject().synchronizeContextModel(); - - idMapping.removeGeneratedValue(); - - assertNull(idMapping.getGeneratedValue()); - assertNull(attributeResource.getAnnotation(JPA.GENERATED_VALUE)); - - //try removing the generatedValue again, should get an IllegalStateException - try { - idMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java deleted file mode 100644 index 3d6bc5689d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java +++ /dev/null @@ -1,547 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 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.core.tests.internal.context.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinColumnJoiningStrategy; -import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaJoinColumnTests extends ContextModelTestCase -{ - public JavaJoinColumnTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOne() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne").append(CR); - sb.append(" private Project project;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", javaJoinColumn.getName()); - - //set name to null in the resource model, annotation removed, specified join column removed - javaJoinColumn.setName(null); - getJpaProject().synchronizeContextModel(); - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", javaJoinColumn.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - // <attribute name>_<referenced column name> - // or - // <target entity name>_<referenced column name> - public void testDefaultName() throws Exception { - createTestEntityWithValidOneToOne(); - createTargetEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - -// JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); -// JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); -// JavaJoinColumn defaultJavaJoinColumn = joinColumns.getDefaultJoinColumn(); -// -// assertNull(defaultJavaJoinColumn.getDefaultName()); -//TODO test default join column name -// //add target entity to the persistence unit, now join table name is [table name]_[target table name] -// addXmlClassRef(PACKAGE_NAME + ".Project"); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// JavaPersistentTypeResource typeResource = jpaProject().javaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); -// JavaPersistentAttributeResource attributeResource = typeResource.attributes().next(); -// assertNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //target entity does not resolve, default name is null -// manyToManyMapping.setSpecifiedTargetEntity("Foo"); -// assertNull(joinTable.getDefaultName()); -// -// //default target entity does resolve, so default name is again [table name]_[target table name] -// manyToManyMapping.setSpecifiedTargetEntity(null); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// -// //add the join table annotation, verify default join table name is the same -// attributeResource.addAnnotation(JoinTable.ANNOTATION_NAME); -// assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); -// assertNotNull(attributeResource.annotation(JoinTable.ANNOTATION_NAME)); -// -// //set a table on the target entity, very default join table name updates -// manyToManyMapping.getResolvedTargetEntity().getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME + "_FOO", joinTable.getDefaultName()); -// -// //set a table on the owning entity, very default join table name updates -// javaEntity().getTable().setSpecifiedName("BAR"); -// assertEquals("BAR_FOO", joinTable.getDefaultName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set referenced column name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setReferencedColumnName("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the resource model, - javaJoinColumn.setReferencedColumnName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull("BAR", javaJoinColumn.getReferencedColumnName()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set referenced column name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedReferencedColumnName("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(javaJoinColumn.getReferencedColumnName()); - } - - public void testDefaultReferencedColumnName() throws Exception { - //TODO test default join column referenced column name - - } - - public void testUpdateTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set table in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setTable("BAR"); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the resource model, - javaJoinColumn.setTable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedTable()); - assertNull("BAR", javaJoinColumn.getTable()); - } - - public void testModifyTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set table in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedTable("BAR"); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the context model - joinColumn.setSpecifiedTable(null); - assertNull(joinColumn.getSpecifiedTable()); - assertNull(javaJoinColumn.getTable()); - } - - public void testDefaultTable() throws Exception { - //TODO test default join column table - - } - - public void testUpdateUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set unique in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUnique(Boolean.TRUE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the resource model, - javaJoinColumn.setUnique(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testModifyUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set unique in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUnique(Boolean.TRUE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the context model - joinColumn.setSpecifiedUnique(null); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testUpdateNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set nullable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setNullable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the resource model, - javaJoinColumn.setNullable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testModifyNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set nullable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedNullable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the context model - joinColumn.setSpecifiedNullable(null); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testUpdateInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set insertable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setInsertable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the resource model, - javaJoinColumn.setInsertable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testModifyInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set insertable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedInsertable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the context model - joinColumn.setSpecifiedInsertable(null); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testUpdateUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, joinColumns.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set updatable in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - javaJoinColumn.setUpdatable(Boolean.FALSE); - getJpaProject().synchronizeContextModel(); - JavaJoinColumn joinColumn = joinColumns.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the resource model, - javaJoinColumn.setUpdatable(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } - - public void testModifyUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) getJavaPersistentType().attributes().next().getMapping(); - JavaJoinColumnJoiningStrategy joinColumns = oneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - - JavaJoinColumn joinColumn = joinColumns.addSpecifiedJoinColumn(0); - //set updatable in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - joinColumn.setSpecifiedUpdatable(Boolean.FALSE); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the context model - joinColumn.setSpecifiedUpdatable(null); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java deleted file mode 100644 index 2b49da9e61..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java +++ /dev/null @@ -1,1163 +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.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -import org.eclipse.jpt.core.context.JoinTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -@SuppressWarnings("nls") -public class JavaJoinTableTests extends ContextModelTestCase -{ - public JavaJoinTableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntityWithManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - sb.append(" private Collection<Project> projects;").append(CR); - } - }); - } - - private void createTargetEntity() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - private void createTargetEntityWithBackPointer() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("import "); - sb.append(JPA.ENTITY); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.MANY_TO_MANY); - sb.append(";"); - sb.append(CR); - sb.append(CR); - sb.append("@Entity"); - sb.append(CR); - sb.append("public class Project {").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int proj_id;").append(CR); - sb.append(" @ManyToMany(mappedBy=\"projects\"").append(CR); - sb.append(" private java.util.Collection<" + TYPE_NAME + "> employees;").append(CR); - sb.append(CR); - sb.append("}"); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable); - - - //set name in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - //set name to null in the resource model - javaJoinTable.setName(null); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable.getName()); - - javaJoinTable.setName("FOO"); - getJpaProject().synchronizeContextModel(); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - getJpaProject().synchronizeContextModel(); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - JavaResourcePersistentType typeResource = getJpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.persistableAttributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable); - - //set name in the context model, verify resource model modified - joinTable.setSpecifiedName("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedName()); - assertEquals("foo", javaJoinTable.getName()); - - //set name to null in the context model - joinTable.setSpecifiedName(null); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultName() throws Exception { - createTestEntityWithValidManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) getJavaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getRelationshipReference().getJoinTableJoiningStrategy().getJoinTable(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinTable.getDefaultName()); - - //add target entity |