diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse')
151 files changed, 0 insertions, 61340 deletions
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java deleted file mode 100644 index 9b0e632be8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptAllCoreTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 junit.framework.Test; - -/** - * This test suite is temporary, until jpa.jar can be checked into the CVS - * repository and used during the nightly builds. - * - * Runs ALL JPT Core Tests. Currently we do not have a jpa.jar checked in to CVS. - * As a result we cannot run any tests that depend on that jar during the build. - * In our local development environments we should run this suite (JptAllCoreTests) - * until jpa.jar is checked into CVS. - * In the nightly build we should continue to run JptCoreTests. - */ -public class JptAllCoreTests { - - public static Test suite() { - return JptCoreTests.suite(true); - } - - private JptAllCoreTests() { - super(); - throw new UnsupportedOperationException(); - } - -} 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 f879593cd6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/JptCoreTests.java +++ /dev/null @@ -1,48 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal; - -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.resource.JptCoreResourceModelTests; -import org.eclipse.jpt.core.tests.internal.utility.jdt.JptCoreUtilityJdtTests; - -/** - * Runs MOST JPT Core Tests. Currently we do not have a jpa.jar checked into cvs. - * As a result we cannot run any tests that depend on that jar during the nightly build. - * In our development environments we should run JptAllCoreTests (NOT this suite) - * until jpa.jar is checked into CVS. - */ -public class JptCoreTests { - - public static Test suite() { - return suite(false); - } - - public static Test suite(boolean all) { - String quantity = all ? "All" : "Most"; - TestSuite suite = new TestSuite(quantity + " JPT Core Tests"); - suite.addTest(JptCoreUtilityJdtTests.suite(all)); - suite.addTest(JptCoreModelTests.suite(all)); - suite.addTest(JptCoreResourceModelTests.suite(all)); - if (all) { - suite.addTest(JptCoreContextModelTests.suite(all)); - } - return suite; - } - - private JptCoreTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/ProjectUtility.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/ProjectUtility.java deleted file mode 100644 index f4abdb741b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/ProjectUtility.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import junit.framework.Assert; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.AssertionFailedException; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Plugin; - -/** - * Copied from org.eclipse.wst.common.tests - */ -public class ProjectUtility { - public static IProject[] getAllProjects() { - IProject[] projects = new IProject[0]; - try { - projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - } catch (AssertionFailedException ex) { - // Catch Malformed tree exception that occurs from time to time... - } - return projects; - } - public static boolean projectExists(String projectName) { - return getProject(projectName) != null; - } - public static IProject verifyAndReturnProject(String projectName, boolean exists) { - IProject project = getProject(projectName); - if (exists) { - Assert.assertTrue("Project Does Not Exist:" + projectName, project.exists()); - } else { - Assert.assertTrue("Project Exists:" + projectName, !project.exists()); - } - return project; - } - public static void verifyProject(String projectName, boolean exists) { - IProject project = getProject(projectName); - if (exists) { - Assert.assertTrue("Project Does Not Exist:" + projectName, project.exists()); - } else { - Assert.assertTrue("Project Exists:" + projectName, !project.exists()); - } - } - public static IProject getProject(String projectName) { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - String pathString = projectName; - if (!(workspace.getRoot().getProject(pathString) == null)) - return workspace.getRoot().getProject(pathString); - else - return null; - } - public static void verifyNoProjects() { - IProject[] projects = getAllProjects(); - String projectNames = ""; - for (int i = 0; i < projects.length; i++) { - projectNames += " " + projects[i].getName(); - } - Assert.assertTrue("All projects not deleted" + projectNames, projects.length == 0); - } - public static void deleteProjectIfExists(String projectName) { - if (projectName == null) - return; - IProject project = getProject(projectName); - if (project != null && project.isAccessible()) { - try { - project.close(null); - project.delete(true, true, null); - ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - } - public static void deleteAllProjects() throws Exception { - //closing projects and tread work in here is a hack because of a BeanInfo bug holding - //onto jars loaded in another VM - -// for (int i = 0; i < projects.length; i++) { -// if (projects[i].exists()) { -// projects[i].close(null); // This should signal the extra VM to kill itself -// } -// } - // Thread.yield(); // give the VM a chance to die - IWorkspaceRunnable runnable = new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) { - IProject[] projects = getAllProjects(); - for (int i = 0; i < projects.length; i++) { - IProject project = projects[i]; - boolean success = false; - Exception lastException = null; - // Don't make 2^12 is about 4 seconds which is the max we - // will wait for the VM to die - for (int j = 0; j < 14 && !success; j++) { - try { - if (project.exists()) { - project.delete(true, true, null); - ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); - } - success = true; - } catch (Exception ex) { - lastException = ex; - if (project.exists()) { - try { - project.close(null); - project.open(null); - } catch (Exception ex2) { - // ignore this exception - } - } - try { - Thread.sleep((int) Math.pow(2, j)); - } catch (InterruptedException ex2) { - // probably won't happen - } - } - } - if ( ! success) { - System.out.println("Problem while deleting: " + project.getName()); - lastException.printStackTrace(System.out); - } - } - } - }; - try { - ResourcesPlugin.getWorkspace().run(runnable, null); - } catch (CoreException ce) { - } - //verifyNoProjects(); - } - /** - * Return the absolute path Strings to the files based on the fileSuffix and - * path within the plugin. - * - * @param path - * @param fileSuffix - * the file ending with the "." if required (the suffix will be - * used as is) - * @return - */ - public static List getSpecificFilesInDirectory(Plugin plugin, String path, final String fileSuffix) { - URL entry = null; - entry = plugin.getBundle().getEntry(path); - List result = null; - File folder = null; - if (entry != null) { - try { - entry = Platform.asLocalURL(entry); - folder = new File(new URI(entry.toString())); - } catch (Exception e1) { - e1.printStackTrace(); - return Collections.EMPTY_LIST; - } - List files = Arrays.asList(folder.list()); - if (!files.isEmpty()) { - String folderPath = folder.getAbsolutePath() + File.separator; - result = new ArrayList(); - for (int i = 0; i < files.size(); i++) { - String fileName = (String) files.get(i); - if (!fileName.endsWith(fileSuffix)) - continue; - result.add(folderPath + fileName); - } - } - } - if (result == null) - result = Collections.EMPTY_LIST; - return result; - } - public static List getJarsInDirectory(Plugin plugin, String path) { - return getSpecificFilesInDirectory(plugin, path, ".jar"); - } - public static List getRarsInDirectory(Plugin plugin, String path) { - return getSpecificFilesInDirectory(plugin, path, ".rar"); - } - public static List getEarsInDirectory(Plugin plugin, String path) { - return getSpecificFilesInDirectory(plugin, path, ".ear"); - } - public static List getWarsInDirectory(Plugin plugin, String path) { - return getSpecificFilesInDirectory(plugin, path, ".war"); - } - public static String getFullFileName(Plugin plugin, String pluginRelativeFileName) throws IOException { - IPath path = new Path(pluginRelativeFileName); - if (path.getDevice() != null) - return pluginRelativeFileName; - URL url = plugin.getBundle().getEntry(pluginRelativeFileName); - if (url != null) { - url = Platform.asLocalURL(url); - IPath iPath = new Path(url.getPath()); - return iPath.toOSString(); - } - return null; - } -}
\ No newline at end of file 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 ff50fc7509..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/ContextModelTestCase.java +++ /dev/null @@ -1,194 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IType; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.JpaRootContextNode; -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.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -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.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; - -public abstract class ContextModelTestCase extends AnnotationTestCase -{ - protected static final String BASE_PROJECT_NAME = "ContextModelTestProject"; - - protected PersistenceArtifactEdit persistenceArtifactEdit; - protected OrmArtifactEdit ormArtifactEdit; - - - protected ContextModelTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.persistenceArtifactEdit = PersistenceArtifactEdit.getArtifactEditForWrite(getJavaProject().getProject()); - this.ormArtifactEdit = OrmArtifactEdit.getArtifactEditForWrite(getJavaProject().getProject()); - waitForWorkspaceJobs(); - } - - @Override - protected void deleteAllProjects() throws Exception{ - //don't delete projects, creating a new one with a new name - //workspace will be deleted next time tests are run. - //not saying this is the ultimate solution, but it will work for now - //until we can figure out how to properly delete projects in tests - } - - @Override - protected void tearDown() throws Exception { - //at least delete the project from the workspace since, deleting from the file system doesn't work well. - //tests run too slow otherwise because so many projects are created in the workspace - this.persistenceArtifactEdit.dispose(); - this.persistenceArtifactEdit = null; - this.ormArtifactEdit.dispose(); - this.ormArtifactEdit = null; - getJavaProject().getProject().delete(false, true, null); - super.tearDown(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return buildJpaProject(BASE_PROJECT_NAME, autoBuild, null); - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) - throws Exception { - return TestJpaProject.buildJpaProject(projectName, autoBuild, jpaConfig); - } - - protected JpaProject jpaProject() { - return getJavaProject().getJpaProject(); - } - - protected void waitForWorkspaceJobs() { - // This job will not finish running until the 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(); - try { - waitJob.join(); - } catch (InterruptedException ex) { - // the job thread was interrupted during a wait - ignore - } - } - - protected PersistenceResource persistenceResource() { - return this.persistenceArtifactEdit.getResource(); - } - - protected OrmResource ormResource() { - return this.ormArtifactEdit.getResource(JptCorePlugin.getDefaultOrmXmlDeploymentURI(jpaProject().getProject())); - } - - protected XmlPersistence xmlPersistence() { - return persistenceResource().getPersistence(); - } - - protected EntityMappings entityMappings() { - return persistenceUnit().mappingFileRefs().next().getOrmXml().getEntityMappings(); - } - - protected XmlPersistenceUnit xmlPersistenceUnit() { - return persistenceResource().getPersistence().getPersistenceUnits().get(0); - } - - protected PersistenceUnit persistenceUnit() { - return rootContext().getPersistenceXml().getPersistence().persistenceUnits().next(); - } - - protected ClassRef classRef() { - return persistenceUnit().specifiedClassRefs().next(); - } - - protected JavaPersistentType javaPersistentType() { - return classRef().getJavaPersistentType(); - } - - protected Entity javaEntity() { - return (Entity) javaPersistentType().getMapping(); - } - - protected void addXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass(className); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - } - - protected void removeXmlClassRef(String className) { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - 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 JpaRootContextNode rootContext() { - return getJavaProject().getJpaProject().getRootContext(); - } - - @Override - protected TestJpaProject getJavaProject() { - return (TestJpaProject) super.getJavaProject(); - } - - protected void deleteResource(Resource resource) throws CoreException { - System.gc(); - WorkbenchResourceHelper.deleteResource(resource); - waitForWorkspaceJobs(); - } - - protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - return this.javaProject.createCompilationUnit("javax.persistence", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - protected ICompilationUnit createEnumAndMembers(String enumName, String enumBody) throws Exception { - return this.javaProject.createCompilationUnit("javax.persistence", enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } -} 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 745987618b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JpaFileTests.java +++ /dev/null @@ -1,410 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - ******************************************************************************/ -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.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmXml; -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.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - 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 = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - IFile file = ormResource().getResourceModel().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertEquals(entityMappings(), 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()); - - entityMappings().removeOrmPersistentType(ormPersistentType); - - assertEquals(javaEntity().getPersistentType(), javaJpaFile.rootStructureNodes().next()); - - ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - public void testEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = ormResource().getResourceModel().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(entityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - ((OrmXml) entityMappings().getParent()).removeEntityMappings(); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testImpliedEntityMappingsRootStructureNodeRemoved() throws Exception { - IFile file = ormResource().getResourceModel().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - - assertNull(persistenceUnit().getImpliedMappingFileRef()); - - xmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(persistenceUnit().getImpliedMappingFileRef()); - assertEquals(persistenceUnit().getImpliedMappingFileRef().getOrmXml().getEntityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - persistenceUnit().getImpliedMappingFileRef().getOrmXml().removeEntityMappings(); - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testEntityMappingsRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = ormResource().getResourceModel().getFile(); - JpaFile ormXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(entityMappings(), ormXmlJpaFile.rootStructureNodes().next()); - - ormResource().getContents().remove(ormResource().getEntityMappings()); - - assertFalse(ormXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdatePersistenceRootStructureNodePersistenceRemoved() throws Exception { - IFile file = persistenceResource().getResourceModel().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(rootContext().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - rootContext().getPersistenceXml().removePersistence(); - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceRemoved() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - rootContext().getPersistenceXml().removePersistence(); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateJavaRootStructureNodePersistenceRemoved() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - assertEquals(javaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - rootContext().getPersistenceXml().removePersistence(); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testPersistenceRootStructureNodeRemovedFromResourceModel() throws Exception { - IFile file = persistenceResource().getResourceModel().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - rootContext().getPersistenceXml().getPersistence(); - assertEquals(rootContext().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - persistenceResource().getContents().remove(persistenceResource().getPersistence()); - - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdatePersistenceRootStructureNodePersistenceXmlRemoved() throws Exception { - IFile file = persistenceResource().getResourceModel().getFile(); - JpaFile persistenceXmlJpaFile = JptCorePlugin.getJpaFile(file); - assertEquals(rootContext().getPersistenceXml().getPersistence(), persistenceXmlJpaFile.rootStructureNodes().next()); - - rootContext().removePersistenceXml(); - assertFalse(persistenceXmlJpaFile.rootStructureNodes().hasNext()); - } - - public void testUpdateOrmJavaRootStructureNodePersistenceXmlRemoved() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - rootContext().removePersistenceXml(); - 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(javaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - rootContext().removePersistenceXml(); - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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 OrmEntity); - - - entityMappings().removeOrmPersistentType(0); - - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertTrue(javaJpaFile.rootStructureNodes().next().getParent() instanceof ClassRef); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - } - - public void testOrmJavaPersistentTypeRootStructureNodeRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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 OrmEntity); - - ormResource().getEntityMappings().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 = javaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(entityMappings().getPersistenceUnit().specifiedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - - entityMappings().getPersistenceUnit().removeSpecifiedClassRef(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(entityMappings().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 = javaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(entityMappings().getPersistenceUnit().specifiedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(entityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testImpliedJavaPersistentTypeRootStructureNodeRemoved() throws Exception { - jpaProject().setDiscoversAnnotatedClasses(true); - ICompilationUnit cu = createTestEntity(); - JpaFile javaJpaFile = JptCorePlugin.getJpaFile((IFile) cu.getResource()); - - JavaPersistentType javaPersistentType = persistenceUnit().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 = entityMappings().addOrmPersistentType(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()); - - ormResource().getContents().remove(ormResource().getEntityMappings()); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(persistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemovedFromResourceModel() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - persistenceResource().getPersistence().getPersistenceUnits().remove(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesPersistenceUnitRemoved() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - jpaProject().getRootContext().getPersistenceXml().getPersistence().removePersistenceUnit(0); - - assertFalse(javaJpaFile.rootStructureNodes().hasNext()); - assertEquals(0, javaJpaFile.rootStructureNodesSize()); - } - - public void testJavaRootStructureNodesOrmPersistentTypeRemoved() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - entityMappings().removeOrmPersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(entityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testJavaRootStructureNodesOrmTypeMappingMorphed() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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 = entityMappings().ormPersistentTypes().next().getJavaPersistentType(); - assertEquals(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - - entityMappings().removeOrmPersistentType(0); - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(entityMappings().getPersistenceUnit().impliedClassRefs().next(), javaJpaFile.rootStructureNodes().next().getParent()); - } - - public void testUpdateOrmJavaRootStructureNodeMappingFileRefChanged() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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 = persistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - - ormPersistentType = persistenceUnit().getImpliedMappingFileRef().getOrmXml().getEntityMappings().ormPersistentTypes().next(); - assertEquals(ormPersistentType.getJavaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - IFile file = persistenceResource().getResourceModel().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(javaPersistentType(), javaJpaFile.rootStructureNodes().next()); - - MappingFileRef mappingFileRef = persistenceUnit().mappingFileRefs().next(); - mappingFileRef.setFileName("foo"); - assertEquals(javaPersistentType(), javaJpaFile.rootStructureNodes().next()); - } - - - public void testUpdateJavaRootStrucutreNodeDeleteOrmResource() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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(ormResource()); - - assertNotSame(javaPersistentType, javaJpaFile.rootStructureNodes().next()); - assertEquals(1, javaJpaFile.rootStructureNodesSize()); - assertEquals(persistenceUnit().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/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 307e3051db..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/JptCoreContextModelTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.context.java.JptCoreContextJavaModelTests; -import org.eclipse.jpt.core.tests.internal.context.orm.JptCoreOrmContextModelTests; -import org.eclipse.jpt.core.tests.internal.context.persistence.JptCorePersistenceContextModelTests; - -public class JptCoreContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreContextModelTests.class.getName()); - suite.addTestSuite(JpaFileTests.class); - suite.addTest(JptCorePersistenceContextModelTests.suite(all)); - suite.addTest(JptCoreOrmContextModelTests.suite(all)); - suite.addTest(JptCoreContextJavaModelTests.suite(all)); - 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/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 dd26243b9b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAssociationOverrideTests.java +++ /dev/null @@ -1,421 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - ******************************************************************************/ -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.Entity; -import org.eclipse.jpt.core.context.JoinColumn; -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; - -public class JavaAssociationOverrideTests extends ContextModelTestCase -{ - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE_NAME"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createMappedSuperclassAnnotation() throws Exception{ - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - } - - private void createAssociationOverrideAnnotation() throws Exception { - createJoinColumnAnnotation(); - this.createAnnotationAndMembers("AssociationOverride", - "String name();" + - "JoinColumn[] joinColumns();"); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - createMappedSuperclassAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(" @OneToOne"); - sb.append(CR); - sb.append(" private int address;").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityWithAssociationOverride() throws Exception { - createEntityAnnotation(); - createAssociationOverrideAnnotation(); - - 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(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 JavaAssociationOverrideTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(javaEntity().associationOverrides().hasNext()); - - //set name in the resource model, verify context model updated - associationOverrideResource.setName("FOO"); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - //set name to null in the resource model - associationOverrideResource.setName(null); - assertNull(javaAssociationOverride.getName()); - assertNull(associationOverrideResource.getName()); - - associationOverrideResource.setName("FOO"); - assertEquals("FOO", javaAssociationOverride.getName()); - assertEquals("FOO", associationOverrideResource.getName()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertFalse(javaEntity().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 = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals("address", javaAssociationOverride.getName()); - assertEquals("address", associationOverrideResource.getName()); - assertTrue(javaEntity().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); - - Entity entity = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - JoinColumn joinColumn = javaAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", associationOverrideResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = javaAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = javaAssociationOverride.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverrideResource.joinColumnAt(2).getName()); - - ListIterator<JoinColumn> joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = javaAssociationOverride.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 = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - javaAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - javaAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - javaAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, associationOverrideResource.joinColumnsSize()); - - javaAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(2, associationOverrideResource.joinColumnsSize()); - assertEquals("BAR", associationOverrideResource.joinColumnAt(0).getName()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(1).getName()); - - javaAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(1, associationOverrideResource.joinColumnsSize()); - assertEquals("BAZ", associationOverrideResource.joinColumnAt(0).getName()); - - javaAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(0, associationOverrideResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - javaAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - javaAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - javaAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, associationOverrideResource.joinColumnsSize()); - - - javaAssociationOverride.moveSpecifiedJoinColumn(2, 0); - ListIterator<JoinColumn> joinColumns = javaAssociationOverride.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()); - - - javaAssociationOverride.moveSpecifiedJoinColumn(0, 1); - joinColumns = javaAssociationOverride.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); - - Entity entity = javaEntity(); - AssociationOverride javaAssociationOverride = entity.virtualAssociationOverrides().next(); - javaAssociationOverride = javaAssociationOverride.setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.addJoinColumn(0); - associationOverrideResource.addJoinColumn(1); - associationOverrideResource.addJoinColumn(2); - - associationOverrideResource.joinColumnAt(0).setName("FOO"); - associationOverrideResource.joinColumnAt(1).setName("BAR"); - associationOverrideResource.joinColumnAt(2).setName("BAZ"); - - ListIterator<JoinColumn> joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(2, 0); - joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.moveJoinColumn(0, 1); - joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(1); - joinColumns = javaAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - associationOverrideResource.removeJoinColumn(0); - assertFalse(javaAssociationOverride.specifiedJoinColumns().hasNext()); - } - - - - - public void testGetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverride specifiedAssociationOverride = javaEntity().specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - AssociationOverrideAnnotation associationOverrideResource = (AssociationOverrideAnnotation) typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverrideResource.setName("FOO"); - specifiedAssociationOverride = javaEntity().specifiedAssociationOverrides().next(); - assertEquals("FOO", specifiedAssociationOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAssociationOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AssociationOverride specifiedAssociationOverride = javaEntity().specifiedAssociationOverrides().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, specifiedAssociationOverride.getName()); - - specifiedAssociationOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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 = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, entity.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = entity.virtualAssociationOverrides().next(); - assertEquals("address", associationOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(1, entity.virtualAssociationOverridesSize()); - - AssociationOverride associationOverride = entity.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 4d9c48dc08..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaAttributeOverrideTests.java +++ /dev/null @@ -1,296 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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; - -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createMappedSuperclassAnnotation() throws Exception{ - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createAttributeOverrideAnnotation() throws Exception { - createColumnAnnotation(); - this.createAnnotationAndMembers("AttributeOverride", - "String name();" + - "Column column();"); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - createMappedSuperclassAnnotation(); - - 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 { - createEntityAnnotation(); - createAttributeOverrideAnnotation(); - - 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 ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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").append(CR); - } - }); - } - - 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); - - AttributeOverride specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - attributeOverrideResource.setName("FOO"); - specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - assertEquals("FOO", specifiedAttributeOverride.getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverride specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, specifiedAttributeOverride.getName()); - - specifiedAttributeOverride.setName("FOO"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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); - - AttributeOverride specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation columnResource = attributeOverrideResource.getColumn(); - columnResource.setName("FOO"); - - - column = javaEntity().specifiedAttributeOverrides().next().getColumn(); - assertEquals("FOO", column.getName()); - } - - public void testColumnSetName() throws Exception { - createTestEntityWithAttributeOverride(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - AttributeOverride specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - Column column = specifiedAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, column.getName()); - - column.setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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 = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, entity.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = entity.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(persistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedName("FOO"); - - attributeOverride = entity.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 = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, entity.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = entity.virtualAttributeOverrides().next(); - assertEquals("AnnotationTestTypeChild", attributeOverride.getColumn().getDefaultTable()); - - - JavaPersistentType mappedSuperclass = CollectionTools.list(persistenceUnit().specifiedClassRefs()).get(1).getJavaPersistentType(); - BasicMapping basicMapping = (BasicMapping) mappedSuperclass.getAttributeNamed("id").getMapping(); - basicMapping.getColumn().setSpecifiedTable("BAR"); - - attributeOverride = entity.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 = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, entity.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = entity.virtualAttributeOverrides().next(); - assertEquals("id", attributeOverride.getName()); - } - - public void testIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - assertEquals("AnnotationTestTypeChild", entity.getName()); - assertEquals(2, entity.virtualAttributeOverridesSize()); - - AttributeOverride attributeOverride = entity.virtualAttributeOverrides().next(); - assertTrue(attributeOverride.isVirtual()); - } - - public void testSetColumn() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - AttributeOverride attributeOverride = entity.virtualAttributeOverrides().next(); - attributeOverride = attributeOverride.setVirtual(false); - attributeOverride.getColumn().setSpecifiedName("FOO"); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(PACKAGE_NAME + ".AnnotationTestTypeChild"); - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals("FOO", attributeOverrideResource.getColumn().getName()); - assertEquals("FOO", entity.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 de450d0459..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaBasicMappingTests.java +++ /dev/null @@ -1,1000 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.EnumType; -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.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.iterators.ArrayIterator; - -public class JavaBasicMappingTests extends ContextModelTestCase -{ - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createBasicAnnotation() throws Exception{ - this.createAnnotationAndMembers("Basic", "FetchType fetch() default EAGER; boolean optional() default true;"); - } - - private void createLobAnnotation() throws Exception{ - this.createAnnotationAndMembers("Lob", ""); - } - - private void createEnumeratedAnnotation() throws Exception{ - this.createAnnotationAndMembers("Enumerated", "EnumType value() default ORDINAL;"); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - createBasicAnnotation(); - - 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 { - createEntityAnnotation(); - createBasicAnnotation(); - - 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 { - createEntityAnnotation(); - createLobAnnotation(); - - 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 { - createEntityAnnotation(); - createEnumeratedAnnotation(); - - 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 { - createEntityAnnotation(); - createTemporalAnnotation(); - - 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 = javaPersistentType().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 = javaPersistentType().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 = javaPersistentType().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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedFetch()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - basic.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - - assertEquals(FetchType.LAZY, basicMapping.getSpecifiedFetch()); - } - - public void testGetSpecifiedFetch2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, basic.getFetch()); - - basicMapping.setSpecifiedFetch(null); - assertNotNull(attributeResource.getMappingAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedFetch2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - createOrmXmlFile(); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedFetch()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedFetch(FetchType.LAZY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.properties().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(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.getMappingAnnotation(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testSetBasicRemovedFromResourceModel() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertFalse(basicMapping.isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.setMappingAnnotation(null); - - 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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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(TemporalType.TIME, ((BasicMapping) persistentAttribute.getMapping()).getTemporal()); - assertTrue(((BasicMapping) persistentAttribute.getMapping()).isLob()); - assertEquals(EnumType.ORDINAL, ((BasicMapping) persistentAttribute.getMapping()).getEnumerated()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); - assertNull(((BasicMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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, ((IdMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((VersionMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertFalse(basicMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); -//TODO assertEquals(FetchType.EAGER, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IOneToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); -//TODO assertEquals(FetchType.EAGER, ((IOneToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(OneToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); -//TODO assertEquals(FetchType.EAGER, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertEquals(Boolean.FALSE, ((IManyToOneMapping) persistentAttribute.getMapping()).getSpecifiedOptional()); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setLob(true); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - 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); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); -//TODO assertEquals(FetchType.EAGER, ((IManyToManyMapping) persistentAttribute.getMapping()).getSpecifiedFetch()); -// assertNotNull(attributeResource.mappingAnnotation(ManyToMany.ANNOTATION_NAME)); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, basicMapping.getDefaultOptional()); - } - - public void testSpecifiedBasicGetDefaultOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(Boolean.TRUE, basicMapping.getDefaultOptional()); - } - - public void testGetOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(Boolean.TRUE, basicMapping.getOptional()); - - basicMapping.setSpecifiedOptional(basicMapping.getOptional()); - assertEquals(Boolean.TRUE, basicMapping.getOptional()); - } - - public void testGetSpecifiedOptional() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - } - - public void testGetSpecifiedOptional2() throws Exception { - createTestEntityWithBasicMappingFetchOptionalSpecified(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - - basicMapping.setSpecifiedOptional(Boolean.FALSE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - - assertEquals(Boolean.FALSE, basic.getOptional()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getMappingAnnotation(JPA.BASIC)); - } - - public void testSetSpecifiedOptional2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertNull(basicMapping.getSpecifiedOptional()); - assertTrue(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(Boolean.TRUE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - - assertEquals(Boolean.TRUE, basic.getOptional()); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(Boolean.TRUE, basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - - basicMapping.setSpecifiedOptional(null); - assertNotNull(attributeResource.getMappingAnnotation(JPA.BASIC)); - - basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - } - - - public void testGetSpecifiedOptionalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedOptional()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - basic.setOptional(Boolean.FALSE); - - assertEquals(Boolean.FALSE, basicMapping.getSpecifiedOptional()); - - basic.setOptional(null); - assertNull(basicMapping.getSpecifiedOptional()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - - basic.setOptional(Boolean.FALSE); - attributeResource.setMappingAnnotation(null); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertEquals(Boolean.TRUE, ((BasicMapping) persistentAttribute.getMapping()).getOptional()); - } - - - public void testIsLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.isLob()); - } - - public void testIsLob2() throws Exception { - createTestEntityWithLob(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertTrue(basicMapping.isLob()); - } - - public void testSetLob() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - basicMapping.setLob(true); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNotNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - - basicMapping.setLob(false); - assertNull(attributeResource.getAnnotation(LobAnnotation.ANNOTATION_NAME)); - } - - public void testIsLobUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertFalse(basicMapping.isLob()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(LobAnnotation.ANNOTATION_NAME); - - assertTrue(basicMapping.isLob()); - - attributeResource.removeAnnotation(LobAnnotation.ANNOTATION_NAME); - - assertFalse(basicMapping.isLob()); - } - - public void testDefaultBasicGetDefaultEnumerated() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - assertEquals(EnumType.ORDINAL, basicMapping.getDefaultEnumerated()); - } - - public void testSpecifiedBasicGetDefaultEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertEquals(EnumType.ORDINAL, basicMapping.getDefaultEnumerated()); - } - - public void testGetEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(EnumType.ORDINAL, basicMapping.getEnumerated()); - - basicMapping.setSpecifiedEnumerated(EnumType.STRING); - assertEquals(EnumType.STRING, basicMapping.getEnumerated()); - } - - public void testGetSpecifiedEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedEnumerated()); - } - - public void testGetSpecifiedEnumerated2() throws Exception { - createTestEntityWithEnumerated(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(EnumType.STRING, basicMapping.getSpecifiedEnumerated()); - } - - public void testSetSpecifiedEnumerated() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getSpecifiedEnumerated()); - - basicMapping.setSpecifiedEnumerated(EnumType.STRING); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.EnumType.STRING, enumerated.getValue()); - - basicMapping.setSpecifiedEnumerated(null); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - } - - public void testGetSpecifieEnumeratedUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getSpecifiedEnumerated()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.addAnnotation(EnumeratedAnnotation.ANNOTATION_NAME); - enumerated.setValue(org.eclipse.jpt.core.resource.java.EnumType.STRING); - - assertEquals(EnumType.STRING, basicMapping.getSpecifiedEnumerated()); - - enumerated.setValue(null); - assertNull(attributeResource.getAnnotation(EnumeratedAnnotation.ANNOTATION_NAME)); - assertNull(basicMapping.getSpecifiedEnumerated()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - - public void testGetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getTemporal()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getMapping(); - - assertEquals(TemporalType.TIMESTAMP, basicMapping.getTemporal()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(basicMapping.getTemporal()); - - basicMapping.setTemporal(TemporalType.TIME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - basicMapping.setTemporal(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getTemporal()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - - assertEquals(TemporalType.DATE, basicMapping.getTemporal()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertNull(basicMapping.getTemporal()); - assertFalse(basicMapping.isDefault()); - assertSame(basicMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithBasicMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - BasicMapping basicMapping = (BasicMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - assertEquals("id", basicMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - - 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/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 ba77742084..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaColumnTests.java +++ /dev/null @@ -1,848 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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; - -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createBasicAnnotation() throws Exception{ - this.createAnnotationAndMembers("Basic", "String name() default \"\";"); - } - - private void createColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - createColumnAnnotation(); - - 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 { - createEntityAnnotation(); - createColumnAnnotation(); - createBasicAnnotation(); - - 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 { - createEntityAnnotation(); - createColumnAnnotation(); - createBasicAnnotation(); - - 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) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().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) javaPersistentType().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals("id", basicMapping.getColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDefaultBasicColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_NAME, basicMapping.getColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedName(null); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetNameUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setName("foo"); - assertEquals("foo", basicMapping.getColumn().getSpecifiedName()); - assertEquals("foo", basicMapping.getColumn().getName()); - - column.setName(null); - assertNull(basicMapping.getColumn().getSpecifiedName()); - } - - - - - - - - - - - - - - public void testGetSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetSpecifiedTable() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetDefaultTableSpecifiedTableNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().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) javaPersistentType().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(TABLE_NAME, basicMapping.getColumn().getTable()); - } - - public void testSetSpecifiedTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable("foo"); - - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setSpecifiedTable(null); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testGetTableUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedTable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setTable("foo"); - assertEquals("foo", basicMapping.getColumn().getSpecifiedTable()); - assertEquals("foo", basicMapping.getColumn().getTable()); - - column.setTable(null); - assertNull(basicMapping.getColumn().getSpecifiedTable()); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(COLUMN_DEFINITION, basicMapping.getColumn().getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithBasicColumnTableSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - basicMapping.getColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - - column.setColumnDefinition("foo"); - assertEquals("foo", basicMapping.getColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - assertNull(basicMapping.getColumn().getColumnDefinition()); - - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_LENGTH, basicMapping.getColumn().getLength()); - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(Integer.valueOf(55), basicMapping.getColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().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) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setLength(Integer.valueOf(66)); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedLength()); - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getLength()); - - column.setLength(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedLength()); - - basicMapping.getColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_PRECISION, basicMapping.getColumn().getPrecision()); - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(55)); - assertEquals(Integer.valueOf(55), basicMapping.getColumn().getPrecision()); - } - - public void testGetDefaultPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().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) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setPrecision(Integer.valueOf(66)); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedPrecision()); - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getPrecision()); - - column.setPrecision(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - } - - public void testSetSpecifiedPrecision() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedPrecision()); - - basicMapping.getColumn().setSpecifiedPrecision(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(Column.DEFAULT_SCALE, basicMapping.getColumn().getScale()); - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(55)); - assertEquals(Integer.valueOf(55), basicMapping.getColumn().getScale()); - } - - public void testGetDefaultScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().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) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setScale(Integer.valueOf(66)); - - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getSpecifiedScale()); - assertEquals(Integer.valueOf(66), basicMapping.getColumn().getScale()); - - column.setScale(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedScale()); - } - - public void testSetSpecifiedScale() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedScale()); - - basicMapping.getColumn().setSpecifiedScale(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().getUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getUnique()); - } - - public void testGetDefaultUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().getDefaultUnique()); - basicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UNIQUE, basicMapping.getColumn().getDefaultUnique()); - } - - public void testGetSpecifiedUnique() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUnique(Boolean.TRUE); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUnique()); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getUnique()); - - column.setUnique(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - } - - public void testSetSpecifiedUnique() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUnique()); - - basicMapping.getColumn().setSpecifiedUnique(Boolean.FALSE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().getInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getInsertable()); - } - - public void testGetDefaultInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().getDefaultInsertable()); - basicMapping.getColumn().setSpecifiedInsertable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_INSERTABLE, basicMapping.getColumn().getDefaultInsertable()); - } - - public void testGetSpecifiedInsertable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setInsertable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getInsertable()); - - column.setInsertable(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - } - - public void testSetSpecifiedInsertable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedInsertable()); - - basicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().getNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getNullable()); - } - - public void testGetDefaultNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().getDefaultNullable()); - basicMapping.getColumn().setSpecifiedNullable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_NULLABLE, basicMapping.getColumn().getDefaultNullable()); - } - - public void testGetSpecifiedNullable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setNullable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedNullable()); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getNullable()); - - column.setNullable(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - } - - public void testSetSpecifiedNullable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedNullable()); - - basicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().getUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getUpdatable()); - } - - public void testGetDefaultUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().getDefaultUpdatable()); - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.TRUE); - - assertEquals(BaseColumn.DEFAULT_UPDATABLE, basicMapping.getColumn().getDefaultUpdatable()); - } - - public void testGetSpecifiedUpdatable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setUpdatable(Boolean.TRUE); - - assertEquals(Boolean.TRUE, basicMapping.getColumn().getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, basicMapping.getColumn().getUpdatable()); - - column.setUpdatable(null); - - assertNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - } - - public void testSetSpecifiedUpdatable() throws Exception { - createTestEntityWithBasicColumnColumnDefinitionSet(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - BasicMapping basicMapping = (BasicMapping) javaPersistentType().attributes().next().getMapping(); - - assertNull(basicMapping.getColumn().getSpecifiedUpdatable()); - - basicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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 8d59ae5e32..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaDiscriminatorColumnTests.java +++ /dev/null @@ -1,326 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.DiscriminatorColumn; -import org.eclipse.jpt.core.context.DiscriminatorType; -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.utility.internal.iterators.ArrayIterator; - -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - private void createDiscriminatorColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("DiscriminatorColumn", - "String name() default \"DTYPE\";" + - "DiscriminatorType discriminatorType() default STRING;" + - "String columnDefinition() default \"\";" + - "int length() default 31;"); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - createDiscriminatorColumnAnnotation(); - - 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 + "\")"); - } - }); - } - - - public JavaDiscriminatorColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, javaEntity().getDiscriminatorColumn().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("DTYPE", javaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("DTYPE", javaEntity().getDiscriminatorColumn().getDefaultName()); - - javaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - assertEquals("DTYPE", javaEntity().getDiscriminatorColumn().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("DTYPE", javaEntity().getDiscriminatorColumn().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_COLUMN_NAME, javaEntity().getDiscriminatorColumn().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().getDiscriminatorColumn().setSpecifiedName("foo"); - - assertEquals("foo", javaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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); - - javaEntity().getDiscriminatorColumn().setSpecifiedName(null); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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(DiscriminatorType.STRING, javaEntity().getDiscriminatorColumn().getDefaultDiscriminatorType()); - } - - public void testGetDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorType.STRING, javaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - javaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, javaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR); - - assertEquals(DiscriminatorType.CHAR, javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - } - - public void testSetSpecifiedDiscriminatorType() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - javaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.CHAR); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(org.eclipse.jpt.core.resource.java.DiscriminatorType.CHAR, discriminatorColumn.getDiscriminatorType()); - - javaEntity().getDiscriminatorColumn().setSpecifiedName(null); - javaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetDiscriminatorTypeUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setDiscriminatorType(org.eclipse.jpt.core.resource.java.DiscriminatorType.INTEGER); - assertEquals(DiscriminatorType.INTEGER, javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(DiscriminatorType.INTEGER, javaEntity().getDiscriminatorColumn().getDiscriminatorType()); - - column.setDiscriminatorType(null); - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedDiscriminatorType()); - assertEquals(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE, javaEntity().getDiscriminatorColumn().getDiscriminatorType()); - } - - public void testGetLength() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, javaEntity().getDiscriminatorColumn().getLength()); - javaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - assertEquals(Integer.valueOf(55), javaEntity().getDiscriminatorColumn().getLength()); - } - - public void testGetDefaultLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, javaEntity().getDiscriminatorColumn().getDefaultLength()); - javaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(55)); - - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, javaEntity().getDiscriminatorColumn().getDefaultLength()); - } - - public void testGetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - discriminatorColumn.setLength(Integer.valueOf(66)); - - assertEquals(Integer.valueOf(66), javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(Integer.valueOf(66), javaEntity().getDiscriminatorColumn().getLength()); - discriminatorColumn.setName(null); - discriminatorColumn.setLength(null); - - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - } - - public void testSetSpecifiedLength() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - javaEntity().getDiscriminatorColumn().setSpecifiedLength(Integer.valueOf(100)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation discriminatorColumn = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(100), discriminatorColumn.getLength()); - - javaEntity().getDiscriminatorColumn().setSpecifiedName(null); - javaEntity().getDiscriminatorColumn().setSpecifiedLength(null); - assertNull(typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN)); - } - - public void testGetLengthUpdatesFromResourceChange() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - - column.setLength(Integer.valueOf(78)); - assertEquals(Integer.valueOf(78), javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(Integer.valueOf(78), javaEntity().getDiscriminatorColumn().getLength()); - - column.setLength(null); - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedLength()); - assertEquals(DiscriminatorColumn.DEFAULT_LENGTH, javaEntity().getDiscriminatorColumn().getLength()); - } - - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDiscriminatorColumn().getColumnDefinition()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - - assertEquals(COLUMN_DEFINITION, javaEntity().getDiscriminatorColumn().getColumnDefinition()); - - column.setColumnDefinition(null); - - assertNull(javaEntity().getDiscriminatorColumn().getColumnDefinition()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithDiscriminatorColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().getDiscriminatorColumn().setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - javaEntity().getDiscriminatorColumn().setColumnDefinition(null); - column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNull(column.getColumnDefinition()); - } - -} 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 ef2c90d91e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddableTests.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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; - -public class JavaEmbeddableTests extends ContextModelTestCase -{ - - private void createEmbeddableAnnotation() throws Exception { - this.createAnnotationAndMembers("Embeddable", ""); - } - - private ICompilationUnit createTestEmbeddable() throws Exception { - createEmbeddableAnnotation(); - - 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); - - javaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof MappedSuperclass); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(EmbeddableAnnotation.ANNOTATION_NAME)); - } - - public void testEmbeddable() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(javaPersistentType().getMapping() instanceof Embeddable); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = embeddable.overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = embeddable.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().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) javaPersistentType().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) javaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTablesIncludingInherited().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().getMapping(); - - assertFalse(embeddable.associatedTableNamesIncludingInherited().hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestEmbeddable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Embeddable embeddable = (Embeddable) javaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = embeddable.overridableAttributeNames(); - assertFalse(overridableAttributeNames.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) javaPersistentType().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 60a012b8b7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedIdMappingTests.java +++ /dev/null @@ -1,605 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.persistence.ClassRef; -import org.eclipse.jpt.core.internal.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.JavaResourceNode; -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.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; - -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createEmbeddableAnnotation() throws Exception{ - this.createAnnotationAndMembers("Embeddable", ""); - } - - private void createEmbeddedIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("EmbeddedId", ""); - } - - private ICompilationUnit createTestEntityWithEmbeddedIdMapping() throws Exception { - createEntityAnnotation(); - createEmbeddedIdAnnotation(); - - 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 { - createEmbeddableAnnotation(); - 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 = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedIdMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - specifiedAttributeOverrides = embeddedIdMapping.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"); - specifiedAttributeOverrides = embeddedIdMapping.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.move(1, 0, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedIdMapping.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); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertEquals("myEmbeddedId", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, embeddedIdMapping.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = embeddedIdMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - - - ListIterator<ClassRef> classRefs = persistenceUnit().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"); - - assertEquals(2, embeddedIdMapping.virtualAttributeOverridesSize()); - defaultAttributeOverride = embeddedIdMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - defaultAttributeOverride = embeddedIdMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - assertEquals(1, embeddedIdMapping.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - assertEquals(0, embeddedIdMapping.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - - assertEquals(2, embeddedIdMapping.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - assertEquals(2, embeddedIdMapping.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - assertEquals(2, embeddedIdMapping.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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, embeddedIdMapping.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - assertEquals(1, embeddedIdMapping.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - assertEquals(0, embeddedIdMapping.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdMapping.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", embeddedIdMapping.virtualAttributeOverrides().next().getName()); - assertEquals(1, embeddedIdMapping.virtualAttributeOverridesSize()); - - embeddedIdMapping.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, embeddedIdMapping.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedIdMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - ListIterator<AttributeOverride> virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> 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); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) javaPersistentType().getAttributeNamed("myEmbeddedId").getMapping(); - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - attributeResource.move(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<JavaResourceNode> 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 b84f2f94e4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEmbeddedMappingTests.java +++ /dev/null @@ -1,653 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.persistence.ClassRef; -import org.eclipse.jpt.core.internal.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.JavaResourceNode; -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.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; - -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createEmbeddableAnnotation() throws Exception{ - this.createAnnotationAndMembers("Embeddable", ""); - } - - private void createEmbeddedAnnotation() throws Exception{ - this.createAnnotationAndMembers("Embedded", ""); - } - - private ICompilationUnit createTestEntityWithEmbeddedMapping() throws Exception { - createEntityAnnotation(); - createEmbeddedAnnotation(); - - 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 { - createEmbeddableAnnotation(); - 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 JavaEmbeddedMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertFalse(embeddedMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(((EmbeddedMapping) persistentAttribute.getMapping()).attributeOverrides().hasNext()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - assertNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testDefaultEmbeddedMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().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 = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - EmbeddedMapping embeddedMapping = (EmbeddedMapping) persistentAttribute.getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - specifiedAttributeOverrides = embeddedMapping.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"); - specifiedAttributeOverrides = embeddedMapping.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.move(1, 0, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedMapping.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); - specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = embeddedMapping.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) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, embeddedMapping.virtualAttributeOverridesSize()); - AttributeOverride defaultAttributeOverride = embeddedMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - - - ListIterator<ClassRef> classRefs = persistenceUnit().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"); - - assertEquals("myEmbedded", attributeResource.getName()); - assertNull(attributeResource.getAnnotation(AttributeOverrideAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(AttributeOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, embeddedMapping.virtualAttributeOverridesSize()); - defaultAttributeOverride = embeddedMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("FOO", defaultAttributeOverride.getColumn().getName()); - assertEquals("BAR", defaultAttributeOverride.getColumn().getTable()); - - cityMapping.getColumn().setSpecifiedName(null); - cityMapping.getColumn().setSpecifiedTable(null); - defaultAttributeOverride = embeddedMapping.virtualAttributeOverrides().next(); - assertEquals("city", defaultAttributeOverride.getName()); - assertEquals("city", defaultAttributeOverride.getColumn().getName()); - assertEquals(TYPE_NAME, defaultAttributeOverride.getColumn().getTable()); - - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("city"); - assertEquals(1, embeddedMapping.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - assertEquals(0, embeddedMapping.specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - - assertEquals(2, embeddedMapping.specifiedAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - assertEquals(2, embeddedMapping.attributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - - assertEquals(4, embeddedMapping.attributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - } - - public void testVirtualAttributeOverridesSize() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - assertEquals(2, embeddedMapping.virtualAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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, embeddedMapping.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("city"); - assertEquals(1, embeddedMapping.virtualAttributeOverridesSize()); - - attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("state"); - assertEquals(0, embeddedMapping.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("city", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedMapping.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("state", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertFalse(attributeOverrides.hasNext()); - - assertEquals("city", embeddedMapping.virtualAttributeOverrides().next().getName()); - assertEquals(1, embeddedMapping.virtualAttributeOverridesSize()); - - embeddedMapping.specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrides = attributeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrides.hasNext()); - - Iterator<AttributeOverride> virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - assertEquals("city", virtualAttributeOverrides.next().getName()); - assertEquals("state", virtualAttributeOverrides.next().getName()); - assertEquals(2, embeddedMapping.virtualAttributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual2() throws Exception { - createTestEntityWithEmbeddedMapping(); - createEmbeddableType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_EMBEDDABLE_TYPE_NAME); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - ListIterator<AttributeOverride> virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> 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) javaPersistentType().getAttributeNamed("myEmbedded").getMapping(); - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - attributeResource.move(1, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - - Iterator<JavaResourceNode> 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/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 c050e2bf64..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaEntityTests.java +++ /dev/null @@ -1,2960 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.AttributeOverride; -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.MappedSuperclass; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.PersistentAttribute; -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.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -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.JavaResourceNode; -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.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumns; -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; - -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 void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private void createMappedSuperclassAnnotation() throws Exception{ - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private void createTableAnnotation() throws Exception { - this.createAnnotationAndMembers("Table", "String name() default \"\";"); - } - - private void createInheritanceAnnotation() throws Exception { - createInheritanceTypeEnum(); - this.createAnnotationAndMembers("Inheritance", "InheritanceType strategy() default SINGLE_TABLE;"); - } - - private void createInheritanceTypeEnum() throws Exception { - this.createEnumAndMembers("InheritanceType", "SINGLE_TABLE, JOINED, TABLE_PER_CLASS"); - } - - private void createDiscriminatorValueAnnotation() throws Exception { - this.createAnnotationAndMembers("DiscriminatorValue", "String value();"); - } - - private void createSecondaryTableAnnotation() throws Exception { - this.createAnnotationAndMembers("SecondaryTable", - "String name(); " + - "String catalog() default \"\"; " + - "String schema() default \"\"; "); -// PrimaryKeyJoinColumn[] pkJoinColumns() default {}; -// UniqueConstraint[] uniqueConstraints() default {}; - } - - private void createSecondaryTablesAnnotation() throws Exception { - createSecondaryTableAnnotation(); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", - "String name(); " + - "String referencedColumnName() default \"\"; " + - "String columnDefinition() default \"\"; "); - } - - private void createPrimaryKeyJoinColumnsAnnotation() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - this.createAnnotationAndMembers("PrimaryKeyJoinColumns", "PrimaryKeyJoinColumn[] value();"); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 void createTestAbstractEntity() throws Exception { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - createIdAnnotation(); - - 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 { - createMappedSuperclassAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @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 { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - createTableAnnotation(); - - 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 { - createEntityAnnotation(); - createInheritanceAnnotation(); - - 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 { - createEntityAnnotation(); - createDiscriminatorValueAnnotation(); - - 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 { - createEntityAnnotation(); - createSecondaryTableAnnotation(); - - 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 { - createEntityAnnotation(); - createSecondaryTablesAnnotation(); - - 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\")})"); - } - }); - } - - public void testMorphToMappedSuperclass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) javaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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.addTableGenerator(); - entity.addSequenceGenerator(); - entity.setIdClass("myIdClass"); - entity.addNamedNativeQuery(0); - entity.addNamedQuery(0); - - javaPersistentType().setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof MappedSuperclass); - - assertNull(typeResource.getMappingAnnotation(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); - - Entity entity = (Entity) javaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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.addTableGenerator(); - entity.addSequenceGenerator(); - entity.setIdClass("myIdClass"); - entity.addNamedNativeQuery(0); - entity.addNamedQuery(0); - - javaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof Embeddable); - - assertNull(typeResource.getMappingAnnotation(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); - - Entity entity = (Entity) javaPersistentType().getMapping(); - entity.getTable().setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(0); - entity.addSpecifiedPrimaryKeyJoinColumn(0); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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.addTableGenerator(); - entity.addSequenceGenerator(); - entity.setIdClass("myIdClass"); - entity.addNamedNativeQuery(0); - entity.addNamedQuery(0); - - javaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - assertNull(typeResource.getMappingAnnotation(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, javaPersistentType().getAccess()); - } - - public void testAccessAnnotationsOnParent() 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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - JavaPersistentType childPersistentType = javaPersistentType(); - PersistentType parentPersistentType = childPersistentType.getParentPersistentType(); - - assertEquals(AccessType.PROPERTY, parentPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((IdMapping) parentPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.properties().next().setMappingAnnotation(null); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, parentPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - ((BasicMapping) parentPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - assertEquals(AccessType.FIELD, parentPersistentType.getAccess()); - assertEquals(AccessType.FIELD, childPersistentType.getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, parentPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - entityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, parentPersistentType.getAccess()); - assertEquals(AccessType.PROPERTY, childPersistentType.getAccess()); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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 = entityMappings().addOrmPersistentType(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - assertEquals(AccessType.PROPERTY, javaPersistentType().getAccess()); - - ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("FOO"); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.properties().next().setMappingAnnotation(null); - //no mapping(Id) annotation, but still a Column annotation, so access should still be property - assertEquals(AccessType.PROPERTY, javaPersistentType().getAccess()); - - ((BasicMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName(null); - assertEquals(AccessType.FIELD, javaPersistentType().getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType().getAccess()); - - entityMappings().setSpecifiedAccess(AccessType.FIELD); - //still accessType of PROPERTY because the java class is not specified in this orm.xml - assertEquals(AccessType.PROPERTY, javaPersistentType().getAccess()); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(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()); - - ((OrmEntity) ormPersistentType.getMapping()).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(javaEntity().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, javaEntity().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getDefaultName()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(ENTITY_NAME, javaEntity().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().setSpecifiedName("foo"); - - assertEquals("foo", javaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals("foo", ((EntityAnnotation) typeResource.getMappingAnnotation()).getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().setSpecifiedName(null); - - assertNull(javaEntity().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(((EntityAnnotation) typeResource.getMappingAnnotation()).getName()); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithName(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(); - entity.setName("foo"); - - assertEquals("foo", javaEntity().getSpecifiedName()); - } - - public void testGetTableName() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithName(); - - assertEquals(ENTITY_NAME, javaEntity().getTableName()); - } - - public void testGetTableName2() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getTableName()); - } - - public void testGetTableName3() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, javaEntity().getTableName()); - } - - public void testSetTableNameWithNullTable() throws Exception { - ICompilationUnit cu = createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - assertEquals(TYPE_NAME, table.getName()); - assertSourceDoesNotContain("@Table", cu); - - table.setSpecifiedName(TABLE_NAME); - assertSourceContains("@Table(name=\"" + TABLE_NAME + "\")", cu); - - assertEquals(TABLE_NAME, javaEntity().getTableName()); - 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, javaEntity().getInheritanceStrategy()); - } - - public void testGetDefaultInheritanceStrategy() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotSame(javaEntity(), javaEntity().getRootEntity()); - assertEquals(InheritanceType.SINGLE_TABLE, javaEntity().getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - javaEntity().getRootEntity().setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.SINGLE_TABLE, javaEntity().getRootEntity().getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, javaEntity().getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, javaEntity().getInheritanceStrategy()); - assertNull(javaEntity().getSpecifiedInheritanceStrategy()); - } - - public void testGetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(InheritanceType.TABLE_PER_CLASS, javaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(InheritanceAnnotation.ANNOTATION_NAME); - - inheritance.setStrategy(org.eclipse.jpt.core.resource.java.InheritanceType.JOINED); - - assertEquals(InheritanceType.JOINED, javaEntity().getSpecifiedInheritanceStrategy()); - - inheritance.setStrategy(null); - - assertNull(javaEntity().getSpecifiedInheritanceStrategy()); - } - - public void testSetSpecifiedInheritanceStrategy() throws Exception { - createTestEntityWithInheritance(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(InheritanceType.TABLE_PER_CLASS, javaEntity().getSpecifiedInheritanceStrategy()); - - javaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - assertEquals(InheritanceType.JOINED, javaEntity().getSpecifiedInheritanceStrategy()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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, javaEntity().getDiscriminatorValue()); - } - - public void testGetDefaultDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(javaEntity().getName(), javaEntity().getDefaultDiscriminatorValue()); - - javaEntity().getDiscriminatorColumn().setSpecifiedDiscriminatorType(DiscriminatorType.INTEGER); - assertNull(javaEntity().getDefaultDiscriminatorValue()); - } - - public void testGetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(DISCRIMINATOR_VALUE, javaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME); - - discriminatorValue.setValue("foo"); - - assertEquals("foo", javaEntity().getSpecifiedDiscriminatorValue()); - - discriminatorValue.setValue(null); - - assertNull(javaEntity().getSpecifiedDiscriminatorValue()); - assertNull(typeResource.getAnnotation(DiscriminatorValueAnnotation.ANNOTATION_NAME)); - } - - public void testSetSpecifiedDiscriminatorValue() throws Exception { - createTestEntityWithDiscriminatorValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertEquals(DISCRIMINATOR_VALUE, javaEntity().getSpecifiedDiscriminatorValue()); - - javaEntity().setSpecifiedDiscriminatorValue("foo"); - - assertEquals("foo", javaEntity().getSpecifiedDiscriminatorValue()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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 = javaEntity().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 = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - assertEquals(3, entity.secondaryTablesSize()); - } - - public void testSpecifiedSecondaryTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaSecondaryTable> specifiedSecondaryTables = javaEntity().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 = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - assertEquals(3, entity.specifiedSecondaryTablesSize()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaResourceNode> 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); - - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaResourceNode> 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 = javaEntity().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 = javaEntity().addSpecifiedSecondaryTable(1); - specifiedSecondaryTable2.setSpecifiedName("BAR"); - - - Iterator<SecondaryTable> secondaryTables = javaEntity().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); - - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - javaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME))); - - javaEntity().removeSpecifiedSecondaryTable(1); - - Iterator<JavaResourceNode> 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<SecondaryTable> secondaryTables = javaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - javaEntity().removeSpecifiedSecondaryTable(1); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTableResources.next()).getName()); - assertFalse(secondaryTableResources.hasNext()); - - secondaryTables = javaEntity().secondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - - javaEntity().removeSpecifiedSecondaryTable(0); - secondaryTableResources = typeResource.annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - assertFalse(secondaryTableResources.hasNext()); - secondaryTables = javaEntity().secondaryTables(); - assertFalse(secondaryTables.hasNext()); - - assertNull(typeResource.getAnnotation(SecondaryTablesAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - entity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - entity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - ListIterator<SecondaryTableAnnotation> 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", javaSecondaryTables.next().getName()); - assertEquals("BAZ", javaSecondaryTables.next().getName()); - assertEquals("FOO", 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", javaSecondaryTables.next().getName()); - assertEquals("BAR", javaSecondaryTables.next().getName()); - assertEquals("FOO", javaSecondaryTables.next().getName()); - } - - public void testUpdateSpecifiedSecondaryTables() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - ListIterator<SecondaryTable> secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.move(2, 0, SecondaryTablesAnnotation.ANNOTATION_NAME); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.move(0, 1, SecondaryTablesAnnotation.ANNOTATION_NAME); - 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); - 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); - secondaryTables = entity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - typeResource.removeAnnotation(0, SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); - secondaryTables = entity.specifiedSecondaryTables(); - assertFalse(secondaryTables.hasNext()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(javaEntity().associatedTables())); - Iterator<Table> associatedTables = javaEntity().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); - - Entity parentEntity = javaEntity().getRootEntity(); - assertEquals(3, CollectionTools.size(parentEntity.associatedTablesIncludingInherited())); - Iterator<Table> associatedTables = parentEntity.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()); - - Entity childEntity = javaEntity(); - //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); - - Entity parentEntity = javaEntity().getRootEntity(); - assertEquals(3, CollectionTools.size(parentEntity.associatedTableNamesIncludingInherited())); - Iterator<String> associatedTables = parentEntity.associatedTableNamesIncludingInherited(); - String table1 = associatedTables.next(); - String table2 = associatedTables.next(); - String table3 = associatedTables.next(); - assertEquals(TYPE_NAME, table1); - assertEquals("foo", table2); - assertEquals("bar", table3); - - Entity childEntity = javaEntity(); - //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 = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("FOO"); - - assertEquals(1, javaEntity().secondaryTablesSize()); - assertEquals("FOO", javaEntity().secondaryTables().next().getSpecifiedName()); - assertEquals("FOO", javaEntity().secondaryTables().next().getName()); - - SecondaryTableAnnotation secondaryTable2 = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable2.setName("BAR"); - - assertEquals(2, javaEntity().secondaryTablesSize()); - ListIterator<SecondaryTable> secondaryTables = javaEntity().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"); - - assertEquals(3, javaEntity().secondaryTablesSize()); - secondaryTables = javaEntity().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); - - javaEntity().addSpecifiedSecondaryTable(2).setSpecifiedName("baz"); - ListIterator<SecondaryTable> secondaryTables = javaEntity().secondaryTables(); - - assertEquals(3, javaEntity().secondaryTablesSize()); - assertEquals("foo", secondaryTables.next().getSpecifiedName()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = javaEntity().secondaryTables(); - assertEquals(2, javaEntity().secondaryTablesSize()); - assertEquals("bar", secondaryTables.next().getSpecifiedName()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = javaEntity().secondaryTables(); - assertEquals(1, javaEntity().secondaryTablesSize()); - assertEquals("baz", secondaryTables.next().getSpecifiedName()); - - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - secondaryTables = javaEntity().secondaryTables(); - assertEquals(0, javaEntity().secondaryTablesSize()); - assertFalse(secondaryTables.hasNext()); - } - - public void testGetSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getSequenceGenerator()); - assertEquals(0, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - - assertNotNull(javaEntity().getSequenceGenerator()); - assertEquals(1, typeResource.annotationsSize()); - assertEquals(1, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - - javaEntity().getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getSequenceGenerator()); - - javaEntity().addSequenceGenerator(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(javaEntity().getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - javaEntity().addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - - javaEntity().removeSequenceGenerator(); - - assertNull(javaEntity().getSequenceGenerator()); - assertNull(typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - javaEntity().removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getTableGenerator()); - assertEquals(0, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - - assertNotNull(javaEntity().getTableGenerator()); - assertEquals(1, typeResource.annotationsSize()); - assertEquals(1, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - - javaEntity().getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(javaEntity().getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getTableGenerator()); - - javaEntity().addTableGenerator(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(javaEntity().getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - javaEntity().addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.addAnnotation(JPA.TABLE_GENERATOR); - - javaEntity().removeTableGenerator(); - - assertNull(javaEntity().getTableGenerator()); - assertNull(typeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - javaEntity().removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetDiscriminatorColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(javaEntity().getDiscriminatorColumn()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.addAnnotation(JPA.DISCRIMINATOR_COLUMN); - column.setName("foo"); - - assertEquals("foo", javaEntity().getDiscriminatorColumn().getSpecifiedName()); - - column.setName(null); - - assertNull(javaEntity().getDiscriminatorColumn().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(javaEntity().getDiscriminatorColumn()); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - specifiedPkJoinColumns = javaEntity().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"); - specifiedPkJoinColumns = javaEntity().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"); - specifiedPkJoinColumns = javaEntity().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.move(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - specifiedPkJoinColumns = javaEntity().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); - specifiedPkJoinColumns = javaEntity().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); - specifiedPkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - - typeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - specifiedPkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, javaEntity().specifiedPrimaryKeyJoinColumnsSize()); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, javaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - //just the default pkJoinColumn, so 1 - assertEquals(1, javaEntity().primaryKeyJoinColumnsSize()); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, javaEntity().primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaResourceNode> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.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); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - Iterator<JavaResourceNode> pkJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.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); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - javaEntity().addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, CollectionTools.size(typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME))); - - javaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator<JavaResourceNode> pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator<PrimaryKeyJoinColumn> pkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - javaEntity().removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumnResources.next()).getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - javaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = javaEntity().specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertNull(typeResource.getAnnotation(PrimaryKeyJoinColumns.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - entity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - entity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - ListIterator<PrimaryKeyJoinColumnAnnotation> javaPrimaryKeyJoinColumns = typeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.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, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("BAR", javaPrimaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", javaPrimaryKeyJoinColumns.next().getName()); - assertEquals("FOO", 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, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("BAZ", javaPrimaryKeyJoinColumns.next().getName()); - assertEquals("BAR", javaPrimaryKeyJoinColumns.next().getName()); - assertEquals("FOO", javaPrimaryKeyJoinColumns.next().getName()); - } - - public void testUpdateSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) typeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("BAZ"); - - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.move(2, 0, PrimaryKeyJoinColumns.ANNOTATION_NAME); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.move(0, 1, PrimaryKeyJoinColumns.ANNOTATION_NAME); - 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, PrimaryKeyJoinColumns.ANNOTATION_NAME); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - typeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - primaryKeyJoinColumns = entity.specifiedPrimaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(javaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual()); - - javaEntity().addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertFalse(javaEntity().tableNameIsInvalid(TYPE_NAME)); - assertTrue(javaEntity().tableNameIsInvalid("FOO")); - - javaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - - assertFalse(javaEntity().tableNameIsInvalid("BAR")); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = (Entity) javaPersistentType().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<PersistentAttribute> overridableAttributes = javaEntity().overridableAttributes(); - assertFalse(overridableAttributes.hasNext()); - } - - public void testOverridableAttributeNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = javaEntity().overridableAttributeNames(); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testAllOverridableAttributes() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<PersistentAttribute> overridableAttributes = javaEntity().allOverridableAttributes(); - assertEquals("id", overridableAttributes.next().getName()); - assertEquals("name", overridableAttributes.next().getName()); - assertEquals("foo", overridableAttributes.next().getName()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributesMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<PersistentAttribute> overridableAttributes = javaEntity().allOverridableAttributes(); - assertEquals("id", overridableAttributes.next().getName()); - assertEquals("name", overridableAttributes.next().getName()); - assertEquals("foo", overridableAttributes.next().getName()); - assertFalse(overridableAttributes.hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAttributeNames = javaEntity().allOverridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertEquals("foo", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaAttributeOverride> specifiedAttributeOverrides = javaEntity().specifiedAttributeOverrides(); - - assertFalse(specifiedAttributeOverrides.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - specifiedAttributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertEquals("FOO", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - specifiedAttributeOverrides = javaEntity().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"); - specifiedAttributeOverrides = javaEntity().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.move(1, 0, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = javaEntity().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); - specifiedAttributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertEquals("BAZ", specifiedAttributeOverrides.next().getName()); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertEquals("BAR", specifiedAttributeOverrides.next().getName()); - assertFalse(specifiedAttributeOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - specifiedAttributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertFalse(specifiedAttributeOverrides.hasNext()); - } - - public void testDefaultAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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, javaEntity.virtualAttributeOverridesSize()); - AttributeOverride virtualAttributeOverride = javaEntity.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - BasicMapping idMapping = (BasicMapping) mappedSuperclass.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, javaEntity.virtualAttributeOverridesSize()); - virtualAttributeOverride = javaEntity.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 = javaEntity.virtualAttributeOverrides().next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertEquals("id", virtualAttributeOverride.getColumn().getName()); - assertEquals(SUB_TYPE_NAME, virtualAttributeOverride.getColumn().getTable()); - - virtualAttributeOverride = virtualAttributeOverride.setVirtual(false); - assertEquals(2, javaEntity.virtualAttributeOverridesSize()); - } - - public void testSpecifiedAttributeOverridesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, javaEntity().specifiedAttributeOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - assertEquals(2, javaEntity().specifiedAttributeOverridesSize()); - } - - public void testDefaultAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity javaEntity = javaEntity(); - - assertEquals(3, javaEntity.virtualAttributeOverridesSize()); - - javaEntity.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(2, javaEntity.virtualAttributeOverridesSize()); - - javaEntity.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(1, javaEntity.virtualAttributeOverridesSize()); - - javaEntity.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(0, javaEntity.virtualAttributeOverridesSize()); - } - - public void testAttributeOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity javaEntity = javaEntity(); - - assertEquals(3, javaEntity.attributeOverridesSize()); - - javaEntity.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(3, javaEntity.attributeOverridesSize()); - - javaEntity.virtualAttributeOverrides().next().setVirtual(false); - assertEquals(3, javaEntity.attributeOverridesSize()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - AttributeOverrideAnnotation annotation = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - annotation.setName("bar"); - assertEquals(4, javaEntity.attributeOverridesSize()); - } - - public void testAttributeOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<JavaResourceNode> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("id", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("name", ((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); - - ListIterator<JavaAttributeOverride> virtualAttributeOverrides = javaEntity().virtualAttributeOverrides(); - virtualAttributeOverrides.next(); - virtualAttributeOverrides.next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<JavaResourceNode> attributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("id", ((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); - - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(3, CollectionTools.size(typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME))); - - javaEntity().specifiedAttributeOverrides().next().setVirtual(true); - - Iterator<JavaResourceNode> attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - Iterator<AttributeOverride> attributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - javaEntity().specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", ((AttributeOverrideAnnotation) attributeOverrideResources.next()).getName()); - assertFalse(attributeOverrideResources.hasNext()); - - attributeOverrides = javaEntity().specifiedAttributeOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - - javaEntity().specifiedAttributeOverrides().next().setVirtual(true); - attributeOverrideResources = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertFalse(attributeOverrideResources.hasNext()); - attributeOverrides = javaEntity().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); - - Entity entity = javaEntity(); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<AttributeOverrideAnnotation> javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaAttributeOverrides)); - - - entity.moveSpecifiedAttributeOverride(2, 0); - ListIterator<AttributeOverride> attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("name", javaAttributeOverrides.next().getName()); - assertEquals("foo", javaAttributeOverrides.next().getName()); - assertEquals("id", javaAttributeOverrides.next().getName()); - - - entity.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("foo", attributeOverrides.next().getName()); - assertEquals("name", attributeOverrides.next().getName()); - assertEquals("id", attributeOverrides.next().getName()); - - javaAttributeOverrides = typeResource.annotations(AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - assertEquals("foo", javaAttributeOverrides.next().getName()); - assertEquals("name", javaAttributeOverrides.next().getName()); - assertEquals("id", javaAttributeOverrides.next().getName()); - } -// - public void testUpdateSpecifiedAttributeOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - ListIterator<AttributeOverride> attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.move(2, 0, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.move(0, 1, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverrides = entity.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); - attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(1, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverrides = entity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - typeResource.removeAnnotation(0, AttributeOverrideAnnotation.ANNOTATION_NAME, AttributeOverridesAnnotation.ANNOTATION_NAME); - attributeOverrides = entity.specifiedAttributeOverrides(); - assertFalse(attributeOverrides.hasNext()); - } - - public void testAttributeOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<AttributeOverride> virtualAttributeOverrides = javaEntity().virtualAttributeOverrides(); - AttributeOverride virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - - javaEntity().virtualAttributeOverrides().next().setVirtual(false); - AttributeOverride specifiedAttributeOverride = javaEntity().specifiedAttributeOverrides().next(); - assertFalse(specifiedAttributeOverride.isVirtual()); - - - virtualAttributeOverrides = javaEntity().virtualAttributeOverrides(); - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - - virtualAttributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", virtualAttributeOverride.getName()); - assertTrue(virtualAttributeOverride.isVirtual()); - assertFalse(virtualAttributeOverrides.hasNext()); - } - - - public void testOverridableAssociations() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<PersistentAttribute> overridableAssociations = javaEntity().overridableAssociations(); - assertFalse(overridableAssociations.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = javaEntity().overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - -// //TODO add all mapping types to the mapped superclass to test which ones are overridable - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<String> overridableAssociationNames = javaEntity().allOverridableAssociationNames(); - assertEquals("address", overridableAssociationNames.next()); - assertEquals("address2", overridableAssociationNames.next()); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAllOverridableAssociations() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<PersistentAttribute> overridableAssociations = javaEntity().allOverridableAssociations(); - assertEquals("address", overridableAssociations.next().getName()); - assertEquals("address2", overridableAssociations.next().getName()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testAllOverridableAssociationsMappedSuperclassInOrmXml() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - Iterator<PersistentAttribute> overridableAssociations = javaEntity().allOverridableAssociations(); - assertEquals("address", overridableAssociations.next().getName()); - assertEquals("address2", overridableAssociations.next().getName()); - assertFalse(overridableAssociations.hasNext()); - } - - public void testSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaAssociationOverride> specifiedAssociationOverrides = javaEntity().specifiedAssociationOverrides(); - - assertFalse(specifiedAssociationOverrides.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - specifiedAssociationOverrides = javaEntity().specifiedAssociationOverrides(); - assertEquals("FOO", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - specifiedAssociationOverrides = javaEntity().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"); - specifiedAssociationOverrides = javaEntity().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.move(1, 0, JPA.ASSOCIATION_OVERRIDES); - specifiedAssociationOverrides = javaEntity().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); - specifiedAssociationOverrides = javaEntity().specifiedAssociationOverrides(); - assertEquals("BAZ", specifiedAssociationOverrides.next().getName()); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - specifiedAssociationOverrides = javaEntity().specifiedAssociationOverrides(); - assertEquals("BAR", specifiedAssociationOverrides.next().getName()); - assertFalse(specifiedAssociationOverrides.hasNext()); - - - typeResource.removeAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - specifiedAssociationOverrides = javaEntity().specifiedAssociationOverrides(); - assertFalse(specifiedAssociationOverrides.hasNext()); - } - - public void testDefaultAssociationOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - JavaEntity javaEntity = (JavaEntity) classRefs.next().getJavaPersistentType().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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, javaEntity.virtualAssociationOverridesSize()); - AssociationOverride virtualAssociationOverride = javaEntity.virtualAssociationOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - - //MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - //BasicMapping idMapping = (BasicMapping) mappedSuperclass.persistentType().attributeNamed("id").getMapping(); - //idMapping.getColumn().setSpecifiedName("FOO"); - //idMapping.getColumn().setSpecifiedTable("BAR"); - - assertEquals(SUB_TYPE_NAME, typeResource.getName()); - assertNull(typeResource.getAnnotation(AssociationOverrideAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(AssociationOverridesAnnotation.ANNOTATION_NAME)); - - assertEquals(2, javaEntity.virtualAssociationOverridesSize()); - virtualAssociationOverride = javaEntity.virtualAssociationOverrides().next(); - assertEquals("address", virtualAssociationOverride.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 = javaEntity.virtualAssociationOverrides().next(); - assertEquals("address", virtualAssociationOverride.getName()); - - virtualAssociationOverride = virtualAssociationOverride.setVirtual(false); - assertEquals(1, javaEntity.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); - - assertEquals(0, javaEntity().specifiedAssociationOverridesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - assertEquals(2, javaEntity().specifiedAssociationOverridesSize()); - } - - public void testDefaultAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity javaEntity = javaEntity(); - - assertEquals(2, javaEntity.virtualAssociationOverridesSize()); - - javaEntity.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(1, javaEntity.virtualAssociationOverridesSize()); - - javaEntity.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(0, javaEntity.virtualAssociationOverridesSize()); - } - - public void testAssociationOverridesSize() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity javaEntity = javaEntity(); - - assertEquals(2, javaEntity.associationOverridesSize()); - - javaEntity.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, javaEntity.associationOverridesSize()); - - javaEntity.virtualAssociationOverrides().next().setVirtual(false); - assertEquals(2, javaEntity.associationOverridesSize()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - AssociationOverrideAnnotation annotation = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - annotation.setName("bar"); - assertEquals(3, javaEntity.associationOverridesSize()); - } - - public void testAssociationOverrideSetVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_SUB_TYPE_NAME); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<JavaResourceNode> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address2", ((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); - - ListIterator<JavaAssociationOverride> virtualAssociationOverrides = javaEntity().virtualAssociationOverrides(); - virtualAssociationOverrides.next(); - virtualAssociationOverrides.next().setVirtual(false); - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - Iterator<JavaResourceNode> associationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("address", ((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); - - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - assertEquals(2, CollectionTools.size(typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME))); - - javaEntity().specifiedAssociationOverrides().next().setVirtual(true); - - Iterator<JavaResourceNode> associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", ((AssociationOverrideAnnotation) associationOverrideResources.next()).getName()); - assertFalse(associationOverrideResources.hasNext()); - - Iterator<AssociationOverride> associationOverrides = javaEntity().specifiedAssociationOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - - javaEntity().specifiedAssociationOverrides().next().setVirtual(true); - associationOverrideResources = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertFalse(associationOverrideResources.hasNext()); - associationOverrides = javaEntity().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); - - Entity entity = javaEntity(); - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_SUB_TYPE_NAME); - - ListIterator<AssociationOverrideAnnotation> javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals(2, CollectionTools.size(javaAssociationOverrides)); - - - entity.moveSpecifiedAssociationOverride(1, 0); - ListIterator<AssociationOverride> associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("address2", associationOverrides.next().getName()); - assertEquals("address", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address2", javaAssociationOverrides.next().getName()); - assertEquals("address", javaAssociationOverrides.next().getName()); - - - entity.moveSpecifiedAssociationOverride(0, 1); - associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("address", associationOverrides.next().getName()); - assertEquals("address2", associationOverrides.next().getName()); - - javaAssociationOverrides = typeResource.annotations(AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - assertEquals("address", javaAssociationOverrides.next().getName()); - assertEquals("address2", javaAssociationOverrides.next().getName()); - } - - public void testUpdateSpecifiedAssociationOverrides() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(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"); - - ListIterator<AssociationOverride> associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.move(2, 0, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.move(0, 1, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverrides = entity.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); - associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(1, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverrides = entity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - typeResource.removeAnnotation(0, AssociationOverrideAnnotation.ANNOTATION_NAME, AssociationOverridesAnnotation.ANNOTATION_NAME); - associationOverrides = entity.specifiedAssociationOverrides(); - assertFalse(associationOverrides.hasNext()); - } - - public void testAssociationOverrideIsVirtual() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<AssociationOverride> virtualAssociationOverrides = javaEntity().virtualAssociationOverrides(); - AssociationOverride virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - - javaEntity().virtualAssociationOverrides().next().setVirtual(false); - AssociationOverride specifiedAssociationOverride = javaEntity().specifiedAssociationOverrides().next(); - assertFalse(specifiedAssociationOverride.isVirtual()); - - - virtualAssociationOverrides = javaEntity().virtualAssociationOverrides(); - virtualAssociationOverride = virtualAssociationOverrides.next(); - assertEquals("address2", virtualAssociationOverride.getName()); - assertTrue(virtualAssociationOverride.isVirtual()); - assertFalse(virtualAssociationOverrides.hasNext()); - } - - public void testAddNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - NamedQuery namedQuery = entity.addNamedQuery(0); - namedQuery.setName("FOO"); - - ListIterator<NamedQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", javaNamedQueries.next().getName()); - - NamedQuery namedQuery2 = entity.addNamedQuery(0); - namedQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - NamedQuery namedQuery3 = entity.addNamedQuery(1); - namedQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - ListIterator<NamedQuery> namedQueries = entity.namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = entity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - entity.addNamedNativeQuery(0).setName("foo"); - } - - public void testRemoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedQuery(0).setName("FOO"); - entity.addNamedQuery(1).setName("BAR"); - entity.addNamedQuery(2).setName("BAZ"); - - ListIterator<NamedQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.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", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - - entity.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", javaNamedQueries.next().getName()); - - entity.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); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedQuery(0).setName("FOO"); - - - NamedNativeQueryAnnotation nativeQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - nativeQuery.setName("BAR"); - - assertEquals(1, entity.namedNativeQueriesSize()); - assertEquals("BAR", entity.namedNativeQueries().next().getName()); - } - - public void testAddNamedQueryWithNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedNativeQuery(0).setName("FOO"); - - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - - assertEquals(1, entity.namedQueriesSize()); - assertEquals("BAR", entity.namedQueries().next().getName()); - } - - public void testMoveNamedQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedQuery(0).setName("FOO"); - entity.addNamedQuery(1).setName("BAR"); - entity.addNamedQuery(2).setName("BAZ"); - - ListIterator<NamedQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.moveNamedQuery(2, 0); - ListIterator<NamedQuery> namedQueries = entity.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", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - - entity.moveNamedQuery(0, 1); - namedQueries = entity.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", javaNamedQueries.next().getName()); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - } - - public void testUpdateNamedQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - ((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"); - ListIterator<NamedQuery> namedQueries = entity.namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.move(2, 0, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.move(0, 1, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.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); - namedQueries = entity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.removeAnnotation(1, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.removeAnnotation(0, NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - } - - public void testNamedQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.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"); - - assertEquals(3, entity.namedQueriesSize()); - } - - public void testAddNamedNativeQuery() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - NamedNativeQuery namedNativeQuery = entity.addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - ListIterator<NamedNativeQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("FOO", javaNamedQueries.next().getName()); - - NamedNativeQuery namedNativeQuery2 = entity.addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - NamedNativeQuery namedNativeQuery3 = entity.addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - ListIterator<NamedNativeQuery> namedQueries = entity.namedNativeQueries(); - assertEquals(namedNativeQuery2, namedQueries.next()); - assertEquals(namedNativeQuery3, namedQueries.next()); - assertEquals(namedNativeQuery, namedQueries.next()); - - namedQueries = entity.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); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedNativeQuery(0).setName("FOO"); - entity.addNamedNativeQuery(1).setName("BAR"); - entity.addNamedNativeQuery(2).setName("BAZ"); - - ListIterator<NamedNativeQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - entity.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", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - - entity.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", javaNamedQueries.next().getName()); - - entity.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); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - entity.addNamedNativeQuery(0).setName("FOO"); - entity.addNamedNativeQuery(1).setName("BAR"); - entity.addNamedNativeQuery(2).setName("BAZ"); - - ListIterator<NamedNativeQueryAnnotation> javaNamedQueries = typeResource.annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaNamedQueries)); - - - entity.moveNamedNativeQuery(2, 0); - ListIterator<NamedNativeQuery> namedQueries = entity.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", javaNamedQueries.next().getName()); - assertEquals("BAZ", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - - - entity.moveNamedNativeQuery(0, 1); - namedQueries = entity.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", javaNamedQueries.next().getName()); - assertEquals("BAR", javaNamedQueries.next().getName()); - assertEquals("FOO", javaNamedQueries.next().getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - ((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"); - ListIterator<NamedNativeQuery> namedQueries = entity.namedNativeQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.move(2, 0, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedNativeQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - typeResource.move(0, 1, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.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); - namedQueries = entity.namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.removeAnnotation(1, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedNativeQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - - typeResource.removeAnnotation(0, NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); - namedQueries = entity.namedNativeQueries(); - assertFalse(namedQueries.hasNext()); - assertEquals(0, CollectionTools.size(entity.getPersistenceUnit().allQueries())); - } - - public void testNamedNativeQueriesSize() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, entity.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"); - - assertEquals(3, entity.namedNativeQueriesSize()); - } - - public void testUpdateIdClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - assertNull(javaEntity().getIdClass()); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - idClass.setValue("model.Foo"); - assertEquals("model.Foo", javaEntity().getIdClass()); - assertEquals("model.Foo", ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClass.setValue(null); - assertNull(javaEntity().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - //reset @IdClass value and then remove @IdClass - idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClass.setValue("model.Foo"); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - - assertNull(javaEntity().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testModifyIdClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - javaEntity().setIdClass("model.Foo"); - assertEquals("model.Foo", ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals("model.Foo", javaEntity().getIdClass()); - - javaEntity().setIdClass(null); - assertNull(javaEntity().getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Iterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - JavaPersistentType entityPersistentType = classRefs.next().getJavaPersistentType(); - JavaEntity javaEntity = (JavaEntity) entityPersistentType.getMapping(); - JavaPersistentType mappedSuperclassPersistentType = classRefs.next().getJavaPersistentType(); - - assertNull(javaEntity.getPrimaryKeyColumnName()); - - mappedSuperclassPersistentType.getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("id", javaEntity.getPrimaryKeyColumnName()); - - ((JavaIdMapping) mappedSuperclassPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", javaEntity.getPrimaryKeyColumnName()); - - JavaAttributeOverride javaAttributeOverride = javaEntity.virtualAttributeOverrides().next(); - assertEquals("id", javaAttributeOverride.getName()); - - javaAttributeOverride = (JavaAttributeOverride) javaAttributeOverride.setVirtual(false); - javaAttributeOverride.getColumn().setSpecifiedName("ID"); - assertEquals("ID", javaEntity.getPrimaryKeyColumnName()); - } - - public void testDiscriminatorValueIsAllowedConcreteClass() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(javaEntity().isDiscriminatorValueAllowed()); - } - - public void testDiscriminatorValueIsAllowedAbstractClass() throws Exception { - createTestAbstractEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertFalse(javaEntity().isDiscriminatorValueAllowed()); - } -} 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 21e03ea446..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaGeneratedValueTests.java +++ /dev/null @@ -1,160 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createGeneratedValueAnnotation() throws Exception{ - this.createAnnotationAndMembers("GeneratedValue", - "GenerationType strategy() default;" + - "String generator() default \"\"; "); - } - - private ICompilationUnit createTestEntityWithGeneratedValue() throws Exception { - createEntityAnnotation(); - createGeneratedValueAnnotation(); - - 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) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setGenerator("foo"); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - } - - public void testSetSpecifiedGenerator() throws Exception { - createTestEntityWithGeneratedValue(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator("foo"); - - assertEquals("foo", idMapping.getGeneratedValue().getGenerator()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GENERATOR, idMapping.getGeneratedValue().getGenerator()); - - idMapping.getGeneratedValue().setSpecifiedGenerator(null); - - assertNotNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - - generatedValue.setStrategy(org.eclipse.jpt.core.resource.java.GenerationType.IDENTITY); - - 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) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(GeneratedValue.DEFAULT_STRATEGY, idMapping.getGeneratedValue().getStrategy()); - - idMapping.getGeneratedValue().setSpecifiedStrategy(GenerationType.IDENTITY); - - assertEquals(GenerationType.IDENTITY, idMapping.getGeneratedValue().getStrategy()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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 ed11c86c69..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaIdMappingTests.java +++ /dev/null @@ -1,729 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.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.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaIdMappingTests extends ContextModelTestCase -{ - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("Id", ""); - } - - private void createGeneratedValueAnnotation() throws Exception{ - this.createAnnotationAndMembers("GeneratedValue", ""); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private ICompilationUnit createTestEntityWithIdMapping() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 { - createEntityAnnotation(); - createTemporalAnnotation(); - - 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 { - createEntityAnnotation(); - createIdAnnotation(); - createGeneratedValueAnnotation(); - - 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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((BasicMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((BasicMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((VersionMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((VersionMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - idMapping.addGeneratedValue(); - idMapping.addTableGenerator(); - idMapping.addSequenceGenerator(); - assertFalse(idMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(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 { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getTemporal()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(TemporalType.TIMESTAMP, idMapping.getTemporal()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getTemporal()); - - idMapping.setTemporal(TemporalType.TIME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - idMapping.setTemporal(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getTemporal()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - - assertEquals(TemporalType.DATE, idMapping.getTemporal()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertNull(idMapping.getTemporal()); - assertFalse(idMapping.isDefault()); - assertSame(idMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getColumn().getSpecifiedName()); - assertEquals("id", idMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - - 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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - assertNotNull(idMapping.getSequenceGenerator()); - assertEquals(1, attributeResource.annotationsSize()); - assertEquals(1, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - - idMapping.getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getSequenceGenerator()); - - idMapping.addSequenceGenerator(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - assertNotNull(idMapping.getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - idMapping.addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.SEQUENCE_GENERATOR); - - - idMapping.removeSequenceGenerator(); - - assertNull(idMapping.getSequenceGenerator()); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - - //try removing the sequence generator again, should get an IllegalStateException - try { - idMapping.removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(idMapping.getTableGenerator()); - assertEquals(0, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - assertNotNull(idMapping.getTableGenerator()); - assertEquals(1, attributeResource.annotationsSize()); - assertEquals(1, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - - idMapping.getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(idMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getTableGenerator()); - - idMapping.addTableGenerator(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - assertNotNull(idMapping.getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - idMapping.addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.TABLE_GENERATOR); - - - idMapping.removeTableGenerator(); - - assertNull(idMapping.getTableGenerator()); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - - //try removing the table generator again, should get an IllegalStateException - try { - idMapping.removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testGetGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(1, attributeResource.annotationsSize()); - } - - public void testGetGeneratedValue2() throws Exception { - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - createTestEntityWithIdMappingGeneratedValue(); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNotNull(idMapping.getGeneratedValue()); - assertEquals(1, attributeResource.annotationsSize()); - } - - public void testAddGeneratedValue() throws Exception { - createTestEntityWithIdMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(idMapping.getGeneratedValue()); - - idMapping.addGeneratedValue(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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 = javaPersistentType().attributes().next(); - IdMapping idMapping = (IdMapping) persistentAttribute.getSpecifiedMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.addAnnotation(JPA.GENERATED_VALUE); - - - 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 8e3b989d04..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinColumnTests.java +++ /dev/null @@ -1,540 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - ******************************************************************************/ -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.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 void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createOneToOneAnnotation() throws Exception{ - this.createAnnotationAndMembers("OneToOne", ""); - } - - private void createJoinColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\"; " + - "String referencedColumnName() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\";"); - } - - - private ICompilationUnit createTestEntityWithOneToOne() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - createJoinColumnAnnotation(); - - 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 { - createEntityAnnotation(); - createOneToOneAnnotation(); - createJoinColumnAnnotation(); - - 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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.specifiedJoinColumnsSize()); - assertNull(javaJoinColumn); - - - //set name in the resource model, verify context model updated - javaJoinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - javaJoinColumn.setName("FOO"); - JavaJoinColumn joinColumn = oneToOneMapping.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); - assertEquals(0, oneToOneMapping.specifiedJoinColumnsSize()); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - JavaJoinColumn defaultJavaJoinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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"); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("BAR", javaJoinColumn.getReferencedColumnName()); - - //set referenced column name to null in the resource model, - javaJoinColumn.setReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull("BAR", javaJoinColumn.getReferencedColumnName()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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"); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals("BAR", joinColumn.getSpecifiedTable()); - assertEquals("BAR", javaJoinColumn.getTable()); - - //set table to null in the resource model, - javaJoinColumn.setTable(null); - assertNull(joinColumn.getSpecifiedTable()); - assertNull("BAR", javaJoinColumn.getTable()); - } - - public void testModifyTable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals(Boolean.TRUE, joinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, javaJoinColumn.getUnique()); - - //set unique to null in the resource model, - javaJoinColumn.setUnique(null); - assertNull(joinColumn.getSpecifiedUnique()); - assertNull(javaJoinColumn.getUnique()); - } - - public void testModifyUnique() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getNullable()); - - //set nullable to null in the resource model, - javaJoinColumn.setNullable(null); - assertNull(joinColumn.getSpecifiedNullable()); - assertNull(javaJoinColumn.getNullable()); - } - - public void testModifyNullable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getInsertable()); - - //set insertable to null in the resource model, - javaJoinColumn.setInsertable(null); - assertNull(joinColumn.getSpecifiedInsertable()); - assertNull(javaJoinColumn.getInsertable()); - } - - public void testModifyInsertable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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) javaPersistentType().attributes().next().getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinColumnAnnotation javaJoinColumn = (JoinColumnAnnotation) attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME); - - assertEquals(0, oneToOneMapping.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); - JavaJoinColumn joinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertEquals(Boolean.FALSE, joinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, javaJoinColumn.getUpdatable()); - - //set updatable to null in the resource model, - javaJoinColumn.setUpdatable(null); - assertNull(joinColumn.getSpecifiedUpdatable()); - assertNull(javaJoinColumn.getUpdatable()); - } - - public void testModifyUpdatable() throws Exception { - createTestEntityWithOneToOne(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaOneToOneMapping oneToOneMapping = (JavaOneToOneMapping) javaPersistentType().attributes().next().getMapping(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JavaJoinColumn joinColumn = oneToOneMapping.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()); - } -}
\ No newline at end of file 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 f2776c5b33..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaJoinTableTests.java +++ /dev/null @@ -1,999 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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; - -public class JavaJoinTableTests extends ContextModelTestCase -{ - public JavaJoinTableTests(String name) { - super(name); - } - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createManyToManyAnnotation() throws Exception{ - this.createAnnotationAndMembers("ManyToMany", ""); - } - - private void createJoinTableAnnotation() throws Exception{ - //TODO - this.createAnnotationAndMembers("JoinTable", - "String name() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";"); - } - - private void createUniqueConstraintAnnotation() throws Exception{ - this.createAnnotationAndMembers("UniqueConstraint", - "String[] columnNames(); "); - } - - private ICompilationUnit createTestEntityWithManyToMany() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - createJoinTableAnnotation(); - - 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 { - createEntityAnnotation(); - createManyToManyAnnotation(); - createJoinTableAnnotation(); - - 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); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Project.java", sourceWriter); - } - public void testUpdateSpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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"); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - //set name to null in the resource model - javaJoinTable.setName(null); - assertNull(joinTable.getSpecifiedName()); - assertNull(javaJoinTable.getName()); - - javaJoinTable.setName("FOO"); - assertEquals("FOO", joinTable.getSpecifiedName()); - assertEquals("FOO", javaJoinTable.getName()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTable.getSpecifiedName()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedName() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().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) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - //joinTable default name is null because targetEntity is not in the persistence unit - assertNull(joinTable.getDefaultName()); - - //add target entity to the persistence unit, now join table name is [table name]_[target table name] - createTargetEntity(); - addXmlClassRef(PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.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(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(TYPE_NAME + "_Project", joinTable.getDefaultName()); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.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 testUpdateSpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable); - - - //set schema in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setSchema("FOO"); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - //set schema to null in the resource model - javaJoinTable.setSchema(null); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable.getSchema()); - - javaJoinTable.setSchema("FOO"); - assertEquals("FOO", joinTable.getSpecifiedSchema()); - assertEquals("FOO", javaJoinTable.getSchema()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedSchema() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedSchema()); - assertNull(javaJoinTable); - - //set schema in the context model, verify resource model modified - joinTable.setSpecifiedSchema("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedSchema()); - assertEquals("foo", javaJoinTable.getSchema()); - - //set schema to null in the context model - joinTable.setSpecifiedSchema(null); - assertNull(joinTable.getSpecifiedSchema()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable); - - - //set catalog in the resource model, verify context model updated - attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - javaJoinTable.setCatalog("FOO"); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - //set catalog to null in the resource model - javaJoinTable.setCatalog(null); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable.getCatalog()); - - javaJoinTable.setCatalog("FOO"); - assertEquals("FOO", joinTable.getSpecifiedCatalog()); - assertEquals("FOO", javaJoinTable.getCatalog()); - - attributeResource.removeAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testModifySpecifiedCatalog() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(javaJoinTable); - - //set catalog in the context model, verify resource model modified - joinTable.setSpecifiedCatalog("foo"); - javaJoinTable = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals("foo", joinTable.getSpecifiedCatalog()); - assertEquals("foo", javaJoinTable.getCatalog()); - - //set catalog to null in the context model - joinTable.setSpecifiedCatalog(null); - assertNull(joinTable.getSpecifiedCatalog()); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.joinColumnAt(0).getName()); - - JoinColumn joinColumn2 = joinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(1).getName()); - - JoinColumn joinColumn3 = joinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.joinColumnsSize()); - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.joinColumnsSize()); - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.joinColumnsSize()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - joinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.joinColumnsSize()); - - - joinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - - - joinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.joinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.joinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.joinColumnAt(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addJoinColumn(0); - joinTableResource.addJoinColumn(1); - joinTableResource.addJoinColumn(2); - - joinTableResource.joinColumnAt(0).setName("FOO"); - joinTableResource.joinColumnAt(1).setName("BAR"); - joinTableResource.joinColumnAt(2).setName("BAZ"); - - ListIterator<JoinColumn> joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(2, 0); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.moveJoinColumn(0, 1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(1); - joinColumns = joinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.removeJoinColumn(0); - assertFalse(joinTable.specifiedJoinColumns().hasNext()); - } - - public void testGetDefaultJoinColumn() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.specifiedJoinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTable.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - joinTable.addSpecifiedJoinColumn(0); - assertEquals(2, joinTable.joinColumnsSize()); - - joinTable.removeSpecifiedJoinColumn(0); - joinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTable.joinColumnsSize()); - - //if non-owning side of the relationship then no default join column - manyToManyMapping.setMappedBy("foo"); - assertEquals(0, joinTable.joinColumnsSize()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - - JoinColumn inverseJoinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("FOO"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(0).getName()); - - JoinColumn inverseJoinColumn2 = joinTable.addSpecifiedInverseJoinColumn(0); - inverseJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(1).getName()); - - JoinColumn inverseJoinColumn3 = joinTable.addSpecifiedInverseJoinColumn(1); - inverseJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals(inverseJoinColumn2, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn3, inverseJoinColumns.next()); - assertEquals(inverseJoinColumn, inverseJoinColumns.next()); - - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.inverseJoinColumnsSize()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.inverseJoinColumnsSize()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - joinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - joinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - joinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - assertEquals(3, joinTableResource.inverseJoinColumnsSize()); - - - joinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - - - joinTable.moveSpecifiedInverseJoinColumn(0, 1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.inverseJoinColumnAt(0).getName()); - assertEquals("BAR", joinTableResource.inverseJoinColumnAt(1).getName()); - assertEquals("FOO", joinTableResource.inverseJoinColumnAt(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - JoinTableAnnotation joinTableResource = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableResource.addInverseJoinColumn(0); - joinTableResource.addInverseJoinColumn(1); - joinTableResource.addInverseJoinColumn(2); - - joinTableResource.inverseJoinColumnAt(0).setName("FOO"); - joinTableResource.inverseJoinColumnAt(1).setName("BAR"); - joinTableResource.inverseJoinColumnAt(2).setName("BAZ"); - - ListIterator<JoinColumn> inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(2, 0); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.moveInverseJoinColumn(0, 1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(1); - inverseJoinColumns = joinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - joinTableResource.removeInverseJoinColumn(0); - assertFalse(joinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testGetDefaultInverseJoinColumn() { - //TODO - } - - public void testSpecifiedInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.specifiedInverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTable.specifiedInverseJoinColumnsSize()); - } - - public void testInverseJoinColumnsSize() throws Exception { - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaManyToManyMapping manyToManyMapping = (JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping(); - JoinTable joinTable = manyToManyMapping.getJoinTable(); - - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - joinTable.addSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTable.inverseJoinColumnsSize()); - - joinTable.removeSpecifiedInverseJoinColumn(0); - joinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTable.inverseJoinColumnsSize()); - - //if non-owning side of the relationship then no default join column - manyToManyMapping.setMappedBy("foo"); - assertEquals(0, joinTable.inverseJoinColumnsSize()); - } - - public void testUniqueConstraints() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - - assertEquals(0, joinTable.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - assertEquals(2, joinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = joinTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - joinTable.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - joinTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - joinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - joinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - joinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - assertEquals(3, joinTableAnnotation.uniqueConstraintsSize()); - - - joinTable.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - joinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = joinTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithManyToMany(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JoinTable joinTable = ((JavaManyToManyMapping) javaPersistentType().attributes().next().getMapping()).getJoinTable(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - JoinTableAnnotation joinTableAnnotation = (JoinTableAnnotation) attributeResource.addAnnotation(JoinTableAnnotation.ANNOTATION_NAME); - - joinTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - joinTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - joinTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - - - ListIterator<UniqueConstraint> uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(2, 0); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.moveUniqueConstraint(0, 1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = joinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableAnnotation.removeUniqueConstraint(0); - uniqueConstraints = joinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java deleted file mode 100644 index 961c029b3c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToManyMappingTests.java +++ /dev/null @@ -1,922 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -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.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -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.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -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; - -public class JavaManyToManyMappingTests extends ContextModelTestCase -{ - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createManyToManyAnnotation() throws Exception{ - this.createAnnotationAndMembers("ManyToMany", ""); - } - - private void createTestTargetEntityAddress() 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("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToManyMapping() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - - 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").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToManyMapping() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithCollectionManyToManyMapping() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionManyToManyMapping() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaManyToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - manyToManyMapping.setOrderBy("asdf"); - manyToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(manyToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the resource model - manyToMany.setTargetEntity(null); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - manyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(manyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - - //set fetch to null in the resource model - manyToMany.setFetch(null); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, manyToMany.getFetch()); - - manyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, manyToMany.getFetch()); - - - //set fetch to null in the context model - manyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyMapping.getSpecifiedFetch()); - assertNull(manyToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", manyToManyMapping.getMappedBy()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedBy to null in the resource model - manyToMany.setMappedBy(null); - assertNull(manyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.setMappedBy("newTargetEntity"); - assertEquals("newTargetEntity", manyToManyMapping.getMappedBy()); - assertEquals("newTargetEntity", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - manyToManyMapping.setMappedBy(null); - assertNull(manyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = manyToManyMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = manyToManyMapping.candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = manyToManyMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertNull(manyToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToManyMapping.getTargetEntity()); - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - - - manyToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(manyToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - assertEquals("myMapKey", manyToManyMapping.getMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - assertNull(manyToManyMapping.getMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(manyToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - manyToManyMapping.setMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", manyToManyMapping.getMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - manyToManyMapping.setMapKey(null); - assertNull(manyToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(manyToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertEquals("newOrderBy", manyToManyMapping.getOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertNull(manyToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(manyToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - manyToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", manyToManyMapping.getOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - manyToManyMapping.setOrderBy(null); - assertNull(manyToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertTrue(manyToManyMapping.isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertFalse(manyToManyMapping.isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertTrue(manyToManyMapping.isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyNoOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertTrue(manyToManyMapping.isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - -// manyToManyMapping.setNoOrdering(false); //this does nothing -// //set mappedBy in the context model, verify resource model updated -// manyToManyMapping.setOrderBy("newOrderBy"); -// assertEquals("newOrderBy", manyToManyMapping.getOrderBy()); -// OrderBy orderBy = (OrderBy) attributeResource.annotation(OrderBy.ANNOTATION_NAME); -// assertEquals("newOrderBy", orderBy.getValue()); -// -// //set mappedBy to null in the context model -// manyToManyMapping.setOrderBy(null); -// assertNull(manyToManyMapping.getOrderBy()); -// assertNull(attributeResource.annotation(OrderBy.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertFalse(manyToManyMapping.isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertTrue(manyToManyMapping.isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertFalse(manyToManyMapping.isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithManyToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertFalse(manyToManyMapping.isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertTrue(manyToManyMapping.isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(manyToManyMapping.isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java deleted file mode 100644 index a78ffeb2d5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaManyToOneMappingTests.java +++ /dev/null @@ -1,904 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.BasicMapping; -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.JoinColumn; -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.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -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.JavaResourceNode; -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.resource.java.JoinColumnsAnnotation; -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.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.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaManyToOneMappingTests extends ContextModelTestCase -{ - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createManyToOneAnnotation() throws Exception{ - this.createAnnotationAndMembers("ManyToOne", ""); - } - - private void createTestTargetEntityAddress() 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("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithManyToOneMapping() throws Exception { - createEntityAnnotation(); - createManyToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidManyToOneMapping() throws Exception { - createEntityAnnotation(); - createManyToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionManyToOneMapping() throws Exception { - createEntityAnnotation(); - createManyToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionManyToOneMapping() throws Exception { - createEntityAnnotation(); - createManyToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne").append(CR); - sb.append(" private Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaManyToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - manyToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(manyToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - manyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", manyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - manyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(manyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOne.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - - //set optional to null in the resource model - manyToOne.setOptional(null); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - - //set optional in the context model, verify resource model updated - manyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - - //set optional to null in the context model - manyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOne.getOptional()); - } - - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - ListIterator<JavaJoinColumn> specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.move(1, 0, JPA.JOIN_COLUMNS); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertEquals(0, manyToOneMapping.specifiedJoinColumnsSize()); - - manyToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(1, manyToOneMapping.specifiedJoinColumnsSize()); - - manyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, manyToOneMapping.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertEquals(1, manyToOneMapping.joinColumnsSize()); - - manyToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(1, manyToOneMapping.joinColumnsSize()); - - manyToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(2, manyToOneMapping.joinColumnsSize()); - - manyToOneMapping.removeSpecifiedJoinColumn(0); - manyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, manyToOneMapping.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - manyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - manyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - manyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - manyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - manyToOneMapping.removeSpecifiedJoinColumn(1); - - Iterator<JavaResourceNode> joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<JoinColumn> joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - manyToOneMapping.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - manyToOneMapping.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertFalse(joinColumns.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - manyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - manyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - manyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ListIterator<JoinColumnAnnotation> javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - manyToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<JoinColumn> primaryKeyJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - - - manyToOneMapping.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - ListIterator<JoinColumn> joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = manyToOneMapping.specifiedJoinColumns(); - assertFalse(joinColumns.hasNext()); - } - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertTrue(manyToOneMapping.getDefaultJoinColumn().isVirtual()); - - manyToOneMapping.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = manyToOneMapping.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isVirtual()); - - assertNull(manyToOneMapping.getDefaultJoinColumn()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertNull(manyToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", manyToOneMapping.getTargetEntity()); - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", manyToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidManyToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - ManyToOneMapping manyToOneMapping = (ManyToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - manyToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - - - manyToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, manyToOneMapping.getResolvedTargetEntity()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java deleted file mode 100644 index 66897d2c86..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaMappedSuperclassTests.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaMappedSuperclassTests extends ContextModelTestCase -{ - - private void createMappedSuperclassAnnotation() throws Exception { - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - createMappedSuperclassAnnotation(); - - 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"); - } - }); - } - - - public JavaMappedSuperclassTests(String name) { - super(name); - } - - public void testMorphToEntity() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - mappedSuperclass.setIdClass("myIdClass"); - - javaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof Entity); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddable() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - mappedSuperclass.setIdClass("myIdClass"); - - javaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof Embeddable); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToNull() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - mappedSuperclass.setIdClass("myIdClass"); - - javaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertTrue(javaPersistentType().getMapping() instanceof JavaNullTypeMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation(MappedSuperclassAnnotation.ANNOTATION_NAME)); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - - public void testMappedSuperclass() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - assertTrue(javaPersistentType().getMapping() instanceof MappedSuperclass); - } - - public void testOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - public void testOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testTableNameIsInvalid() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.tableNameIsInvalid(FULLY_QUALIFIED_TYPE_NAME)); - assertFalse(mappedSuperclass.tableNameIsInvalid("FOO")); - } - - public void testAssociatedTables() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTables().hasNext()); - } - - public void testAssociatedTablesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTablesIncludingInherited().hasNext()); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertFalse(mappedSuperclass.associatedTableNamesIncludingInherited().hasNext()); - } - - public void testAllOverridableAttributeNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - Iterator<String> overridableAttributeNames = mappedSuperclass.overridableAttributeNames(); - assertEquals("id", overridableAttributeNames.next()); - assertEquals("name", overridableAttributeNames.next()); - assertFalse(overridableAttributeNames.hasNext()); - } - - //TODO need to create a subclass mappedSuperclass and test this - public void testAllOverridableAssociationNames() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - Iterator<String> overridableAssociationNames = mappedSuperclass.overridableAssociationNames(); - assertFalse(overridableAssociationNames.hasNext()); - } - - public void testAttributeMappingKeyAllowed() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - assertTrue(mappedSuperclass.attributeMappingKeyAllowed(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY)); - } - - public void testUpdateIdClass() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertNull(mappedSuperclass.getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - assertNull(mappedSuperclass.getIdClass()); - assertNotNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - idClass.setValue("model.Foo"); - assertEquals("model.Foo", mappedSuperclass.getIdClass()); - assertEquals("model.Foo", ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - - //test setting @IdClass value to null, IdClass annotation is removed - idClass.setValue(null); - assertNull(mappedSuperclass.getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - //reset @IdClass value and then remove @IdClass - idClass = (IdClassAnnotation) typeResource.addAnnotation(IdClassAnnotation.ANNOTATION_NAME); - idClass.setValue("model.Foo"); - typeResource.removeAnnotation(IdClassAnnotation.ANNOTATION_NAME); - - assertNull(mappedSuperclass.getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - - public void testModifyIdClass() throws Exception { - createTestMappedSuperclass(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - MappedSuperclass mappedSuperclass = (MappedSuperclass) javaPersistentType().getMapping(); - - assertNull(mappedSuperclass.getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - - mappedSuperclass.setIdClass("model.Foo"); - assertEquals("model.Foo", ((IdClassAnnotation) typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)).getValue()); - assertEquals("model.Foo", mappedSuperclass.getIdClass()); - - mappedSuperclass.setIdClass(null); - assertNull(mappedSuperclass.getIdClass()); - assertNull(typeResource.getAnnotation(IdClassAnnotation.ANNOTATION_NAME)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java deleted file mode 100644 index 15c0b0067d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedNativeQueryTests.java +++ /dev/null @@ -1,447 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.IType; -import org.eclipse.jpt.core.context.Entity; -import org.eclipse.jpt.core.context.NamedNativeQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaNamedNativeQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createNamedNativeQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedNativeQuery", - "String name();" + - "String query();" + - "QueryHint[] hints() default {};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", - "String name();" + - "String value();"); - } - - private ICompilationUnit createTestEntityWithNamedNativeQuery() throws Exception { - createEntityAnnotation(); - createNamedNativeQueryAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedNativeQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedNativeQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the resource model - javaNamedNativeQuery.setName(null); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setName("foo"); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedNativeQuery.getName()); - assertEquals(QUERY_NAME, namedNativeQuery.getName()); - - //set name to null in the context model - namedNativeQuery.setName(null); - assertNull(javaNamedNativeQuery.getName()); - assertNull(namedNativeQuery.getName()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setName("foo"); - assertEquals("foo", javaNamedNativeQuery.getName()); - assertEquals("foo", namedNativeQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the resource model - javaNamedNativeQuery.setQuery(null); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setQuery("foo"); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedNativeQuery.getQuery()); - assertEquals(QUERY_QUERY, namedNativeQuery.getQuery()); - - //set name to null in the context model - namedNativeQuery.setQuery(null); - assertNull(javaNamedNativeQuery.getQuery()); - assertNull(namedNativeQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setQuery("foo"); - assertEquals("foo", javaNamedNativeQuery.getQuery()); - assertEquals("foo", namedNativeQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedNativeQuery.addHint(0); - ormResource().save(null); - queryHint.setName("FOO"); - ormResource().save(null); - - assertEquals("FOO", javaNamedNativeQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedNativeQuery.addHint(0); - ormResource().save(null); - queryHint2.setName("BAR"); - ormResource().save(null); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedNativeQuery.addHint(1); - ormResource().save(null); - queryHint3.setName("BAZ"); - ormResource().save(null); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - namedNativeQuery.removeHint(0); - assertEquals(2, javaNamedNativeQuery.hintsSize()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(1, javaNamedNativeQuery.hintsSize()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - - namedNativeQuery.removeHint(0); - assertEquals(0, javaNamedNativeQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - namedNativeQuery.addHint(0).setName("FOO"); - namedNativeQuery.addHint(1).setName("BAR"); - namedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedNativeQuery.hintsSize()); - - - namedNativeQuery.moveHint(2, 0); - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - - - namedNativeQuery.moveHint(0, 1); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedNativeQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedNativeQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedNativeQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - javaNamedNativeQuery.addHint(0); - javaNamedNativeQuery.addHint(1); - javaNamedNativeQuery.addHint(2); - - javaNamedNativeQuery.hintAt(0).setName("FOO"); - javaNamedNativeQuery.hintAt(1).setName("BAR"); - javaNamedNativeQuery.hintAt(2).setName("BAZ"); - - ListIterator<QueryHint> hints = namedNativeQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.moveHint(2, 0); - hints = namedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.moveHint(0, 1); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(1); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(1); - hints = namedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedNativeQuery.removeHint(0); - assertFalse(namedNativeQuery.hints().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - assertEquals(0, namedNativeQuery.hintsSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - - javaNamedNativeQuery.addHint(0); - assertEquals(1, namedNativeQuery.hintsSize()); - - javaNamedNativeQuery.addHint(0); - assertEquals(2, namedNativeQuery.hintsSize()); - - javaNamedNativeQuery.removeHint(0); - javaNamedNativeQuery.removeHint(0); - assertEquals(0, namedNativeQuery.hintsSize()); - } - - public void testUpdateResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setResultClass("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the resource model - javaNamedNativeQuery.setResultClass(null); - assertNull(javaNamedNativeQuery.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultClass()); - assertEquals(null, namedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultClass("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultClass()); - assertEquals("foo", namedNativeQuery.getResultClass()); - - //set name to null in the context model - namedNativeQuery.setResultClass(null); - assertNull(javaNamedNativeQuery.getResultClass()); - assertNull(namedNativeQuery.getResultClass()); - } - - public void testUpdateResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - javaNamedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - javaNamedNativeQuery.setResultSetMapping(null); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - createTestEntityWithNamedNativeQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedNativeQuery namedNativeQuery = entity.namedNativeQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedNativeQueryAnnotation javaNamedNativeQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(NamedNativeQueryAnnotation.ANNOTATION_NAME); - - assertEquals(null, javaNamedNativeQuery.getResultSetMapping()); - assertEquals(null, namedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - namedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", javaNamedNativeQuery.getResultSetMapping()); - assertEquals("foo", namedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - namedNativeQuery.setResultSetMapping(null); - assertNull(javaNamedNativeQuery.getResultSetMapping()); - assertNull(namedNativeQuery.getResultSetMapping()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java deleted file mode 100644 index 00bfbaf4b0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaNamedQueryTests.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.Entity; -import org.eclipse.jpt.core.context.NamedQuery; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaNamedQueryTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - private static final String QUERY_QUERY = "MY_QUERY"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createNamedQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedQuery", - "String name();" + - "String query();" + - "QueryHint[] hints() default {};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", - "String name();" + - "String value();"); - } - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - createEntityAnnotation(); - createNamedQueryAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", query=\"" + QUERY_QUERY + "\")"); - } - }); - } - - - - public JavaNamedQueryTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the resource model - javaNamedQuery.setName(null); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setName("foo"); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_NAME, javaNamedQuery.getName()); - assertEquals(QUERY_NAME, namedQuery.getName()); - - //set name to null in the context model - namedQuery.setName(null); - assertNull(javaNamedQuery.getName()); - assertNull(namedQuery.getName()); - - //set name in the context model, verify resource model updated - namedQuery.setName("foo"); - assertEquals("foo", javaNamedQuery.getName()); - assertEquals("foo", namedQuery.getName()); - } - - public void testUpdateQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the resource model - javaNamedQuery.setQuery(null); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the resource model, verify context model updated - javaNamedQuery.setQuery("foo"); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - public void testModifyQuery() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - assertEquals(QUERY_QUERY, javaNamedQuery.getQuery()); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - //set name to null in the context model - namedQuery.setQuery(null); - assertNull(javaNamedQuery.getQuery()); - assertNull(namedQuery.getQuery()); - - //set name in the context model, verify resource model updated - namedQuery.setQuery("foo"); - assertEquals("foo", javaNamedQuery.getQuery()); - assertEquals("foo", namedQuery.getQuery()); - } - - - public void testAddHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - QueryHint queryHint = namedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", javaNamedQuery.hintAt(0).getName()); - - QueryHint queryHint2 = namedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(1).getName()); - - QueryHint queryHint3 = namedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals(queryHint2, hints.next()); - assertEquals(queryHint3, hints.next()); - assertEquals(queryHint, hints.next()); - - hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - } - - public void testRemoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - namedQuery.removeHint(0); - assertEquals(2, javaNamedQuery.hintsSize()); - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - - namedQuery.removeHint(0); - assertEquals(1, javaNamedQuery.hintsSize()); - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - - namedQuery.removeHint(0); - assertEquals(0, javaNamedQuery.hintsSize()); - } - - public void testMoveHint() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1).setName("BAR"); - namedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, javaNamedQuery.hintsSize()); - - - namedQuery.moveHint(2, 0); - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAZ", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - - - namedQuery.moveHint(0, 1); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", javaNamedQuery.hintAt(0).getName()); - assertEquals("BAR", javaNamedQuery.hintAt(1).getName()); - assertEquals("FOO", javaNamedQuery.hintAt(2).getName()); - } - - public void testUpdateHints() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - NamedQuery namedQuery = entity.namedQueries().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - javaNamedQuery.addHint(0); - javaNamedQuery.addHint(1); - javaNamedQuery.addHint(2); - - javaNamedQuery.hintAt(0).setName("FOO"); - javaNamedQuery.hintAt(1).setName("BAR"); - javaNamedQuery.hintAt(2).setName("BAZ"); - - ListIterator<QueryHint> hints = namedQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.moveHint(2, 0); - hints = namedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.moveHint(0, 1); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(1); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(1); - hints = namedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - javaNamedQuery.removeHint(0); - assertFalse(namedQuery.hints().hasNext()); - } - - public void testHintsSize() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Entity entity = javaEntity(); - - NamedQuery namedQuery = entity.namedQueries().next(); - assertEquals(0, namedQuery.hintsSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - NamedQueryAnnotation javaNamedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME); - - - javaNamedQuery.addHint(0); - assertEquals(1, namedQuery.hintsSize()); - - javaNamedQuery.addHint(0); - assertEquals(2, namedQuery.hintsSize()); - - javaNamedQuery.removeHint(0); - javaNamedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java deleted file mode 100644 index 9f35bad1aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToManyMappingTests.java +++ /dev/null @@ -1,898 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -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.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -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.JoinTableAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToManyAnnotation; -import org.eclipse.jpt.core.resource.java.ManyToOneAnnotation; -import org.eclipse.jpt.core.resource.java.MapKeyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.resource.java.OneToOneAnnotation; -import org.eclipse.jpt.core.resource.java.OrderByAnnotation; -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; - -public class JavaOneToManyMappingTests extends ContextModelTestCase -{ - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createOneToManyAnnotation() throws Exception{ - this.createAnnotationAndMembers("OneToMany", ""); - } - - private void createTestTargetEntityAddress() 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("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - private ICompilationUnit createTestEntityWithOneToManyMapping() throws Exception { - createEntityAnnotation(); - createOneToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToManyMapping() throws Exception { - createEntityAnnotation(); - createOneToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection<Address> addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToManyMapping() throws Exception { - createEntityAnnotation(); - createOneToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Collection addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonCollectionOneToManyMapping() throws Exception { - createEntityAnnotation(); - createOneToManyAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToMany").append(CR); - sb.append(" private Address addresses;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - - public JavaOneToManyMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - oneToManyMapping.setOrderBy("asdf"); - oneToManyMapping.getJoinTable().setSpecifiedName("FOO"); - assertFalse(oneToManyMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinTableAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the resource model - oneToMany.setTargetEntity(null); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - oneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(oneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - - //set fetch to null in the resource model - oneToMany.setFetch(null); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToMany.getFetch()); - - oneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToMany.getFetch()); - - - //set fetch to null in the context model - oneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyMapping.getSpecifiedFetch()); - assertNull(oneToMany.getFetch()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", oneToManyMapping.getMappedBy()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the resource model - oneToMany.setMappedBy(null); - assertNull(oneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.setMappedBy("newTargetEntity"); - assertEquals("newTargetEntity", oneToManyMapping.getMappedBy()); - assertEquals("newTargetEntity", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - oneToManyMapping.setMappedBy(null); - assertNull(oneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = oneToManyMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - attributeNames = oneToManyMapping.candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - attributeNames = oneToManyMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityNonCollectionType() throws Exception { - createTestEntityWithNonCollectionOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertNull(oneToManyMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToManyMapping.getTargetEntity()); - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToManyMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToManyMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - - - oneToManyMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToManyMapping.getResolvedTargetEntity()); - } - - - public void testUpdateMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(oneToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the resource model, verify context model does not change - attributeResource.addAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getMapKey()); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNotNull(mapKey); - - //set mapKey name in the resource model, verify context model updated - mapKey.setName("myMapKey"); - assertEquals("myMapKey", oneToManyMapping.getMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey name to null in the resource model - mapKey.setName(null); - assertNull(oneToManyMapping.getMapKey()); - assertNull(mapKey.getName()); - - mapKey.setName("myMapKey"); - attributeResource.removeAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testModifyMapKey() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(oneToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - - //set mapKey in the context model, verify resource model updated - oneToManyMapping.setMapKey("myMapKey"); - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME); - assertEquals("myMapKey", oneToManyMapping.getMapKey()); - assertEquals("myMapKey", mapKey.getName()); - - //set mapKey to null in the context model - oneToManyMapping.setMapKey(null); - assertNull(oneToManyMapping.getMapKey()); - assertNull(attributeResource.getAnnotation(MapKeyAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(oneToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertEquals("newOrderBy", oneToManyMapping.getOrderBy()); - assertEquals("newOrderBy", orderBy.getValue()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertNull(oneToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testModifyOrderBy() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertNull(oneToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set mappedBy in the context model, verify resource model updated - oneToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", oneToManyMapping.getOrderBy()); - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertEquals("newOrderBy", orderBy.getValue()); - - //set mappedBy to null in the context model - oneToManyMapping.setOrderBy(null); - assertNull(oneToManyMapping.getOrderBy()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateNoOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertTrue(oneToManyMapping.isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isNoOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertFalse(oneToManyMapping.isNoOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertTrue(oneToManyMapping.isNoOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdatePkOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertFalse(oneToManyMapping.isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertTrue(oneToManyMapping.isPkOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertFalse(oneToManyMapping.isPkOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isPkOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } - - public void testUpdateCustomOrdering() throws Exception { - createTestEntityWithOneToManyMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToManyMapping oneToManyMapping = (OneToManyMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertFalse(oneToManyMapping.isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - - //set orderBy in the resource model, verify context model updated - attributeResource.addAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isCustomOrdering()); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME); - orderBy.setValue("newOrderBy"); - assertTrue(oneToManyMapping.isCustomOrdering()); - - //set orderBy to null in the resource model - attributeResource.removeAnnotation(OrderByAnnotation.ANNOTATION_NAME); - assertFalse(oneToManyMapping.isCustomOrdering()); - assertNull(attributeResource.getAnnotation(OrderByAnnotation.ANNOTATION_NAME)); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java deleted file mode 100644 index 43ecc37ba9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaOneToOneMappingTests.java +++ /dev/null @@ -1,1310 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -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.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaPersistentType; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.persistence.ClassRef; -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.JavaResourceNode; -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.resource.java.JoinColumnsAnnotation; -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.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumns; -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.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaOneToOneMappingTests extends ContextModelTestCase -{ - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createOneToOneAnnotation() throws Exception{ - this.createAnnotationAndMembers("OneToOne", ""); - } - - private void createTestTargetEntityAddress() 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("@Entity"); - sb.append(CR); - sb.append("public class ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - - private ICompilationUnit createTestEntityWithOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - - 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); - } - }); - } - - private ICompilationUnit createTestEntityWithValidOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithCollectionOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithGenericizedCollectionOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.ID, "java.util.Collection"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne").append(CR); - sb.append(" private Collection<Address> address;").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - } - }); - } - - public JavaOneToOneMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertNull(persistentAttribute.getSpecifiedMapping()); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - oneToOneMapping.addSpecifiedJoinColumn(0); - assertFalse(oneToOneMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(JoinColumnAnnotation.ANNOTATION_NAME)); - } - - - public void testUpdateSpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the resource model - oneToOne.setTargetEntity(null); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - oneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - oneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(oneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", oneToOneMapping.getMappedBy()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - assertNull(oneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - oneToOneMapping.setMappedBy("newTargetEntity"); - assertEquals("newTargetEntity", oneToOneMapping.getMappedBy()); - assertEquals("newTargetEntity", oneToOne.getMappedBy()); - - //set mappedBy to null in the context model - oneToOneMapping.setMappedBy(null); - assertNull(oneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOne.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the resource model - oneToOne.setOptional(null); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - - //set optional in the context model, verify resource model updated - oneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - - //set optional to null in the context model - oneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOne.getOptional()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(org.eclipse.jpt.core.resource.java.FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - - //set fetch to null in the resource model - oneToOne.setFetch(null); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(); - - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - - //set fetch in the context model, verify resource model updated - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(FetchType.EAGER, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.EAGER, oneToOne.getFetch()); - - oneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.java.FetchType.LAZY, oneToOne.getFetch()); - - - //set fetch to null in the context model - oneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOne.getFetch()); - } - - public void testSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - ListIterator<JavaJoinColumn> specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - - assertFalse(specifiedJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - //add an annotation to the resource model and verify the context model is updated - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAR"); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.move(1, 0, JPA.JOIN_COLUMNS); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", specifiedJoinColumns.next().getName()); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", specifiedJoinColumns.next().getName()); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", specifiedJoinColumns.next().getName()); - assertFalse(specifiedJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - specifiedJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertFalse(specifiedJoinColumns.hasNext()); - } - - public void testGetDefaultJoin() { - //TODO - } - - public void testSpecifiedJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(0, oneToOneMapping.specifiedJoinColumnsSize()); - - oneToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(1, oneToOneMapping.specifiedJoinColumnsSize()); - - oneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, oneToOneMapping.specifiedJoinColumnsSize()); - } - - public void testJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(1, oneToOneMapping.joinColumnsSize()); - - oneToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(1, oneToOneMapping.joinColumnsSize()); - - oneToOneMapping.addSpecifiedJoinColumn(0); - assertEquals(2, oneToOneMapping.joinColumnsSize()); - - oneToOneMapping.removeSpecifiedJoinColumn(0); - oneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, oneToOneMapping.joinColumnsSize()); - - //if non-owning side of the relationship then no default join column - oneToOneMapping.setMappedBy("foo"); - assertEquals(0, oneToOneMapping.joinColumnsSize()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("BAR"); - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testAddSpecifiedJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - public void testRemoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME))); - - oneToOneMapping.removeSpecifiedJoinColumn(1); - - Iterator<JavaResourceNode> joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<JoinColumn> joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - oneToOneMapping.removeSpecifiedJoinColumn(1); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - oneToOneMapping.removeSpecifiedJoinColumn(0); - joinColumnResources = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertFalse(joinColumns.hasNext()); - - assertNull(attributeResource.getAnnotation(JoinColumnsAnnotation.ANNOTATION_NAME)); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ListIterator<JoinColumnAnnotation> javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - oneToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<JoinColumn> primaryKeyJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - - - oneToOneMapping.moveSpecifiedJoinColumn(0, 1); - primaryKeyJoinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - } - - public void testUpdateSpecifiedJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ((JoinColumnAnnotation) attributeResource.addAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("FOO"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAR"); - ((JoinColumnAnnotation) attributeResource.addAnnotation(2, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME)).setName("BAZ"); - - ListIterator<JoinColumn> joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(2, 0, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(0, 1, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); - joinColumns = oneToOneMapping.specifiedJoinColumns(); - assertFalse(joinColumns.hasNext()); - } - - public void testJoinColumnIsVirtual() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertTrue(oneToOneMapping.getDefaultJoinColumn().isVirtual()); - - oneToOneMapping.addSpecifiedJoinColumn(0); - JoinColumn specifiedJoinColumn = oneToOneMapping.specifiedJoinColumns().next(); - assertFalse(specifiedJoinColumn.isVirtual()); - - assertNull(oneToOneMapping.getDefaultJoinColumn()); - } - - public void testCandidateMappedByAttributeNames() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - Iterator<String> attributeNames = oneToOneMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - attributeNames = oneToOneMapping.candidateMappedByAttributeNames(); - assertFalse(attributeNames.hasNext()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - attributeNames = oneToOneMapping.candidateMappedByAttributeNames(); - assertEquals("id", attributeNames.next()); - assertEquals("city", attributeNames.next()); - assertEquals("state", attributeNames.next()); - assertEquals("zip", attributeNames.next()); - assertFalse(attributeNames.hasNext()); - } - - public void testDefaultTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit, default still set, handled by validation - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //add targetEntity to the persistence unit - addXmlClassRef(PACKAGE_NAME + ".Address"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - JavaPersistentType addressPersistentType = addressClassRef.getJavaPersistentType(); - - //test target is not an Entity, default target entity still exists, this case handled with validation - addressPersistentType.setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityCollectionType() throws Exception { - createTestEntityWithCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testDefaultTargetEntityGenericizedCollectionType() throws Exception { - createTestEntityWithGenericizedCollectionOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".Address"); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertNull(oneToOneMapping.getDefaultTargetEntity()); - } - - public void testTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - createTestTargetEntityAddress(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertEquals("foo", oneToOneMapping.getTargetEntity()); - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(PACKAGE_NAME + ".Address", oneToOneMapping.getTargetEntity()); - } - - public void testResolvedTargetEntity() throws Exception { - createTestEntityWithValidOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - //targetEntity not in the persistence unit - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - //add targetEntity to the persistence unit, now target entity should resolve - createTestTargetEntityAddress(); - addXmlClassRef(PACKAGE_NAME + ".Address"); - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - classRefs.next(); - ClassRef addressClassRef = classRefs.next(); - TypeMapping addressTypeMapping = addressClassRef.getJavaPersistentType().getMapping(); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - //test default still the same when specified target entity it set - oneToOneMapping.setSpecifiedTargetEntity("foo"); - assertNull(oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(PACKAGE_NAME + ".Address"); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - - - oneToOneMapping.setSpecifiedTargetEntity(null); - assertEquals(addressTypeMapping, oneToOneMapping.getResolvedTargetEntity()); - } - - public void testPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - ListIterator<JavaPrimaryKeyJoinColumn> primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - - assertFalse(primaryKeyJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAR"); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - //move an annotation to the resource model and verify the context model is updated - attributeResource.move(1, 0, JPA.PRIMARY_KEY_JOIN_COLUMNS); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - - attributeResource.removeAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertFalse(primaryKeyJoinColumns.hasNext()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - assertEquals(0, oneToOneMapping.primaryKeyJoinColumnsSize()); - - oneToOneMapping.addPrimaryKeyJoinColumn(0); - assertEquals(1, oneToOneMapping.primaryKeyJoinColumnsSize()); - - oneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(0, oneToOneMapping.primaryKeyJoinColumnsSize()); - } - - public void testAddPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testAddPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumns.next()).getName()); - assertFalse(joinColumns.hasNext()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - - assertEquals(3, CollectionTools.size(attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME))); - - oneToOneMapping.removePrimaryKeyJoinColumn(1); - - Iterator<JavaResourceNode> joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - Iterator<PrimaryKeyJoinColumn> joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - oneToOneMapping.removePrimaryKeyJoinColumn(1); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) joinColumnResources.next()).getName()); - assertFalse(joinColumnResources.hasNext()); - - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - - oneToOneMapping.removePrimaryKeyJoinColumn(0); - joinColumnResources = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertFalse(joinColumnResources.hasNext()); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - - assertNull(attributeResource.getAnnotation(PrimaryKeyJoinColumns.ANNOTATION_NAME)); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - - oneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - oneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - oneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ListIterator<PrimaryKeyJoinColumnAnnotation> javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals(3, CollectionTools.size(javaJoinColumns)); - - - oneToOneMapping.movePrimaryKeyJoinColumn(2, 0); - ListIterator<PrimaryKeyJoinColumn> primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - - - oneToOneMapping.movePrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getSpecifiedName()); - - javaJoinColumns = attributeResource.annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - assertEquals("BAZ", javaJoinColumns.next().getName()); - assertEquals("BAR", javaJoinColumns.next().getName()); - assertEquals("FOO", javaJoinColumns.next().getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - createTestEntityWithOneToOneMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - OneToOneMapping oneToOneMapping = (OneToOneMapping) persistentAttribute.getMapping(); - JavaResourcePersistentAttribute attributeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME).attributes().next(); - - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("FOO"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("BAR"); - ((PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(2, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME)).setName("BAZ"); - - ListIterator<PrimaryKeyJoinColumn> joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(2, 0, PrimaryKeyJoinColumns.ANNOTATION_NAME); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.move(0, 1, PrimaryKeyJoinColumns.ANNOTATION_NAME); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(1, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - attributeResource.removeAnnotation(0, PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumns.ANNOTATION_NAME); - joinColumns = oneToOneMapping.primaryKeyJoinColumns(); - assertFalse(joinColumns.hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentAttributeTests.java deleted file mode 100644 index c93bf5a38d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentAttributeTests.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.iterators.ArrayIterator; - -public class JavaPersistentAttributeTests extends ContextModelTestCase -{ - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 JavaPersistentAttributeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - - assertEquals("id", persistentAttribute.getName()); - } - - public void testGetMapping() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().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 = javaPersistentType().attributes().next(); - - assertNull(persistentAttribute.getSpecifiedMapping()); - assertNotNull(persistentAttribute.getMapping()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().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 = javaPersistentType().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 = javaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNotNull(attributeResource.getMappingAnnotation()); - assertTrue(attributeResource.getMappingAnnotation() instanceof EmbeddedAnnotation); - - 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 = javaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNotNull(attributeResource.getMappingAnnotation()); - assertTrue(attributeResource.getMappingAnnotation() instanceof EmbeddedAnnotation); - - 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 = javaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation()); - assertNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - - assertNull(persistentAttribute.getSpecifiedMapping()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.setMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME); - - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - assertNull(persistentAttribute.getSpecifiedMapping()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - attributeResource.setMappingAnnotation(BasicAnnotation.ANNOTATION_NAME); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, persistentAttribute.getSpecifiedMapping().getKey()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentTypeTests.java deleted file mode 100644 index 539bfede5c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPersistentTypeTests.java +++ /dev/null @@ -1,747 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.iterators.ArrayIterator; - -public class JavaPersistentTypeTests extends ContextModelTestCase -{ - @Override - protected void setUp() throws Exception { - super.setUp(); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 JavaPersistentTypeTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, javaPersistentType().getName()); - } - - public void testGetAccessNothingAnnotated() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, javaPersistentType().getAccess()); - } - - public void testAccessField() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, javaPersistentType().getAccess()); - } - - public void testAccessProperty() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.PROPERTY, javaPersistentType().getAccess()); - } - - public void testAccessFieldAndMethodAnnotated() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(AccessType.FIELD, javaPersistentType().getAccess()); - } - - public void testAccessInheritance() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubType(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = persistenceUnit().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 = persistenceUnit().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 = persistenceUnit().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 = persistenceUnit().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"); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - - ListIterator<ClassRef> classRefs = persistenceUnit().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 = entityMappings().addOrmPersistentType(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 = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessNoAnnotations() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntity(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is property - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - } - - public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is field - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - //inheritance wins over entity-mappings specified access - public void testAccessXmlEntityMappingsAccessWithInheritance() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childEntityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - - createTestEntityAnnotatedMethod(); - createTestSubType(); - JavaPersistentType childJavaPersistentType = childEntityPersistentType.getJavaPersistentType(); - - entityMappings().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.PROPERTY, entityPersistentType.getJavaPersistentType().getAccess()); - assertEquals(AccessType.PROPERTY, childJavaPersistentType.getAccess()); - } - - public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, so even though there are field annotations, JavaPersistentType - //access should be property - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); - - } - - public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access - //is field?? - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); - } - - public void testParentPersistentType() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getParentPersistentType()); - assertNull(rootJavaPersistentType.getParentPersistentType()); - } - - public void testParentPersistentType2() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeWithFieldAnnotation(); - - //parent is not added to the persistenceUnit, but it should still be found - //as the parentPersistentType because of impliedClassRefs and changes for bug 190317 - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - JavaPersistentType javaPersistentType = classRefs.next().getJavaPersistentType(); - - assertNotNull(javaPersistentType.getParentPersistentType()); - } - - //Entity extends Non-Entity extends Entity - public void testParentPersistentType3() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = persistenceUnit().specifiedClassRefs(); - ClassRef classRef = classRefs.next(); - JavaPersistentType rootJavaPersistentType = classRef.getJavaPersistentType(); - - classRef = classRefs.next(); - JavaPersistentType childJavaPersistentType = classRef.getJavaPersistentType(); - - assertEquals(rootJavaPersistentType, childJavaPersistentType.getParentPersistentType()); - assertNull(rootJavaPersistentType.getParentPersistentType()); - } - - public void testInheritanceHierarchy() throws Exception { - createTestEntityAnnotatedMethod(); - createTestSubTypeNonPersistent(); - createTestSubTypePersistentExtendsNonPersistent(); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild2"); - - ListIterator<ClassRef> classRefs = persistenceUnit().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 = persistenceUnit().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, javaPersistentType().getMapping().getKey()); - } - - public void testGetMappingNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, javaPersistentType().getMapping().getKey()); - } - - public void testMappingKey() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testMappingKeyNull() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testSetMappingKey() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - - javaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getMappingAnnotation()); - assertTrue(typeResource.getMappingAnnotation() instanceof EntityAnnotation); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testSetMappingKey2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - - javaPersistentType().setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNotNull(typeResource.getMappingAnnotation()); - assertTrue(typeResource.getMappingAnnotation() instanceof EmbeddableAnnotation); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testSetMappingKeyNull() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - - javaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getMappingAnnotation()); - assertNull(typeResource.getMappingAnnotation(EntityAnnotation.ANNOTATION_NAME)); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setMappingAnnotation(EmbeddableAnnotation.ANNOTATION_NAME); - - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testGetMappingKeyMappingChangeInResourceModel2() throws Exception { - createTestType(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(MappingKeys.NULL_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - typeResource.setMappingAnnotation(EntityAnnotation.ANNOTATION_NAME); - - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType().getMappingKey()); - } - - public void testIsMapped() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertTrue(javaPersistentType().isMapped()); - - javaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertFalse(javaPersistentType().isMapped()); - } - - public void testAttributes() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - ListIterator<JavaPersistentAttribute> attributes = javaPersistentType().attributes(); - - assertEquals("id", attributes.next().getName()); - assertFalse(attributes.hasNext()); - } - - public void testAttributes2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaPersistentAttribute> attributes = javaPersistentType().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, javaPersistentType().attributesSize()); - } - - public void testAttributesSize2() throws Exception { - createTestEntityAnnotatedFieldAndMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, javaPersistentType().attributesSize()); - } - - public void testAttributeNamed() throws Exception { - createTestEntityAnnotatedMethod(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = javaPersistentType().getAttributeNamed("id"); - - assertEquals("id", attribute.getName()); - assertNull(javaPersistentType().getAttributeNamed("name")); - assertNull(javaPersistentType().getAttributeNamed("foo")); - } - - public void testAttributeNamed2() throws Exception { - createTestEntityAnnotatedField(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute attribute = javaPersistentType().getAttributeNamed("name"); - - assertEquals("name", attribute.getName()); - - assertNull(javaPersistentType().getAttributeNamed("foo")); - } - - public void testParentPersistentTypeGeneric() throws Exception { - createTestGenericEntity(); - createTestGenericMappedSuperclass(); - - addXmlClassRef(PACKAGE_NAME + ".Entity1"); - addXmlClassRef(PACKAGE_NAME + ".Entity2"); - - JavaPersistentType javaPersistentType = javaPersistentType(); - assertEquals("test.Entity1", javaPersistentType.getName()); - assertNotNull(javaPersistentType.getParentPersistentType()); - - assertEquals("test.Entity2", javaPersistentType.getParentPersistentType().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/JavaPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java deleted file mode 100644 index b403006cab..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,317 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - private static final String PRIMARY_KEY_JOIN_COLUMN_NAME = "MY_PRIMARY_KEY_JOIN_COLUMN"; - private static final String COLUMN_DEFINITION = "MY_COLUMN_DEFINITION"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("Id", ""); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", - "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "String columnDefinition() default \"\";"); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 createTestEntityWithPrimaryKeyJoinColumn() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - createPrimaryKeyJoinColumnAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@PrimaryKeyJoinColumn(name=\"" + PRIMARY_KEY_JOIN_COLUMN_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - - public JavaPrimaryKeyJoinColumnTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getSpecifiedName()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setName("FOO"); - specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getName()); - } - - public void testGetDefaultNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = javaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultName()); - - //remove @Id annotation - PersistentAttribute idAttribute = javaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals(PRIMARY_KEY_JOIN_COLUMN_NAME, specifiedPkJoinColumn.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", pkJoinColumn.getName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedName()); - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(pkJoinColumn); - } - - public void testGetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - column.setColumnDefinition(COLUMN_DEFINITION); - - assertEquals(COLUMN_DEFINITION, specifiedPkJoinColumn.getColumnDefinition()); - - column.setColumnDefinition(null); - - assertNull(specifiedPkJoinColumn.getColumnDefinition()); - - typeResource.removeAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals(0, javaEntity().specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testSetColumnDefinition() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - specifiedPkJoinColumn.setColumnDefinition("foo"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", column.getColumnDefinition()); - - specifiedPkJoinColumn.setColumnDefinition(null); - column = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(column.getColumnDefinition()); - } - - public void testGetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnNameNoSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn pkJoinColumn = javaEntity().getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", pkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("id", specifiedPkJoinColumn.getDefaultReferencedColumnName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = javaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(specifiedPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testGetReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumnResource = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - pkJoinColumnResource.setReferencedColumnName("FOO"); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertEquals("FOO", specifiedPkJoinColumn.getReferencedColumnName()); - } - - public void testSetSpecifiedReferencedColumnName() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - PrimaryKeyJoinColumnAnnotation pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals("foo", pkJoinColumn.getReferencedColumnName()); - - specifiedPkJoinColumn.setSpecifiedName(null); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(specifiedPkJoinColumn.getSpecifiedReferencedColumnName()); - pkJoinColumn = (PrimaryKeyJoinColumnAnnotation) typeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNull(pkJoinColumn); - } - - public void testIsVirtual() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(javaEntity().getDefaultPrimaryKeyJoinColumn()); - javaEntity().removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(javaEntity().getDefaultPrimaryKeyJoinColumn().isVirtual()); - } - - public void testIsReferencedColumnResolved() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isReferencedColumnResolved()); - } - - public void testDbColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbColumn()); - } - - public void testDbReferencedColumn() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbReferencedColumn()); - } - - public void testDbTable() throws Exception { - createTestEntityWithPrimaryKeyJoinColumn(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PrimaryKeyJoinColumn specifiedPkJoinColumn = javaEntity().specifiedPrimaryKeyJoinColumns().next(); - assertNull(specifiedPkJoinColumn.getDbTable()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java deleted file mode 100644 index c8c143ac00..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaQueryHintTests.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.Entity; -import org.eclipse.jpt.core.context.QueryHint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaQueryHintTests extends ContextModelTestCase -{ - private static final String QUERY_NAME = "QUERY_NAME"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createNamedQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedQuery", - "String name();" + - "String query();" + - "QueryHint[] hints() default {};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", - "String name();" + - "String value();"); - } - - private ICompilationUnit createTestEntityWithNamedQuery() throws Exception { - createEntityAnnotation(); - createNamedQueryAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@NamedQuery(name=\"" + QUERY_NAME + "\", hints=@QueryHint())"); - } - }); - } - - - - public JavaQueryHintTests(String name) { - super(name); - } - - public void testUpdateName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - QueryHint queryHint = entity.namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryHint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryHint.getName()); - assertNull(queryHint.getName()); - - //set name in the resource model, verify context model updated - javaQueryHint.setName("foo"); - assertEquals("foo", javaQueryHint.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the resource model - javaQueryHint.setName(null); - assertNull(javaQueryHint.getName()); - assertEquals(0, entity.namedQueries().next().hintsSize()); - } - - public void testModifyName() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - QueryHint queryHint = entity.namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - - //set name in the context model, verify resource model updated - queryHint.setName("foo"); - assertEquals("foo", javaQueryhint.getName()); - assertEquals("foo", queryHint.getName()); - - //set name to null in the context model - queryHint.setName(null); - assertNull(javaQueryhint.getName()); - assertNull(queryHint.getName()); - } - - public void testUpdateValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - QueryHint queryHint = entity.namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - - //set name in the resource model, verify context model updated - javaQueryhint.setValue("foo"); - assertEquals("foo", javaQueryhint.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the resource model - javaQueryhint.setValue(null); - assertNull(javaQueryhint.getValue()); - assertEquals(0, entity.namedQueries().next().hintsSize()); - } - - public void testModifyValue() throws Exception { - createTestEntityWithNamedQuery(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Entity entity = javaEntity(); - QueryHint queryHint = entity.namedQueries().next().hints().next(); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - QueryHintAnnotation javaQueryhint = ((NamedQueryAnnotation) typeResource.getAnnotation(NamedQueryAnnotation.ANNOTATION_NAME)).hints().next(); - - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - - //set name in the context model, verify resource model updated - queryHint.setValue("foo"); - assertEquals("foo", javaQueryhint.getValue()); - assertEquals("foo", queryHint.getValue()); - - //set name to null in the context model - queryHint.setValue(null); - assertNull(javaQueryhint.getValue()); - assertNull(queryHint.getValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java deleted file mode 100644 index 7d75bfc081..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSecondaryTableTests.java +++ /dev/null @@ -1,758 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.PersistentAttribute; -import org.eclipse.jpt.core.context.PrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaSecondaryTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("Id", ""); - } - - private void createSecondaryTableAnnotation() throws Exception{ - this.createAnnotationAndMembers("SecondaryTable", - "String name() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";"); - } - - private void createSecondaryTablesAnnotation() throws Exception { - createSecondaryTableAnnotation(); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - createSecondaryTableAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append("@SecondaryTable(name=\"" + TABLE_NAME + "\")"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - createEntityAnnotation(); - createSecondaryTablesAnnotation(); - - 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\")})"); - } - }); - } - - - - - public JavaSecondaryTableTests(String name) { - super(name); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getSpecifiedName()); - } - - public void testGetDefaultNameNull() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().secondaryTables().next(); - assertNull(secondaryTable.getDefaultName()); - } - - public void testGetName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().secondaryTables().next(); - assertEquals(TABLE_NAME, secondaryTable.getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().secondaryTables().next(); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", javaEntity().secondaryTables().next().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("foo", table.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().secondaryTables().next(); - secondaryTable.setSpecifiedName(null); - - assertEquals(0, javaEntity().secondaryTablesSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - table.setName("foo"); - - assertEquals("foo", javaEntity().secondaryTables().next().getSpecifiedName()); - } - - public void testUpdateFromSpecifiedCatalogChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - ListIterator<SecondaryTableAnnotation> secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResources.next().setCatalog("foo"); - secondaryTableResources.next().setCatalog("bar"); - - ListIterator<SecondaryTable> secondaryTsbles = javaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedCatalog()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedCatalog()); - } - - public void testUpdateFromSpecifiedSchemaChangeInResourceModel() throws Exception { - createTestEntityWithSecondaryTables(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - ListIterator<SecondaryTableAnnotation> secondaryTableResources = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResources.next().setSchema("foo"); - secondaryTableResources.next().setSchema("bar"); - - ListIterator<SecondaryTable> secondaryTsbles = javaEntity().secondaryTables(); - assertEquals("foo", secondaryTsbles.next().getSpecifiedSchema()); - assertEquals("bar", secondaryTsbles.next().getSpecifiedSchema()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.setCatalog("myCatalog"); - - assertEquals("myCatalog", javaEntity().secondaryTables().next().getSpecifiedCatalog()); - assertEquals("myCatalog", javaEntity().secondaryTables().next().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().secondaryTables().next().getDefaultCatalog()); - - javaEntity().secondaryTables().next().setSpecifiedCatalog("myCatalog"); - - assertNull(javaEntity().secondaryTables().next().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = javaEntity().secondaryTables().next(); - table.setSpecifiedCatalog("myCatalog"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("myCatalog", tableResource.getCatalog()); - - table.setSpecifiedCatalog(null); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - tableResource.setSchema("mySchema"); - - assertEquals("mySchema", javaEntity().secondaryTables().next().getSpecifiedSchema()); - assertEquals("mySchema", javaEntity().secondaryTables().next().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().secondaryTables().next().getDefaultSchema()); - - javaEntity().secondaryTables().next().setSpecifiedSchema("mySchema"); - - assertNull(javaEntity().secondaryTables().next().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable table = javaEntity().secondaryTables().next(); - table.setSpecifiedSchema("mySchema"); - table.setSpecifiedName(null); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("mySchema", tableResource.getSchema()); - - table.setSpecifiedSchema(null); - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - } - - public void testSpecifiedPrimaryKeyJoinColumns() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - ListIterator<JavaPrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - - assertFalse(specifiedPkJoinColumns.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - //add an annotation to the resource model and verify the context model is updated - PrimaryKeyJoinColumnAnnotation pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("FOO"); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - pkJoinColumn = tableResource.addPkJoinColumn(0); - pkJoinColumn.setName("BAR"); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - 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 - tableResource.movePkJoinColumn(1, 0); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertFalse(specifiedPkJoinColumns.hasNext()); - - tableResource.removePkJoinColumn(0); - specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(specifiedPkJoinColumns.hasNext()); - } - - public void testSpecifiedPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - assertEquals(0, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTable.specifiedPrimaryKeyJoinColumnsSize()); - } - - public void testPrimaryKeyJoinColumnsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - //just the default pkJoinColumn, so 1 - assertEquals(1, secondaryTable.primaryKeyJoinColumnsSize()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - //only the specified pkJoinColumns, 3 - assertEquals(3, secondaryTable.primaryKeyJoinColumnsSize()); - } - - public void testGetDefaultPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - assertNotNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - public void testPrimaryKeyJoinColumnDefaults() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertNotNull(defaultPkJoinColumn); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - - IdMapping idMapping = (IdMapping) javaEntity().getPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getColumn().setSpecifiedName("FOO"); - assertEquals("FOO", defaultPkJoinColumn.getDefaultName()); - assertEquals("FOO", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - idMapping.getColumn().setSpecifiedName(null); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - } - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, tableResource.pkJoinColumnsSize()); - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertEquals("BAZ", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - Iterator<PrimaryKeyJoinColumn> pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(1); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertEquals("FOO", pkJoinColumnResources.next().getName()); - assertFalse(pkJoinColumnResources.hasNext()); - - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", pkJoinColumns.next().getName()); - assertFalse(pkJoinColumns.hasNext()); - - - secondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumnResources = tableResource.pkJoinColumns(); - assertFalse(pkJoinColumnResources.hasNext()); - pkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertFalse(pkJoinColumns.hasNext()); - - assertEquals(0, tableResource.pkJoinColumnsSize()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - Iterator<PrimaryKeyJoinColumn> specifiedPkJoinColumns = secondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", specifiedPkJoinColumns.next().getName()); - assertEquals("BAR", specifiedPkJoinColumns.next().getName()); - assertEquals("BAZ", specifiedPkJoinColumns.next().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation tableResource = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - Iterator<PrimaryKeyJoinColumnAnnotation> pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("FOO", pkJoinColumns.next().getName()); - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - - - secondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - pkJoinColumns = tableResource.pkJoinColumns(); - - assertEquals("BAR", pkJoinColumns.next().getName()); - assertEquals("BAZ", pkJoinColumns.next().getName()); - assertEquals("FOO", pkJoinColumns.next().getName()); - } - - public void testPrimaryKeyJoinColumnGetDefaultName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultName()); - - - //remove @Id annotation - PersistentAttribute idAttribute = javaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultName()); - } - public void testPrimaryKeyJoinColumnGetDefaultReferencedColumnName() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - PrimaryKeyJoinColumn defaultPkJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn(); - assertEquals("id", defaultPkJoinColumn.getDefaultReferencedColumnName()); - - //remove @Id annotation - PersistentAttribute idAttribute = javaPersistentType().getAttributeNamed("id"); - idAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - - assertNull(defaultPkJoinColumn.getDefaultReferencedColumnName()); - } - - public void testPrimaryKeyJoinColumnIsVirtual() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - - assertTrue(secondaryTable.getDefaultPrimaryKeyJoinColumn().isVirtual()); - - secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - PrimaryKeyJoinColumn specifiedPkJoinColumn = secondaryTable.specifiedPrimaryKeyJoinColumns().next(); - assertFalse(specifiedPkJoinColumn.isVirtual()); - - assertNull(secondaryTable.getDefaultPrimaryKeyJoinColumn()); - } - - - public void testUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - - assertEquals(0, secondaryTable.uniqueConstraintsSize()); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = secondaryTableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - secondaryTable.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(1); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - secondaryTable.removeUniqueConstraint(0); - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - secondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - secondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - secondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, secondaryTableAnnotation.uniqueConstraintsSize()); - - - secondaryTable.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - secondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = secondaryTableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithSecondaryTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - SecondaryTable secondaryTable = javaEntity().specifiedSecondaryTables().next(); - JavaResourcePersistentType resourcePersistentType = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - SecondaryTableAnnotation secondaryTableAnnotation = (SecondaryTableAnnotation) resourcePersistentType.getAnnotation(JPA.SECONDARY_TABLE); - - secondaryTableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - secondaryTableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - secondaryTableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - - - ListIterator<UniqueConstraint> uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(2, 0); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.moveUniqueConstraint(0, 1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableAnnotation.removeUniqueConstraint(0); - uniqueConstraints = secondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java deleted file mode 100644 index cbc1da2301..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaSequenceGeneratorTests.java +++ /dev/null @@ -1,269 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.SequenceGenerator; -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.SequenceGeneratorAnnotation; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaSequenceGeneratorTests extends ContextModelTestCase -{ - private static final String SEQUENCE_GENERATOR_NAME = "MY_SEQUENCE_GENERATOR"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createSequenceGeneratorAnnotation() throws Exception{ - this.createAnnotationAndMembers("SequenceGenerator", - "String name();" + - "String sequenceName() default \"\"; " + - "int initialValue() default 0; " + - "int allocationSize() default 50;"); - } - - private ICompilationUnit createTestEntityWithSequenceGenerator() throws Exception { - createEntityAnnotation(); - createSequenceGeneratorAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SEQUENCE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@SequenceGenerator(name=\"" + SEQUENCE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaSequenceGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getSequenceGenerator().getName()); - - //change resource model sequenceGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setName("foo"); - - assertEquals("foo", idMapping.getSequenceGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getSequenceGenerator().getName()); - - idMapping.getSequenceGenerator().setName("foo"); - - assertEquals("foo", idMapping.getSequenceGenerator().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("foo", sequenceGenerator.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(SEQUENCE_GENERATOR_NAME, idMapping.getSequenceGenerator().getName()); - - idMapping.getSequenceGenerator().setName(null); - - assertNull(idMapping.getSequenceGenerator()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertNull(sequenceGenerator); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getSequenceGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setInitialValue(Integer.valueOf(82)); - - assertEquals(Integer.valueOf(82), idMapping.getSequenceGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getSequenceGenerator().getDefaultInitialValue()); - - idMapping.getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(SequenceGenerator.DEFAULT_INITIAL_VALUE, idMapping.getSequenceGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getSequenceGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getSequenceGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(20), sequenceGenerator.getInitialValue()); - - idMapping.getSequenceGenerator().setName(null); - idMapping.getSequenceGenerator().setSpecifiedInitialValue(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getSequenceGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setAllocationSize(Integer.valueOf(20)); - - assertEquals(Integer.valueOf(20), idMapping.getSequenceGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getSequenceGenerator().getDefaultAllocationSize()); - - idMapping.getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getSequenceGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getSequenceGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getSequenceGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals(Integer.valueOf(25), sequenceGenerator.getAllocationSize()); - - idMapping.getSequenceGenerator().setName(null); - idMapping.getSequenceGenerator().setSpecifiedAllocationSize(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - - - - public void testGetSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getSequenceGenerator().getSequenceName()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - sequenceGenerator.setSequenceName("mySequenceName"); - - assertEquals("mySequenceName", idMapping.getSequenceGenerator().getSequenceName()); - assertEquals("mySequenceName", idMapping.getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testGetDefaultSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getSequenceGenerator().getDefaultSequenceName()); - - idMapping.getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - assertNull(idMapping.getSequenceGenerator().getDefaultSequenceName()); - assertEquals("mySequenceName", idMapping.getSequenceGenerator().getSpecifiedSequenceName()); - } - - public void testSetSpecifiedSequenceName() throws Exception { - createTestEntityWithSequenceGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getSequenceGenerator().setSpecifiedSequenceName("mySequenceName"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - - assertEquals("mySequenceName", sequenceGenerator.getSequenceName()); - - idMapping.getSequenceGenerator().setName(null); - idMapping.getSequenceGenerator().setSpecifiedSequenceName(null); - assertNull(attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java deleted file mode 100644 index 32c0d3a61d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableGeneratorTests.java +++ /dev/null @@ -1,732 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.Generator; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -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.TableGeneratorAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -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.iterators.ArrayIterator; - -public class JavaTableGeneratorTests extends ContextModelTestCase -{ - private static final String TABLE_GENERATOR_NAME = "MY_TABLE_GENERATOR"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createTableGeneratorAnnotation() throws Exception{ - this.createAnnotationAndMembers("TableGenerator", - "String name(); " + - "String table() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";" + - "String pkColumnName() default \"\"; " + - "String valueColumnName() default \"\"; " + - "String pkColumnValue() default \"\"; " + - "int initialValue() default 0; " + - "int allocationSize() default 50; " + - "UniqueConstraint[] uniqueConstraints() default {};"); - } - - private void createUniqueConstraintAnnotation() throws Exception{ - this.createAnnotationAndMembers("UniqueConstraint", - "String[] columnNames(); "); - } - - private ICompilationUnit createTestEntityWithTableGenerator() throws Exception { - createEntityAnnotation(); - createTableGeneratorAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE_GENERATOR, JPA.ID); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id").append(CR); - sb.append("@TableGenerator(name=\"" + TABLE_GENERATOR_NAME + "\")"); - } - }); - } - - public JavaTableGeneratorTests(String name) { - super(name); - } - - public void testGetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getTableGenerator().getName()); - - //change resource model tableGenerator name, verify the context model is updated - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setName("foo"); - - assertEquals("foo", idMapping.getTableGenerator().getName()); - } - - public void testSetName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getTableGenerator().getName()); - - idMapping.getTableGenerator().setName("foo"); - - assertEquals("foo", idMapping.getTableGenerator().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("foo", tableGenerator.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - assertEquals(TABLE_GENERATOR_NAME, idMapping.getTableGenerator().getName()); - - idMapping.getTableGenerator().setName(null); - - assertNull(idMapping.getTableGenerator()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertNull(tableGenerator); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getCatalog()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setCatalog("myCatalog"); - - assertEquals("myCatalog", idMapping.getTableGenerator().getCatalog()); - assertEquals("myCatalog", idMapping.getTableGenerator().getSpecifiedCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultCatalog()); - - idMapping.getTableGenerator().setSpecifiedCatalog("myCatalog"); - - assertNull(idMapping.getTableGenerator().getDefaultCatalog()); - assertEquals("myCatalog", idMapping.getTableGenerator().getSpecifiedCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myCatalog", tableGenerator.getCatalog()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedCatalog(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getSchema()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setSchema("mySchema"); - - assertEquals("mySchema", idMapping.getTableGenerator().getSchema()); - assertEquals("mySchema", idMapping.getTableGenerator().getSpecifiedSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultSchema()); - - idMapping.getTableGenerator().setSpecifiedSchema("mySchema"); - - assertNull(idMapping.getTableGenerator().getDefaultSchema()); - assertEquals("mySchema", idMapping.getTableGenerator().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntityWithTableGenerator(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - IdMapping idMapping = (IdMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", idMapping.getTableGenerator().getDefaultSchema()); - - ormEntity.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", idMapping.getTableGenerator().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", idMapping.getTableGenerator().getDefaultSchema()); - - entityMappings().removeOrmPersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("mySchema", tableGenerator.getSchema()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedSchema(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getPkColumnName()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnName("myPkColumnName"); - - assertEquals("myPkColumnName", idMapping.getTableGenerator().getPkColumnName()); - assertEquals("myPkColumnName", idMapping.getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testGetDefaultPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultPkColumnName()); - - idMapping.getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - assertNull(idMapping.getTableGenerator().getDefaultPkColumnName()); - assertEquals("myPkColumnName", idMapping.getTableGenerator().getSpecifiedPkColumnName()); - } - - public void testSetSpecifiedPkColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedPkColumnName("myPkColumnName"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnName", tableGenerator.getPkColumnName()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedPkColumnName(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getValueColumnName()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setValueColumnName("myValueColumnName"); - - assertEquals("myValueColumnName", idMapping.getTableGenerator().getValueColumnName()); - assertEquals("myValueColumnName", idMapping.getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testGetDefaultValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultValueColumnName()); - - idMapping.getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - assertNull(idMapping.getTableGenerator().getDefaultValueColumnName()); - assertEquals("myValueColumnName", idMapping.getTableGenerator().getSpecifiedValueColumnName()); - } - - public void testSetSpecifiedValueColumnName() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedValueColumnName("myValueColumnName"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myValueColumnName", tableGenerator.getValueColumnName()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedValueColumnName(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getPkColumnValue()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setPkColumnValue("myPkColumnValue"); - - assertEquals("myPkColumnValue", idMapping.getTableGenerator().getPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testGetDefaultPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertNull(idMapping.getTableGenerator().getDefaultPkColumnValue()); - - idMapping.getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - assertNull(idMapping.getTableGenerator().getDefaultPkColumnValue()); - assertEquals("myPkColumnValue", idMapping.getTableGenerator().getSpecifiedPkColumnValue()); - } - - public void testSetSpecifiedPkColumnValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedPkColumnValue("myPkColumnValue"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals("myPkColumnValue", tableGenerator.getPkColumnValue()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedPkColumnValue(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getTableGenerator().getInitialValue()); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setInitialValue(Integer.valueOf(82)); - - assertEquals(Integer.valueOf(82), idMapping.getTableGenerator().getInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getTableGenerator().getSpecifiedInitialValue()); - } - - public void testGetDefaultInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getTableGenerator().getDefaultInitialValue()); - - idMapping.getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(82)); - - assertEquals(TableGenerator.DEFAULT_INITIAL_VALUE, idMapping.getTableGenerator().getDefaultInitialValue()); - assertEquals(Integer.valueOf(82), idMapping.getTableGenerator().getSpecifiedInitialValue()); - } - - public void testSetSpecifiedInitialValue() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedInitialValue(Integer.valueOf(20)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(20), tableGenerator.getInitialValue()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedInitialValue(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - public void testGetAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getTableGenerator().getAllocationSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.setAllocationSize(Integer.valueOf(20)); - - assertEquals(Integer.valueOf(20), idMapping.getTableGenerator().getAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testGetDefaultAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getTableGenerator().getDefaultAllocationSize()); - - idMapping.getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(20)); - - assertEquals(Generator.DEFAULT_ALLOCATION_SIZE, idMapping.getTableGenerator().getDefaultAllocationSize()); - assertEquals(Integer.valueOf(20), idMapping.getTableGenerator().getSpecifiedAllocationSize()); - } - - public void testSetSpecifiedAllocationSize() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - IdMapping idMapping = (IdMapping) javaPersistentType().getAttributeNamed("id").getMapping(); - idMapping.getTableGenerator().setSpecifiedAllocationSize(Integer.valueOf(25)); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(Integer.valueOf(25), tableGenerator.getAllocationSize()); - - idMapping.getTableGenerator().setName(null); - idMapping.getTableGenerator().setSpecifiedAllocationSize(null); - assertNull(attributeResource.getAnnotation(JPA.TABLE_GENERATOR)); - } - - - public void testUniqueConstraints() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGeneratorAnnotation.uniqueConstraintsSize()); - - - tableGenerator.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - tableGenerator.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = tableGeneratorAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTableGenerator(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - TableGenerator tableGenerator = ((IdMapping) javaPersistentType().getAttributeNamed("id").getMapping()).getTableGenerator(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TableGeneratorAnnotation tableGeneratorAnnotation = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGeneratorAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableGeneratorAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableGeneratorAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - - - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(2, 0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorAnnotation.removeUniqueConstraint(0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java deleted file mode 100644 index 134aebfea0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTableTests.java +++ /dev/null @@ -1,572 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaUniqueConstraint; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -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.iterators.ArrayIterator; - -public class JavaTableTests extends ContextModelTestCase -{ - private static final String TABLE_NAME = "MY_TABLE"; - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - private void createTableAnnotation() throws Exception{ - this.createAnnotationAndMembers("Table", - "String name() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";"); - } - - private void createUniqueConstraintAnnotation() throws Exception{ - this.createAnnotationAndMembers("UniqueConstraint", - "String[] columnNames(); "); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 createTestEntityWithTable() throws Exception { - createEntityAnnotation(); - createTableAnnotation(); - - 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 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"); - } - - }); - } - - - - public JavaTableTests(String name) { - super(name); - } - - public void testGetSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getTable().getSpecifiedName()); - } - - public void testGetSpecifiedName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, javaEntity().getTable().getSpecifiedName()); - } - - public void testGetDefaultNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getTable().getDefaultName()); - - //test that setting the java entity name will change the table default name - javaEntity().setSpecifiedName("foo"); - assertEquals("foo", javaEntity().getTable().getDefaultName()); - } - - public void testGetDefaultNameSingleTableInheritance() throws Exception { - createTestEntity(); - createTestSubType(); - - addXmlClassRef(PACKAGE_NAME + ".AnnotationTestTypeChild"); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNotSame(javaEntity(), javaEntity().getRootEntity()); - assertEquals(TYPE_NAME, javaEntity().getTable().getDefaultName()); - assertEquals(TYPE_NAME, javaEntity().getRootEntity().getTable().getDefaultName()); - - //test that setting the root java entity name will change the table default name of the child - javaEntity().getRootEntity().setSpecifiedName("foo"); - assertEquals("foo", javaEntity().getTable().getDefaultName()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaEntity(); - - assertNull(javaEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedSchema("XML_SCHEMA"); - assertEquals("BAR", javaEntity.getTable().getDefaultSchema()); - - entityMappings().removeOrmPersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default schema taken from persistence-unit-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", javaEntity().getTable().getDefaultSchema()); - - IFile file = ormResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - xmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", javaEntity().getTable().getDefaultSchema()); - - file.delete(true, null); - assertNull(javaEntity().getTable().getDefaultSchema()); - } - - public void testGetNameSpecifiedNameNull() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TYPE_NAME, javaEntity().getTable().getName()); - } - - public void testGetName() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(TABLE_NAME, javaEntity().getTable().getName()); - } - - public void testSetSpecifiedName() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().getTable().setSpecifiedName("foo"); - - assertEquals("foo", javaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("foo", table.getName()); - } - - public void testSetSpecifiedNameNull() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - javaEntity().getTable().setSpecifiedName(null); - - assertNull(javaEntity().getTable().getSpecifiedName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertNull(table); - } - - public void testUpdateFromSpecifiedNameChangeInResourceModel() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.setName("foo"); - - assertEquals("foo", javaEntity().getTable().getSpecifiedName()); - - typeResource.removeAnnotation(JPA.TABLE); - assertNull(javaEntity().getTable().getSpecifiedName()); - } - - public void testGetCatalog() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setCatalog("myCatalog"); - - assertEquals("myCatalog", javaEntity().getTable().getSpecifiedCatalog()); - assertEquals("myCatalog", javaEntity().getTable().getCatalog()); - } - - public void testGetDefaultCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getTable().getDefaultCatalog()); - - javaEntity().getTable().setSpecifiedCatalog("myCatalog"); - - assertNull(javaEntity().getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - JavaEntity javaEntity = ormEntity.getJavaEntity(); - - assertNull(javaEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", javaEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedCatalog("XML_CATALOG"); - assertEquals("BAR", javaEntity.getTable().getDefaultCatalog()); - - entityMappings().removeOrmPersistentType(0); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - //default catalog taken from persistence-unite-defaults not entity-mappings since the entity is not in an orm.xml file - assertEquals("FOO", javaEntity().getTable().getDefaultCatalog()); - - IFile file = ormResource().getFile(); - //remove the mapping file reference from the persistence.xml. default schema - //should still come from persistence-unit-defaults because of implied mapped-file-ref - xmlPersistenceUnit().getMappingFiles().remove(mappingFileRef); - assertEquals("FOO", javaEntity().getTable().getDefaultCatalog()); - - file.delete(true, null); - assertNull(javaEntity().getTable().getDefaultCatalog()); - } - - public void testSetSpecifiedCatalog() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = javaEntity().getTable(); - table.setSpecifiedCatalog("myCatalog"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("myCatalog", tableResource.getCatalog()); - - table.setSpecifiedCatalog(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testGetSchema() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.setSchema("mySchema"); - - assertEquals("mySchema", javaEntity().getTable().getSpecifiedSchema()); - assertEquals("mySchema", javaEntity().getTable().getSchema()); - } - - public void testGetDefaultSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertNull(javaEntity().getTable().getDefaultSchema()); - - javaEntity().getTable().setSpecifiedSchema("mySchema"); - - assertNull(javaEntity().getTable().getDefaultSchema()); - } - - public void testSetSpecifiedSchema() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - Table table = javaEntity().getTable(); - table.setSpecifiedSchema("mySchema"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals("mySchema", tableResource.getSchema()); - - table.setSpecifiedSchema(null); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testUniqueConstraints() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - ListIterator<JavaUniqueConstraint> uniqueConstraints = javaEntity().getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); - - uniqueConstraints = javaEntity().getTable().uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(0, javaEntity().getTable().uniqueConstraintsSize()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); - tableAnnotation.addUniqueConstraint(1).addColumnName(0, "bar"); - - assertEquals(2, javaEntity().getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - ListIterator<UniqueConstraintAnnotation> uniqueConstraints = tableAnnotation.uniqueConstraints(); - - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - assertFalse(uniqueConstraintAnnotations.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertFalse(uniqueConstraintAnnotations.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createUniqueConstraintAnnotation(); - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, tableAnnotation.uniqueConstraintsSize()); - - - table.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<UniqueConstraintAnnotation> uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - - - table.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintAnnotations = tableAnnotation.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("BAR", uniqueConstraintAnnotations.next().columnNames().next()); - assertEquals("FOO", uniqueConstraintAnnotations.next().columnNames().next()); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntityWithTable(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - Table table = javaEntity().getTable(); - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - TableAnnotation tableAnnotation = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - tableAnnotation.addUniqueConstraint(0).addColumnName("FOO"); - tableAnnotation.addUniqueConstraint(1).addColumnName("BAR"); - tableAnnotation.addUniqueConstraint(2).addColumnName("BAZ"); - - - ListIterator<UniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(2, 0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableAnnotation.removeUniqueConstraint(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java deleted file mode 100644 index f79334a822..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaTransientMappingTests.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.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.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.utility.internal.iterators.ArrayIterator; - -public class JavaTransientMappingTests extends ContextModelTestCase -{ - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createTransientAnnotation() throws Exception{ - this.createAnnotationAndMembers("Transient", ""); - } - - private ICompilationUnit createTestEntityWithTransientMapping() throws Exception { - createEntityAnnotation(); - createTransientAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient").append(CR); - } - }); - } - - public JavaTransientMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertFalse(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof BasicMapping); - assertTrue(persistentAttribute.getMapping().isDefault()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToVersionMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof VersionMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof IdMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - } - - public void testTransientMapping() throws Exception { - createTestEntityWithTransientMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - TransientMapping transientMapping = (TransientMapping) persistentAttribute.getSpecifiedMapping(); - - assertNotNull(transientMapping); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java deleted file mode 100644 index 77f268aace..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JavaVersionMappingTests.java +++ /dev/null @@ -1,412 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -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.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.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.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.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; - -public class JavaVersionMappingTests extends ContextModelTestCase -{ - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createVersionAnnotation() throws Exception{ - this.createAnnotationAndMembers("Version", ""); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private ICompilationUnit createTestEntityWithVersionMapping() throws Exception { - createEntityAnnotation(); - createVersionAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithTemporal() throws Exception { - createEntityAnnotation(); - createTemporalAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version").append(CR); - sb.append("@Temporal(TemporalType.TIMESTAMP)").append(CR); - } - }); - } - - public JavaVersionMappingTests(String name) { - super(name); - } - - public void testMorphToBasicMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((BasicMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(BasicAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToDefault() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((BasicMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((BasicMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("FOO", ((IdMapping) persistentAttribute.getMapping()).getColumn().getSpecifiedName()); - assertEquals(TemporalType.TIME, ((IdMapping) persistentAttribute.getMapping()).getTemporal()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(IdAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToTransientMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof TransientMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(TransientAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToEmbeddedIdMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof EmbeddedIdMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(EmbeddedIdAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToOneToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof OneToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(OneToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToOneMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToOneMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToOneAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testMorphToManyToManyMapping() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - persistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(persistentAttribute.getMapping() instanceof ManyToManyMapping); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - assertNull(attributeResource.getMappingAnnotation(VersionAnnotation.ANNOTATION_NAME)); - assertNotNull(attributeResource.getMappingAnnotation(ManyToManyAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(ColumnAnnotation.ANNOTATION_NAME)); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporal() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(versionMapping.getTemporal()); - } - - public void testGetTemporal2() throws Exception { - createTestEntityWithTemporal(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertEquals(TemporalType.TIMESTAMP, versionMapping.getTemporal()); - } - - public void testSetTemporal() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - assertNull(versionMapping.getTemporal()); - - versionMapping.setTemporal(TemporalType.TIME); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertEquals(org.eclipse.jpt.core.resource.java.TemporalType.TIME, temporal.getValue()); - - versionMapping.setTemporal(null); - assertNull(attributeResource.getAnnotation(TemporalAnnotation.ANNOTATION_NAME)); - } - - public void testGetTemporalUpdatesFromResourceModelChange() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(versionMapping.getTemporal()); - - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.addAnnotation(TemporalAnnotation.ANNOTATION_NAME); - temporal.setValue(org.eclipse.jpt.core.resource.java.TemporalType.DATE); - - assertEquals(TemporalType.DATE, versionMapping.getTemporal()); - - attributeResource.removeAnnotation(TemporalAnnotation.ANNOTATION_NAME); - - assertNull(versionMapping.getTemporal()); - assertFalse(versionMapping.isDefault()); - assertSame(versionMapping, persistentAttribute.getSpecifiedMapping()); - } - - public void testGetColumn() throws Exception { - createTestEntityWithVersionMapping(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); - VersionMapping versionMapping = (VersionMapping) persistentAttribute.getSpecifiedMapping(); - - assertNull(versionMapping.getColumn().getSpecifiedName()); - assertEquals("id", versionMapping.getColumn().getName()); - - JavaResourcePersistentType typeResource = jpaProject().getJavaPersistentTypeResource(FULLY_QUALIFIED_TYPE_NAME); - JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.addAnnotation(JPA.COLUMN); - column.setName("foo"); - - assertEquals("foo", versionMapping.getColumn().getSpecifiedName()); - assertEquals("foo", versionMapping.getColumn().getName()); - assertEquals("id", versionMapping.getColumn().getDefaultName()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java deleted file mode 100644 index 26e0df5cc6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/JptCoreContextJavaModelTests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreContextJavaModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreContextJavaModelTests.class.getName()); - suite.addTestSuite(JavaAssociationOverrideTests.class); - suite.addTestSuite(JavaAttributeOverrideTests.class); - suite.addTestSuite(JavaBasicMappingTests.class); - suite.addTestSuite(JavaColumnTests.class); - suite.addTestSuite(JavaDiscriminatorColumnTests.class); - suite.addTestSuite(JavaEmbeddableTests.class); - suite.addTestSuite(JavaEmbeddedIdMappingTests.class); - suite.addTestSuite(JavaEmbeddedMappingTests.class); - suite.addTestSuite(JavaEntityTests.class); - suite.addTestSuite(JavaGeneratedValueTests.class); - suite.addTestSuite(JavaIdMappingTests.class); - suite.addTestSuite(JavaJoinColumnTests.class); - suite.addTestSuite(JavaJoinTableTests.class); - suite.addTestSuite(JavaMappedSuperclassTests.class); - suite.addTestSuite(JavaManyToManyMappingTests.class); - suite.addTestSuite(JavaManyToOneMappingTests.class); - suite.addTestSuite(JavaNamedQueryTests.class); - suite.addTestSuite(JavaNamedNativeQueryTests.class); - suite.addTestSuite(JavaQueryHintTests.class); - suite.addTestSuite(JavaOneToManyMappingTests.class); - suite.addTestSuite(JavaOneToOneMappingTests.class); - suite.addTestSuite(JavaPersistentTypeTests.class); - suite.addTestSuite(JavaPersistentAttributeTests.class); - suite.addTestSuite(JavaPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(JavaSecondaryTableTests.class); - suite.addTestSuite(JavaSequenceGeneratorTests.class); - suite.addTestSuite(JavaTableGeneratorTests.class); - suite.addTestSuite(JavaTableTests.class); - suite.addTestSuite(JavaTransientMappingTests.class); - suite.addTestSuite(JavaVersionMappingTests.class); - return suite; - } - - private JptCoreContextJavaModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java deleted file mode 100644 index cc8b88427b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/EntityMappingsTests.java +++ /dev/null @@ -1,1067 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.ListIterator; -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.SequenceGenerator; -import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -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.CollectionTools; - -public class EntityMappingsTests extends ContextModelTestCase -{ - public EntityMappingsTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testGetVersion() throws Exception { - assertEquals("1.0", entityMappings().getVersion()); - } - - public void testUpdateDescription() throws Exception { - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - - //set description in the resource model, verify context model updated - ormResource().getEntityMappings().setDescription("newDescription"); - assertEquals("newDescription", entityMappings().getDescription()); - assertEquals("newDescription", ormResource().getEntityMappings().getDescription()); - - //set description to null in the resource model - ormResource().getEntityMappings().setDescription(null); - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - } - - public void testModifyDescription() throws Exception { - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - - //set description in the context model, verify resource model modified - entityMappings().setDescription("newDescription"); - assertEquals("newDescription", entityMappings().getDescription()); - assertEquals("newDescription", ormResource().getEntityMappings().getDescription()); - - //set description to null in the context model - entityMappings().setDescription(null); - assertNull(entityMappings().getDescription()); - assertNull(ormResource().getEntityMappings().getDescription()); - } - - public void testUpdatePackage() throws Exception { - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - - //set package in the resource model, verify context model updated - ormResource().getEntityMappings().setPackage("foo.model"); - assertEquals("foo.model", entityMappings().getPackage()); - assertEquals("foo.model", ormResource().getEntityMappings().getPackage()); - - //set package to null in the resource model - ormResource().getEntityMappings().setPackage(null); - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - } - - public void testModifyPackage() throws Exception { - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - - //set package in the context model, verify resource model modified - entityMappings().setPackage("foo.model"); - assertEquals("foo.model", entityMappings().getPackage()); - assertEquals("foo.model", ormResource().getEntityMappings().getPackage()); - - //set package to null in the context model - entityMappings().setPackage(null); - assertNull(entityMappings().getPackage()); - assertNull(ormResource().getEntityMappings().getPackage()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - //set schema in the resource model, verify context model updated - ormResource().getEntityMappings().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - //set schema to null in the resource model - ormResource().getEntityMappings().setSchema(null); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - //set schema in the context model, verify resource model modified - entityMappings().setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - //set schema to null in the context model - entityMappings().setSpecifiedSchema(null); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - //set catalog in the resource model, verify context model updated - ormResource().getEntityMappings().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - //set catalog to null in the resource model - ormResource().getEntityMappings().setCatalog(null); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateDefaultSchema() throws Exception { - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - persistenceUnitDefaults.setSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testUpdateSchema() throws Exception { - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setSchema("MY_SCHEMA"); - assertNull(entityMappings().getDefaultSchema()); - assertEquals("MY_SCHEMA", entityMappings().getSchema()); - assertEquals("MY_SCHEMA", entityMappings().getSpecifiedSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getSchema()); - - ormResource().getEntityMappings().setSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("DEFAULT_SCHEMA"); - assertEquals("DEFAULT_SCHEMA", entityMappings().getDefaultSchema()); - assertEquals("DEFAULT_SCHEMA", entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(entityMappings().getDefaultSchema()); - assertNull(entityMappings().getSchema()); - assertNull(entityMappings().getSpecifiedSchema()); - assertNull(ormResource().getEntityMappings().getSchema()); - } - - public void testModifySpecifiedCatalog() throws Exception { - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - //set catalog in the context model, verify resource model modified - entityMappings().setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - //set catalog to null in the context model - entityMappings().setSpecifiedCatalog(null); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateDefaultCatalog() throws Exception { - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - persistenceUnitDefaults.setCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testUpdateCatalog() throws Exception { - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setCatalog("MY_CATALOG"); - assertNull(entityMappings().getDefaultCatalog()); - assertEquals("MY_CATALOG", entityMappings().getCatalog()); - assertEquals("MY_CATALOG", entityMappings().getSpecifiedCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getCatalog()); - - ormResource().getEntityMappings().setCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("DEFAULT_CATALOG"); - assertEquals("DEFAULT_CATALOG", entityMappings().getDefaultCatalog()); - assertEquals("DEFAULT_CATALOG", entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(entityMappings().getDefaultCatalog()); - assertNull(entityMappings().getCatalog()); - assertNull(entityMappings().getSpecifiedCatalog()); - assertNull(ormResource().getEntityMappings().getCatalog()); - } - - public void testUpdateSpecifiedAccess() throws Exception { - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - //set access in the resource model, verify context model updated - ormResource().getEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getAccess()); - - //set access to null in the resource model - ormResource().getEntityMappings().setAccess(null); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - //set access in the context model, verify resource model modified - entityMappings().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getAccess()); - - //set access to null in the context model - entityMappings().setSpecifiedAccess(null); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testUpdateDefaultAccess() throws Exception { - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaults = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(persistenceUnitDefaults); - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - persistenceUnitDefaults.setAccess(null); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - public void testUpdateAccess() throws Exception { - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertNull(entityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, entityMappings().getAccess()); - assertEquals(AccessType.FIELD, entityMappings().getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getAccess()); - - ormResource().getEntityMappings().setAccess(null); - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, entityMappings().getDefaultAccess()); - assertEquals(AccessType.FIELD, entityMappings().getAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(entityMappings().getDefaultAccess()); - assertNull(entityMappings().getAccess()); - assertNull(entityMappings().getSpecifiedAccess()); - assertNull(ormResource().getEntityMappings().getAccess()); - } - - - public void testUpdateOrmPersistentTypes() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the resource model, verify context model updated - XmlEmbeddable embeddable = OrmFactory.eINSTANCE.createXmlEmbeddable(); - ormResource().getEntityMappings().getEmbeddables().add(embeddable); - embeddable.setClassName("model.Foo"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the resource model, verify context model updated - XmlEntity entity = OrmFactory.eINSTANCE.createXmlEntity(); - ormResource().getEntityMappings().getEntities().add(entity); - entity.setClassName("model.Foo2"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the resource model, verify context model updated - XmlMappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createXmlMappedSuperclass(); - ormResource().getEntityMappings().getMappedSuperclasses().add(mappedSuperclass); - mappedSuperclass.setClassName("model.Foo3"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - - public void testAddOrmPersistentType() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - //add embeddable in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - - //add entity in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); - - //add mapped-superclass in the context model, verify resource model modified - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - assertTrue(entityMappings().ormPersistentTypes().hasNext()); - assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, entityMappings().ormPersistentTypes().next().getMapping().getKey()); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); - } - - public void testRemoveOrmPersistentType() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - //remove ormPersistentType from the context model, verify resource model modified - entityMappings().removeOrmPersistentType(1); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().removeOrmPersistentType(1); - assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - entityMappings().removeOrmPersistentType(0); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - } - - public void testUpdateTableGenerators() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(tableGeneratorResource); - tableGeneratorResource.setName("FOO"); - - TableGenerator tableGenerator = entityMappings().tableGenerators().next(); - assertEquals("FOO", tableGenerator.getName()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource2 = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(0, tableGeneratorResource2); - tableGeneratorResource2.setName("BAR"); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlTableGenerator tableGeneratorResource3 = OrmFactory.eINSTANCE.createXmlTableGeneratorImpl(); - ormResource().getEntityMappings().getTableGenerators().add(1, tableGeneratorResource3); - tableGeneratorResource3.setName("BAZ"); - - tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().move(2, 0); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAZ", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().remove(0); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("FOO", tableGenerators.next().getName()); - assertEquals("BAR", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().remove(1); - tableGenerators = entityMappings().tableGenerators(); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getTableGenerators().clear(); - tableGenerators = entityMappings().tableGenerators(); - assertFalse(tableGenerators.hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - entityMappings().addTableGenerator(0).setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - - entityMappings().addTableGenerator(0).setName("BAR"); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals(2, ormResource().getEntityMappings().getTableGenerators().size()); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - assertEquals("BAR", tableGenerators.next().getName()); - assertEquals("FOO", tableGenerators.next().getName()); - assertFalse(tableGenerators.hasNext()); - } - - public void testRemoveTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().removeTableGenerator(0); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - - ListIterator<OrmTableGenerator> tableGenerators = entityMappings().tableGenerators(); - OrmTableGenerator xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAZ", xmlTableGenerator.getName()); - assertEquals(tableGenerator3, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - entityMappings().removeTableGenerator(1); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - tableGenerators = entityMappings().tableGenerators(); - xmlTableGenerator = tableGenerators.next(); - assertEquals("BAR", xmlTableGenerator.getName()); - assertEquals(tableGenerator2, xmlTableGenerator); - assertFalse(tableGenerators.hasNext()); - - - entityMappings().removeTableGenerator(0); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - tableGenerators = entityMappings().tableGenerators(); - assertFalse(tableGenerators.hasNext()); - } - - public void testMoveTableGenerator() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().moveTableGenerator(2, 0); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - - entityMappings().moveTableGenerator(0, 2); - assertEquals("FOO", ormResource().getEntityMappings().getTableGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getTableGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getTableGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getTableGenerators().size()); - } - - public void testTableGeneratorsSize() throws Exception { - assertEquals(0, entityMappings().tableGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getTableGenerators().size()); - - - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - tableGenerator.setName("FOO"); - TableGenerator tableGenerator2 = entityMappings().addTableGenerator(1); - tableGenerator2.setName("BAR"); - TableGenerator tableGenerator3 = entityMappings().addTableGenerator(2); - tableGenerator3.setName("BAZ"); - - assertEquals(3, entityMappings().tableGeneratorsSize()); - - ormResource().getEntityMappings().getTableGenerators().remove(0); - assertEquals(2, entityMappings().tableGeneratorsSize()); - } - - public void testUpdateSequenceGenerators() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(sequenceGeneratorResource); - sequenceGeneratorResource.setName("FOO"); - - SequenceGenerator sequenceGenerator = entityMappings().sequenceGenerators().next(); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource2 = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(0, sequenceGeneratorResource2); - sequenceGeneratorResource2.setName("BAR"); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - XmlSequenceGenerator sequenceGeneratorResource3 = OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl(); - ormResource().getEntityMappings().getSequenceGenerators().add(1, sequenceGeneratorResource3); - sequenceGeneratorResource3.setName("BAZ"); - - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().move(2, 0); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAZ", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - - ormResource().getEntityMappings().getSequenceGenerators().remove(0); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().remove(1); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - - ormResource().getEntityMappings().getSequenceGenerators().clear(); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertFalse(sequenceGenerators.hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allGenerators())); - } - - public void testAddSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().addSequenceGenerator(0).setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - - entityMappings().addSequenceGenerator(0).setName("BAR"); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals(2, ormResource().getEntityMappings().getSequenceGenerators().size()); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - assertEquals("BAR", sequenceGenerators.next().getName()); - assertEquals("FOO", sequenceGenerators.next().getName()); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testRemoveSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().removeSequenceGenerator(0); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - - ListIterator<OrmSequenceGenerator> sequenceGenerators = entityMappings().sequenceGenerators(); - SequenceGenerator xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAZ", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator3, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - entityMappings().removeSequenceGenerator(1); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - sequenceGenerators = entityMappings().sequenceGenerators(); - xmlSequenceGenerator = sequenceGenerators.next(); - assertEquals("BAR", xmlSequenceGenerator.getName()); - assertEquals(sequenceGenerator2, xmlSequenceGenerator); - assertFalse(sequenceGenerators.hasNext()); - - - entityMappings().removeSequenceGenerator(0); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - sequenceGenerators = entityMappings().sequenceGenerators(); - assertFalse(sequenceGenerators.hasNext()); - } - - public void testMoveSequenceGenerator() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().moveSequenceGenerator(2, 0); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - entityMappings().moveSequenceGenerator(0, 2); - assertEquals("FOO", ormResource().getEntityMappings().getSequenceGenerators().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getSequenceGenerators().get(1).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getSequenceGenerators().get(2).getName()); - assertEquals(3, ormResource().getEntityMappings().getSequenceGenerators().size()); - - } - - public void testSequenceGeneratorsSize() throws Exception { - assertEquals(0, entityMappings().sequenceGeneratorsSize()); - assertEquals(0, ormResource().getEntityMappings().getSequenceGenerators().size()); - - - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - sequenceGenerator.setName("FOO"); - SequenceGenerator sequenceGenerator2 = entityMappings().addSequenceGenerator(1); - sequenceGenerator2.setName("BAR"); - SequenceGenerator sequenceGenerator3 = entityMappings().addSequenceGenerator(2); - sequenceGenerator3.setName("BAZ"); - - assertEquals(3, entityMappings().sequenceGeneratorsSize()); - - ormResource().getEntityMappings().getSequenceGenerators().remove(0); - assertEquals(2, entityMappings().sequenceGeneratorsSize()); - } - - - public void testAddNamedQuery() throws Exception { - OrmNamedQuery namedQuery = entityMappings().addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = entityMappings().addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = entityMappings().addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - entityMappings().addNamedQuery(0).setName("FOO"); - entityMappings().addNamedQuery(1).setName("BAR"); - entityMappings().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedQueries().size()); - - entityMappings().removeNamedQuery(0); - assertEquals(2, ormResource().getEntityMappings().getNamedQueries().size()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - - entityMappings().removeNamedQuery(0); - assertEquals(1, ormResource().getEntityMappings().getNamedQueries().size()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - - entityMappings().removeNamedQuery(0); - assertEquals(0, ormResource().getEntityMappings().getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - entityMappings().addNamedQuery(0).setName("FOO"); - entityMappings().addNamedQuery(1).setName("BAR"); - entityMappings().addNamedQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedQueries().size()); - - - entityMappings().moveNamedQuery(2, 0); - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - - - entityMappings().moveNamedQuery(0, 1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", ormResource().getEntityMappings().getNamedQueries().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - ormResource().getEntityMappings().getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - - ormResource().getEntityMappings().getNamedQueries().get(0).setName("FOO"); - ormResource().getEntityMappings().getNamedQueries().get(1).setName("BAR"); - ormResource().getEntityMappings().getNamedQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedQuery> namedQueries = entityMappings().namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().move(2, 0); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - ormResource().getEntityMappings().getNamedQueries().move(0, 1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - ormResource().getEntityMappings().getNamedQueries().remove(1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().remove(1); - namedQueries = entityMappings().namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedQueries().remove(0); - assertFalse(entityMappings().namedQueries().hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmNamedNativeQuery namedNativeQuery = entityMappings().addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = entityMappings().addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = entityMappings().addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - entityMappings().addNamedNativeQuery(0).setName("FOO"); - entityMappings().addNamedNativeQuery(1).setName("BAR"); - entityMappings().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedNativeQueries().size()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(2, ormResource().getEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(1, ormResource().getEntityMappings().getNamedNativeQueries().size()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - - entityMappings().removeNamedNativeQuery(0); - assertEquals(0, ormResource().getEntityMappings().getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - entityMappings().addNamedNativeQuery(0).setName("FOO"); - entityMappings().addNamedNativeQuery(1).setName("BAR"); - entityMappings().addNamedNativeQuery(2).setName("BAZ"); - - assertEquals(3, ormResource().getEntityMappings().getNamedNativeQueries().size()); - - - entityMappings().moveNamedNativeQuery(2, 0); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - - - entityMappings().moveNamedNativeQuery(0, 1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", ormResource().getEntityMappings().getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", ormResource().getEntityMappings().getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", ormResource().getEntityMappings().getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - ormResource().getEntityMappings().getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - - ormResource().getEntityMappings().getNamedNativeQueries().get(0).setName("FOO"); - ormResource().getEntityMappings().getNamedNativeQueries().get(1).setName("BAR"); - ormResource().getEntityMappings().getNamedNativeQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().move(2, 0); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - ormResource().getEntityMappings().getNamedNativeQueries().move(0, 1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(1); - namedNativeQueries = entityMappings().namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - - ormResource().getEntityMappings().getNamedNativeQueries().remove(0); - assertFalse(entityMappings().namedNativeQueries().hasNext()); - assertEquals(0, CollectionTools.size(entityMappings().getPersistenceUnit().allQueries())); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java deleted file mode 100644 index 2c98ed8e0b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/JptCoreOrmContextModelTests.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCoreOrmContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreOrmContextModelTests.class.getName()); - suite.addTestSuite(OrmXmlTests.class); - suite.addTestSuite(EntityMappingsTests.class); - suite.addTestSuite(PersistenceUnitMetadataTests.class); - suite.addTestSuite(PersistenceUnitDefaultsTests.class); - suite.addTestSuite(OrmPersistentAttributeTests.class); - suite.addTestSuite(OrmPersistentTypeTests.class); - suite.addTestSuite(OrmAssociationOverrideTests.class); - suite.addTestSuite(OrmAttributeOverrideTests.class); - suite.addTestSuite(OrmBasicMappingTests.class); - suite.addTestSuite(OrmCascadeTests.class); - suite.addTestSuite(OrmColumnTests.class); - suite.addTestSuite(OrmDiscriminatorColumnTests.class); - suite.addTestSuite(OrmIdMappingTests.class); - suite.addTestSuite(OrmEmbeddableTests.class); - suite.addTestSuite(OrmEmbeddedMappingTests.class); - suite.addTestSuite(OrmEmbeddedIdMappingTests.class); - suite.addTestSuite(OrmEntityTests.class); - suite.addTestSuite(OrmGeneratedValueTests.class); - suite.addTestSuite(OrmJoinColumnTests.class); - suite.addTestSuite(OrmJoinTableTests.class); - suite.addTestSuite(OrmMappedSuperclassTests.class); - suite.addTestSuite(OrmManyToManyMappingTests.class); - suite.addTestSuite(OrmManyToOneMappingTests.class); - suite.addTestSuite(OrmNamedQueryTests.class); - suite.addTestSuite(OrmNamedNativeQueryTests.class); - suite.addTestSuite(OrmOneToManyMappingTests.class); - suite.addTestSuite(OrmOneToOneMappingTests.class); - suite.addTestSuite(OrmPrimaryKeyJoinColumnTests.class); - suite.addTestSuite(OrmQueryHintTests.class); - suite.addTestSuite(OrmSecondaryTableTests.class); - suite.addTestSuite(OrmSequenceGeneratorTests.class); - suite.addTestSuite(OrmTableGeneratorTests.class); - suite.addTestSuite(OrmTableTests.class); - suite.addTestSuite(OrmTransientMappingTests.class); - suite.addTestSuite(OrmVersionMappingTests.class); - return suite; - } - - private JptCoreOrmContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java deleted file mode 100644 index 5ab76feb9a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAssociationOverrideTests.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAssociationOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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; - -public class OrmAssociationOverrideTests extends ContextModelTestCase -{ - public OrmAssociationOverrideTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - assertTrue(ormEntity.associationOverrides().hasNext()); - assertFalse(entityResource.getAssociationOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - //set name to null in the resource model - xmlAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - xmlAssociationOverride.setName("FOO"); - assertEquals("FOO", ormAssociationOverride.getName()); - assertEquals("FOO", xmlAssociationOverride.getName()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(ormEntity.associationOverrides().hasNext()); - assertTrue(entityResource.getAssociationOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - assertNull(ormAssociationOverride.getName()); - assertNull(xmlAssociationOverride.getName()); - - //set name in the context model, verify resource model modified - ormAssociationOverride.setName("foo"); - assertEquals("foo", ormAssociationOverride.getName()); - assertEquals("foo", xmlAssociationOverride.getName()); - - //set name to null in the context model - ormAssociationOverride.setName(null); - assertNull(ormAssociationOverride.getName()); - assertNull(entityResource.getAssociationOverrides().get(0).getName()); - } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - OrmJoinColumn joinColumn = ormAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormAssociationOverride.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormAssociationOverride.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ormAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(2, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(1, xmlAssociationOverride.getJoinColumns().size()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - - ormAssociationOverride.removeSpecifiedJoinColumn(0); - assertEquals(0, xmlAssociationOverride.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - ormAssociationOverride.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormAssociationOverride.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormAssociationOverride.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, xmlAssociationOverride.getJoinColumns().size()); - - - ormAssociationOverride.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - - - ormAssociationOverride.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", xmlAssociationOverride.getJoinColumns().get(0).getName()); - assertEquals("BAR", xmlAssociationOverride.getJoinColumns().get(1).getName()); - assertEquals("FOO", xmlAssociationOverride.getJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - OrmAssociationOverride ormAssociationOverride = ormEntity.specifiedAssociationOverrides().next(); - - XmlAssociationOverride xmlAssociationOverride = entityResource.getAssociationOverrides().get(0); - - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - xmlAssociationOverride.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - xmlAssociationOverride.getJoinColumns().get(0).setName("FOO"); - xmlAssociationOverride.getJoinColumns().get(1).setName("BAR"); - xmlAssociationOverride.getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(2, 0); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().move(0, 1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(1); - joinColumns = ormAssociationOverride.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - xmlAssociationOverride.getJoinColumns().remove(0); - assertFalse(ormAssociationOverride.specifiedJoinColumns().hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java deleted file mode 100644 index f511d12f58..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmAttributeOverrideTests.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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; - -public class OrmAttributeOverrideTests extends ContextModelTestCase -{ - public OrmAttributeOverrideTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = ormEntity.specifiedAttributeOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - assertTrue(ormEntity.attributeOverrides().hasNext()); - assertFalse(entityResource.getAttributeOverrides().isEmpty()); - - //set name in the resource model, verify context model updated - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - //set name to null in the resource model - attributeOverrideResource.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - attributeOverrideResource.setName("FOO"); - assertEquals("FOO", ormAttributeOverride.getName()); - assertEquals("FOO", attributeOverrideResource.getName()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(ormEntity.attributeOverrides().hasNext()); - assertTrue(entityResource.getAttributeOverrides().isEmpty()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - XmlAttributeOverride attributeOverrideResource = entityResource.getAttributeOverrides().get(0); - OrmAttributeOverride ormAttributeOverride = ormEntity.specifiedAttributeOverrides().next(); - - assertNull(ormAttributeOverride.getName()); - assertNull(attributeOverrideResource.getName()); - - //set name in the context model, verify resource model modified - ormAttributeOverride.setName("foo"); - assertEquals("foo", ormAttributeOverride.getName()); - assertEquals("foo", attributeOverrideResource.getName()); - - //set name to null in the context model - ormAttributeOverride.setName(null); - assertNull(ormAttributeOverride.getName()); - assertNull(entityResource.getAttributeOverrides().get(0).getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java deleted file mode 100644 index 5869f60a59..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmBasicMappingTests.java +++ /dev/null @@ -1,763 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.BasicMapping; -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.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.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -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.iterators.ArrayIterator; - -public class OrmBasicMappingTests extends ContextModelTestCase -{ - public OrmBasicMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createBasicAnnotation() throws Exception{ - this.createAnnotationAndMembers("Basic", "FetchType fetch() default EAGER; boolean optional() default true;"); - } - - private void createColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createLobAnnotation() throws Exception{ - this.createAnnotationAndMembers("Lob", ""); - } - - private void createEnumeratedAnnotation() throws Exception{ - this.createAnnotationAndMembers("Enumerated", "EnumType value() default ORDINAL;"); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private ICompilationUnit createTestEntityBasicMapping() throws Exception { - createEntityAnnotation(); - createBasicAnnotation(); - createColumnAnnotation(); - createLobAnnotation(); - createTemporalAnnotation(); - createEnumeratedAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.BASIC, JPA.FETCH_TYPE, JPA.COLUMN, JPA.LOB, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.LAZY, optional=false)"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Lob"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @Enumerated(EnumType.STRING)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the resource model, verify context model updated - basicResource.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the resource model - basicResource.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertEquals("basicMapping", ormBasicMapping.getName()); - assertEquals("basicMapping", basicResource.getName()); - - //set name in the context model, verify resource model updated - ormBasicMapping.setName("newName"); - assertEquals("newName", ormBasicMapping.getName()); - assertEquals("newName", basicResource.getName()); - - //set name to null in the context model - ormBasicMapping.setName(null); - assertNull(ormBasicMapping.getName()); - assertNull(basicResource.getName()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the resource model, verify context model updated - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - - basicResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - - //set fetch to null in the resource model - basicResource.setFetch(null); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(basicResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormBasicMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, basicResource.getFetch()); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - - ormBasicMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, basicResource.getFetch()); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormBasicMapping.setSpecifiedFetch(null); - assertNull(basicResource.getFetch()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the resource model, verify context model updated - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL); - assertEquals(EnumType.ORDINAL, ormBasicMapping.getSpecifiedEnumerated()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - - basicResource.setEnumerated(org.eclipse.jpt.core.resource.orm.EnumType.STRING); - assertEquals(EnumType.STRING, ormBasicMapping.getSpecifiedEnumerated()); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - - //set enumerated to null in the resource model - basicResource.setEnumerated(null); - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - assertNull(basicResource.getEnumerated()); - } - - public void testModifySpecifiedEnumerated() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - assertNull(basicResource.getEnumerated()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.ORDINAL, basicResource.getEnumerated()); - assertEquals(EnumType.ORDINAL, ormBasicMapping.getSpecifiedEnumerated()); - - ormBasicMapping.setSpecifiedEnumerated(EnumType.STRING); - assertEquals(org.eclipse.jpt.core.resource.orm.EnumType.STRING, basicResource.getEnumerated()); - assertEquals(EnumType.STRING, ormBasicMapping.getSpecifiedEnumerated()); - - //set enumerated to null in the context model - ormBasicMapping.setSpecifiedEnumerated(null); - assertNull(basicResource.getEnumerated()); - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the resource model, verify context model updated - basicResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - - basicResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - - //set enumerated to null in the resource model - basicResource.setOptional(null); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertNull(basicResource.getOptional()); - - //set enumerated in the context model, verify resource model updated - ormBasicMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, basicResource.getOptional()); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - - ormBasicMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, basicResource.getOptional()); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - - //set enumerated to null in the context model - ormBasicMapping.setSpecifiedOptional(null); - assertNull(basicResource.getOptional()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - } - - public void testUpdateSpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertFalse(ormBasicMapping.isLob()); - assertFalse(basicResource.isLob()); - - //set lob in the resource model, verify context model updated - basicResource.setLob(true); - assertTrue(ormBasicMapping.isLob()); - assertTrue(basicResource.isLob()); - - //set lob to null in the resource model - basicResource.setLob(false); - assertFalse(ormBasicMapping.isLob()); - assertFalse(basicResource.isLob()); - } - - public void testModifySpecifiedLob() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertFalse(ormBasicMapping.isLob()); - assertFalse(basicResource.isLob()); - - //set lob in the context model, verify resource model updated - ormBasicMapping.setLob(true); - assertTrue(basicResource.isLob()); - assertTrue(ormBasicMapping.isLob()); - - //set lob to false in the context model - ormBasicMapping.setLob(false); - assertFalse(basicResource.isLob()); - assertFalse(ormBasicMapping.isLob()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getTemporal()); - assertNull(basicResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ormBasicMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ormBasicMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - - basicResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ormBasicMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - - //set temporal to null in the resource model - basicResource.setTemporal(null); - assertNull(ormBasicMapping.getTemporal()); - assertNull(basicResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - XmlBasic basicResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getBasics().get(0); - - assertNull(ormBasicMapping.getTemporal()); - assertNull(basicResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormBasicMapping.setTemporal(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, basicResource.getTemporal()); - assertEquals(TemporalType.DATE, ormBasicMapping.getTemporal()); - - ormBasicMapping.setTemporal(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, basicResource.getTemporal()); - assertEquals(TemporalType.TIME, ormBasicMapping.getTemporal()); - - ormBasicMapping.setTemporal(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, basicResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ormBasicMapping.getTemporal()); - - //set temporal to null in the context model - ormBasicMapping.setTemporal(null); - assertNull(basicResource.getTemporal()); - assertNull(ormBasicMapping.getTemporal()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testBasicMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormBasicMapping.getName()); - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertFalse(ormBasicMapping.isLob()); - assertEquals(EnumType.ORDINAL, ormBasicMapping.getEnumerated()); - assertEquals(FetchType.EAGER, ormBasicMapping.getFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getOptional()); - assertNull(ormBasicMapping.getTemporal()); - - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormBasicMapping.getName()); - assertTrue(ormBasicMapping.isLob()); - assertEquals(EnumType.STRING, ormBasicMapping.getSpecifiedEnumerated()); - assertEquals(FetchType.LAZY, ormBasicMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormBasicMapping.getSpecifiedOptional()); - assertEquals(TemporalType.TIMESTAMP, ormBasicMapping.getTemporal()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormBasicMapping.getName()); - assertFalse(ormBasicMapping.isLob()); - assertEquals(EnumType.ORDINAL, ormBasicMapping.getSpecifiedEnumerated()); - assertEquals(FetchType.EAGER, ormBasicMapping.getSpecifiedFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getSpecifiedOptional()); - assertNull(ormBasicMapping.getTemporal()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(255), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(0), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getSpecifiedScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityBasicMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormBasicMapping.getName()); - assertNull(ormBasicMapping.getSpecifiedEnumerated()); - assertNull(ormBasicMapping.getSpecifiedFetch()); - assertNull(ormBasicMapping.getSpecifiedOptional()); - assertFalse(ormBasicMapping.isLob()); - assertEquals(EnumType.ORDINAL, ormBasicMapping.getDefaultEnumerated()); - assertEquals(FetchType.EAGER, ormBasicMapping.getDefaultFetch()); - assertEquals(Boolean.TRUE, ormBasicMapping.getDefaultOptional()); - assertNull(ormBasicMapping.getTemporal()); - - OrmColumn ormColumn = ormBasicMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - - } - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - - public void testBasicMorphToIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((IdMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToVersionMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((VersionMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testBasicMorphToTransientMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToEmbeddedIdMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToOneToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToOneMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } - - public void testBasicMorphToManyToManyMapping() throws Exception { - createTestEntityBasicMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basic"); - - BasicMapping basicMapping = (BasicMapping) ormPersistentAttribute.getMapping(); - assertFalse(basicMapping.isDefault()); - basicMapping.getColumn().setSpecifiedName("FOO"); - basicMapping.setLob(true); - basicMapping.setTemporal(TemporalType.TIME); - basicMapping.setSpecifiedEnumerated(EnumType.ORDINAL); - basicMapping.setSpecifiedFetch(FetchType.EAGER); - basicMapping.setSpecifiedOptional(Boolean.FALSE); - assertFalse(basicMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("basic", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java deleted file mode 100644 index 88a74c4dd0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmCascadeTests.java +++ /dev/null @@ -1,280 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -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; - -public class OrmCascadeTests extends ContextModelTestCase -{ - public OrmCascadeTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isAll()); - assertNotNull(oneToOne.getCascade()); - - //set all in the resource model, verify context model updated - oneToOne.getCascade().setCascadeAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the resource model - oneToOne.getCascade().setCascadeAll(false); - assertEquals(false, cascade.isAll()); - assertEquals(false, oneToOne.getCascade().isCascadeAll()); - } - - public void testModifyCascadeAll() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - - //set all in the context model, verify resource model updated - cascade.setAll(true); - assertEquals(true, cascade.isAll()); - assertEquals(true, oneToOne.getCascade().isCascadeAll()); - - //set all to false in the context model - cascade.setAll(false); - assertEquals(false, cascade.isAll()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isPersist()); - assertNotNull(oneToOne.getCascade()); - - //set Persist in the resource model, verify context model updated - oneToOne.getCascade().setCascadePersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the resource model - oneToOne.getCascade().setCascadePersist(false); - assertEquals(false, cascade.isPersist()); - assertEquals(false, oneToOne.getCascade().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - - //set Persist in the context model, verify resource model updated - cascade.setPersist(true); - assertEquals(true, cascade.isPersist()); - assertEquals(true, oneToOne.getCascade().isCascadePersist()); - - //set Persist to false in the context model - cascade.setPersist(false); - assertEquals(false, cascade.isPersist()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isMerge()); - assertNotNull(oneToOne.getCascade()); - - //set Merge in the resource model, verify context model updated - oneToOne.getCascade().setCascadeMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the resource model - oneToOne.getCascade().setCascadeMerge(false); - assertEquals(false, cascade.isMerge()); - assertEquals(false, oneToOne.getCascade().isCascadeMerge()); - } - - public void testModifyCascadeMerge() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - - //set Merge in the context model, verify resource model updated - cascade.setMerge(true); - assertEquals(true, cascade.isMerge()); - assertEquals(true, oneToOne.getCascade().isCascadeMerge()); - - //set Merge to false in the context model - cascade.setMerge(false); - assertEquals(false, cascade.isMerge()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isRemove()); - assertNotNull(oneToOne.getCascade()); - - //set Remove in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the resource model - oneToOne.getCascade().setCascadeRemove(false); - assertEquals(false, cascade.isRemove()); - assertEquals(false, oneToOne.getCascade().isCascadeRemove()); - } - - public void testModifyCascadeRemove() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - - //set Remove in the context model, verify resource model updated - cascade.setRemove(true); - assertEquals(true, cascade.isRemove()); - assertEquals(true, oneToOne.getCascade().isCascadeRemove()); - - //set Remove to false in the context model - cascade.setRemove(false); - assertEquals(false, cascade.isRemove()); - assertNull(oneToOne.getCascade()); - } - - public void testUpdateCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set cascade in the resource model, verify context model does not change - oneToOne.setCascade(OrmFactory.eINSTANCE.createCascadeTypeImpl()); - assertEquals(false, cascade.isRefresh()); - assertNotNull(oneToOne.getCascade()); - - //set Refresh in the resource model, verify context model updated - oneToOne.getCascade().setCascadeRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the resource model - oneToOne.getCascade().setCascadeRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertEquals(false, oneToOne.getCascade().isCascadeRefresh()); - } - - public void testModifyCascadeRefresh() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - Cascade cascade = ormOneToOneMapping.getCascade(); - - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - - //set Refresh in the context model, verify resource model updated - cascade.setRefresh(true); - assertEquals(true, cascade.isRefresh()); - assertEquals(true, oneToOne.getCascade().isCascadeRefresh()); - - //set Refresh to false in the context model - cascade.setRefresh(false); - assertEquals(false, cascade.isRefresh()); - assertNull(oneToOne.getCascade()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java deleted file mode 100644 index c77df9fe26..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmColumnTests.java +++ /dev/null @@ -1,849 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.Column; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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.iterators.ArrayIterator; - -public class OrmColumnTests extends ContextModelTestCase -{ - public OrmColumnTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setName("FOO"); - ormResource().save(null); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - //set name to null in the resource model - basic.getColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn().getName()); - - basic.getColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", basic.getColumn().getName()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", basic.getColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(basic.getColumn()); - } - - public void testUpdateColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - //set name to null in the resource model - basic.getColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn().getColumnDefinition()); - - basic.getColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", basic.getColumn().getColumnDefinition()); - - basic.setColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testModifyColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", basic.getColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - //set name to null in the resource model - basic.getColumn().setTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn().getTable()); - - basic.getColumn().setTable("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedTable()); - assertEquals("FOO", basic.getColumn().getTable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormColumn.getSpecifiedTable()); - assertEquals("foo", basic.getColumn().getTable()); - - //set name to null in the context model - ormColumn.setSpecifiedTable(null); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, basic.getColumn().getNullable()); - - //set name to null in the resource model - basic.getColumn().setNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn().getNullable()); - - basic.getColumn().setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, basic.getColumn().getNullable()); - - //set name to null in the context model - ormColumn.setSpecifiedNullable(null); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, basic.getColumn().getUpdatable()); - - //set name to null in the resource model - basic.getColumn().setUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn().getUpdatable()); - - basic.getColumn().setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, basic.getColumn().getUpdatable()); - - //set name to null in the context model - ormColumn.setSpecifiedUpdatable(null); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, basic.getColumn().getInsertable()); - - //set name to null in the resource model - basic.getColumn().setInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn().getInsertable()); - - basic.getColumn().setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, basic.getColumn().getInsertable()); - - //set name to null in the context model - ormColumn.setSpecifiedInsertable(null); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, basic.getColumn().getUnique()); - - //set name to null in the resource model - basic.getColumn().setUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn().getUnique()); - - basic.getColumn().setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, basic.getColumn().getUnique()); - - //set name to null in the context model - ormColumn.setSpecifiedUnique(null); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), basic.getColumn().getLength()); - - //set name to null in the resource model - basic.getColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getLength()); - - basic.getColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), basic.getColumn().getLength()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), basic.getColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setPrecision(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(8), basic.getColumn().getPrecision()); - - //set name to null in the resource model - basic.getColumn().setPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getPrecision()); - - basic.getColumn().setPrecision(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(11), basic.getColumn().getPrecision()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedPrecision() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedPrecision(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), basic.getColumn().getPrecision()); - - //set name to null in the context model - ormColumn.setSpecifiedPrecision(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testUpdateSpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the resource model, verify context model updated - basic.setColumn(OrmFactory.eINSTANCE.createXmlColumnImpl()); - basic.getColumn().setScale(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(8), basic.getColumn().getScale()); - - //set name to null in the resource model - basic.getColumn().setScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn().getScale()); - - basic.getColumn().setScale(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(11), basic.getColumn().getScale()); - - basic.setColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testModifySpecifiedScale() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - OrmBasicMapping ormBasicMapping = (OrmBasicMapping) ormPersistentAttribute.getMapping(); - OrmColumn ormColumn = ormBasicMapping.getColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entityResource.getAttributes().getBasics().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedScale(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - assertEquals(Integer.valueOf(7), basic.getColumn().getScale()); - - //set name to null in the context model - ormColumn.setSpecifiedScale(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(basic.getColumn()); - } - - public void testVirtualColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ListIterator<OrmPersistentAttribute> attributes = ormPersistentType.virtualAttributes(); - attributes.next(); - - //virtual attrubte in orm.xml, java attribute has no Column annotation - OrmPersistentAttribute namePersistentAttribute = attributes.next(); - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("FOO"); - javaBasicMapping.getColumn().setSpecifiedTable("FOO_TABLE"); - javaBasicMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaBasicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - javaBasicMapping.getColumn().setSpecifiedLength(new Integer(45)); - javaBasicMapping.getColumn().setSpecifiedPrecision(new Integer(46)); - javaBasicMapping.getColumn().setSpecifiedScale(new Integer(47)); - - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - - - //set metadata-complete, orm.xml virtual column ignores java column annotation - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - ormPersistentType.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - assertEquals("name", ormColumn.getSpecifiedName()); - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getSpecifiedLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getSpecifiedPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getSpecifiedScale()); - - //set metadata-complete false, orm.xml virtual column gets setting from java annotation - ormPersistentType.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO_TABLE", ormColumn.getSpecifiedTable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Integer.valueOf(45), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(46), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(47), ormColumn.getSpecifiedScale()); - } - - public void testNullColumnDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute namePersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - - //set Column annotation in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("FOO"); - javaBasicMapping.getColumn().setSpecifiedTable("FOO_TABLE"); - javaBasicMapping.getColumn().setColumnDefinition("COLUMN_DEFINITION"); - javaBasicMapping.getColumn().setSpecifiedInsertable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUpdatable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedNullable(Boolean.FALSE); - javaBasicMapping.getColumn().setSpecifiedUnique(Boolean.TRUE); - javaBasicMapping.getColumn().setSpecifiedLength(new Integer(45)); - javaBasicMapping.getColumn().setSpecifiedPrecision(new Integer(46)); - javaBasicMapping.getColumn().setSpecifiedScale(new Integer(47)); - - - assertEquals("name", ormColumn.getDefaultName()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Column.DEFAULT_LENGTH, ormColumn.getDefaultLength()); - assertEquals(Column.DEFAULT_PRECISION, ormColumn.getDefaultPrecision()); - assertEquals(Column.DEFAULT_SCALE, ormColumn.getDefaultScale()); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - } - - public void testVirtualColumnTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ListIterator<OrmPersistentAttribute> attributes = ormPersistentType.virtualAttributes(); - attributes.next(); - - //virtual attribute in orm.xml, java attribute has no Column annotation - OrmPersistentAttribute namePersistentAttribute = attributes.next(); - OrmBasicMapping nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - OrmColumn ormColumn = nameVirtualMapping.getColumn(); - - assertEquals(TYPE_NAME, ormColumn.getSpecifiedTable()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE"); - assertEquals("ORM_TABLE", ormColumn.getSpecifiedTable()); - - //set Column table element in Java - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("name").getMapping(); - javaBasicMapping.getColumn().setSpecifiedTable("JAVA_TABLE"); - assertEquals("JAVA_TABLE", ormColumn.getSpecifiedTable()); - - //make name persistent attribute not virtual - namePersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "name"); - nameVirtualMapping = (OrmBasicMapping) namePersistentAttribute.getMapping(); - ormColumn = nameVirtualMapping.getColumn(); - assertNull(ormColumn.getSpecifiedTable()); - assertEquals("ORM_TABLE", ormColumn.getDefaultTable()); - - } - -//public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", xmlEntity.getTable().getDefaultName()); -//} -// -//public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -//} - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java deleted file mode 100644 index f00a629567..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmDiscriminatorColumnTests.java +++ /dev/null @@ -1,349 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.DiscriminatorType; -import org.eclipse.jpt.core.context.orm.OrmDiscriminatorColumn; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -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.iterators.ArrayIterator; - -public class OrmDiscriminatorColumnTests extends ContextModelTestCase -{ - public OrmDiscriminatorColumnTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName("FOO"); - assertEquals("FOO", ormColumn.getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedName("foo"); - assertEquals("foo", ormColumn.getSpecifiedName()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getName()); - - //set name to null in the context model - ormColumn.setSpecifiedName(null); - assertNull(ormColumn.getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - public void testUpdateSpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(8)); - assertEquals(Integer.valueOf(8), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(8), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn().getLength()); - - entityResource.getDiscriminatorColumn().setLength(Integer.valueOf(11)); - assertEquals(Integer.valueOf(11), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(11), entityResource.getDiscriminatorColumn().getLength()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedLength() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setSpecifiedLength(Integer.valueOf(7)); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(7), entityResource.getDiscriminatorColumn().getLength()); - - //set name to null in the context model - ormColumn.setSpecifiedLength(null); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the resource model - entityResource.getDiscriminatorColumn().setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.getDiscriminatorColumn().setColumnDefinition("FOO"); - assertEquals("FOO", ormColumn.getColumnDefinition()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set name in the context model, verify resource model modified - ormColumn.setColumnDefinition("foo"); - assertEquals("foo", ormColumn.getColumnDefinition()); - assertEquals("foo", entityResource.getDiscriminatorColumn().getColumnDefinition()); - - //set name to null in the context model - ormColumn.setColumnDefinition(null); - assertNull(ormColumn.getColumnDefinition()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testUpdateSpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the resource model, verify context model updated - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the resource model - entityResource.getDiscriminatorColumn().setDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.getDiscriminatorColumn().setDiscriminatorType(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR); - assertEquals(DiscriminatorType.CHAR, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.CHAR, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - entityResource.setDiscriminatorColumn(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } - - public void testModifySpecifiedDiscriminatorType() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmDiscriminatorColumn ormColumn = ormEntity.getDiscriminatorColumn(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - - //set discriminator type in the context model, verify resource model modified - ormColumn.setSpecifiedDiscriminatorType(DiscriminatorType.STRING); - assertEquals(DiscriminatorType.STRING, ormColumn.getSpecifiedDiscriminatorType()); - assertEquals(org.eclipse.jpt.core.resource.orm.DiscriminatorType.STRING, entityResource.getDiscriminatorColumn().getDiscriminatorType()); - - //set discriminator type to null in the context model - ormColumn.setSpecifiedDiscriminatorType(null); - assertNull(ormColumn.getSpecifiedDiscriminatorType()); - assertNull(entityResource.getDiscriminatorColumn()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java deleted file mode 100644 index c1f8207037..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddableTests.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.ListIterator; -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.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmEmbeddableTests extends ContextModelTestCase -{ - public OrmEmbeddableTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the resource model, verify context model updated - embeddableResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the resource model - embeddableResource.setClassName(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals("model.Foo", embeddableResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEmbeddable.setClass("com.Bar"); - assertEquals("com.Bar", ormEmbeddable.getClass_()); - assertEquals("com.Bar", embeddableResource.getClassName()); - - //set class to null in the context model - ormEmbeddable.setClass(null); - assertNull(ormEmbeddable.getClass_()); - assertNull(embeddableResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the resource model, verify context model updated - embeddableResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEmbeddable.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, embeddableResource.getAccess()); - - //set access to null in the resource model - embeddableResource.setAccess(null); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - - //set access in the context model, verify resource model modified - ormEmbeddable.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddableResource.getAccess()); - - //set access to null in the context model - ormEmbeddable.setSpecifiedAccess(null); - assertNull(ormEmbeddable.getSpecifiedAccess()); - assertNull(embeddableResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - embeddableResource.setMetadataComplete(true); - assertTrue(ormEmbeddable.getSpecifiedMetadataComplete()); - assertTrue(embeddableResource.getMetadataComplete()); - - //set access to false in the resource model - embeddableResource.setMetadataComplete(false); - assertFalse(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(embeddableResource.getMetadataComplete()); - - embeddableResource.setMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(embeddableResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormEmbeddable.getSpecifiedMetadataComplete()); - assertTrue(embeddableResource.getMetadataComplete()); - - //set access to null in the context model - ormEmbeddable.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(embeddableResource.getMetadataComplete()); - - ormEmbeddable.setSpecifiedMetadataComplete(null); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isDefaultMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) ormPersistentType.getMapping(); - XmlEmbeddable embeddableResource = ormResource().getEntityMappings().getEmbeddables().get(0); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEmbeddable.isMetadataComplete()); - assertNull(ormEmbeddable.getSpecifiedMetadataComplete()); - assertNull(embeddableResource.getMetadataComplete()); - } - - public void testMakeEmbeddableEntity() throws Exception { - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one an Entity so it has to move to the front of the list - public void testMakeEmbeddableEntity2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeEmbeddableMappedSuperclass() throws Exception { - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - //test with 2 Embeddables, make the second one a MappedSuperclass so it has to move to the front of the list - public void testMakeEmbeddableMappedSuperclass2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmEmbeddable embeddable = (OrmEmbeddable) embeddablePersistentType.getMapping(); - embeddable.setSpecifiedAccess(AccessType.PROPERTY); - embeddable.setSpecifiedMetadataComplete(Boolean.TRUE); - - embeddablePersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) embeddablePersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java deleted file mode 100644 index 5a05f082bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedIdMappingTests.java +++ /dev/null @@ -1,905 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.AttributeOverride; -import org.eclipse.jpt.core.context.BasicMapping; -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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; -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.iterators.ArrayIterator; - -public class OrmEmbeddedIdMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedIdMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createEmbeddedIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("EmbeddedId", ""); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createAttributeOverrideAnnotation() throws Exception { - createColumnAnnotation(); - this.createAnnotationAndMembers("AttributeOverride", - "String name();" + - "Column column();"); - } - private ICompilationUnit createTestEntityEmbeddedIdMapping() throws Exception { - createEntityAnnotation(); - createEmbeddedIdAnnotation(); - createAttributeOverrideAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED_ID, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @EmbeddedId"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - 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(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the resource model, verify context model updated -// embeddedIdResource.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the resource model -// embeddedIdResource.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testModifyName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// assertEquals("embeddedIdMapping", xmlEmbeddedIdMapping.getName()); -// assertEquals("embeddedIdMapping", embeddedIdResource.getName()); -// -// //set name in the context model, verify resource model updated -// xmlEmbeddedIdMapping.setName("newName"); -// assertEquals("newName", xmlEmbeddedIdMapping.getName()); -// assertEquals("newName", embeddedIdResource.getName()); -// -// //set name to null in the context model -// xmlEmbeddedIdMapping.setName(null); -// assertNull(xmlEmbeddedIdMapping.getName()); -// assertNull(embeddedIdResource.getName()); -// } -// -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// XmlAttributeOverride attributeOverride = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride.setName("FOO"); -// ormResource().save(null); -// -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// XmlAttributeOverride attributeOverride2 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0); -// ormResource().save(null); -// attributeOverride2.setName("BAR"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// XmlAttributeOverride attributeOverride3 = xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1); -// ormResource().save(null); -// attributeOverride3.setName("BAZ"); -// ormResource().save(null); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedIdResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// -// xmlEmbeddedIdMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedIdResource.getAttributeOverrides().size()); -// } -// -// public void testMoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// xmlEmbeddedIdMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0); -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// -// -// xmlEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// -// assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); -// } -// -// public void testUpdateAttributeOverrides() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedIdMapping"); -// XmlEmbeddedIdMapping xmlEmbeddedIdMapping = (XmlEmbeddedIdMapping) ormPersistentAttribute.getMapping(); -// EmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); -// -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createAttributeOverrideImpl()); -// -// embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); -// embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); -// embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); -// -// ListIterator<XmlAttributeOverride> attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(2, 0); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().move(0, 1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(1); -// attributeOverrides = xmlEmbeddedIdMapping.specifiedAttributeOverrides(); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertFalse(attributeOverrides.hasNext()); -// -// embeddedIdResource.getAttributeOverrides().remove(0); -// assertFalse(xmlEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); -// } - - public void testEmbeddedIdMorphToIdMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToEmbeddedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedMapping) ormPersistentAttribute.getMapping()).specifiedAttributeOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedIdMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedIdMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedId"); - - EmbeddedIdMapping embeddedIdMapping = (EmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedIdMapping.isDefault()); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedIdMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedIdMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embeddedId", ormPersistentAttribute.getMapping().getName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedIdResource.getAttributeOverrides().size()); - - ormEmbeddedIdMapping.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - - - ormEmbeddedIdMapping.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedIdResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedIdResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedIdResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - XmlEmbeddedId embeddedIdResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddedIds().get(0); - - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedIdResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedIdResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedIdResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedIdResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedIdResource.getAttributeOverrides().remove(0); - assertFalse(ormEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormEmbeddedIdMapping.getName()); - - - assertFalse(ormEmbeddedIdMapping.specifiedAttributeOverrides().hasNext()); - assertFalse(ormEmbeddedIdMapping.virtualAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmEmbeddedIdMapping embeddedIdMapping = (OrmEmbeddedIdMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(0, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedIdMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - OrmAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedIdMapping javaEmbeddedIdMapping = (JavaEmbeddedIdMapping) embeddedIdMapping.getJavaPersistentAttribute().getMapping(); - javaEmbeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - javaEmbeddedIdMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO_COLUMN"); - javaEmbeddedIdMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedTable("FOO_TABLE"); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(0, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedIdMapping.specifiedAttributeOverridesSize()); - specifiedAttributeOverrides = embeddedIdMapping.specifiedAttributeOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").makeSpecified(); - embeddedIdMapping = (OrmEmbeddedIdMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(4, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals(0, embeddedIdMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("city", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - embeddedIdMapping.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(4, embeddedIdMapping.attributeOverridesSize()); - assertEquals(1, embeddedIdMapping.specifiedAttributeOverridesSize()); - assertEquals(3, embeddedIdMapping.virtualAttributeOverridesSize()); - assertEquals("id", embeddedIdMapping.specifiedAttributeOverrides().next().getName()); - virtualAttributeOverrides = embeddedIdMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedIdMapping.getName()); - - assertEquals(4, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); - assertEquals(0, ormEmbeddedIdMapping.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); - - OrmAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); - OrmColumn ormColumn = ormAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, ormColumn.getSpecifiedName()); - - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("id", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("state", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("A_STATE", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("zip", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("zip", ormColumn.getSpecifiedName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - //will be an OrmEmbeddedMapping instead of OrmEmbeddedIdMapping since that is the default - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedIdMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedIdMapping ormEmbeddedIdMapping = (OrmEmbeddedIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedIdMapping.getName()); - - assertEquals(0, ormEmbeddedIdMapping.specifiedAttributeOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedIdMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedIdMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java deleted file mode 100644 index a8abb3bcab..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEmbeddedMappingTests.java +++ /dev/null @@ -1,775 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.AttributeOverride; -import org.eclipse.jpt.core.context.BasicMapping; -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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.java.JavaBasicMapping; -import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -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.iterators.ArrayIterator; - -public class OrmEmbeddedMappingTests extends ContextModelTestCase -{ - private static final String ATTRIBUTE_OVERRIDE_NAME = "city"; - private static final String ATTRIBUTE_OVERRIDE_COLUMN_NAME = "E_CITY"; - - public OrmEmbeddedMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createEmbeddedAnnotation() throws Exception{ - this.createAnnotationAndMembers("Embedded", ""); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createAttributeOverrideAnnotation() throws Exception { - createColumnAnnotation(); - this.createAnnotationAndMembers("AttributeOverride", - "String name();" + - "Column column();"); - } - - private ICompilationUnit createTestEntityEmbeddedMapping() throws Exception { - createEntityAnnotation(); - createEmbeddedAnnotation(); - createAttributeOverrideAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @Embedded"); - sb.append(CR); - sb.append(" @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column=@Column(name=\"" + ATTRIBUTE_OVERRIDE_COLUMN_NAME + "\"))"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - 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.ID); - sb.append(";"); - sb.append(CR); - sb.append("import "); - sb.append(JPA.COLUMN); - sb.append(";"); - sb.append(CR); - 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(" @Id").append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" private String city;").append(CR); - sb.append(CR); - sb.append(" @Column(name=\"A_STATE\")").append(CR); - sb.append(" private String state;").append(CR); - sb.append(CR); - sb.append(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the resource model, verify context model updated - embeddedResource.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the resource model - embeddedResource.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - assertEquals("embeddedMapping", ormEmbeddedMapping.getName()); - assertEquals("embeddedMapping", embeddedResource.getName()); - - //set name in the context model, verify resource model updated - ormEmbeddedMapping.setName("newName"); - assertEquals("newName", ormEmbeddedMapping.getName()); - assertEquals("newName", embeddedResource.getName()); - - //set name to null in the context model - ormEmbeddedMapping.setName(null); - assertNull(ormEmbeddedMapping.getName()); - assertNull(embeddedResource.getName()); - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// OrmAttributeOverride attributeOverride = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEmbeddedMapping.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEmbeddedMapping.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); -// OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); -// XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); -// -// ormEmbeddedMapping.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEmbeddedMapping.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// assertEquals(3, embeddedResource.getAttributeOverrides().size()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(2, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(1, embeddedResource.getAttributeOverrides().size()); -// assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); -// -// ormEmbeddedMapping.removeSpecifiedAttributeOverride(0); -// assertEquals(0, embeddedResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, embeddedResource.getAttributeOverrides().size()); - - ormEmbeddedMapping.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - - - ormEmbeddedMapping.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", embeddedResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", embeddedResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", embeddedResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedMapping"); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - embeddedResource.getAttributeOverrides().get(0).setName("FOO"); - embeddedResource.getAttributeOverrides().get(1).setName("BAR"); - embeddedResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - embeddedResource.getAttributeOverrides().remove(0); - assertFalse(ormEmbeddedMapping.specifiedAttributeOverrides().hasNext()); - } - - - public void testEmbeddedMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormEmbeddedMapping.getName()); - - - assertFalse(ormEmbeddedMapping.specifiedAttributeOverrides().hasNext()); - assertFalse(ormEmbeddedMapping.virtualAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - //embedded mapping is virtual, specified attribute overrides should exist - OrmEmbeddedMapping embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(0, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - OrmAttributeOverride attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - JavaEmbeddedMapping javaEmbeddedMapping = (JavaEmbeddedMapping) embeddedMapping.getJavaPersistentAttribute().getMapping(); - javaEmbeddedMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO_COLUMN"); - javaEmbeddedMapping.specifiedAttributeOverrides().next().getColumn().setSpecifiedTable("FOO_TABLE"); - JavaBasicMapping javaBasicMapping = (JavaBasicMapping) persistentType2.getJavaPersistentType().getAttributeNamed("state").getMapping(); - javaBasicMapping.getColumn().setSpecifiedName("MY_STATE_COLUMN"); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(0, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(4, embeddedMapping.specifiedAttributeOverridesSize()); - specifiedAttributeOverrides = embeddedMapping.specifiedAttributeOverrides(); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("FOO_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - assertEquals("FOO_TABLE", attributeOverride.getColumn().getSpecifiedTable()); - - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = specifiedAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - - - //embedded mapping is specified, virtual attribute overrides should exist - persistentType.getAttributeNamed("address").makeSpecified(); - ormResource().save(null); - embeddedMapping = (OrmEmbeddedMapping) persistentType.getAttributeNamed("address").getMapping(); - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(4, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals(0, embeddedMapping.specifiedAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - assertEquals("city", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - assertEquals("MY_STATE_COLUMN", attributeOverride.getColumn().getDefaultName()); - assertEquals(TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - - //set one of the virtual attribute overrides to specified, verify others are still virtual - embeddedMapping.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(4, embeddedMapping.attributeOverridesSize()); - assertEquals(1, embeddedMapping.specifiedAttributeOverridesSize()); - assertEquals(3, embeddedMapping.virtualAttributeOverridesSize()); - assertEquals("id", embeddedMapping.specifiedAttributeOverrides().next().getName()); - virtualAttributeOverrides = embeddedMapping.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("city", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("state", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("zip", attributeOverride.getName()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); - assertEquals(0, ormEmbeddedMapping.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); - - OrmAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); - OrmColumn ormColumn = ormAttributeOverride.getColumn(); - assertEquals(ATTRIBUTE_OVERRIDE_COLUMN_NAME, ormColumn.getSpecifiedName()); - - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("id", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("id", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("state", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("A_STATE", ormColumn.getSpecifiedName()); - - ormAttributeOverride = ormAttributeOverrides.next(); - assertEquals("zip", ormAttributeOverride.getName()); - ormColumn = ormAttributeOverride.getColumn(); - assertEquals("zip", ormColumn.getSpecifiedName()); - - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormEmbeddedMapping.getName()); - - //TODO -// assertEquals(4, ormEmbeddedMapping.specifiedAttributeOverridesSize()); -// assertEquals(0, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.specifiedAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getSpecifiedName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getSpecifiedName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getSpecifiedName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityEmbeddedMapping(); - createTestEmbeddableAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmEmbeddedMapping ormEmbeddedMapping = (OrmEmbeddedMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormEmbeddedMapping.getName()); - - assertEquals(0, ormEmbeddedMapping.specifiedAttributeOverridesSize()); - //TODO -// assertEquals(4, CollectionTools.size(ormEmbeddedMapping.defaultAttributeOverrides())); -// ListIterator<XmlAttributeOverride> ormAttributeOverrides = ormEmbeddedMapping.defaultAttributeOverrides(); -// -// XmlAttributeOverride ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals(ATTRIBUTE_OVERRIDE_NAME, ormAttributeOverride.getName()); -// XmlColumn xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("city", xmlColumn.getDefaultName()); -//// assertEquals(Boolean.TRUE, xmlColumn.getSpecifiedUnique()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedNullable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedInsertable()); -//// assertEquals(Boolean.FALSE, xmlColumn.getSpecifiedUpdatable()); -//// assertEquals("COLUMN_DEFINITION", xmlColumn.getColumnDefinition()); -//// assertEquals("MY_TABLE", xmlColumn.getSpecifiedTable()); -//// assertEquals(Integer.valueOf(5), xmlColumn.getSpecifiedLength()); -//// assertEquals(Integer.valueOf(6), xmlColumn.getSpecifiedPrecision()); -//// assertEquals(Integer.valueOf(7), xmlColumn.getSpecifiedScale()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("id", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("id", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("state", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("state", xmlColumn.getDefaultName()); -// -// ormAttributeOverride = ormAttributeOverrides.next(); -// assertEquals("zip", ormAttributeOverride.getName()); -// xmlColumn = ormAttributeOverride.getColumn(); -// assertEquals("zip", xmlColumn.getDefaultName()); - } - - - public void testEmbeddedMorphToIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToVersionMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToTransientMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToBasicMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToEmbeddedIdMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - attributeOverride = ((EmbeddedIdMapping) ormPersistentAttribute.getMapping()).specifiedAttributeOverrides().next(); - assertEquals("override", attributeOverride.getName()); - assertEquals("OVERRIDE_COLUMN", attributeOverride.getColumn().getSpecifiedName()); - } - - public void testEmbeddedMorphToOneToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToOneToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToOneMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - - public void testEmbeddedMorphToManyToManyMapping() throws Exception { - createTestEntityEmbeddedMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embedded"); - - EmbeddedMapping embeddedMapping = (EmbeddedMapping) ormPersistentAttribute.getMapping(); - assertFalse(embeddedMapping.isDefault()); - XmlEmbedded embeddedResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getEmbeddeds().get(0); - embeddedResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - AttributeOverride attributeOverride = embeddedMapping.specifiedAttributeOverrides().next(); - attributeOverride.setName("override"); - attributeOverride.getColumn().setSpecifiedName("OVERRIDE_COLUMN"); - assertFalse(embeddedMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("embedded", ormPersistentAttribute.getMapping().getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java deleted file mode 100644 index a0db2dc0e0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmEntityTests.java +++ /dev/null @@ -1,2246 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmAssociationOverride; -import org.eclipse.jpt.core.context.orm.OrmAttributeOverride; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; -import org.eclipse.jpt.core.context.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmEntityTests extends ContextModelTestCase -{ - - protected static final String CHILD_TYPE_NAME = "AnnotationTestTypeChild"; - protected static final String FULLY_QUALIFIED_CHILD_TYPE_NAME = PACKAGE_NAME + "." + CHILD_TYPE_NAME; - - public OrmEntityTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private void createMappedSuperclassAnnotation() throws Exception{ - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private ICompilationUnit createTestEntityDefaultFieldAccess() throws Exception { - createEntityAnnotation(); - - 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 createTestEntityFieldAccess() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 createTestEntityPropertyAccess() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - private void createTestSubTypeUnmapped() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public class ").append(CHILD_TYPE_NAME).append(" "); - sb.append("extends ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "AnnotationTestTypeChild.java", sourceWriter); - } - - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - createMappedSuperclassAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ONE_TO_ONE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - } - - @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 void createTestAbstractType() throws Exception { - SourceWriter sourceWriter = new SourceWriter() { - public void appendSourceTo(StringBuilder sb) { - sb.append(CR); - sb.append("public abstract class ").append(TYPE_NAME).append(" "); - sb.append("{}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, sourceWriter); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the resource model, verify context model updated - entityResource.setName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the resource model - entityResource.setName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - - //set name in the context model, verify resource model modified - ormEntity.setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getSpecifiedName()); - assertEquals("foo", entityResource.getName()); - - //set name to null in the context model - ormEntity.setSpecifiedName(null); - assertNull(ormEntity.getSpecifiedName()); - assertNull(entityResource.getName()); - } - - public void testUpdateDefaultName() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("Foo"); - //xml default entity name comes from java - assertEquals("Foo", ormEntity.getDefaultName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getDefaultName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getDefaultName()); - - entityResource.setClassName(FULLY_QUALIFIED_TYPE_NAME); - assertEquals("Foo", ormEntity.getDefaultName()); - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("Foo1"); - assertEquals(TYPE_NAME, ormEntity.getDefaultName()); - - entityResource.setMetadataComplete(null); - assertEquals("Foo1", ormEntity.getDefaultName()); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("Foo", ormEntity.getName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("Bar", ormEntity.getName()); - - entityResource.setName("Baz"); - assertEquals("Baz", ormEntity.getName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertEquals("Baz", ormEntity.getName()); - - entityResource.setName(null); - assertNull(ormEntity.getName()); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the resource model, verify context model updated - entityResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the resource model - entityResource.setClassName(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals("model.Foo", entityResource.getClassName()); - - //set class in the context model, verify resource model modified - ormEntity.setClass("com.Bar"); - assertEquals("com.Bar", ormEntity.getClass_()); - assertEquals("com.Bar", entityResource.getClassName()); - - //set class to null in the context model - ormEntity.setClass(null); - assertNull(ormEntity.getClass_()); - assertNull(entityResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the resource model, verify context model updated - entityResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEntity.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, entityResource.getAccess()); - - //set access to null in the resource model - entityResource.setAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - //set access in the context model, verify resource model modified - ormEntity.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entityResource.getAccess()); - - //set access to null in the context model - ormEntity.setSpecifiedAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromPersistenceUnitDefaults() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(ormEntity.getDefaultAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(entityResource.getAccess()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(ormEntity.getSpecifiedAccess()); - assertNull(ormEntity.getDefaultAccess()); - assertNull(entityResource.getAccess()); - } - - public void testUpdateDefaultAccessFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - //java has no annotations, so defaultAccess in xml is null - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(AccessType.FIELD); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - //entityMappings access wins over persistence-unit-defaults access - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(null); - //persistence-unit-defaults access used now - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(ormEntity.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - //java has annotations on fields now, that should win in all cases - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().setSpecifiedAccess(AccessType.PROPERTY); - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("id").setSpecifiedMappingKey(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaFieldAccess() throws Exception { - createTestEntityFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.FIELD, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessFromJavaPropertyAccess() throws Exception { - createTestEntityPropertyAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertNull(ormEntity.getDefaultAccess()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals(AccessType.PROPERTY, ormEntity.getDefaultAccess()); - } - - public void testUpdateDefaultAccessNoUnderlyingJava() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getDefaultAccess()); - } - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - entityResource.setMetadataComplete(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.TRUE, entityResource.getMetadataComplete()); - - //set access to false in the resource model - entityResource.setMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(Boolean.FALSE, entityResource.getMetadataComplete()); - - entityResource.setMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertTrue(entityResource.getMetadataComplete().booleanValue()); - - //set access to null in the context model - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormEntity.getSpecifiedMetadataComplete().booleanValue()); - assertFalse(entityResource.getMetadataComplete().booleanValue()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isDefaultMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isDefaultMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isDefaultMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormEntity.getSpecifiedMetadataComplete()); - assertTrue(ormEntity.isDefaultMetadataComplete()); - assertTrue(ormEntity.isMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormEntity.isMetadataComplete()); - assertNull(ormEntity.getSpecifiedMetadataComplete()); - assertNull(entityResource.getMetadataComplete()); - } - - - public void testUpdateInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set inheritance strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS); - - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromJava() throws Exception { - createTestEntityDefaultFieldAccess(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - //no inheritance strategy specified in java so single-table is default - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - //inheritance tag exists in xml, so it overrides anything in java - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedInheritanceStrategy(null); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(InheritanceType.JOINED, ormEntity.getDefaultInheritanceStrategy()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //this setting overrides the false meta-data complete found on ormEntity - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateDefaultInheritanceStrategyFromParent() throws Exception { - createTestEntityDefaultFieldAccess(); - createTestSubType(); - - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childPersistentType.getMapping(); - - assertEquals(parentXmlEntity, childXmlEntity.getParentEntity()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - - //change root inheritance strategy, verify default is changed for child entity - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.TABLE_PER_CLASS, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - //set specified inheritance strategy in java and verify defaults in xml are correct - parentXmlEntity.setSpecifiedInheritanceStrategy(null); - parentXmlEntity.getJavaEntity().setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.JOINED, childXmlEntity.getDefaultInheritanceStrategy()); - assertNull(parentXmlEntity.getSpecifiedInheritanceStrategy()); - assertNull(childXmlEntity.getSpecifiedInheritanceStrategy()); - - parentPersistentType.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(InheritanceType.SINGLE_TABLE, parentXmlEntity.getDefaultInheritanceStrategy()); - assertEquals(InheritanceType.SINGLE_TABLE, childXmlEntity.getDefaultInheritanceStrategy()); - } - - public void testUpdateSpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the resource model, verify context model updated - entityResource.setInheritance(OrmFactory.eINSTANCE.createInheritance()); - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED); - assertEquals(InheritanceType.JOINED, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.JOINED, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the resource model - entityResource.getInheritance().setStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance().getStrategy()); - - entityResource.getInheritance().setStrategy(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE); - assertEquals(InheritanceType.SINGLE_TABLE, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.SINGLE_TABLE, entityResource.getInheritance().getStrategy()); - - entityResource.setInheritance(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testModifySpecifiedInheritanceStrategy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - - //set strategy in the context model, verify resource model modified - ormEntity.setSpecifiedInheritanceStrategy(InheritanceType.TABLE_PER_CLASS); - assertEquals(InheritanceType.TABLE_PER_CLASS, ormEntity.getSpecifiedInheritanceStrategy()); - assertEquals(org.eclipse.jpt.core.resource.orm.InheritanceType.TABLE_PER_CLASS, entityResource.getInheritance().getStrategy()); - - //set strategy to null in the context model - ormEntity.setSpecifiedInheritanceStrategy(null); - assertNull(ormEntity.getSpecifiedInheritanceStrategy()); - assertNull(entityResource.getInheritance()); - } - - public void testAddSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - OrmSecondaryTable secondaryTable2 = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(1).getName()); - - OrmSecondaryTable secondaryTable3 = ormEntity.addSpecifiedSecondaryTable(1); - secondaryTable3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals(secondaryTable2, secondaryTables.next()); - assertEquals(secondaryTable3, secondaryTables.next()); - assertEquals(secondaryTable, secondaryTables.next()); - - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - } - - public void testRemoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(2, entityResource.getSecondaryTables().size()); - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(1, entityResource.getSecondaryTables().size()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testMoveSpecifiedSecondaryTable() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedSecondaryTable(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedSecondaryTable(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getSecondaryTables().size()); - - - ormEntity.moveSpecifiedSecondaryTable(2, 0); - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAR", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAZ", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - - - ormEntity.moveSpecifiedSecondaryTable(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - - assertEquals("BAZ", entityResource.getSecondaryTables().get(0).getName()); - assertEquals("BAR", entityResource.getSecondaryTables().get(1).getName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(2).getName()); - } - - public void testUpdateSecondaryTables() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - - entityResource.getSecondaryTables().get(0).setName("FOO"); - entityResource.getSecondaryTables().get(1).setName("BAR"); - entityResource.getSecondaryTables().get(2).setName("BAZ"); - - ListIterator<OrmSecondaryTable> secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(2, 0); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().move(0, 1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(1); - secondaryTables = ormEntity.specifiedSecondaryTables(); - assertEquals("BAZ", secondaryTables.next().getName()); - assertFalse(secondaryTables.hasNext()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - } - - public void testVirtualSecondaryTables() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) parentPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) childPersistentType.getMapping(); - JavaEntity javaEntity = childOrmEntity.getJavaEntity(); - - JavaSecondaryTable javaSecondaryTableFoo = javaEntity.addSpecifiedSecondaryTable(0); - javaSecondaryTableFoo.setSpecifiedName("FOO"); - OrmSecondaryTable virtualSecondaryTableFoo = childOrmEntity.virtualSecondaryTables().next(); - assertEquals("FOO", childOrmEntity.secondaryTables().next().getName()); - assertEquals("FOO", virtualSecondaryTableFoo.getName()); - assertEquals(0, virtualSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", virtualSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - - javaEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - ListIterator<OrmSecondaryTable> virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - ListIterator<OrmSecondaryTable> secondaryTables = childOrmEntity.secondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - assertEquals("BAR", secondaryTables.next().getName()); - assertEquals("FOO", secondaryTables.next().getName()); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - - childOrmEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - - - childOrmEntity.setSecondaryTablesDefinedInXml(true); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - ListIterator<OrmSecondaryTable> specifiedSecondaryTables = childOrmEntity.specifiedSecondaryTables(); - assertEquals("BAR", specifiedSecondaryTables.next().getName()); - OrmSecondaryTable specifiedSecondaryTableFoo = specifiedSecondaryTables.next(); - assertEquals("FOO", specifiedSecondaryTableFoo.getName()); - assertEquals(0, specifiedSecondaryTableFoo.specifiedPrimaryKeyJoinColumnsSize()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultName()); - assertEquals("id", specifiedSecondaryTableFoo.getDefaultPrimaryKeyJoinColumn().getDefaultReferencedColumnName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(1, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(1, childOrmEntity.secondaryTablesSize()); - assertEquals("FOO", childOrmEntity.specifiedSecondaryTables().next().getName()); - - - childOrmEntity.removeSpecifiedSecondaryTable(0); - assertEquals(0, childOrmEntity.specifiedSecondaryTablesSize()); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - assertEquals(2, childOrmEntity.secondaryTablesSize()); - virtualSecondaryTables = childOrmEntity.virtualSecondaryTables(); - assertEquals("BAR", virtualSecondaryTables.next().getName()); - assertEquals("FOO", virtualSecondaryTables.next().getName()); - - - //add a specified secondary table to the parent, this will not affect virtual secondaryTables in child - parentOrmEntity.addSpecifiedSecondaryTable(0).setSpecifiedName("PARENT_TABLE"); - assertEquals(2, childOrmEntity.virtualSecondaryTablesSize()); - } - - public void testAssociatedTables() throws Exception { - createTestEntityFieldAccess(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertEquals(1, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - assertEquals(2, CollectionTools.size(entity.associatedTables())); - - entity.addSpecifiedSecondaryTable(0).setSpecifiedName("BAR"); - assertEquals(3, CollectionTools.size(entity.associatedTables())); - } - - public void testAssociatedTableNamesIncludingInherited() throws Exception { - - } - - public void testTableNameIsInvalid() throws Exception { - - } - - public void testMakeEntityEmbeddable() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - } - - //TODO test that attribute mappings are not removed when changing type mapping. - public void testMakeEntityEmbeddable2() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); -// entityPersistentType.addSpecifiedPersistentAttribute(IMappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicMapping"); - - entityPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); -// assertEquals("basicMapping", embeddable.getAttributes().getBasics().get(0).getName()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); -// assertEquals("basicMapping", ormEmbeddable.persistentType().attributes().next().getName()); - } - - public void testMakeEntityMappedSuperclass() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - public void testMakeEntityMappedSuperclass2() throws Exception { - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity entity = (OrmEntity) entityPersistentType.getMapping(); - entity.setSpecifiedAccess(AccessType.PROPERTY); - entity.setSpecifiedDiscriminatorValue("DISC_VALUE"); - entity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - entity.setSpecifiedName("ENTITY_NAME"); - - entityPersistentType.setMappingKey(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY); - - XmlMappedSuperclass mappedSuperclass = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", mappedSuperclass.getClassName()); - assertEquals(Boolean.TRUE, mappedSuperclass.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclass.getAccess()); - - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) entityPersistentType.getMapping(); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals(Boolean.TRUE, ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - } - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.addSequenceGenerator(); - - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormEntity.addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - ormEntity.addSequenceGenerator(); - assertNotNull(entityResource.getSequenceGenerator()); - assertNotNull(ormEntity.getSequenceGenerator()); - - ormEntity.removeSequenceGenerator(); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormEntity.removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - - assertNotNull(ormEntity.getSequenceGenerator()); - assertNotNull(entityResource.getSequenceGenerator()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - ormEntity.getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setSequenceGenerator(null); - assertNull(ormEntity.getSequenceGenerator()); - assertNull(entityResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.addTableGenerator(); - - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormEntity.addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - ormEntity.addTableGenerator(); - assertNotNull(entityResource.getTableGenerator()); - assertNotNull(ormEntity.getTableGenerator()); - - ormEntity.removeTableGenerator(); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormEntity.removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - - assertNotNull(ormEntity.getTableGenerator()); - assertNotNull(entityResource.getTableGenerator()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - ormEntity.getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - - entityResource.setTableGenerator(null); - assertNull(ormEntity.getTableGenerator()); - assertNull(entityResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allGenerators())); - } - - public void testUpdateDiscriminatorColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - - entityResource.setDiscriminatorColumn(OrmFactory.eINSTANCE.createXmlDiscriminatorColumn()); - entityResource.getDiscriminatorColumn().setName("FOO"); - - assertEquals("FOO", ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertEquals("FOO", entityResource.getDiscriminatorColumn().getName()); - - entityResource.getDiscriminatorColumn().setName(null); - - assertNull(ormEntity.getDiscriminatorColumn().getSpecifiedName()); - assertNull(entityResource.getDiscriminatorColumn().getName()); - - entityResource.setDiscriminatorColumn(null); - - assertNotNull(ormEntity.getDiscriminatorColumn()); - } - - public void testUpdateDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - entityResource.setDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testModifyDiscriminatorValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue("FOO"); - - assertEquals("FOO", ormEntity.getSpecifiedDiscriminatorValue()); - assertEquals("FOO", entityResource.getDiscriminatorValue()); - - ormEntity.setSpecifiedDiscriminatorValue(null); - - assertNull(ormEntity.getSpecifiedDiscriminatorValue()); - assertNull(entityResource.getDiscriminatorValue()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormEntity.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, entityResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, entityResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormEntity.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getPrimaryKeyJoinColumns().size()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormEntity.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", entityResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", entityResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - entityResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - - entityResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - entityResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - entityResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormEntity.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - public void testDefaultPrimaryKeyJoinColumns() throws Exception { - createTestType(); - createTestSubTypeUnmapped(); - - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - persistentType.getAttributeNamed("id").makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - ((OrmEntity) persistentType.getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - OrmPrimaryKeyJoinColumn specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - - //remove the pkJoinColumn from the context mode, verify context model has a default pkJoinColumn - childEntity.removeSpecifiedPrimaryKeyJoinColumn(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - - specifiedPkJoinColumn = childEntity.addSpecifiedPrimaryKeyJoinColumn(0); - specifiedPkJoinColumn.setSpecifiedName("FOO"); - specifiedPkJoinColumn.setSpecifiedReferencedColumnName("BAR"); - assertFalse(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - //now remove the pkJoinColumn from the resource model, verify context model updates and has a default pkJoinColumn - ((XmlEntity)childEntity.getTypeMappingResource()).getPrimaryKeyJoinColumns().remove(0); - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - } - - public void testDefaultPrimaryKeyJoinColumnsFromJava() throws Exception { - createTestEntityFieldAccess(); - createTestSubType(); - - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - - OrmEntity childEntity = (OrmEntity) childPersistentType.getMapping(); - - assertTrue(childEntity.defaultPrimaryKeyJoinColumns().hasNext()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultName()); - assertEquals("id", childEntity.defaultPrimaryKeyJoinColumns().next().getDefaultReferencedColumnName()); - - JavaEntity javaEntity = (JavaEntity) childPersistentType.getJavaPersistentType().getMapping(); - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn = javaEntity.addSpecifiedPrimaryKeyJoinColumn(0); - javaPrimaryKeyJoinColumn.setSpecifiedName("FOO"); - javaPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("BAR"); - - JavaPrimaryKeyJoinColumn javaPrimaryKeyJoinColumn2 = javaEntity.addSpecifiedPrimaryKeyJoinColumn(1); - javaPrimaryKeyJoinColumn2.setSpecifiedName("FOO2"); - javaPrimaryKeyJoinColumn2.setSpecifiedReferencedColumnName("BAR2"); - - childPersistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - ListIterator<OrmPrimaryKeyJoinColumn> defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - OrmPrimaryKeyJoinColumn defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("FOO2", defaultPrimaryKeyJoinColumn.getName()); - assertEquals("BAR2", defaultPrimaryKeyJoinColumn.getReferencedColumnName()); - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - childEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - defaultPrimaryKeyJoinColumns = childEntity.defaultPrimaryKeyJoinColumns(); - defaultPrimaryKeyJoinColumn = defaultPrimaryKeyJoinColumns.next(); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultName()); - assertEquals("id", defaultPrimaryKeyJoinColumn.getDefaultReferencedColumnName()); - - assertFalse(defaultPrimaryKeyJoinColumns.hasNext()); - - } - -// public void testAddSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// -// OrmAttributeOverride attributeOverride = ormEntity.addSpecifiedAttributeOverride(0); -// attributeOverride.setName("FOO"); -// -// assertEquals("FOO", entityResource.getAttributeOverrides().get(0).getName()); -// -// OrmAttributeOverride attributeOverride2 = ormEntity.addSpecifiedAttributeOverride(0); -// attributeOverride2.setName("BAR"); -// -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("FOO", entityResource.getAttributeOverrides().get(1).getName()); -// -// OrmAttributeOverride attributeOverride3 = ormEntity.addSpecifiedAttributeOverride(1); -// attributeOverride3.setName("BAZ"); -// -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); -// assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); -// -// ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); -// assertEquals(attributeOverride2, attributeOverrides.next()); -// assertEquals(attributeOverride3, attributeOverrides.next()); -// assertEquals(attributeOverride, attributeOverrides.next()); -// -// attributeOverrides = ormEntity.specifiedAttributeOverrides(); -// assertEquals("BAR", attributeOverrides.next().getName()); -// assertEquals("BAZ", attributeOverrides.next().getName()); -// assertEquals("FOO", attributeOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAttributeOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// -// ormEntity.addSpecifiedAttributeOverride(0).setName("FOO"); -// ormEntity.addSpecifiedAttributeOverride(1).setName("BAR"); -// ormEntity.addSpecifiedAttributeOverride(2).setName("BAZ"); -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals(3, entityResource.getAttributeOverrides().size()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(2, entityResource.getAttributeOverrides().size()); -// assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(1, entityResource.getAttributeOverrides().size()); -// assertEquals("BAZ", entityResource.getAttributeOverrides().get(0).getName()); -// -// ormEntity.removeSpecifiedAttributeOverride(0); -// assertEquals(0, entityResource.getAttributeOverrides().size()); -// } - - public void testMoveSpecifiedAttributeOverride() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAttributeOverrides().size()); - - - ormEntity.moveSpecifiedAttributeOverride(2, 0); - ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - - - ormEntity.moveSpecifiedAttributeOverride(0, 1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAttributeOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAttributeOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAttributeOverrides().get(2).getName()); - } - - public void testUpdateAttributeOverrides() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - entityResource.getAttributeOverrides().add(OrmFactory.eINSTANCE.createXmlAttributeOverrideImpl()); - - entityResource.getAttributeOverrides().get(0).setName("FOO"); - entityResource.getAttributeOverrides().get(1).setName("BAR"); - entityResource.getAttributeOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAttributeOverride> attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("FOO", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(2, 0); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().move(0, 1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("BAR", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertEquals("FOO", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(1); - attributeOverrides = ormEntity.specifiedAttributeOverrides(); - assertEquals("BAZ", attributeOverrides.next().getName()); - assertFalse(attributeOverrides.hasNext()); - - entityResource.getAttributeOverrides().remove(0); - assertFalse(ormEntity.specifiedAttributeOverrides().hasNext()); - } - - public void testVirtualAttributeOverrides() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - OrmPersistentType persistentType2 = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - assertEquals(3, entity.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = entity.virtualAttributeOverrides(); - OrmAttributeOverride attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.virtualAttributeOverrides().next().setVirtual(false); - - assertEquals(2, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - entity.specifiedAttributeOverrides().next().setVirtual(true); - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getJavaEntity().virtualAttributeOverrides().next().setVirtual(false); - entity.getJavaEntity().specifiedAttributeOverrides().next().getColumn().setSpecifiedName("FOO"); - assertEquals(3, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - assertEquals("FOO", attributeOverride.getColumn().getSpecifiedName());//TODO specified or default? - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - assertEquals("name", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - - persistentType2.getAttributeNamed("name").makeSpecified(); - OrmBasicMapping basicMapping = (OrmBasicMapping) persistentType2.getAttributeNamed("name").getMapping(); - basicMapping.getColumn().setSpecifiedName("MY_NAME"); - - assertEquals(3, entity.virtualAttributeOverridesSize()); - virtualAttributeOverrides = entity.virtualAttributeOverrides(); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - assertEquals("MY_NAME", attributeOverride.getColumn().getSpecifiedName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - assertEquals("FOO", attributeOverride.getColumn().getSpecifiedName());//TODO specified or default? - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - } - - public void testVirtualAttributeOverridesNoJavaEntity() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - persistentType.getJavaPersistentType().setMappingKey(MappingKeys.NULL_TYPE_MAPPING_KEY); - assertEquals(3, entity.virtualAttributeOverridesSize()); - ListIterator<OrmAttributeOverride> virtualAttributeOverrides = entity.virtualAttributeOverrides(); - OrmAttributeOverride attributeOverride = virtualAttributeOverrides.next(); - assertEquals("id", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("name", attributeOverride.getName()); - attributeOverride = virtualAttributeOverrides.next(); - assertEquals("foo", attributeOverride.getName()); - } - - public void testAttributeOverrideColumnDefaults() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_CHILD_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - - entity.virtualAttributeOverrides().next().setVirtual(false); - - OrmAttributeOverride attributeOverride = entity.specifiedAttributeOverrides().next(); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - ((JavaEntity) persistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals("FOO", attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals(CHILD_TYPE_NAME, attributeOverride.getColumn().getDefaultTable()); - - entity.setSpecifiedMetadataComplete(Boolean.FALSE); - entity.getTable().setSpecifiedName("BAR"); - assertEquals("id", attributeOverride.getColumn().getDefaultName()); - assertEquals("BAR", attributeOverride.getColumn().getDefaultTable()); - } - -// public void testAddSpecifiedAssociationOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// -// OrmAssociationOverride associationOverride = ormEntity.addSpecifiedAssociationOverride(0); -// associationOverride.setName("FOO"); -// -// assertEquals("FOO", entityResource.getAssociationOverrides().get(0).getName()); -// -// OrmAssociationOverride associationOverride2 = ormEntity.addSpecifiedAssociationOverride(0); -// associationOverride2.setName("BAR"); -// -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("FOO", entityResource.getAssociationOverrides().get(1).getName()); -// -// OrmAssociationOverride associationOverride3 = ormEntity.addSpecifiedAssociationOverride(1); -// associationOverride3.setName("BAZ"); -// -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); -// assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); -// -// ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); -// assertEquals(associationOverride2, associationOverrides.next()); -// assertEquals(associationOverride3, associationOverrides.next()); -// assertEquals(associationOverride, associationOverrides.next()); -// -// associationOverrides = ormEntity.specifiedAssociationOverrides(); -// assertEquals("BAR", associationOverrides.next().getName()); -// assertEquals("BAZ", associationOverrides.next().getName()); -// assertEquals("FOO", associationOverrides.next().getName()); -// } -// -// public void testRemoveSpecifiedAssociationOverride() throws Exception { -// OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); -// -// ormEntity.addSpecifiedAssociationOverride(0).setName("FOO"); -// ormEntity.addSpecifiedAssociationOverride(1).setName("BAR"); -// ormEntity.addSpecifiedAssociationOverride(2).setName("BAZ"); -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals(3, entityResource.getAssociationOverrides().size()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(2, entityResource.getAssociationOverrides().size()); -// assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(1, entityResource.getAssociationOverrides().size()); -// assertEquals("BAZ", entityResource.getAssociationOverrides().get(0).getName()); -// -// ormEntity.removeSpecifiedAssociationOverride(0); -// assertEquals(0, entityResource.getAssociationOverrides().size()); -// } - - public void testMoveSpecifiedAssociationOverride() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - assertEquals(3, entityResource.getAssociationOverrides().size()); - - - ormEntity.moveSpecifiedAssociationOverride(2, 0); - ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAR", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAZ", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - - - ormEntity.moveSpecifiedAssociationOverride(0, 1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - - assertEquals("BAZ", entityResource.getAssociationOverrides().get(0).getName()); - assertEquals("BAR", entityResource.getAssociationOverrides().get(1).getName()); - assertEquals("FOO", entityResource.getAssociationOverrides().get(2).getName()); - } - - public void testUpdateAssociationOverrides() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - entityResource.getAssociationOverrides().add(OrmFactory.eINSTANCE.createXmlAssociationOverrideImpl()); - - entityResource.getAssociationOverrides().get(0).setName("FOO"); - entityResource.getAssociationOverrides().get(1).setName("BAR"); - entityResource.getAssociationOverrides().get(2).setName("BAZ"); - - ListIterator<OrmAssociationOverride> associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("FOO", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(2, 0); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().move(0, 1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("BAR", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertEquals("FOO", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(1); - associationOverrides = ormEntity.specifiedAssociationOverrides(); - assertEquals("BAZ", associationOverrides.next().getName()); - assertFalse(associationOverrides.hasNext()); - - entityResource.getAssociationOverrides().remove(0); - assertFalse(ormEntity.specifiedAssociationOverrides().hasNext()); - } - - - public void testAddNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmNamedQuery namedQuery = ormEntity.addNamedQuery(0); - namedQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedQueries().get(0).getName()); - - OrmNamedQuery namedQuery2 = ormEntity.addNamedQuery(0); - namedQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(1).getName()); - - OrmNamedQuery namedQuery3 = ormEntity.addNamedQuery(1); - namedQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals(namedQuery2, namedQueries.next()); - assertEquals(namedQuery3, namedQueries.next()); - assertEquals(namedQuery, namedQueries.next()); - - namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - } - - public void testRemoveNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedQuery(0).setName("FOO"); - ormEntity.addNamedQuery(1).setName("BAR"); - ormEntity.addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - ormEntity.removeNamedQuery(0); - assertEquals(2, entityResource.getNamedQueries().size()); - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - - ormEntity.removeNamedQuery(0); - assertEquals(1, entityResource.getNamedQueries().size()); - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - - ormEntity.removeNamedQuery(0); - assertEquals(0, entityResource.getNamedQueries().size()); - } - - public void testMoveNamedQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedQuery(0).setName("FOO"); - ormEntity.addNamedQuery(1).setName("BAR"); - ormEntity.addNamedQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedQueries().size()); - - - ormEntity.moveNamedQuery(2, 0); - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - - - ormEntity.moveNamedQuery(0, 1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedQueries().get(2).getName()); - } - - public void testUpdateNamedQueries() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().add(OrmFactory.eINSTANCE.createXmlNamedQuery()); - entityResource.getNamedQueries().get(0).setName("FOO"); - entityResource.getNamedQueries().get(1).setName("BAR"); - entityResource.getNamedQueries().get(2).setName("BAZ"); - - ListIterator<OrmNamedQuery> namedQueries = ormEntity.namedQueries(); - assertEquals("FOO", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(3, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().move(2, 0); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().move(0, 1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("BAR", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertEquals("FOO", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(2, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().remove(1); - namedQueries = ormEntity.namedQueries(); - assertEquals("BAZ", namedQueries.next().getName()); - assertFalse(namedQueries.hasNext()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedQueries().remove(0); - assertFalse(ormEntity.namedQueries().hasNext()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - } - - public void testAddNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - OrmNamedNativeQuery namedNativeQuery = ormEntity.addNamedNativeQuery(0); - namedNativeQuery.setName("FOO"); - - assertEquals("FOO", entityResource.getNamedNativeQueries().get(0).getName()); - - OrmNamedNativeQuery namedNativeQuery2 = ormEntity.addNamedNativeQuery(0); - namedNativeQuery2.setName("BAR"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(1).getName()); - - OrmNamedNativeQuery namedNativeQuery3 = ormEntity.addNamedNativeQuery(1); - namedNativeQuery3.setName("BAZ"); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals(namedNativeQuery2, namedNativeQueries.next()); - assertEquals(namedNativeQuery3, namedNativeQueries.next()); - assertEquals(namedNativeQuery, namedNativeQueries.next()); - - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - } - - public void testRemoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedNativeQuery(0).setName("FOO"); - ormEntity.addNamedNativeQuery(1).setName("BAR"); - ormEntity.addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(2, entityResource.getNamedNativeQueries().size()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(1, entityResource.getNamedNativeQueries().size()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - - ormEntity.removeNamedNativeQuery(0); - assertEquals(0, entityResource.getNamedNativeQueries().size()); - } - - public void testMoveNamedNativeQuery() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - ormEntity.addNamedNativeQuery(0).setName("FOO"); - ormEntity.addNamedNativeQuery(1).setName("BAR"); - ormEntity.addNamedNativeQuery(2).setName("BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertEquals(3, entityResource.getNamedNativeQueries().size()); - - - ormEntity.moveNamedNativeQuery(2, 0); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAR", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - - - ormEntity.moveNamedNativeQuery(0, 1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - - assertEquals("BAZ", entityResource.getNamedNativeQueries().get(0).getName()); - assertEquals("BAR", entityResource.getNamedNativeQueries().get(1).getName()); - assertEquals("FOO", entityResource.getNamedNativeQueries().get(2).getName()); - } - - public void testUpdateNamedNativeQueries() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().add(OrmFactory.eINSTANCE.createXmlNamedNativeQuery()); - entityResource.getNamedNativeQueries().get(0).setName("FOO"); - entityResource.getNamedNativeQueries().get(1).setName("BAR"); - entityResource.getNamedNativeQueries().get(2).setName("BAZ"); - ListIterator<OrmNamedNativeQuery> namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(3, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().move(2, 0); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().move(0, 1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("BAR", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertEquals("FOO", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(2, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().remove(1); - namedNativeQueries = ormEntity.namedNativeQueries(); - assertEquals("BAZ", namedNativeQueries.next().getName()); - assertFalse(namedNativeQueries.hasNext()); - assertEquals(1, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - - entityResource.getNamedNativeQueries().remove(0); - assertFalse(ormEntity.namedNativeQueries().hasNext()); - assertEquals(0, CollectionTools.size(ormEntity.getPersistenceUnit().allQueries())); - } - - public void testUpdateIdClass() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - - assertNull(ormEntity.getIdClass()); - assertNotNull(entityResource.getIdClass()); - - entityResource.getIdClass().setClassName("model.Foo"); - assertEquals("model.Foo", ormEntity.getIdClass()); - assertEquals("model.Foo", entityResource.getIdClass().getClassName()); - - //test setting @IdClass value to null, id-class tag is not removed - entityResource.getIdClass().setClassName(null); - assertNull(ormEntity.getIdClass()); - assertNotNull(entityResource.getIdClass()); - - //reset @IdClass value and then remove id-class tag - entityResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - entityResource.getIdClass().setClassName("model.Foo"); - entityResource.setIdClass(null); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - - ormEntity.setIdClass("model.Foo"); - assertEquals("model.Foo", entityResource.getIdClass().getClassName()); - assertEquals("model.Foo", ormEntity.getIdClass()); - - ormEntity.setIdClass(null); - assertNull(ormEntity.getIdClass()); - assertNull(entityResource.getIdClass()); - } - - - public void testGetPrimaryKeyColumnNameWithAttributeOverride() throws Exception { - createTestMappedSuperclass(); - createTestSubType(); - OrmPersistentType parentPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity childXmlEntity = (OrmEntity) childPersistentType.getMapping(); - - assertNull(childXmlEntity.getPrimaryKeyColumnName()); - - parentPersistentType.getAttributeNamed("id").makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals("id", childXmlEntity.getPrimaryKeyColumnName()); - - ((OrmIdMapping) parentPersistentType.getAttributeNamed("id").getMapping()).getColumn().setSpecifiedName("MY_ID"); - assertEquals("MY_ID", childXmlEntity.getPrimaryKeyColumnName()); - - //TODO once bug 228718 is fixed -// OrmAttributeOverride ormAttributeOverride = childXmlEntity.virtualAttributeOverrides().next(); -// assertEquals("id", ormAttributeOverride.getName()); -// -// ormAttributeOverride = (OrmAttributeOverride) ormAttributeOverride.setVirtual(false); -// ormAttributeOverride.getColumn().setSpecifiedName("ID"); -// assertEquals("ID", childXmlEntity.getPrimaryKeyColumnName()); - } - - - public void testDiscriminatorValueIsAllowedConcreteClass() throws Exception { - createTestType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertTrue(entity.isDiscriminatorValueAllowed()); - } - - public void testDiscriminatorValueIsAllowedAbstractClass() throws Exception { - createTestAbstractType(); - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity entity = (OrmEntity) persistentType.getMapping(); - assertFalse(entity.isDiscriminatorValueAllowed()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java deleted file mode 100644 index a9366c2959..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmGeneratedValueTests.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; -import org.eclipse.jpt.core.resource.orm.XmlId; -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.iterators.ArrayIterator; - -public class OrmGeneratedValueTests extends ContextModelTestCase -{ - public OrmGeneratedValueTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set generator in the resource model, verify context model updated - generatedValueResource.setGenerator("FOO"); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - assertEquals("FOO", generatedValueResource.getGenerator()); - - //set name to null in the resource model - generatedValueResource.setGenerator(null); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - assertNull(generatedValueResource.getGenerator()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - OrmGeneratedValue ormGeneratedValue = ormIdMapping.addGeneratedValue(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - XmlGeneratedValue generatedValueResource = idResource.getGeneratedValue(); - - //set name in the context model, verify resource model modified - ormGeneratedValue.setSpecifiedGenerator("FOO"); - assertEquals("FOO", generatedValueResource.getGenerator()); - assertEquals("FOO", ormGeneratedValue.getSpecifiedGenerator()); - - //set name to null in the context model - ormGeneratedValue.setSpecifiedGenerator(null); - assertNull(generatedValueResource.getGenerator()); - assertNull(ormGeneratedValue.getSpecifiedGenerator()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java deleted file mode 100644 index 8199e6f116..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmIdMappingTests.java +++ /dev/null @@ -1,795 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.GenerationType; -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.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlId; -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.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class OrmIdMappingTests extends ContextModelTestCase -{ - public OrmIdMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception{ - this.createAnnotationAndMembers("Id", ""); - } - - private void createColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private void createGeneratedValueAnnotation() throws Exception{ - this.createAnnotationAndMembers("GeneratedValue", - "GenerationType strategy() default AUTO;" + - "String generator() default \"\"; "); - } - - - private void createSequenceGeneratorAnnotation() throws Exception{ - this.createAnnotationAndMembers("SequenceGenerator", - "String name();" + - "String sequenceName() default \"\"; " + - "int initialValue() default 0; " + - "int allocationSize() default 50;"); - } - - private void createTableGeneratorAnnotation() throws Exception{ - this.createAnnotationAndMembers("TableGenerator", - "String name(); " + - "String table() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";" + - "String pkColumnName() default \"\"; " + - "String valueColumnName() default \"\"; " + - "String pkColumnValue() default \"\"; " + - "int initialValue() default 0; " + - "int allocationSize() default 50; " + - "UniqueConstraint[] uniqueConstraints() default {};"); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - createColumnAnnotation(); - createTemporalAnnotation(); - createGeneratedValueAnnotation(); - createSequenceGeneratorAnnotation(); - createTableGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE, JPA.GENERATED_VALUE, JPA.GENERATION_TYPE, JPA.TABLE_GENERATOR, JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - sb.append(CR); - sb.append(" @GeneratedValue(strategy=GenerationType.TABLE, generator=\"myTableGenerator\")"); - sb.append(CR); - sb.append(" @TableGenerator(name=\"myTableGenerator\", table=\"myTable\", catalog=\"myCatalog\", schema=\"mySchema\", pkColumnName=\"myPkColumnName\", valueColumnName=\"myValueColumnName\", pkColumnValue=\"myPkColumnValue\", initialValue=1, allocationSize=1)"); - sb.append(CR); - sb.append(" @SequenceGenerator(name=\"mySequenceGenerator\")"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the resource model, verify context model updated - idResource.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the resource model - idResource.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertEquals("idMapping", ormIdMapping.getName()); - assertEquals("idMapping", idResource.getName()); - - //set name in the context model, verify resource model updated - ormIdMapping.setName("newName"); - assertEquals("newName", ormIdMapping.getName()); - assertEquals("newName", idResource.getName()); - - //set name to null in the context model - ormIdMapping.setName(null); - assertNull(ormIdMapping.getName()); - assertNull(idResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTemporal()); - assertNull(idResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ormIdMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ormIdMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - - idResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ormIdMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - - //set temporal to null in the resource model - idResource.setTemporal(null); - assertNull(ormIdMapping.getTemporal()); - assertNull(idResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTemporal()); - assertNull(idResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormIdMapping.setTemporal(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, idResource.getTemporal()); - assertEquals(TemporalType.DATE, ormIdMapping.getTemporal()); - - ormIdMapping.setTemporal(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, idResource.getTemporal()); - assertEquals(TemporalType.TIME, ormIdMapping.getTemporal()); - - ormIdMapping.setTemporal(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, idResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ormIdMapping.getTemporal()); - - //set temporal to null in the context model - ormIdMapping.setTemporal(null); - assertNull(idResource.getTemporal()); - assertNull(ormIdMapping.getTemporal()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - - public void testAddSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.addSequenceGenerator(); - - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.addSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - ormIdMapping.addSequenceGenerator(); - assertNotNull(idResource.getSequenceGenerator()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - - ormIdMapping.removeSequenceGenerator(); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.removeSequenceGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateSequenceGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setSequenceGenerator(OrmFactory.eINSTANCE.createXmlSequenceGeneratorImpl()); - assertNotNull(ormIdMapping.getSequenceGenerator()); - assertNotNull(idResource.getSequenceGenerator()); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - ormIdMapping.getSequenceGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setSequenceGenerator(null); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(idResource.getSequenceGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.addTableGenerator(); - - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getTableGenerator()); - - //try adding another table generator, should get an IllegalStateException - try { - ormIdMapping.addTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - ormIdMapping.addTableGenerator(); - assertNotNull(idResource.getTableGenerator()); - assertNotNull(ormIdMapping.getTableGenerator()); - - ormIdMapping.removeTableGenerator(); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - - //try removing the table generator again, should get an IllegalStateException - try { - ormIdMapping.removeTableGenerator(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateTableGenerator() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setTableGenerator(OrmFactory.eINSTANCE.createXmlTableGeneratorImpl()); - assertNotNull(ormIdMapping.getTableGenerator()); - assertNotNull(idResource.getTableGenerator()); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - ormIdMapping.getTableGenerator().setName("foo"); - assertEquals(1, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - - idResource.setTableGenerator(null); - assertNull(ormIdMapping.getTableGenerator()); - assertNull(idResource.getTableGenerator()); - assertEquals(0, CollectionTools.size(ormIdMapping.getPersistenceUnit().allGenerators())); - } - - public void testAddGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - //try adding another sequence generator, should get an IllegalStateException - try { - ormIdMapping.addGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testRemoveGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - ormIdMapping.addGeneratedValue(); - assertNotNull(idResource.getGeneratedValue()); - assertNotNull(ormIdMapping.getGeneratedValue()); - - ormIdMapping.removeGeneratedValue(); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - //try removing the sequence generator again, should get an IllegalStateException - try { - ormIdMapping.removeGeneratedValue(); - } catch (IllegalStateException e) { - return; - } - fail("IllegalStateException not thrown"); - } - - public void testUpdateGeneratedValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idMapping"); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - XmlId idResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getIds().get(0); - - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(OrmFactory.eINSTANCE.createXmlGeneratedValueImpl()); - - assertNotNull(ormIdMapping.getGeneratedValue()); - assertNotNull(idResource.getGeneratedValue()); - - idResource.setGeneratedValue(null); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(idResource.getGeneratedValue()); - } - - - public void testIdMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormIdMapping.getName()); - assertNull(ormIdMapping.getTemporal()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormIdMapping.getName()); - assertEquals(TemporalType.TIMESTAMP, ormIdMapping.getTemporal()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - - OrmGeneratedValue ormGeneratedValue = ormIdMapping.getGeneratedValue(); - assertEquals("myTableGenerator", ormGeneratedValue.getSpecifiedGenerator()); - assertEquals(GenerationType.TABLE, ormGeneratedValue.getSpecifiedStrategy()); - - OrmTableGenerator ormTableGenerator = ormIdMapping.getTableGenerator(); - assertEquals("myTableGenerator", ormTableGenerator.getName()); - assertEquals("myTable", ormTableGenerator.getSpecifiedTable()); - assertEquals("myCatalog", ormTableGenerator.getSpecifiedCatalog()); - assertEquals("mySchema", ormTableGenerator.getSpecifiedSchema()); - assertEquals("myPkColumnName", ormTableGenerator.getSpecifiedPkColumnName()); - assertEquals("myPkColumnValue", ormTableGenerator.getSpecifiedPkColumnValue()); - assertEquals("myValueColumnName", ormTableGenerator.getSpecifiedValueColumnName()); - assertEquals(Integer.valueOf(1), ormTableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), ormTableGenerator.getSpecifiedAllocationSize()); - - OrmSequenceGenerator ormSequenceGenerator = ormIdMapping.getSequenceGenerator(); - assertEquals("mySequenceGenerator", ormSequenceGenerator.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getTemporal()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(Boolean.FALSE, ormColumn.getUnique()); - assertEquals(Boolean.TRUE, ormColumn.getNullable()); - assertEquals(Boolean.TRUE, ormColumn.getInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(Integer.valueOf(255), ormColumn.getLength()); - assertEquals(Integer.valueOf(0), ormColumn.getPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityIdMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormIdMapping.getName()); - assertNull(ormIdMapping.getTemporal()); - assertNull(ormIdMapping.getGeneratedValue()); - assertNull(ormIdMapping.getSequenceGenerator()); - assertNull(ormIdMapping.getTableGenerator()); - - OrmColumn ormColumn = ormIdMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - - public void testIdMorphToBasicMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((BasicMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToVersionMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((VersionMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((VersionMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testIdMorphToTransientMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToEmbeddedIdMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToOneToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToOneMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } - - public void testIdMorphToManyToManyMapping() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "id"); - - IdMapping idMapping = (IdMapping) ormPersistentAttribute.getMapping(); - assertFalse(idMapping.isDefault()); - idMapping.getColumn().setSpecifiedName("FOO"); - idMapping.setTemporal(TemporalType.TIME); - assertFalse(idMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("id", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java deleted file mode 100644 index 24a19dba28..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinColumnTests.java +++ /dev/null @@ -1,506 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -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; - -public class OrmJoinColumnTests extends ContextModelTestCase -{ - public OrmJoinColumnTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - //set name to null in the resource model - joinColumnResource.setName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - joinColumnResource.setName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedName()); - assertEquals("FOO", joinColumnResource.getName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinColumnResource.getName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedName("foo"); - assertEquals("foo", joinColumn.getSpecifiedName()); - assertEquals("foo", joinColumnResource.getName()); - - //set name to null in the context model - joinColumn.setSpecifiedName(null); - assertNull(joinColumn.getSpecifiedName()); - assertNull(joinTableResource.getJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - joinColumnResource.setReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - joinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", joinColumnResource.getReferencedColumnName()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - joinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", joinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", joinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - joinColumn.setSpecifiedReferencedColumnName(null); - assertNull(joinColumn.getSpecifiedReferencedColumnName()); - assertNull(joinTableResource.getJoinColumns().get(0).getReferencedColumnName()); - } - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - joinColumnResource.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - joinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", joinColumn.getColumnDefinition()); - assertEquals("FOO", joinColumnResource.getColumnDefinition()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - joinColumn.setColumnDefinition("foo"); - assertEquals("foo", joinColumn.getColumnDefinition()); - assertEquals("foo", joinColumnResource.getColumnDefinition()); - - //set name to null in the context model - joinColumn.setColumnDefinition(null); - assertNull(joinColumn.getColumnDefinition()); - assertNull(joinTableResource.getJoinColumns().get(0).getColumnDefinition()); - } - - public void testUpdateSpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the resource model, verify context model updated - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - //set table to null in the resource model - joinColumnResource.setTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - joinColumnResource.setTable("FOO"); - assertEquals("FOO", ormJoinColumn.getSpecifiedTable()); - assertEquals("FOO", joinColumnResource.getTable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedTable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinColumnResource.getTable()); - - //set table in the context model, verify resource model modified - ormJoinColumn.setSpecifiedTable("foo"); - assertEquals("foo", ormJoinColumn.getSpecifiedTable()); - assertEquals("foo", joinColumnResource.getTable()); - - //set table to null in the context model - ormJoinColumn.setSpecifiedTable(null); - assertNull(ormJoinColumn.getSpecifiedTable()); - assertNull(joinTableResource.getJoinColumns().get(0).getTable()); - } - - public void testUpdateSpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the resource model, verify context model updated - joinColumnResource.setNullable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.TRUE, joinColumnResource.getNullable()); - - //set nullable to null in the resource model - joinColumnResource.setNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - joinColumnResource.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedNullable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinColumnResource.getNullable()); - - //set nullable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, joinColumnResource.getNullable()); - - //set nullable to null in the context model - ormJoinColumn.setSpecifiedNullable(null); - assertNull(ormJoinColumn.getSpecifiedNullable()); - assertNull(joinTableResource.getJoinColumns().get(0).getNullable()); - } - - public void testUpdateSpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the resource model, verify context model updated - joinColumnResource.setUpdatable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.TRUE, joinColumnResource.getUpdatable()); - - //set updatable to null in the resource model - joinColumnResource.setUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - joinColumnResource.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUpdatable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinColumnResource.getUpdatable()); - - //set updatable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals(Boolean.FALSE, joinColumnResource.getUpdatable()); - - //set updatable to null in the context model - ormJoinColumn.setSpecifiedUpdatable(null); - assertNull(ormJoinColumn.getSpecifiedUpdatable()); - assertNull(joinTableResource.getJoinColumns().get(0).getUpdatable()); - } - - public void testUpdateSpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the resource model, verify context model updated - joinColumnResource.setInsertable(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.TRUE, joinColumnResource.getInsertable()); - - //set insertable to null in the resource model - joinColumnResource.setInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - joinColumnResource.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedInsertable() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinColumnResource.getInsertable()); - - //set insertable in the context model, verify resource model modified - ormJoinColumn.setSpecifiedInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, joinColumnResource.getInsertable()); - - //set insertable to null in the context model - ormJoinColumn.setSpecifiedInsertable(null); - assertNull(ormJoinColumn.getSpecifiedInsertable()); - assertNull(joinTableResource.getJoinColumns().get(0).getInsertable()); - } - - public void testUpdateSpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the resource model, verify context model updated - joinColumnResource.setUnique(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.TRUE, joinColumnResource.getUnique()); - - //set unique to null in the resource model - joinColumnResource.setUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - joinColumnResource.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - assertTrue(joinTableResource.getJoinColumns().isEmpty()); - } - - public void testModifySpecifiedUnique() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - OrmJoinColumn ormJoinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - XmlJoinColumn joinColumnResource = joinTableResource.getJoinColumns().get(0); - - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinColumnResource.getUnique()); - - //set unique in the context model, verify resource model modified - ormJoinColumn.setSpecifiedUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, joinColumnResource.getUnique()); - - //set unique to null in the context model - ormJoinColumn.setSpecifiedUnique(null); - assertNull(ormJoinColumn.getSpecifiedUnique()); - assertNull(joinTableResource.getJoinColumns().get(0).getUnique()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java deleted file mode 100644 index c167095f56..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmJoinTableTests.java +++ /dev/null @@ -1,1180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaJoinColumn; -import org.eclipse.jpt.core.context.java.JavaJoinTable; -import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; -import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmJoinTable; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlJoinTable; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmJoinTableTests extends ContextModelTestCase -{ - public OrmJoinTableTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private void createManyToManyAnnotation() throws Exception{ - this.createAnnotationAndMembers("ManyToMany", ""); - } - - private void createJoinTableAnnotation() throws Exception{ - //TODO - this.createAnnotationAndMembers("JoinTable", - "String name() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";"); - } - - private ICompilationUnit createTestEntityWithValidManyToMany() throws Exception { - createEntityAnnotation(); - createManyToManyAnnotation(); - createJoinTableAnnotation(); - createIdAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.ID, "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); - sb.append("@Id").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 { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - - //set name in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - //set name to null in the resource model - manyToMany.getJoinTable().setName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable().getName()); - - manyToMany.getJoinTable().setName("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("FOO", manyToMany.getJoinTable().getName()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - - //set name in the context model, verify resource model modified - ormJoinTable.setSpecifiedName("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedName()); - assertEquals("foo", manyToMany.getJoinTable().getName()); - - //set name to null in the context model - ormJoinTable.setSpecifiedName(null); - assertNull(ormJoinTable.getSpecifiedName()); - assertNull(manyToMany.getJoinTable()); - } - - public void testVirtualJoinTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals(null, ormJoinTable.getSpecifiedName()); - - createTargetEntity(); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getSpecifiedName()); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertEquals(0, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize()); - OrmJoinColumn ormJoinColumn = ormJoinTable.getDefaultJoinColumn(); -//TODO need to test joinColumn defaults here as well as in java and all the relatioship mapping types -// assertEquals("id_project_id", ormJoinColumn.getDefaultName()); -// assertEquals("id_project_id", ormJoinColumn.getDefaultReferencedColumnName()); - OrmJoinColumn inverseOrmJoinColumn = ormJoinTable.getDefaultInverseJoinColumn(); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultName()); -// assertEquals("id_project_id", inverseOrmJoinColumn.getDefaultReferencedColumnName()); - - JavaPersistentAttribute javaPersistentAttribute = ormManyToManyMapping.getJavaPersistentAttribute(); - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) javaPersistentAttribute.getMapping(); - JavaJoinTable javaJoinTable = javaManyToManyMapping.getJoinTable(); - javaJoinTable.setSpecifiedName("FOO"); - javaJoinTable.setSpecifiedCatalog("CATALOG"); - javaJoinTable.setSpecifiedSchema("SCHEMA"); - JavaJoinColumn javaJoinColumn = javaJoinTable.addSpecifiedJoinColumn(0); - javaJoinColumn.setSpecifiedName("NAME"); - javaJoinColumn.setSpecifiedReferencedColumnName("REFERENCED_NAME"); - JavaJoinColumn inverseJavaJoinColumn = javaJoinTable.addSpecifiedInverseJoinColumn(0); - inverseJavaJoinColumn.setSpecifiedName("INVERSE_NAME"); - inverseJavaJoinColumn.setSpecifiedReferencedColumnName("INVERSE_REFERENCED_NAME"); - - assertEquals("FOO", ormJoinTable.getSpecifiedName()); - assertEquals("CATALOG", ormJoinTable.getSpecifiedCatalog()); - assertEquals("SCHEMA", ormJoinTable.getSpecifiedSchema()); - assertEquals(1, ormJoinTable.specifiedJoinColumnsSize()); - assertEquals(1, ormJoinTable.specifiedInverseJoinColumnsSize()); - ormJoinColumn = ormJoinTable.specifiedJoinColumns().next(); - assertEquals("NAME", ormJoinColumn.getSpecifiedName()); - assertEquals("REFERENCED_NAME", ormJoinColumn.getSpecifiedReferencedColumnName()); - inverseOrmJoinColumn = ormJoinTable.specifiedInverseJoinColumns().next(); - assertEquals("INVERSE_NAME", inverseOrmJoinColumn.getSpecifiedName()); - assertEquals("INVERSE_REFERENCED_NAME", inverseOrmJoinColumn.getSpecifiedReferencedColumnName()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "projects"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - assertEquals(null, ormJoinTable.getDefaultName()); - - createTargetEntity(); - OrmPersistentType targetPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Project"); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - ((JavaEntity) targetPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME + "_FOO", ormJoinTable.getDefaultName()); - - ((JavaEntity) ormPersistentType.getJavaPersistentType().getMapping()).getTable().setSpecifiedName("BAR"); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - JavaManyToManyMapping javaManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().getAttributeNamed("projects").getMapping(); - javaManyMapping.getJoinTable().setSpecifiedName("JAVA_JOIN_TABLE"); - - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - - //set metadata-complete to true, will ignore java annotation settings - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME + "_Project", ormJoinTable.getDefaultName()); - - - entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - //remove m-m mapping from the orm.xml file - ormPersistentAttribute.makeVirtual(); - //ormPersistentType.getMapping().setSpecifiedMetadataComplete(null); - ormPersistentAttribute = ormPersistentType.getAttributeNamed("projects"); - ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - ormJoinTable = ormManyToManyMapping.getJoinTable(); - assertTrue(ormPersistentAttribute.isVirtual()); - assertEquals("JAVA_JOIN_TABLE", ormManyToManyMapping.getJoinTable().getSpecifiedName());//specifiedName since this is a virtual mapping now - - javaManyMapping.getJoinTable().setSpecifiedName(null); - assertEquals("BAR_FOO", ormJoinTable.getSpecifiedName()); - assertEquals("BAR_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) ormPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TABLE_NAME"); - assertEquals("ORM_TABLE_NAME_FOO", ormJoinTable.getDefaultName()); - - ((OrmEntity) targetPersistentType.getMapping()).getTable().setSpecifiedName("ORM_TARGET"); - assertEquals("ORM_TABLE_NAME_ORM_TARGET", ormJoinTable.getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set schema in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the resource model - manyToMany.getJoinTable().setSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable().getSchema()); - - manyToMany.getJoinTable().setSchema("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedSchema()); - assertEquals("FOO", manyToMany.getJoinTable().getSchema()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultSchemaFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.getTable().setSpecifiedSchema("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultSchema()); -// assertNull(childXmlEntity.getTable().getDefaultSchema()); -// } -// -// public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().setSpecifiedSchema("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedSchema("JAVA_SCHEMA"); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultSchema()); -// -// -// xmlEntity.entityMappings().setSpecifiedSchema(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); -// assertNull(xmlEntity.getTable().getDefaultSchema()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_SCHEMA", xmlEntity.getTable().getDefaultSchema()); -// } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - - //set Schema in the context model, verify resource model modified - ormJoinTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedSchema()); - assertEquals("foo", manyToMany.getJoinTable().getSchema()); - - //set Schema to null in the context model - ormJoinTable.setSpecifiedSchema(null); - assertNull(ormJoinTable.getSpecifiedSchema()); - assertNull(manyToMany.getJoinTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the resource model, verify context model updated - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the resource model - manyToMany.getJoinTable().setCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable().getCatalog()); - - manyToMany.getJoinTable().setCatalog("FOO"); - assertEquals("FOO", ormJoinTable.getSpecifiedCatalog()); - assertEquals("FOO", manyToMany.getJoinTable().getCatalog()); - - manyToMany.setJoinTable(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - - //set Catalog in the context model, verify resource model modified - ormJoinTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormJoinTable.getSpecifiedCatalog()); - assertEquals("foo", manyToMany.getJoinTable().getCatalog()); - - //set Catalog to null in the context model - ormJoinTable.setSpecifiedCatalog(null); - assertNull(ormJoinTable.getSpecifiedCatalog()); - assertNull(manyToMany.getJoinTable()); - } - -// public void testUpdateDefaultCatalogFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("Foo"); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// xmlEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.setSpecifiedMetadataComplete(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("Bar"); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertNull(parentXmlEntity.getTable().getDefaultCatalog()); -// assertNull(childXmlEntity.getTable().getDefaultCatalog()); -// } -// -// public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("FOO"); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().setSpecifiedCatalog("BAR"); -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.javaEntity().getTable().setSpecifiedCatalog("JAVA_CATALOG"); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName("BLAH"); -// //xml entity now has a table element so default schema is not taken from java -// assertEquals("BAR", xmlEntity.getTable().getDefaultCatalog()); -// -// -// xmlEntity.entityMappings().setSpecifiedCatalog(null); -// assertEquals("FOO", xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); -// assertNull(xmlEntity.getTable().getDefaultCatalog()); -// -// xmlEntity.getTable().setSpecifiedName(null); -// assertEquals("JAVA_CATALOG", xmlEntity.getTable().getDefaultCatalog()); -//} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity xmlEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", xmlEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", xmlEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", xmlEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", xmlEntity.getName()); -// -// entityResource.setName(null); -// assertNull(xmlEntity.getName()); -// } - - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(2, joinTableResource.getJoinColumns().size()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(1, joinTableResource.getJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedJoinColumn(0); - assertEquals(0, joinTableResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getJoinColumns().size()); - - - ormJoinTable.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getJoinColumns().get(2).getName()); - } - - public void testUpdateInverseJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getInverseJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - joinTableResource.getInverseJoinColumns().get(0).setName("FOO"); - joinTableResource.getInverseJoinColumns().get(1).setName("BAR"); - joinTableResource.getInverseJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getInverseJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedInverseJoinColumns().hasNext()); - } - - public void testAddSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - OrmJoinColumn joinColumn = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormJoinTable.addSpecifiedInverseJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormJoinTable.addSpecifiedInverseJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(2, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(1, joinTableResource.getInverseJoinColumns().size()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - - ormJoinTable.removeSpecifiedInverseJoinColumn(0); - assertEquals(0, joinTableResource.getInverseJoinColumns().size()); - } - - public void testMoveSpecifiedInverseJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - ormJoinTable.addSpecifiedInverseJoinColumn(0).setSpecifiedName("FOO"); - ormJoinTable.addSpecifiedInverseJoinColumn(1).setSpecifiedName("BAR"); - ormJoinTable.addSpecifiedInverseJoinColumn(2).setSpecifiedName("BAZ"); - - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - assertEquals(3, joinTableResource.getInverseJoinColumns().size()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - - - ormJoinTable.moveSpecifiedInverseJoinColumn(0, 1); - joinColumns = ormJoinTable.specifiedInverseJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", joinTableResource.getInverseJoinColumns().get(0).getName()); - assertEquals("BAR", joinTableResource.getInverseJoinColumns().get(1).getName()); - assertEquals("FOO", joinTableResource.getInverseJoinColumns().get(2).getName()); - } - - public void testUpdateJoinColumns() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - joinTableResource.getJoinColumns().add(OrmFactory.eINSTANCE.createXmlJoinColumnImpl()); - - joinTableResource.getJoinColumns().get(0).setName("FOO"); - joinTableResource.getJoinColumns().get(1).setName("BAR"); - joinTableResource.getJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmJoinColumn> joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(2, 0); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().move(0, 1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(1); - joinColumns = ormJoinTable.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertFalse(joinColumns.hasNext()); - - joinTableResource.getJoinColumns().remove(0); - assertFalse(ormJoinTable.specifiedJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - assertEquals(0, ormJoinTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormJoinTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = joinTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - ormJoinTable.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(1); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormJoinTable.removeUniqueConstraint(0); - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - ormJoinTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormJoinTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormJoinTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, joinTableResource.getUniqueConstraints().size()); - - - ormJoinTable.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormJoinTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = joinTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - manyToMany.setJoinTable(OrmFactory.eINSTANCE.createXmlJoinTableImpl()); - XmlJoinTable joinTableResource = manyToMany.getJoinTable(); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - joinTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - joinTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntityWithValidManyToMany(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.attributes().next().getMapping(); - OrmJoinTable ormJoinTable = ormManyToManyMapping.getJoinTable(); - - assertTrue(ormManyToManyMapping.getPersistentAttribute().isVirtual()); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - JavaManyToManyMapping javaManyToManyMapping = (JavaManyToManyMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - - javaManyToManyMapping.getJoinTable().addUniqueConstraint(0).addColumnName(0, "FOO"); - javaManyToManyMapping.getJoinTable().addUniqueConstraint(1).addColumnName(0, "BAR"); - javaManyToManyMapping.getJoinTable().addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormJoinTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormManyToManyMapping.getPersistentAttribute().makeSpecified(); - - ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentType.attributes().next().getMapping(); - ormManyToManyMapping.getJoinTable(); - assertEquals(0, ormManyToManyMapping.getJoinTable().uniqueConstraintsSize()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java deleted file mode 100644 index 6507b43b0f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java +++ /dev/null @@ -1,654 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; -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; - -public class OrmManyToManyMappingTests extends ContextModelTestCase -{ - public OrmManyToManyMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the resource model, verify context model updated - manyToMany.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the resource model - manyToMany.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertEquals("manyToManyMapping", ormManyToManyMapping.getName()); - assertEquals("manyToManyMapping", manyToMany.getName()); - - //set name in the context model, verify resource model updated - ormManyToManyMapping.setName("newName"); - assertEquals("newName", ormManyToManyMapping.getName()); - assertEquals("newName", manyToMany.getName()); - - //set name to null in the context model - ormManyToManyMapping.setName(null); - assertNull(ormManyToManyMapping.getName()); - assertNull(manyToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the resource model - manyToMany.setTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToMany.getTargetEntity()); - - //set target entity to null in the context model - ormManyToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToManyMapping.getSpecifiedTargetEntity()); - assertNull(manyToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - - manyToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - - //set fetch to null in the resource model - manyToManyResource.setFetch(null); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - assertNull(manyToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch()); - - ormManyToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToManyMapping.setSpecifiedFetch(null); - assertNull(manyToManyResource.getFetch()); - assertNull(ormManyToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - manyToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormManyToManyMapping.getMappedBy()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //setmappedBy to null in the resource model - manyToMany.setMappedBy(null); - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormManyToManyMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormManyToManyMapping.getMappedBy()); - assertEquals("newMappedBy", manyToMany.getMappedBy()); - - //set mappedBy to null in the context model - ormManyToManyMapping.setMappedBy(null); - assertNull(ormManyToManyMapping.getMappedBy()); - assertNull(manyToMany.getMappedBy()); - } - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - manyToMany.setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - assertNull(ormManyToManyMapping.getMapKey()); - assertNotNull(manyToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - manyToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - manyToMany.getMapKey().setName(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey().getName()); - - manyToMany.getMapKey().setName("myMapKey"); - manyToMany.setMapKey(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormManyToManyMapping.setMapKey("myMapKey"); - assertEquals("myMapKey", ormManyToManyMapping.getMapKey()); - assertEquals("myMapKey", manyToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormManyToManyMapping.setMapKey(null); - assertNull(ormManyToManyMapping.getMapKey()); - assertNull(manyToMany.getMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - manyToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set orderBy to null in the resource model - manyToMany.setOrderBy(null); - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - XmlManyToMany manyToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToManys().get(0); - - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormManyToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormManyToManyMapping.getOrderBy()); - assertEquals("newOrderBy", manyToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormManyToManyMapping.setOrderBy(null); - assertNull(ormManyToManyMapping.getOrderBy()); - assertNull(manyToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertFalse(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy(null); - assertTrue(ormManyToManyMapping.isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertFalse(ormManyToManyMapping.isNoOrdering()); - - ormManyToManyMapping.setNoOrdering(true); - assertTrue(ormManyToManyMapping.isNoOrdering()); - assertNull(ormManyToManyMapping.getOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToManyMapping"); - OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormManyToManyMapping.isCustomOrdering()); - - ormManyToManyMapping.setOrderBy("foo"); - assertTrue(ormManyToManyMapping.isCustomOrdering()); - - ormManyToManyMapping.setOrderBy(null); - assertFalse(ormManyToManyMapping.isCustomOrdering()); - } - - public void testManyToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testManyToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((OneToManyMapping) ormPersistentAttribute.getMapping()).getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testManyToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testManyToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, "manyToMany"); - - ManyToManyMapping manyToManyMapping = (ManyToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(manyToManyMapping.isDefault()); - manyToManyMapping.setSpecifiedFetch(FetchType.EAGER); - manyToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - manyToManyMapping.setOrderBy("customOrder"); - manyToManyMapping.setMapKey("mapKey"); - manyToManyMapping.setMappedBy("mappedBy"); - manyToManyMapping.getCascade().setAll(true); - manyToManyMapping.getCascade().setMerge(true); - manyToManyMapping.getCascade().setPersist(true); - manyToManyMapping.getCascade().setRefresh(true); - manyToManyMapping.getCascade().setRemove(true); - manyToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = manyToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = manyToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(manyToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("manyToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java deleted file mode 100644 index 46762ba744..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToOneMappingTests.java +++ /dev/null @@ -1,569 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.Cascade; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; -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.iterators.ArrayIterator; - -public class OrmManyToOneMappingTests extends ContextModelTestCase -{ - public OrmManyToOneMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createManyToOneAnnotation() throws Exception{ - this.createAnnotationAndMembers("ManyToOne", - "Class targetEntity() default void.class;" + - "CascadeType[] cascade() default {};" + - "FetchType fetch() default EAGER;" + - "boolean optional() default true;"); - } - - private void createJoinColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - } - - private ICompilationUnit createTestEntityManyToOneMapping() throws Exception { - createEntityAnnotation(); - createManyToOneAnnotation(); - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() 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 ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the resource model, verify context model updated - manyToOne.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the resource model - manyToOne.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertEquals("manyToOneMapping", ormManyToOneMapping.getName()); - assertEquals("manyToOneMapping", manyToOne.getName()); - - //set name in the context model, verify resource model updated - ormManyToOneMapping.setName("newName"); - assertEquals("newName", ormManyToOneMapping.getName()); - assertEquals("newName", manyToOne.getName()); - - //set name to null in the context model - ormManyToOneMapping.setName(null); - assertNull(ormManyToOneMapping.getName()); - assertNull(manyToOne.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - manyToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the resource model - manyToOne.setTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", manyToOne.getTargetEntity()); - - //set target entity to null in the context model - ormManyToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertNull(manyToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - - manyToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - - //set fetch to null in the resource model - manyToOneResource.setFetch(null); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(manyToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, manyToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getSpecifiedFetch()); - - ormManyToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, manyToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormManyToOneMapping.setSpecifiedFetch(null); - assertNull(manyToOneResource.getFetch()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - manyToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - - manyToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - - //set optional to null in the resource model - manyToOneResource.setOptional(null); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(manyToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormManyToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, manyToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getSpecifiedOptional()); - - ormManyToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormManyToOneMapping.setSpecifiedOptional(null); - assertNull(manyToOneResource.getOptional()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - OrmJoinColumn joinColumn = ormManyToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", manyToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormManyToOneMapping.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormManyToOneMapping.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - ormManyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormManyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormManyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(2, manyToOneResource.getJoinColumns().size()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, manyToOneResource.getJoinColumns().size()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - - ormManyToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, manyToOneResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "manyToOneMapping"); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - XmlManyToOne manyToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getManyToOnes().get(0); - - ormManyToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormManyToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormManyToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, manyToOneResource.getJoinColumns().size()); - - - ormManyToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - - - ormManyToOneMapping.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormManyToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", manyToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", manyToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", manyToOneResource.getJoinColumns().get(2).getName()); - } - - - public void testManyToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormManyToOneMapping.getName()); - - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getOptional()); - assertNull(ormManyToOneMapping.getTargetEntity()); - - - assertFalse(ormManyToOneMapping.specifiedJoinColumns().hasNext()); - //TODO default joinColumns - //assertTrue(ormManyToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional()); - assertEquals("Address", ormManyToOneMapping.getSpecifiedTargetEntity()); - - OrmJoinColumn ormJoinColumn = ormManyToOneMapping.specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormManyToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getDefaultOptional()); - //TODO hmm, is this correct? - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityManyToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormManyToOneMapping.getName()); - assertNull(ormManyToOneMapping.getSpecifiedFetch()); - assertNull(ormManyToOneMapping.getSpecifiedOptional()); - assertNull(ormManyToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormManyToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormManyToOneMapping.getOptional()); - assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity()); - - assertFalse(ormManyToOneMapping.specifiedJoinColumns().hasNext()); - - //TODO default join columns for specified xmlManyToOne mapping -// XmlJoinColumn ormJoinColumn = ormManyToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormManyToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - //3 things tested above - //1. virtual mapping metadata complete=false - defaults are taken from the java annotations - //2. virtual mapping metadata complete=true - defaults are taken from java defaults,annotations ignored - //3. specified mapping (metadata complete=true/false - defaults are taken from java annotations - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java deleted file mode 100644 index 176aa0c4b3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmMappedSuperclassTests.java +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.ListIterator; -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.orm.OrmEmbeddable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddable; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; -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; - -public class OrmMappedSuperclassTests extends ContextModelTestCase -{ - public OrmMappedSuperclassTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the resource model, verify context model updated - mappedSuperclassResource.setClassName("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the resource model - mappedSuperclassResource.setClassName(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - - public void testModifyClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertEquals("model.Foo", ormMappedSuperclass.getClass_()); - assertEquals("model.Foo", mappedSuperclassResource.getClassName()); - - //set class in the context model, verify resource model modified - ormMappedSuperclass.setClass("com.Bar"); - assertEquals("com.Bar", ormMappedSuperclass.getClass_()); - assertEquals("com.Bar", mappedSuperclassResource.getClassName()); - - //set class to null in the context model - ormMappedSuperclass.setClass(null); - assertNull(ormMappedSuperclass.getClass_()); - assertNull(mappedSuperclassResource.getClassName()); - } - //TODO add tests for setting the className when the package is set on entity-mappings - - public void testUpdateSpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the resource model, verify context model updated - mappedSuperclassResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, ormMappedSuperclass.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, mappedSuperclassResource.getAccess()); - - //set access to null in the resource model - mappedSuperclassResource.setAccess(null); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - - public void testModifySpecifiedAccess() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - - //set access in the context model, verify resource model modified - ormMappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, ormMappedSuperclass.getSpecifiedAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, mappedSuperclassResource.getAccess()); - - //set access to null in the context model - ormMappedSuperclass.setSpecifiedAccess(null); - assertNull(ormMappedSuperclass.getSpecifiedAccess()); - assertNull(mappedSuperclassResource.getAccess()); - } - //TODO test default access from - //underlying java - //persistence-unit-defaults - //entity-mappings - //with xml-mapping-metadata-complete set - - public void testUpdateSpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set metadata-complete in the resource model, verify context model updated - mappedSuperclassResource.setMetadataComplete(true); - assertTrue(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertTrue(mappedSuperclassResource.getMetadataComplete()); - - //set access to false in the resource model - mappedSuperclassResource.setMetadataComplete(false); - assertFalse(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(mappedSuperclassResource.getMetadataComplete()); - - mappedSuperclassResource.setMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testModifySpecifiedMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - //set access in the context model, verify resource model modified - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - assertTrue(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertTrue(mappedSuperclassResource.getMetadataComplete()); - - //set access to null in the context model - ormMappedSuperclass.setSpecifiedMetadataComplete(Boolean.FALSE); - assertFalse(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(mappedSuperclassResource.getMetadataComplete()); - - ormMappedSuperclass.setSpecifiedMetadataComplete(null); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateDefaultMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isDefaultMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - public void testUpdateMetadataComplete() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(ormMappedSuperclass.isMetadataComplete()); - assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - assertNull(mappedSuperclassResource.getMetadataComplete()); - } - - - public void testMakeMappedSuperclassEntity() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - } - - //test with 2 MappedSuperclasses, make the first one an Entity so it has to move to the end of the list - public void testMakeMappedSuperclassEntity2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("model.Foo", entity.getClassName()); - assertEquals(Boolean.TRUE, entity.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, entity.getAccess()); - assertNull(entity.getDiscriminatorValue()); - assertNull(entity.getName()); - - OrmEntity ormEntity = (OrmEntity) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEntity.getClass_()); - assertEquals(Boolean.TRUE, ormEntity.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEntity.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.ENTITY_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testMakeMappedSuperclassEmbeddable() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - } - //test with 2 MappedSuperclasses, make the first one an Embeddable so it has to move to the end of the list - public void testMakeMappedSuperclassEmbeddable2() throws Exception { - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo2"); - OrmMappedSuperclass mappedSuperclass = (OrmMappedSuperclass) mappedSuperclassPersistentType.getMapping(); - mappedSuperclass.setSpecifiedAccess(AccessType.PROPERTY); - mappedSuperclass.setSpecifiedMetadataComplete(Boolean.TRUE); - - mappedSuperclassPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - - XmlEmbeddable embeddable = ormResource().getEntityMappings().getEmbeddables().get(0); - assertEquals("model.Foo", embeddable.getClassName()); - assertEquals(Boolean.TRUE, embeddable.getMetadataComplete()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, embeddable.getAccess()); - - OrmEmbeddable ormEmbeddable = (OrmEmbeddable) mappedSuperclassPersistentType.getMapping(); - assertEquals("model.Foo", ormEmbeddable.getClass_()); - assertEquals(Boolean.TRUE, ormEmbeddable.getSpecifiedMetadataComplete()); - assertEquals(AccessType.PROPERTY, ormEmbeddable.getSpecifiedAccess()); - - ListIterator<OrmPersistentType> persistentTypes = entityMappings().ormPersistentTypes(); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - assertEquals(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, persistentTypes.next().getMappingKey()); - } - - public void testUpdateIdClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNotNull(mappedSuperclassResource.getIdClass()); - - mappedSuperclassResource.getIdClass().setClassName("model.Foo"); - assertEquals("model.Foo", ormMappedSuperclass.getIdClass()); - assertEquals("model.Foo", mappedSuperclassResource.getIdClass().getClassName()); - - //test setting @IdClass value to null, id-class tag is not removed - mappedSuperclassResource.getIdClass().setClassName(null); - assertNull(ormMappedSuperclass.getIdClass()); - assertNotNull(mappedSuperclassResource.getIdClass()); - - //reset @IdClass value and then remove id-class tag - mappedSuperclassResource.setIdClass(OrmFactory.eINSTANCE.createXmlIdClass()); - mappedSuperclassResource.getIdClass().setClassName("model.Foo"); - mappedSuperclassResource.setIdClass(null); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - } - - public void testModifyIdClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo"); - OrmMappedSuperclass ormMappedSuperclass = (OrmMappedSuperclass) ormPersistentType.getMapping(); - XmlMappedSuperclass mappedSuperclassResource = ormResource().getEntityMappings().getMappedSuperclasses().get(0); assertNull(ormMappedSuperclass.getSpecifiedMetadataComplete()); - - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - - ormMappedSuperclass.setIdClass("model.Foo"); - assertEquals("model.Foo", mappedSuperclassResource.getIdClass().getClassName()); - assertEquals("model.Foo", ormMappedSuperclass.getIdClass()); - - ormMappedSuperclass.setIdClass(null); - assertNull(ormMappedSuperclass.getIdClass()); - assertNull(mappedSuperclassResource.getIdClass()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java deleted file mode 100644 index 84b6800528..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedNativeQueryTests.java +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedNativeQuery; -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; - -public class OrmNamedNativeQueryTests extends ContextModelTestCase -{ - public OrmNamedNativeQueryTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the resource model - namedNativeQueryResource.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setName("newName"); - assertEquals("newName", ormNamedNativeQuery.getName()); - assertEquals("newName", namedNativeQueryResource.getName()); - - //set name to null in the context model - ormNamedNativeQuery.setName(null); - assertNull(ormNamedNativeQuery.getName()); - assertNull(namedNativeQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the resource model - namedNativeQueryResource.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setQuery("newName"); - assertEquals("newName", ormNamedNativeQuery.getQuery()); - assertEquals("newName", namedNativeQueryResource.getQuery()); - - //set name to null in the context model - ormNamedNativeQuery.setQuery(null); - assertNull(ormNamedNativeQuery.getQuery()); - assertNull(namedNativeQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - OrmQueryHint queryHint = ormNamedNativeQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedNativeQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedNativeQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedNativeQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - ListIterator<OrmQueryHint> queryHints = ormNamedNativeQuery.hints(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedNativeQuery.hints(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(2, namedNativeQueryResource.getHints().size()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(1, namedNativeQueryResource.getHints().size()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - - ormNamedNativeQuery.removeHint(0); - assertEquals(0, namedNativeQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - ormNamedNativeQuery.addHint(0).setName("FOO"); - ormNamedNativeQuery.addHint(1).setName("BAR"); - ormNamedNativeQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedNativeQueryResource.getHints().size()); - - - ormNamedNativeQuery.moveHint(2, 0); - ListIterator<OrmQueryHint> hints = ormNamedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - - - ormNamedNativeQuery.moveHint(0, 1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedNativeQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedNativeQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedNativeQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedNativeQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedNativeQueryResource.getHints().get(0).setName("FOO"); - namedNativeQueryResource.getHints().get(1).setName("BAR"); - namedNativeQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator<OrmQueryHint> hints = ormNamedNativeQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(2, 0); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().move(0, 1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(1); - hints = ormNamedNativeQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedNativeQueryResource.getHints().remove(0); - assertFalse(ormNamedNativeQuery.hints().hasNext()); - } - - - public void testUpdateResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the resource model - namedNativeQueryResource.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testModifyResultSetMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultSetMapping()); - assertEquals(null, ormNamedNativeQuery.getResultSetMapping()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultSetMapping("foo"); - assertEquals("foo", namedNativeQueryResource.getResultSetMapping()); - assertEquals("foo", ormNamedNativeQuery.getResultSetMapping()); - - //set name to null in the context model - ormNamedNativeQuery.setResultSetMapping(null); - assertNull(namedNativeQueryResource.getResultSetMapping()); - assertNull(ormNamedNativeQuery.getResultSetMapping()); - } - - public void testUpdateResultClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the resource model, verify context model updated - namedNativeQueryResource.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the resource model - namedNativeQueryResource.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } - - public void testModifyResultClass() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedNativeQuery ormNamedNativeQuery = ormEntity.addNamedNativeQuery(0); - - XmlNamedNativeQuery namedNativeQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedNativeQueries().get(0); - - assertEquals(null, namedNativeQueryResource.getResultClass()); - assertEquals(null, ormNamedNativeQuery.getResultClass()); - - //set name in the context model, verify resource model updated - ormNamedNativeQuery.setResultClass("foo"); - assertEquals("foo", namedNativeQueryResource.getResultClass()); - assertEquals("foo", ormNamedNativeQuery.getResultClass()); - - //set name to null in the context model - ormNamedNativeQuery.setResultClass(null); - assertNull(namedNativeQueryResource.getResultClass()); - assertNull(ormNamedNativeQuery.getResultClass()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java deleted file mode 100644 index 6825936f29..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmNamedQueryTests.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlNamedQuery; -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; - -public class OrmNamedQueryTests extends ContextModelTestCase -{ - public OrmNamedQueryTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the resource model, verify context model updated - namedQueryResource.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the resource model - namedQueryResource.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setName("newName"); - assertEquals("newName", ormNamedQuery.getName()); - assertEquals("newName", namedQueryResource.getName()); - - //set name to null in the context model - ormNamedQuery.setName(null); - assertNull(ormNamedQuery.getName()); - assertNull(namedQueryResource.getName()); - } - - public void testUpdateQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the resource model, verify context model updated - namedQueryResource.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the resource model - namedQueryResource.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testModifyQuery() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - - //set name in the context model, verify resource model updated - ormNamedQuery.setQuery("newName"); - assertEquals("newName", ormNamedQuery.getQuery()); - assertEquals("newName", namedQueryResource.getQuery()); - - //set name to null in the context model - ormNamedQuery.setQuery(null); - assertNull(ormNamedQuery.getQuery()); - assertNull(namedQueryResource.getQuery()); - } - - public void testAddHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - OrmQueryHint queryHint = ormNamedQuery.addHint(0); - queryHint.setName("FOO"); - - assertEquals("FOO", namedQueryResource.getHints().get(0).getName()); - - OrmQueryHint queryHint2 = ormNamedQuery.addHint(0); - queryHint2.setName("BAR"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(1).getName()); - - OrmQueryHint queryHint3 = ormNamedQuery.addHint(1); - queryHint3.setName("BAZ"); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - ListIterator<OrmQueryHint> queryHints = ormNamedQuery.hints(); - assertEquals(queryHint2, queryHints.next()); - assertEquals(queryHint3, queryHints.next()); - assertEquals(queryHint, queryHints.next()); - - queryHints = ormNamedQuery.hints(); - assertEquals("BAR", queryHints.next().getName()); - assertEquals("BAZ", queryHints.next().getName()); - assertEquals("FOO", queryHints.next().getName()); - } - - public void testRemoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - ormNamedQuery.removeHint(0); - assertEquals(2, namedQueryResource.getHints().size()); - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(1, namedQueryResource.getHints().size()); - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - - ormNamedQuery.removeHint(0); - assertEquals(0, namedQueryResource.getHints().size()); - } - - public void testMoveHint() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - ormNamedQuery.addHint(0).setName("FOO"); - ormNamedQuery.addHint(1).setName("BAR"); - ormNamedQuery.addHint(2).setName("BAZ"); - - assertEquals(3, namedQueryResource.getHints().size()); - - - ormNamedQuery.moveHint(2, 0); - ListIterator<OrmQueryHint> hints = ormNamedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAR", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAZ", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - - - ormNamedQuery.moveHint(0, 1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - - assertEquals("BAZ", namedQueryResource.getHints().get(0).getName()); - assertEquals("BAR", namedQueryResource.getHints().get(1).getName()); - assertEquals("FOO", namedQueryResource.getHints().get(2).getName()); - } - - public void testUpdateHints() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmNamedQuery ormNamedQuery = ormEntity.addNamedQuery(0); - - XmlNamedQuery namedQueryResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0); - - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - namedQueryResource.getHints().add(OrmFactory.eINSTANCE.createXmlQueryHint()); - - namedQueryResource.getHints().get(0).setName("FOO"); - namedQueryResource.getHints().get(1).setName("BAR"); - namedQueryResource.getHints().get(2).setName("BAZ"); - - ListIterator<OrmQueryHint> hints = ormNamedQuery.hints(); - assertEquals("FOO", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(2, 0); - hints = ormNamedQuery.hints(); - assertEquals("BAR", hints.next().getName()); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().move(0, 1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("BAR", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertEquals("FOO", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(1); - hints = ormNamedQuery.hints(); - assertEquals("BAZ", hints.next().getName()); - assertFalse(hints.hasNext()); - - namedQueryResource.getHints().remove(0); - assertFalse(ormNamedQuery.hints().hasNext()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java deleted file mode 100644 index 22225dfef0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java +++ /dev/null @@ -1,655 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.BasicMapping; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; -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; - -public class OrmOneToManyMappingTests extends ContextModelTestCase -{ - public OrmOneToManyMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the resource model, verify context model updated - oneToMany.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the resource model - oneToMany.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertEquals("oneToManyMapping", ormOneToManyMapping.getName()); - assertEquals("oneToManyMapping", oneToMany.getName()); - - //set name in the context model, verify resource model updated - ormOneToManyMapping.setName("newName"); - assertEquals("newName", ormOneToManyMapping.getName()); - assertEquals("newName", oneToMany.getName()); - - //set name to null in the context model - ormOneToManyMapping.setName(null); - assertNull(ormOneToManyMapping.getName()); - assertNull(oneToMany.getName()); - } - - public void testUpdateTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToMany.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the resource model - oneToMany.setTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testModifyTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToManyMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToMany.getTargetEntity()); - - //set target entity to null in the context model - ormOneToManyMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToManyMapping.getSpecifiedTargetEntity()); - assertNull(oneToMany.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - - oneToManyResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - - //set fetch to null in the resource model - oneToManyResource.setFetch(null); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToManyResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - assertNull(oneToManyResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToManyResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch()); - - ormOneToManyMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToManyResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToManyMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToManyMapping.setSpecifiedFetch(null); - assertNull(oneToManyResource.getFetch()); - assertNull(ormOneToManyMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToMany.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToManyMapping.getMappedBy()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //setmappedBy to null in the resource model - oneToMany.setMappedBy(null); - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToManyMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToManyMapping.getMappedBy()); - assertEquals("newMappedBy", oneToMany.getMappedBy()); - - //set mappedBy to null in the context model - ormOneToManyMapping.setMappedBy(null); - assertNull(ormOneToManyMapping.getMappedBy()); - assertNull(oneToMany.getMappedBy()); - } - - - public void testUpdateMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the resource model, verify context model does not change - oneToMany.setMapKey(OrmFactory.eINSTANCE.createMapKeyImpl()); - assertNull(ormOneToManyMapping.getMapKey()); - assertNotNull(oneToMany.getMapKey()); - - //set mapKey name in the resource model, verify context model updated - oneToMany.getMapKey().setName("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey name to null in the resource model - oneToMany.getMapKey().setName(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey().getName()); - - oneToMany.getMapKey().setName("myMapKey"); - oneToMany.setMapKey(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testModifyMapKey() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - - //set mapKey in the context model, verify resource model updated - ormOneToManyMapping.setMapKey("myMapKey"); - assertEquals("myMapKey", ormOneToManyMapping.getMapKey()); - assertEquals("myMapKey", oneToMany.getMapKey().getName()); - - //set mapKey to null in the context model - ormOneToManyMapping.setMapKey(null); - assertNull(ormOneToManyMapping.getMapKey()); - assertNull(oneToMany.getMapKey()); - } - - public void testUpdateOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set orderBy in the resource model, verify context model updated - oneToMany.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set orderBy to null in the resource model - oneToMany.setOrderBy(null); - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testModifyOrderBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - XmlOneToMany oneToMany = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToManys().get(0); - - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToManyMapping.setOrderBy("newOrderBy"); - assertEquals("newOrderBy", ormOneToManyMapping.getOrderBy()); - assertEquals("newOrderBy", oneToMany.getOrderBy()); - - //set mappedBy to null in the context model - ormOneToManyMapping.setOrderBy(null); - assertNull(ormOneToManyMapping.getOrderBy()); - assertNull(oneToMany.getOrderBy()); - } - - public void testIsNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertFalse(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy(null); - assertTrue(ormOneToManyMapping.isNoOrdering()); - } - - public void testSetNoOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertTrue(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertFalse(ormOneToManyMapping.isNoOrdering()); - - ormOneToManyMapping.setNoOrdering(true); - assertTrue(ormOneToManyMapping.isNoOrdering()); - assertNull(ormOneToManyMapping.getOrderBy()); - } -//TODO -// public boolean isOrderByPk() { -// return "".equals(getOrderBy()); -// } -// -// public void setOrderByPk() { -// setOrderBy(""); -// } - - public void testIsCustomOrdering() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToManyMapping"); - OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping(); - - assertFalse(ormOneToManyMapping.isCustomOrdering()); - - ormOneToManyMapping.setOrderBy("foo"); - assertTrue(ormOneToManyMapping.isCustomOrdering()); - - ormOneToManyMapping.setOrderBy(null); - assertFalse(ormOneToManyMapping.isCustomOrdering()); - } - - public void testOneToManyMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToManyMorphToOneToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToOneMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - JoinTable joinTable = ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getJoinTable(); - assertEquals("MY_JOIN_TABLE", joinTable.getName()); - assertEquals("name", joinTable.joinColumns().next().getSpecifiedName()); - assertEquals("referenceName", joinTable.joinColumns().next().getSpecifiedReferencedColumnName()); - assertEquals("inverseName", joinTable.inverseJoinColumns().next().getSpecifiedName()); - assertEquals("inverseReferenceName", joinTable.inverseJoinColumns().next().getSpecifiedReferencedColumnName()); - } - - public void testOneToManyMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToManyMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, "oneToMany"); - - OneToManyMapping oneToManyMapping = (OneToManyMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToManyMapping.isDefault()); - oneToManyMapping.setSpecifiedFetch(FetchType.EAGER); - oneToManyMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToManyMapping.setOrderBy("customOrder"); - oneToManyMapping.setMapKey("mapKey"); - oneToManyMapping.setMappedBy("mappedBy"); - oneToManyMapping.getCascade().setAll(true); - oneToManyMapping.getCascade().setMerge(true); - oneToManyMapping.getCascade().setPersist(true); - oneToManyMapping.getCascade().setRefresh(true); - oneToManyMapping.getCascade().setRemove(true); - oneToManyMapping.getJoinTable().setSpecifiedName("MY_JOIN_TABLE"); - JoinColumn joinColumn = oneToManyMapping.getJoinTable().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - JoinColumn inverseJoinColumn = oneToManyMapping.getJoinTable().addSpecifiedInverseJoinColumn(0); - inverseJoinColumn.setSpecifiedName("inverseName"); - inverseJoinColumn.setSpecifiedReferencedColumnName("inverseReferenceName"); - assertFalse(oneToManyMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToMany", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java deleted file mode 100644 index ce9da74ce2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToOneMappingTests.java +++ /dev/null @@ -1,983 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.BasicMapping; -import org.eclipse.jpt.core.context.Cascade; -import org.eclipse.jpt.core.context.EmbeddedIdMapping; -import org.eclipse.jpt.core.context.EmbeddedMapping; -import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.JoinColumn; -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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; -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.iterators.ArrayIterator; - -public class OrmOneToOneMappingTests extends ContextModelTestCase -{ - public OrmOneToOneMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createOneToOneAnnotation() throws Exception{ - this.createAnnotationAndMembers("OneToOne", - "Class targetEntity() default void.class;" + - "CascadeType[] cascade() default {};" + - "FetchType fetch() default EAGER;" + - "boolean optional() default true;" + - "String mappedBy() default \"\";"); - } - - private void createJoinColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})"); - sb.append(CR); - sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")"); - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - sb.append(" @Id"); - } - }); - } - - private void createTestTargetEntityAddress() 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 ").append("Address").append(" "); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" @Id").append(CR); - sb.append(" private int id;").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(" private int zip;").append(CR); - sb.append(CR); - sb.append("}").append(CR); - } - }; - this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the resource model, verify context model updated - oneToOne.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the resource model - oneToOne.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertEquals("oneToOneMapping", ormOneToOneMapping.getName()); - assertEquals("oneToOneMapping", oneToOne.getName()); - - //set name in the context model, verify resource model updated - ormOneToOneMapping.setName("newName"); - assertEquals("newName", ormOneToOneMapping.getName()); - assertEquals("newName", oneToOne.getName()); - - //set name to null in the context model - ormOneToOneMapping.setName(null); - assertNull(ormOneToOneMapping.getName()); - assertNull(oneToOne.getName()); - } - - public void testUpdateSpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the resource model, verify context model updated - oneToOne.setTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the resource model - oneToOne.setTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testModifySpecifiedTargetEntity() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - - //set target entity in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedTargetEntity("newTargetEntity"); - assertEquals("newTargetEntity", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals("newTargetEntity", oneToOne.getTargetEntity()); - - //set target entity to null in the context model - ormOneToOneMapping.setSpecifiedTargetEntity(null); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(oneToOne.getTargetEntity()); - } - - public void testUpdateSpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the resource model, verify context model updated - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.EAGER); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - - oneToOneResource.setFetch(org.eclipse.jpt.core.resource.orm.FetchType.LAZY); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - - //set fetch to null in the resource model - oneToOneResource.setFetch(null); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - } - - public void testModifySpecifiedFetch() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(oneToOneResource.getFetch()); - - //set fetch in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.EAGER, oneToOneResource.getFetch()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getSpecifiedFetch()); - - ormOneToOneMapping.setSpecifiedFetch(FetchType.LAZY); - assertEquals(org.eclipse.jpt.core.resource.orm.FetchType.LAZY, oneToOneResource.getFetch()); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - - //set fetch to null in the context model - ormOneToOneMapping.setSpecifiedFetch(null); - assertNull(oneToOneResource.getFetch()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - } - - public void testUpdateMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the resource model, verify context model updated - oneToOne.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToOneMapping.getMappedBy()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the resource model - oneToOne.setMappedBy(null); - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - public void testModifyMappedBy() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOne = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - - //set mappedBy in the context model, verify resource model updated - ormOneToOneMapping.setMappedBy("newMappedBy"); - assertEquals("newMappedBy", ormOneToOneMapping.getMappedBy()); - assertEquals("newMappedBy", oneToOne.getMappedBy()); - - //set mappedBy to null in the context model - ormOneToOneMapping.setMappedBy(null); - assertNull(ormOneToOneMapping.getMappedBy()); - assertNull(oneToOne.getMappedBy()); - } - - - public void testUpdateSpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the resource model, verify context model updated - oneToOneResource.setOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - - oneToOneResource.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - - //set optional to null in the resource model - oneToOneResource.setOptional(null); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - } - - public void testModifySpecifiedOptional() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(oneToOneResource.getOptional()); - - //set optional in the context model, verify resource model updated - ormOneToOneMapping.setSpecifiedOptional(Boolean.TRUE); - assertEquals(Boolean.TRUE, oneToOneResource.getOptional()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getSpecifiedOptional()); - - ormOneToOneMapping.setSpecifiedOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOneResource.getOptional()); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - - //set optional to null in the context model - ormOneToOneMapping.setSpecifiedOptional(null); - assertNull(oneToOneResource.getOptional()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - } - - public void testAddSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmJoinColumn joinColumn = ormOneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getJoinColumns().get(0).getName()); - - OrmJoinColumn joinColumn2 = ormOneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(1).getName()); - - OrmJoinColumn joinColumn3 = ormOneToOneMapping.addSpecifiedJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - ListIterator<OrmJoinColumn> joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(2, oneToOneResource.getJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(1, oneToOneResource.getJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - - ormOneToOneMapping.removeSpecifiedJoinColumn(0); - assertEquals(0, oneToOneResource.getJoinColumns().size()); - } - - public void testMoveSpecifiedJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addSpecifiedJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addSpecifiedJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addSpecifiedJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getJoinColumns().size()); - - - ormOneToOneMapping.moveSpecifiedJoinColumn(2, 0); - ListIterator<OrmJoinColumn> joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - - - ormOneToOneMapping.moveSpecifiedJoinColumn(0, 1); - joinColumns = ormOneToOneMapping.specifiedJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getJoinColumns().get(2).getName()); - } - - public void testOneToOneMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormOneToOneMapping.getName()); - - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - assertNull(ormOneToOneMapping.getTargetEntity()); - - - assertFalse(ormOneToOneMapping.specifiedJoinColumns().hasNext()); - //TODO default joinColumns - //assertTrue(ormOneToOneMapping.defaultJoinColumns().hasNext()); - - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch()); - assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional()); - assertEquals("Address", ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - - OrmJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); - assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName()); - assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertTrue(cascade.isAll()); - assertTrue(cascade.isMerge()); - assertTrue(cascade.isPersist()); - assertTrue(cascade.isRemove()); - assertTrue(cascade.isRefresh()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(3, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - assertEquals("address", ormOneToOneMapping.getName()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - assertEquals("test.Address", ormOneToOneMapping.getTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - - //TODO default join columns in xml one-to-one -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next(); -// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner -// //assertEquals("address", ormJoinColumn.getSpecifiedName()); -// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityOneToOneMapping(); - createTestTargetEntityAddress(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address"); - - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - - assertEquals("address", ormOneToOneMapping.getName()); - assertNull(ormOneToOneMapping.getSpecifiedFetch()); - assertNull(ormOneToOneMapping.getSpecifiedOptional()); - assertNull(ormOneToOneMapping.getSpecifiedTargetEntity()); - assertNull(ormOneToOneMapping.getMappedBy()); - assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch()); - assertEquals(Boolean.TRUE, ormOneToOneMapping.getOptional()); - //TODO default target entity in xml - //assertEquals("test.Address", ormOneToOneMapping.getDefaultTargetEntity()); - - assertFalse(ormOneToOneMapping.specifiedJoinColumns().hasNext()); - - //TODO default join columns for specified xmlOneToOne mapping -// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.defaultJoinColumns().next(); -// assertNull(ormJoinColumn.getSpecifiedName()); -// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName()); -// assertNull(ormJoinColumn.getSpecifiedUnique()); -// assertNull(ormJoinColumn.getSpecifiedNullable()); -// assertNull(ormJoinColumn.getSpecifiedInsertable()); -// assertNull(ormJoinColumn.getSpecifiedUpdatable()); -// assertNull(ormJoinColumn.getColumnDefinition()); -// assertNull(ormJoinColumn.getSpecifiedTable()); -// -// assertEquals("address", ormJoinColumn.getDefaultName()); -// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName()); -// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable()); -// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable()); -// assertEquals(null, ormJoinColumn.getColumnDefinition()); -// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable()); - - Cascade cascade = ormOneToOneMapping.getCascade(); - assertFalse(cascade.isAll()); - assertFalse(cascade.isMerge()); - assertFalse(cascade.isPersist()); - assertFalse(cascade.isRemove()); - assertFalse(cascade.isRefresh()); - } - - - public void testOneToOneMorphToIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToVersionMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToTransientMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToEmbeddedIdMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - } - - public void testOneToOneMorphToManyToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((ManyToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToOneToManyMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertEquals("mappedBy", ((OneToManyMapping) ormPersistentAttribute.getMapping()).getMappedBy()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((OneToManyMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - } - - public void testOneToOneMorphToManyToOneMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); - assertEquals(FetchType.EAGER, ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - assertEquals("TargetEntity", ((ManyToOneMapping) ormPersistentAttribute.getMapping()).getSpecifiedTargetEntity()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isAll()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isMerge()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isPersist()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRefresh()); - assertTrue(((ManyToOneMapping) ormPersistentAttribute.getMapping()).getCascade().isRemove()); - - joinColumn = ((ManyToOneMapping) ormPersistentAttribute.getMapping()).specifiedJoinColumns().next(); - assertEquals("name", joinColumn.getName()); - assertEquals("referenceName", joinColumn.getReferencedColumnName()); - } - - public void testOneToOneMorphToBasicMapping() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOne"); - - OneToOneMapping oneToOneMapping = (OneToOneMapping) ormPersistentAttribute.getMapping(); - assertFalse(oneToOneMapping.isDefault()); - oneToOneMapping.setSpecifiedFetch(FetchType.EAGER); - oneToOneMapping.setSpecifiedTargetEntity("TargetEntity"); - oneToOneMapping.setMappedBy("mappedBy"); - oneToOneMapping.getCascade().setAll(true); - oneToOneMapping.getCascade().setMerge(true); - oneToOneMapping.getCascade().setPersist(true); - oneToOneMapping.getCascade().setRefresh(true); - oneToOneMapping.getCascade().setRemove(true); - JoinColumn joinColumn = oneToOneMapping.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName("name"); - joinColumn.setSpecifiedReferencedColumnName("referenceName"); - assertFalse(oneToOneMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("oneToOne", ormPersistentAttribute.getMapping().getName()); -//TODO assertEquals(FetchType.EAGER, ((IBasicMapping) ormPersistentAttribute.getMapping()).getSpecifiedFetch()); - } - - - - - - public void testAddPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - OrmPrimaryKeyJoinColumn joinColumn = ormOneToOneMapping.addPrimaryKeyJoinColumn(0); - joinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn joinColumn2 = ormOneToOneMapping.addPrimaryKeyJoinColumn(0); - joinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn joinColumn3 = ormOneToOneMapping.addPrimaryKeyJoinColumn(1); - joinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals(joinColumn2, joinColumns.next()); - assertEquals(joinColumn3, joinColumns.next()); - assertEquals(joinColumn, joinColumns.next()); - - joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - } - - public void testRemovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(2, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(1, oneToOneResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormOneToOneMapping.removePrimaryKeyJoinColumn(0); - assertEquals(0, oneToOneResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMovePrimaryKeyJoinColumn() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "oneToOneMapping"); - OrmOneToOneMapping ormOneToOneMapping = (OrmOneToOneMapping) ormPersistentAttribute.getMapping(); - XmlOneToOne oneToOneResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getOneToOnes().get(0); - - ormOneToOneMapping.addPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormOneToOneMapping.addPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, oneToOneResource.getPrimaryKeyJoinColumns().size()); - - - ormOneToOneMapping.movePrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormOneToOneMapping.movePrimaryKeyJoinColumn(0, 1); - joinColumns = ormOneToOneMapping.primaryKeyJoinColumns(); - assertEquals("BAZ", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - - assertEquals("BAZ", oneToOneResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", oneToOneResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", oneToOneResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java deleted file mode 100644 index dfdf8ac27c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentAttributeTests.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.BasicMapping; -import org.eclipse.jpt.core.context.IdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmIdMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmNullAttributeMapping; -import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToOneMapping; -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.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class OrmPersistentAttributeTests extends ContextModelTestCase -{ - public OrmPersistentAttributeTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private ICompilationUnit createTestTypeNullAttributeMapping() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" private Address address;").append(CR); - sb.append(CR); - } - }); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private void createOneToOneAnnotation() throws Exception { - this.createAnnotationAndMembers("OneToOne", ""); - } - - private ICompilationUnit createTestEntityIdMapping() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - createColumnAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append("@Column(name=\"FOO\")"); - } - }); - } - - private ICompilationUnit createTestEntityOneToOneMapping() throws Exception { - createEntityAnnotation(); - createOneToOneAnnotation(); - - 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"); - sb.append(" private Address address;"); - } - }); - } - - public void testMakeSpecified() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - ormPersistentAttribute.makeSpecified(); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.makeSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - ListIterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.specifiedAttributes(); - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("name", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeSpecifiedMappingKey() throws Exception { - createTestTypeNullAttributeMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(3, ormPersistentType.virtualAttributesSize()); - - //take a virtual mapping with a mapping type and make it specified - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertTrue(ormPersistentAttribute.isVirtual()); - assertTrue(ormPersistentAttribute.getMapping() instanceof GenericOrmNullAttributeMapping); - ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmOneToOneMapping); - - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - ormPersistentAttribute.makeSpecified(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - ListIterator<OrmPersistentAttribute> specifiedAttributes = ormPersistentType.specifiedAttributes(); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - assertTrue(specifiedOrmPersistentAttribute.getMapping() instanceof GenericOrmIdMapping); - - specifiedOrmPersistentAttribute = specifiedAttributes.next(); - assertEquals("address", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - } - - public void testMakeVirtual() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().makeSpecified(); - ormPersistentType.virtualAttributes().next().makeSpecified(); - - assertEquals(0, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - assertEquals("id", specifiedOrmPersistentAttribute.getName()); - assertFalse(specifiedOrmPersistentAttribute.isVirtual()); - - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - assertEquals(0, ormPersistentType.specifiedAttributesSize()); - - ListIterator<OrmPersistentAttribute> virtualAttributes = ormPersistentType.virtualAttributes(); - OrmPersistentAttribute virtualAttribute = virtualAttributes.next(); - assertEquals("id", virtualAttribute.getName()); - virtualAttribute = virtualAttributes.next(); - assertEquals("name", virtualAttribute.getName()); - } - - public void testMakeVirtualNoUnderlyingJavaAttribute() throws Exception { - createTestType(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - ormPersistentType.virtualAttributes().next().makeSpecified(); - ormPersistentType.virtualAttributes().next().makeSpecified(); - - - ormPersistentType.specifiedAttributes().next().getMapping().setName("noJavaAttribute"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(2, ormPersistentType.specifiedAttributesSize()); - - - OrmPersistentAttribute specifiedOrmPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - specifiedOrmPersistentAttribute.makeVirtual(); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - - assertEquals("id", ormPersistentType.virtualAttributes().next().getName()); - assertEquals("name", ormPersistentType.specifiedAttributes().next().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete() throws Exception { - createTestEntityIdMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("id", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - assertEquals("id", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getName()); - } - - public void testVirtualMappingTypeWhenMetadataComplete2() throws Exception { - createTestEntityOneToOneMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - - ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - assertEquals("address", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java deleted file mode 100644 index c29d9de9e3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPersistentTypeTests.java +++ /dev/null @@ -1,510 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.resource.orm.XmlBasicImpl; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedIdImpl; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedImpl; -import org.eclipse.jpt.core.resource.orm.XmlIdImpl; -import org.eclipse.jpt.core.resource.orm.XmlManyToManyImpl; -import org.eclipse.jpt.core.resource.orm.XmlManyToOneImpl; -import org.eclipse.jpt.core.resource.orm.XmlOneToManyImpl; -import org.eclipse.jpt.core.resource.orm.XmlOneToOneImpl; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTransientImpl; -import org.eclipse.jpt.core.resource.orm.XmlVersionImpl; -import org.eclipse.jpt.core.resource.orm.XmlBasic; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlId; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -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; - -public class OrmPersistentTypeTests extends ContextModelTestCase -{ - public OrmPersistentTypeTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - -// public void testUpdateXmlTypeMapping() throws Exception { -// assertFalse(entityMappings().ormPersistentTypes().hasNext()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// -// //add embeddable in the resource model, verify context model updated -// Embeddable embeddable = OrmFactory.eINSTANCE.createEmbeddable(); -// ormResource().getEntityMappings().getEmbeddables().add(embeddable); -// embeddable.setClassName("model.Foo"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); -// -// //add entity in the resource model, verify context model updated -// Entity entity = OrmFactory.eINSTANCE.createEntity(); -// ormResource().getEntityMappings().getEntities().add(entity); -// entity.setClassName("model.Foo2"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo2", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo2", ormResource().getEntityMappings().getEntities().get(0).getClassName()); -// -// //add mapped-superclass in the resource model, verify context model updated -// MappedSuperclass mappedSuperclass = OrmFactory.eINSTANCE.createMappedSuperclass(); -// ormResource().getEntityMappings().getMappedSuperclasses().add(mappedSuperclass); -// mappedSuperclass.setClassName("model.Foo3"); -// assertTrue(entityMappings().ormPersistentTypes().hasNext()); -// assertEquals("model.Foo3", entityMappings().ormPersistentTypes().next().getMapping().getClass_()); -// assertFalse(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEntities().isEmpty()); -// assertFalse(ormResource().getEntityMappings().getEmbeddables().isEmpty()); -// assertEquals("model.Foo3", ormResource().getEntityMappings().getMappedSuperclasses().get(0).getClassName()); -// } -// - - public void testMorphXmlTypeMapping() throws Exception { - assertFalse(entityMappings().ormPersistentTypes().hasNext()); - assertTrue(ormResource().getEntityMappings().getMappedSuperclasses().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEntities().isEmpty()); - assertTrue(ormResource().getEntityMappings().getEmbeddables().isEmpty()); - - OrmPersistentType embeddablePersistentType = entityMappings().addOrmPersistentType(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - OrmPersistentType mappedSuperclassPersistentType = entityMappings().addOrmPersistentType(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, "model.Foo3"); - - OrmPersistentType ormPersistentType = entityMappings().ormPersistentTypes().next(); - assertEquals(mappedSuperclassPersistentType, ormPersistentType); - assertEquals(MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, ormPersistentType.getMapping().getKey()); - - ormPersistentType.setMappingKey(MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY); - assertEquals(0, ormResource().getEntityMappings().getMappedSuperclasses().size()); - assertEquals(1, ormResource().getEntityMappings().getEntities().size()); - assertEquals(2, ormResource().getEntityMappings().getEmbeddables().size()); - - Iterator<OrmPersistentType> ormPersistentTypes = entityMappings().ormPersistentTypes(); - //the same OrmPersistentTypes should still be in the context model - assertEquals(ormPersistentTypes.next(), entityPersistentType); - assertEquals(ormPersistentTypes.next(), embeddablePersistentType); - assertEquals(ormPersistentTypes.next(), mappedSuperclassPersistentType); - - assertEquals("model.Foo", ormResource().getEntityMappings().getEmbeddables().get(0).getClassName()); - assertEquals("model.Foo3", ormResource().getEntityMappings().getEmbeddables().get(1).getClassName()); - } - - public void testAddSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - XmlBasic basic = entity.getAttributes().getBasics().get(0); - assertEquals("basicAttribute", basic.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - - XmlEmbedded embedded = entity.getAttributes().getEmbeddeds().get(0); - assertEquals("embeddedAttribute", embedded.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlTransient transientResource = entity.getAttributes().getTransients().get(0); - assertEquals("transientAttribute", transientResource.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - - XmlVersion version = entity.getAttributes().getVersions().get(0); - assertEquals("versionAttribute", version.getName()); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - - XmlId id = entity.getAttributes().getIds().get(0); - assertEquals("idAttribute", id.getName()); - - - ListIterator<OrmPersistentAttribute> persistentAttributes = entityPersistentType.specifiedAttributes(); - assertEquals("idAttribute", persistentAttributes.next().getName()); - assertEquals("basicAttribute", persistentAttributes.next().getName()); - assertEquals("versionAttribute", persistentAttributes.next().getName()); - assertEquals("embeddedAttribute", persistentAttributes.next().getName()); - assertEquals("transientAttribute", persistentAttributes.next().getName()); - assertFalse(persistentAttributes.hasNext()); - } - - public void testRemoveSpecifiedPersistentAttribute() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("basicAttribute")); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("embeddedAttribute")); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("versionAttribute")); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("idAttribute")); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("transientAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveId() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, "idAttribute"); - assertEquals("idAttribute", entity.getAttributes().getIds().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("idAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveBasic() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, "basicAttribute"); - assertEquals("basicAttribute", entity.getAttributes().getBasics().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("basicAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveVersion() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionAttribute"); - assertEquals("versionAttribute", entity.getAttributes().getVersions().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("versionAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveEmbedded() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, "embeddedAttribute"); - assertEquals("embeddedAttribute", entity.getAttributes().getEmbeddeds().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("embeddedAttribute")); - assertNull(entity.getAttributes()); - } - - public void testRemoveTransient() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entityPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientAttribute"); - assertEquals("transientAttribute", entity.getAttributes().getTransients().get(0).getName()); - - entityPersistentType.removeSpecifiedPersistentAttribute(entityPersistentType.getAttributeNamed("transientAttribute")); - assertNull(entity.getAttributes()); - } - - public void testUpdateSpecifiedPersistentAttributes() throws Exception { - OrmPersistentType entityPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo2"); - XmlEntity entity = ormResource().getEntityMappings().getEntities().get(0); - - entity.setAttributes(OrmFactory.eINSTANCE.createAttributes()); - XmlBasicImpl basic = OrmFactory.eINSTANCE.createXmlBasicImpl(); - entity.getAttributes().getBasics().add(basic); - basic.setName("basicAttribute"); - - OrmPersistentAttribute ormPersistentAttribute = entityPersistentType.attributes().next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - - XmlEmbeddedImpl embedded = OrmFactory.eINSTANCE.createXmlEmbeddedImpl(); - entity.getAttributes().getEmbeddeds().add(embedded); - embedded.setName("embeddedAttribute"); - - ListIterator<OrmPersistentAttribute> attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlVersionImpl version = OrmFactory.eINSTANCE.createXmlVersionImpl(); - entity.getAttributes().getVersions().add(version); - version.setName("versionAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlIdImpl id = OrmFactory.eINSTANCE.createXmlIdImpl(); - entity.getAttributes().getIds().add(id); - id.setName("idAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlTransientImpl transientResource = OrmFactory.eINSTANCE.createXmlTransientImpl(); - entity.getAttributes().getTransients().add(transientResource); - transientResource.setName("transientAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToOneImpl manyToOneResource = OrmFactory.eINSTANCE.createXmlManyToOneImpl(); - entity.getAttributes().getManyToOnes().add(manyToOneResource); - manyToOneResource.setName("manyToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlManyToManyImpl manyToManyResource = OrmFactory.eINSTANCE.createXmlManyToManyImpl(); - entity.getAttributes().getManyToManys().add(manyToManyResource); - manyToManyResource.setName("manyToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToManyImpl oneToManyResource = OrmFactory.eINSTANCE.createXmlOneToManyImpl(); - entity.getAttributes().getOneToManys().add(oneToManyResource); - oneToManyResource.setName("oneToManyAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - XmlOneToOneImpl oneToOneResource = OrmFactory.eINSTANCE.createXmlOneToOneImpl(); - entity.getAttributes().getOneToOnes().add(oneToOneResource); - oneToOneResource.setName("oneToOneAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - - XmlEmbeddedIdImpl embeddedIdResource = OrmFactory.eINSTANCE.createXmlEmbeddedIdImpl(); - entity.getAttributes().getEmbeddedIds().add(embeddedIdResource); - embeddedIdResource.setName("embeddedIdAttribute"); - - attributes = entityPersistentType.attributes(); - ormPersistentAttribute = attributes.next(); - assertEquals("idAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedIdAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("basicAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("versionAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("oneToOneAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("manyToManyAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("embeddedAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - ormPersistentAttribute = attributes.next(); - assertEquals("transientAttribute", ormPersistentAttribute.getName()); - assertEquals(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMapping().getKey()); - assertFalse(attributes.hasNext()); - - entity.getAttributes().getBasics().remove(0); - entity.getAttributes().getEmbeddeds().remove(0); - entity.getAttributes().getTransients().remove(0); - entity.getAttributes().getIds().remove(0); - entity.getAttributes().getVersions().remove(0); - entity.getAttributes().getManyToOnes().remove(0); - entity.getAttributes().getManyToManys().remove(0); - entity.getAttributes().getOneToManys().remove(0); - entity.getAttributes().getOneToOnes().remove(0); - entity.getAttributes().getEmbeddedIds().remove(0); - assertFalse(entityPersistentType.attributes().hasNext()); - assertNotNull(entity.getAttributes()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java deleted file mode 100644 index b01f8eedde..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmPrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,303 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; -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.iterators.ArrayIterator; - -public class OrmPrimaryKeyJoinColumnTests extends ContextModelTestCase -{ - public OrmPrimaryKeyJoinColumnTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - primaryKeyJoinColumnResource.setName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(primaryKeyJoinColumnResource.getName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertEquals("foo", primaryKeyJoinColumnResource.getName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getName()); - } - - public void testUpdateSpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - primaryKeyJoinColumnResource.setReferencedColumnName("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("FOO", primaryKeyJoinColumnResource.getReferencedColumnName()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedReferencedColumnName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertEquals("foo", primaryKeyJoinColumnResource.getReferencedColumnName()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setSpecifiedReferencedColumnName(null); - assertNull(ormPrimaryKeyJoinColumn.getSpecifiedReferencedColumnName()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getReferencedColumnName()); - } - -// public void testUpdateDefaultNameFromJavaTable() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.javaEntity().getTable().setSpecifiedName("Foo"); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); -// ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.setSpecifiedMetadataComplete(null); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// -// ormEntity.entityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// -// ormEntity.getTable().setSpecifiedName("Bar"); -// assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameNoJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// assertEquals("Foo", ormEntity.getTable().getDefaultName()); -// } -// -// public void testUpdateDefaultNameFromParent() throws Exception { -// createTestEntity(); -// createTestSubType(); -// -// OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); -// XmlEntity parentXmlEntity = (XmlEntity) parentOrmPersistentType.getMapping(); -// XmlEntity childXmlEntity = (XmlEntity) childOrmPersistentType.getMapping(); -// -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.getTable().setSpecifiedName("FOO"); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); -// -// parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); -// assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); -// assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); -// } - - - public void testUpdateSpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the resource model, verify context model updated - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the resource model - primaryKeyJoinColumnResource.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - primaryKeyJoinColumnResource.setColumnDefinition("FOO"); - assertEquals("FOO", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("FOO", primaryKeyJoinColumnResource.getColumnDefinition()); - - entityResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormEntity.specifiedPrimaryKeyJoinColumns().hasNext()); - assertTrue(entityResource.getPrimaryKeyJoinColumns().isEmpty()); - } - - public void testModifySpecifiedColumnDefinition() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmPrimaryKeyJoinColumn ormPrimaryKeyJoinColumn = ormEntity.addSpecifiedPrimaryKeyJoinColumn(0); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlPrimaryKeyJoinColumn primaryKeyJoinColumnResource = entityResource.getPrimaryKeyJoinColumns().get(0); - - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name in the context model, verify resource model modified - ormPrimaryKeyJoinColumn.setColumnDefinition("foo"); - assertEquals("foo", ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertEquals("foo", primaryKeyJoinColumnResource.getColumnDefinition()); - - //set name to null in the context model - ormPrimaryKeyJoinColumn.setColumnDefinition(null); - assertNull(ormPrimaryKeyJoinColumn.getColumnDefinition()); - assertNull(entityResource.getPrimaryKeyJoinColumns().get(0).getColumnDefinition()); - } - - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java deleted file mode 100644 index 1323d381d3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmQueryHintTests.java +++ /dev/null @@ -1,122 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmQueryHint; -import org.eclipse.jpt.core.resource.orm.XmlQueryHint; -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; - -public class OrmQueryHintTests extends ContextModelTestCase -{ - public OrmQueryHintTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the resource model, verify context model updated - queryHintResource.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the resource model - queryHintResource.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - - //set name in the context model, verify resource model updated - ormQueryHint.setName("newName"); - assertEquals("newName", ormQueryHint.getName()); - assertEquals("newName", queryHintResource.getName()); - - //set name to null in the context model - ormQueryHint.setName(null); - assertNull(ormQueryHint.getName()); - assertNull(queryHintResource.getName()); - } - - public void testUpdateValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the resource model, verify context model updated - queryHintResource.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the resource model - queryHintResource.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } - - public void testModifyValue() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmQueryHint ormQueryHint = ormEntity.addNamedQuery(0).addHint(0); - - XmlQueryHint queryHintResource = ormResource().getEntityMappings().getEntities().get(0).getNamedQueries().get(0).getHints().get(0); - - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - - //set name in the context model, verify resource model updated - ormQueryHint.setValue("newName"); - assertEquals("newName", ormQueryHint.getValue()); - assertEquals("newName", queryHintResource.getValue()); - - //set name to null in the context model - ormQueryHint.setValue(null); - assertNull(ormQueryHint.getValue()); - assertNull(queryHintResource.getValue()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java deleted file mode 100644 index 591ac25e33..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSecondaryTableTests.java +++ /dev/null @@ -1,774 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.SecondaryTable; -import org.eclipse.jpt.core.context.java.JavaEntity; -import org.eclipse.jpt.core.context.java.JavaSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; -import org.eclipse.jpt.core.context.orm.OrmSecondaryTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlSecondaryTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmSecondaryTableTests extends ContextModelTestCase -{ - public OrmSecondaryTableTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set name in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setName("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the resource model - entityResource.getSecondaryTables().get(0).setName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set name in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedName("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedName()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getName()); - - //set name to null in the context model - secondaryTable.setSpecifiedName(null); - assertNull(secondaryTable.getSpecifiedName()); - assertNull(entityResource.getSecondaryTables().get(0).getName()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0).setSpecifiedName("FOO"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("FOO", ormSecondaryTable.getSpecifiedName()); - - ormEntity.getJavaEntity().specifiedSecondaryTables().next().setSpecifiedName("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedName()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultName()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedName()); - - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set schema in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setSchema("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the resource model - entityResource.getSecondaryTables().get(0).setSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set schema in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedSchema("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getSchema()); - - //set schema to null in the context model - secondaryTable.setSpecifiedSchema(null); - assertNull(secondaryTable.getSpecifiedSchema()); - assertNull(entityResource.getSecondaryTables().get(0).getSchema()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("BAR"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedSchema()); - - javaSecondaryTable.setSpecifiedSchema("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedSchema()); - - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultSchema()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentOrmEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childOrmEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childOrmEntity.getTable().getDefaultSchema()); - - parentOrmEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentOrmEntity.getTable().getDefaultSchema()); - assertNull(childOrmEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - ormEntity.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("BAR", ormSecondaryTable.getDefaultSchema()); //schema is not defaulted from underlying java - - ormEntity.getEntityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormSecondaryTable.getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormSecondaryTable.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set catalog in the resource model, verify context model updated - entityResource.getSecondaryTables().add(OrmFactory.eINSTANCE.createXmlSecondaryTableImpl()); - entityResource.getSecondaryTables().get(0).setCatalog("FOO"); - OrmSecondaryTable secondaryTable = ormEntity.specifiedSecondaryTables().next(); - assertEquals("FOO", secondaryTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the resource model - entityResource.getSecondaryTables().get(0).setCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - entityResource.getSecondaryTables().remove(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - - //set catalog in the context model, verify resource model modified - OrmSecondaryTable secondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - secondaryTable.setSpecifiedCatalog("foo"); - - assertEquals("foo", secondaryTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getSecondaryTables().get(0).getCatalog()); - - //set catalog to null in the context model - secondaryTable.setSpecifiedCatalog(null); - assertNull(secondaryTable.getSpecifiedCatalog()); - assertNull(entityResource.getSecondaryTables().get(0).getCatalog()); - - ormEntity.removeSpecifiedSecondaryTable(0); - assertFalse(ormEntity.specifiedSecondaryTables().hasNext()); - assertEquals(0, entityResource.getSecondaryTables().size()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("BAR"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.virtualSecondaryTables().next(); - assertEquals("BAR", ormSecondaryTable.getSpecifiedCatalog()); - - javaSecondaryTable.setSpecifiedCatalog("BAZ"); - assertEquals("BAZ", ormSecondaryTable.getSpecifiedCatalog()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - assertNull(ormEntity.specifiedSecondaryTables().next().getDefaultCatalog()); - assertEquals("BAZ", ormEntity.specifiedSecondaryTables().next().getSpecifiedCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - ormSecondaryTable.setSpecifiedName("FOO"); - assertNull(ormSecondaryTable.getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - ormEntity.getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); - - SecondaryTable javaSecondaryTable = ormEntity.getJavaEntity().addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("FOO"); - javaSecondaryTable.setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("BAR", ormSecondaryTable.getDefaultCatalog()); //schema is not defaulted from underlying java - - ormEntity.getEntityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormSecondaryTable.getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormSecondaryTable.getDefaultCatalog()); - } - - public void testAddSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn.setSpecifiedName("FOO"); - - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn2 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - primaryKeyJoinColumn2.setSpecifiedName("BAR"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - OrmPrimaryKeyJoinColumn primaryKeyJoinColumn3 = ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1); - primaryKeyJoinColumn3.setSpecifiedName("BAZ"); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals(primaryKeyJoinColumn2, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn3, primaryKeyJoinColumns.next()); - assertEquals(primaryKeyJoinColumn, primaryKeyJoinColumns.next()); - - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - } - - public void testRemoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(2, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(1, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - - ormSecondaryTable.removeSpecifiedPrimaryKeyJoinColumn(0); - assertEquals(0, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - } - - public void testMoveSpecifiedPrimaryKeyJoinColumn() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(0).setSpecifiedName("FOO"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(1).setSpecifiedName("BAR"); - ormSecondaryTable.addSpecifiedPrimaryKeyJoinColumn(2).setSpecifiedName("BAZ"); - - assertEquals(3, secondaryTableResource.getPrimaryKeyJoinColumns().size()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(2, 0); - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - - - ormSecondaryTable.moveSpecifiedPrimaryKeyJoinColumn(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - - assertEquals("BAZ", secondaryTableResource.getPrimaryKeyJoinColumns().get(0).getName()); - assertEquals("BAR", secondaryTableResource.getPrimaryKeyJoinColumns().get(1).getName()); - assertEquals("FOO", secondaryTableResource.getPrimaryKeyJoinColumns().get(2).getName()); - } - - public void testUpdatePrimaryKeyJoinColumns() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - secondaryTableResource.getPrimaryKeyJoinColumns().add(OrmFactory.eINSTANCE.createXmlPrimaryKeyJoinColumnImpl()); - - secondaryTableResource.getPrimaryKeyJoinColumns().get(0).setName("FOO"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(1).setName("BAR"); - secondaryTableResource.getPrimaryKeyJoinColumns().get(2).setName("BAZ"); - - ListIterator<OrmPrimaryKeyJoinColumn> primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(2, 0); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().move(0, 1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("BAR", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertEquals("FOO", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(1); - primaryKeyJoinColumns = ormSecondaryTable.specifiedPrimaryKeyJoinColumns(); - assertEquals("BAZ", primaryKeyJoinColumns.next().getName()); - assertFalse(primaryKeyJoinColumns.hasNext()); - - secondaryTableResource.getPrimaryKeyJoinColumns().remove(0); - assertFalse(ormSecondaryTable.specifiedPrimaryKeyJoinColumns().hasNext()); - } - - - public void testUniqueConstraints() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - assertEquals(0, ormSecondaryTable.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormSecondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = secondaryTableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - ormSecondaryTable.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(1); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - ormSecondaryTable.removeUniqueConstraint(0); - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - ormSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - ormSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - ormSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, secondaryTableResource.getUniqueConstraints().size()); - - - ormSecondaryTable.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - ormSecondaryTable.moveUniqueConstraint(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = secondaryTableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - OrmPersistentType persistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) persistentType.getMapping(); - OrmSecondaryTable ormSecondaryTable = ormEntity.addSpecifiedSecondaryTable(0); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlSecondaryTable secondaryTableResource = entityResource.getSecondaryTables().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - secondaryTableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(1); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - secondaryTableResource.getUniqueConstraints().remove(0); - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); - JavaSecondaryTable javaSecondaryTable = javaEntity.addSpecifiedSecondaryTable(0); - javaSecondaryTable.setSpecifiedName("SECONDARY"); - - OrmSecondaryTable ormSecondaryTable = ormEntity.secondaryTables().next(); - assertTrue(ormSecondaryTable.isVirtual()); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - - javaSecondaryTable.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaSecondaryTable.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaSecondaryTable.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormSecondaryTable.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormEntity.setSecondaryTablesDefinedInXml(true); - OrmSecondaryTable ormSecondaryTable2 = ormEntity.secondaryTables().next(); - ormSecondaryTable2.setSpecifiedName("SECONDARY"); - - assertEquals("SECONDARY", ormSecondaryTable.getSpecifiedName()); - assertFalse(ormSecondaryTable2.isVirtual()); - assertEquals(0, ormSecondaryTable2.uniqueConstraintsSize()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java deleted file mode 100644 index e7c57c86bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmSequenceGeneratorTests.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.SequenceGenerator; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlSequenceGenerator; -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.iterators.ArrayIterator; - -public class OrmSequenceGeneratorTests extends ContextModelTestCase -{ - public OrmSequenceGeneratorTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setName("FOO"); - assertEquals("FOO", sequenceGenerator.getName()); - assertEquals("FOO", sequenceGeneratorResource.getName()); - - //set name to null in the resource model - sequenceGeneratorResource.setName(null); - assertNull(sequenceGenerator.getName()); - assertNull(sequenceGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getName()); - assertEquals("FOO", sequenceGenerator.getName()); - - //set name to null in the context model - sequenceGenerator.setName(null); - assertNull(sequenceGeneratorResource.getName()); - assertNull(sequenceGenerator.getName()); - } - - public void testUpdateSpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the resource model, verify context model updated - sequenceGeneratorResource.setSequenceName("FOO"); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - - //set name to null in the resource model - sequenceGeneratorResource.setSequenceName(null); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - assertNull(sequenceGeneratorResource.getSequenceName()); - } - - public void testModifySpecifiedSequenceName() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set name in the context model, verify resource model modified - sequenceGenerator.setSpecifiedSequenceName("FOO"); - assertEquals("FOO", sequenceGeneratorResource.getSequenceName()); - assertEquals("FOO", sequenceGenerator.getSpecifiedSequenceName()); - - //set name to null in the context model - sequenceGenerator.setSpecifiedSequenceName(null); - assertNull(sequenceGeneratorResource.getSequenceName()); - assertNull(sequenceGenerator.getSpecifiedSequenceName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the resource model, verify context model updated - sequenceGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - sequenceGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - sequenceGeneratorResource.setInitialValue(null); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - assertNull(sequenceGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set initial value in the context model, verify resource model modified - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedInitialValue()); - - sequenceGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - sequenceGenerator.setSpecifiedInitialValue(null); - assertNull(sequenceGeneratorResource.getInitialValue()); - assertNull(sequenceGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - sequenceGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), sequenceGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), sequenceGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - sequenceGeneratorResource.setAllocationSize(null); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - assertNull(sequenceGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - SequenceGenerator sequenceGenerator = entityMappings().addSequenceGenerator(0); - XmlSequenceGenerator sequenceGeneratorResource = ormResource().getEntityMappings().getSequenceGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), sequenceGenerator.getSpecifiedAllocationSize()); - - sequenceGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), sequenceGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), sequenceGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - sequenceGenerator.setSpecifiedAllocationSize(null); - assertNull(sequenceGeneratorResource.getAllocationSize()); - assertNull(sequenceGenerator.getSpecifiedAllocationSize()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java deleted file mode 100644 index 01d1dd638b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableGeneratorTests.java +++ /dev/null @@ -1,633 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.TableGenerator; -import org.eclipse.jpt.core.context.UniqueConstraint; -import org.eclipse.jpt.core.context.java.JavaIdMapping; -import org.eclipse.jpt.core.context.java.JavaTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlTableGenerator; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmTableGeneratorTests extends ContextModelTestCase -{ - public OrmTableGeneratorTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setName("FOO"); - assertEquals("FOO", tableGenerator.getName()); - assertEquals("FOO", tableGeneratorResource.getName()); - - //set name to null in the resource model - tableGeneratorResource.setName(null); - assertNull(tableGenerator.getName()); - assertNull(tableGeneratorResource.getName()); - } - - public void testModifySpecifiedName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setName("FOO"); - assertEquals("FOO", tableGeneratorResource.getName()); - assertEquals("FOO", tableGenerator.getName()); - - //set name to null in the context model - tableGenerator.setName(null); - assertNull(tableGeneratorResource.getName()); - assertNull(tableGenerator.getName()); - } - - public void testUpdateSpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set initial value in the resource model, verify context model updated - tableGeneratorResource.setInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - - //set initial value to 1, which happens to be the default, in the resource model - tableGeneratorResource.setInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - - //set initial value to null in the resource model - tableGeneratorResource.setInitialValue(null); - assertNull(tableGenerator.getSpecifiedInitialValue()); - assertNull(tableGeneratorResource.getInitialValue()); - } - - public void testModifySpecifiedInitialValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set initial value in the context model, verify resource model modified - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedInitialValue()); - - tableGenerator.setSpecifiedInitialValue(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getInitialValue()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - - //set initial value to null in the context model - tableGenerator.setSpecifiedInitialValue(null); - assertNull(tableGeneratorResource.getInitialValue()); - assertNull(tableGenerator.getSpecifiedInitialValue()); - } - - public void testUpdateSpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set allocation size in the resource model, verify context model updated - tableGeneratorResource.setAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - - //set allocation size to 50, which happens to be the default, in the resource model - tableGeneratorResource.setAllocationSize(Integer.valueOf(1)); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); - assertEquals(Integer.valueOf(1), tableGeneratorResource.getAllocationSize()); - - //set allocation size to null in the resource model - tableGeneratorResource.setAllocationSize(null); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - assertNull(tableGeneratorResource.getAllocationSize()); - } - - public void testModifySpecifiedAllocationSize() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set allocation size in the context model, verify resource model modified - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(10)); - assertEquals(Integer.valueOf(10), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(10), tableGenerator.getSpecifiedAllocationSize()); - - tableGenerator.setSpecifiedAllocationSize(Integer.valueOf(50)); - assertEquals(Integer.valueOf(50), tableGeneratorResource.getAllocationSize()); - assertEquals(Integer.valueOf(50), tableGenerator.getSpecifiedAllocationSize()); - - //set allocation size to null in the context model - tableGenerator.setSpecifiedAllocationSize(null); - assertNull(tableGeneratorResource.getAllocationSize()); - assertNull(tableGenerator.getSpecifiedAllocationSize()); - } - - public void testUpdateSpecifiedTable() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setTable("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - assertEquals("FOO", tableGeneratorResource.getTable()); - - //set name to null in the resource model - tableGeneratorResource.setTable(null); - assertNull(tableGenerator.getSpecifiedTable()); - assertNull(tableGeneratorResource.getTable()); - } - - public void testModifySpecifiedTable() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedTable("FOO"); - assertEquals("FOO", tableGeneratorResource.getTable()); - assertEquals("FOO", tableGenerator.getSpecifiedTable()); - - //set name to null in the context model - tableGenerator.setSpecifiedTable(null); - assertNull(tableGeneratorResource.getTable()); - assertNull(tableGenerator.getSpecifiedTable()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setSchema("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - assertEquals("FOO", tableGeneratorResource.getSchema()); - - //set name to null in the resource model - tableGeneratorResource.setSchema(null); - assertNull(tableGenerator.getSpecifiedSchema()); - assertNull(tableGeneratorResource.getSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGeneratorResource.getSchema()); - assertEquals("FOO", tableGenerator.getSpecifiedSchema()); - - //set name to null in the context model - tableGenerator.setSpecifiedSchema(null); - assertNull(tableGeneratorResource.getSchema()); - assertNull(tableGenerator.getSpecifiedSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - - assertNull(tableGenerator.getDefaultSchema()); - - tableGenerator.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", tableGenerator.getDefaultSchema()); - - tableGenerator.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", tableGenerator.getDefaultSchema()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setCatalog("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - - //set name to null in the resource model - tableGeneratorResource.setCatalog(null); - assertNull(tableGenerator.getSpecifiedCatalog()); - assertNull(tableGeneratorResource.getCatalog()); - } - - public void testModifySpecifiedCatalog() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedCatalog("FOO"); - assertEquals("FOO", tableGeneratorResource.getCatalog()); - assertEquals("FOO", tableGenerator.getSpecifiedCatalog()); - - //set name to null in the context model - tableGenerator.setSpecifiedCatalog(null); - assertNull(tableGeneratorResource.getCatalog()); - assertNull(tableGenerator.getSpecifiedCatalog()); - } - - public void testUpdateSpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnName(null); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - assertNull(tableGeneratorResource.getPkColumnName()); - } - - public void testModifySpecifiedPkColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnName(null); - assertNull(tableGeneratorResource.getPkColumnName()); - assertNull(tableGenerator.getSpecifiedPkColumnName()); - } - - public void testUpdateSpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setValueColumnName("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - - //set name to null in the resource model - tableGeneratorResource.setValueColumnName(null); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - assertNull(tableGeneratorResource.getValueColumnName()); - } - - public void testModifySpecifiedValueColumnName() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedValueColumnName("FOO"); - assertEquals("FOO", tableGeneratorResource.getValueColumnName()); - assertEquals("FOO", tableGenerator.getSpecifiedValueColumnName()); - - //set name to null in the context model - tableGenerator.setSpecifiedValueColumnName(null); - assertNull(tableGeneratorResource.getValueColumnName()); - assertNull(tableGenerator.getSpecifiedValueColumnName()); - } - - public void testUpdateSpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the resource model, verify context model updated - tableGeneratorResource.setPkColumnValue("FOO"); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - - //set name to null in the resource model - tableGeneratorResource.setPkColumnValue(null); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - assertNull(tableGeneratorResource.getPkColumnValue()); - } - - public void testModifySpecifiedPkColumnValue() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - //set name in the context model, verify resource model modified - tableGenerator.setSpecifiedPkColumnValue("FOO"); - assertEquals("FOO", tableGeneratorResource.getPkColumnValue()); - assertEquals("FOO", tableGenerator.getSpecifiedPkColumnValue()); - - //set name to null in the context model - tableGenerator.setSpecifiedPkColumnValue(null); - assertNull(tableGeneratorResource.getPkColumnValue()); - assertNull(tableGenerator.getSpecifiedPkColumnValue()); - } - - - public void testUniqueConstraints() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableGeneratorResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - tableGenerator.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(1); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - tableGenerator.removeUniqueConstraint(0); - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - tableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - tableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - tableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - assertEquals(3, tableGeneratorResource.getUniqueConstraints().size()); - - - tableGenerator.moveUniqueConstraint(2, 0); - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - tableGenerator.moveUniqueConstraint(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = tableGeneratorResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - TableGenerator tableGenerator = entityMappings().addTableGenerator(0); - XmlTableGenerator tableGeneratorResource = ormResource().getEntityMappings().getTableGenerators().get(0); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableGeneratorResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<UniqueConstraint> uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(1); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableGeneratorResource.getUniqueConstraints().remove(0); - uniqueConstraints = tableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsFromJava() throws Exception { - createTestEntity(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - - OrmIdMapping ormIdMapping = (OrmIdMapping) ormPersistentType.attributes().next().getMapping(); - - JavaIdMapping javaIdMapping = (JavaIdMapping) ormPersistentType.getJavaPersistentType().attributes().next().getMapping(); - JavaTableGenerator javaTableGenerator = javaIdMapping.addTableGenerator(); - javaTableGenerator.setName("TABLE_GENERATOR"); - - OrmTableGenerator ormTableGenerator = ormIdMapping.getTableGenerator(); - assertTrue(ormTableGenerator.isVirtual()); - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormTableGenerator.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - - javaTableGenerator.addUniqueConstraint(0).addColumnName(0, "FOO"); - javaTableGenerator.addUniqueConstraint(1).addColumnName(0, "BAR"); - javaTableGenerator.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - uniqueConstraints = ormTableGenerator.uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - ormIdMapping.getPersistentAttribute().makeSpecified(); - ormIdMapping = (OrmIdMapping) ormPersistentType.attributes().next().getMapping(); - - OrmTableGenerator ormTableGenerator2 = ormIdMapping.addTableGenerator(); - ormTableGenerator2.setName("TABLE_GENERATOR"); - - assertFalse(ormTableGenerator2.isVirtual()); - assertEquals(0, ormTableGenerator2.uniqueConstraintsSize()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java deleted file mode 100644 index 1814076701..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTableTests.java +++ /dev/null @@ -1,778 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.InheritanceType; -import org.eclipse.jpt.core.context.orm.OrmEntity; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTable; -import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlEntity; -import org.eclipse.jpt.core.resource.orm.XmlTable; -import org.eclipse.jpt.core.resource.orm.XmlUniqueConstraint; -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.iterators.ArrayIterator; - -public class OrmTableTests extends ContextModelTestCase -{ - public OrmTableTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createIdAnnotation() throws Exception { - this.createAnnotationAndMembers("Id", ""); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - createIdAnnotation(); - - 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 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 void testUpdateSpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - //set name to null in the resource model - entityResource.getTable().setName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable().getName()); - - entityResource.getTable().setName("FOO"); - assertEquals("FOO", ormTable.getSpecifiedName()); - assertEquals("FOO", entityResource.getTable().getName()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmTable ormTable = ((OrmEntity) ormPersistentType.getMapping()).getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - - //set name in the context model, verify resource model modified - ormTable.setSpecifiedName("foo"); - assertEquals("foo", ormTable.getSpecifiedName()); - assertEquals("foo", entityResource.getTable().getName()); - - //set name to null in the context model - ormTable.setSpecifiedName(null); - assertNull(ormTable.getSpecifiedName()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultNameFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaEntity().getTable().setSpecifiedName("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameNoJava() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertEquals("Foo", ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromEntityName() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - ormEntity.setSpecifiedName("foo"); - - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedName(null); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - - ormEntity.getJavaEntity().setSpecifiedName("foo"); - assertEquals("foo", ormEntity.getTable().getDefaultName()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(TYPE_NAME, ormEntity.getTable().getDefaultName()); - } - - public void testUpdateDefaultNameFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals(TYPE_NAME, childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.getTable().setSpecifiedName("FOO"); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultName()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertEquals(TYPE_NAME, parentXmlEntity.getTable().getDefaultName()); - assertEquals("AnnotationTestTypeChild", childXmlEntity.getTable().getDefaultName()); - } - - public void testUpdateSpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set schema in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - //set Schema to null in the resource model - entityResource.getTable().setSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable().getSchema()); - - entityResource.getTable().setSchema("FOO"); - assertEquals("FOO", ormTable.getSpecifiedSchema()); - assertEquals("FOO", entityResource.getTable().getSchema()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultSchemaFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaEntity().getTable().setSpecifiedSchema("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.getTable().setSpecifiedSchema("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultSchema()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultSchema()); - assertNull(childXmlEntity.getTable().getDefaultSchema()); - } - - public void testUpdateDefaultSchemaFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().setSpecifiedSchema("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getJavaEntity().getTable().setSpecifiedSchema("JAVA_SCHEMA"); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultSchema()); - - - ormEntity.getEntityMappings().setSpecifiedSchema(null); - assertEquals("FOO", ormEntity.getTable().getDefaultSchema()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedSchema(null); - assertNull(ormEntity.getTable().getDefaultSchema()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_SCHEMA", ormEntity.getTable().getDefaultSchema()); - } - - public void testModifySpecifiedSchema() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - - //set Schema in the context model, verify resource model modified - ormTable.setSpecifiedSchema("foo"); - assertEquals("foo", ormTable.getSpecifiedSchema()); - assertEquals("foo", entityResource.getTable().getSchema()); - - //set Schema to null in the context model - ormTable.setSpecifiedSchema(null); - assertNull(ormTable.getSpecifiedSchema()); - assertNull(entityResource.getTable()); - } - - public void testUpdateSpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the resource model, verify context model updated - entityResource.setTable(OrmFactory.eINSTANCE.createXmlTable()); - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - //set Catalog to null in the resource model - entityResource.getTable().setCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable().getCatalog()); - - entityResource.getTable().setCatalog("FOO"); - assertEquals("FOO", ormTable.getSpecifiedCatalog()); - assertEquals("FOO", entityResource.getTable().getCatalog()); - - entityResource.setTable(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testModifySpecifiedCatalog() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - OrmTable ormTable = ormEntity.getTable(); - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - - //set Catalog in the context model, verify resource model modified - ormTable.setSpecifiedCatalog("foo"); - assertEquals("foo", ormTable.getSpecifiedCatalog()); - assertEquals("foo", entityResource.getTable().getCatalog()); - - //set Catalog to null in the context model - ormTable.setSpecifiedCatalog(null); - assertNull(ormTable.getSpecifiedCatalog()); - assertNull(entityResource.getTable()); - } - - public void testUpdateDefaultCatalogFromJavaTable() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaEntity().getTable().setSpecifiedCatalog("Foo"); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(Boolean.TRUE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - ormEntity.setSpecifiedMetadataComplete(Boolean.FALSE); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.setSpecifiedMetadataComplete(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertEquals("Foo", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("Bar"); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogNoJava() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromParent() throws Exception { - createTestEntity(); - createTestSubType(); - - OrmPersistentType parentOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentType childOrmPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".AnnotationTestTypeChild"); - OrmEntity parentXmlEntity = (OrmEntity) parentOrmPersistentType.getMapping(); - OrmEntity childXmlEntity = (OrmEntity) childOrmPersistentType.getMapping(); - - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.getTable().setSpecifiedCatalog("FOO"); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertEquals("FOO", childXmlEntity.getTable().getDefaultCatalog()); - - parentXmlEntity.setSpecifiedInheritanceStrategy(InheritanceType.JOINED); - assertNull(parentXmlEntity.getTable().getDefaultCatalog()); - assertNull(childXmlEntity.getTable().getDefaultCatalog()); - } - - public void testUpdateDefaultCatalogFromPersistenceUnitDefaults() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog("FOO"); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().setSpecifiedCatalog("BAR"); - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getJavaEntity().getTable().setSpecifiedCatalog("JAVA_CATALOG"); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName("BLAH"); - //xml entity now has a table element so default schema is not taken from java - assertEquals("BAR", ormEntity.getTable().getDefaultCatalog()); - - - ormEntity.getEntityMappings().setSpecifiedCatalog(null); - assertEquals("FOO", ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSpecifiedCatalog(null); - assertNull(ormEntity.getTable().getDefaultCatalog()); - - ormEntity.getTable().setSpecifiedName(null); - assertEquals("JAVA_CATALOG", ormEntity.getTable().getDefaultCatalog()); -} - -// -// public void testUpdateName() throws Exception { -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(IMappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); -// XmlEntity ormEntity = (XmlEntity) ormPersistentType.getMapping(); -// Entity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertEquals("Foo", ormEntity.getName()); -// -// //set class in the resource model, verify context model updated -// entityResource.setClassName("com.Bar"); -// assertEquals("Bar", ormEntity.getName()); -// -// entityResource.setName("Baz"); -// assertEquals("Baz", ormEntity.getName()); -// -// //set class to null in the resource model -// entityResource.setClassName(null); -// assertEquals("Baz", ormEntity.getName()); -// -// entityResource.setName(null); -// assertNull(ormEntity.getName()); -// } - - public void testUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - ListIterator<OrmUniqueConstraint> uniqueConstraints = ormEntity.getTable().uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - uniqueConstraints = ormEntity.getTable().uniqueConstraints(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("bar", uniqueConstraints.next().columnNames().next()); - assertEquals("foo", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testUniqueConstraintsSize() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "foo"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "bar"); - - assertEquals(2, ormEntity.getTable().uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(0).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testAddUniqueConstraint2() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(0).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - ListIterator<XmlUniqueConstraint> uniqueConstraints = tableResource.getUniqueConstraints().listIterator(); - - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().get(0)); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testRemoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - table.removeUniqueConstraint(1); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - Iterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(1); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - assertFalse(uniqueConstraintResources.hasNext()); - - uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - - table.removeUniqueConstraint(0); - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertFalse(uniqueConstraintResources.hasNext()); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - - public void testMoveUniqueConstraint() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - table.addUniqueConstraint(0).addColumnName(0, "FOO"); - table.addUniqueConstraint(1).addColumnName(0, "BAR"); - table.addUniqueConstraint(2).addColumnName(0, "BAZ"); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = entityResource.getTable(); - - assertEquals(3, tableResource.getUniqueConstraints().size()); - - - table.moveUniqueConstraint(2, 0); - ListIterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - ListIterator<XmlUniqueConstraint> uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - - - table.moveUniqueConstraint(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - - uniqueConstraintResources = tableResource.getUniqueConstraints().listIterator(); - assertEquals("BAZ", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("BAR", uniqueConstraintResources.next().getColumnNames().get(0)); - assertEquals("FOO", uniqueConstraintResources.next().getColumnNames().get(0)); - } - - public void testUpdateUniqueConstraints() throws Exception { - createTestEntity(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); - - OrmTable table = ormEntity.getTable(); - - XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); - XmlTable tableResource = OrmFactory.eINSTANCE.createXmlTable(); - entityResource.setTable(tableResource); - - XmlUniqueConstraint uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(0, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "FOO"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(1, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAR"); - - uniqueConstraintResource = OrmFactory.eINSTANCE.createXmlUniqueConstraintImpl(); - tableResource.getUniqueConstraints().add(2, uniqueConstraintResource); - uniqueConstraintResource.getColumnNames().add(0, "BAZ"); - - - ListIterator<OrmUniqueConstraint> uniqueConstraints = table.uniqueConstraints(); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(2, 0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().move(0, 1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertEquals("FOO", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(1); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - - tableResource.getUniqueConstraints().remove(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - } - -//TODO not yet supporting unique constriants from java -// public void testUniqueConstraintsFromJava() throws Exception { -// createTestEntity(); -// -// OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); -// OrmEntity ormEntity = (OrmEntity) ormPersistentType.getMapping(); -// -// ListIterator<OrmUniqueConstraint> uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertFalse(uniqueConstraints.hasNext()); -// -// JavaEntity javaEntity = (JavaEntity) ormPersistentType.getJavaPersistentType().getMapping(); -// javaEntity.getTable().addUniqueConstraint(0).addColumnName(0, "FOO"); -// javaEntity.getTable().addUniqueConstraint(1).addColumnName(0, "BAR"); -// javaEntity.getTable().addUniqueConstraint(2).addColumnName(0, "BAZ"); -// -// -// XmlEntity entityResource = ormResource().getEntityMappings().getEntities().get(0); -// assertNull(entityResource.getTable()); -// -// uniqueConstraints = ormEntity.getTable().uniqueConstraints(); -// assertTrue(uniqueConstraints.hasNext()); -// assertEquals("FOO", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAR", uniqueConstraints.next().columnNames().next()); -// assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); -// assertFalse(uniqueConstraints.hasNext()); -// -// entityResource.setTable(OrmFactory.eINSTANCE.createXmlTableImpl()); -// assertEquals(0, ormEntity.getTable().uniqueConstraintsSize()); -// } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java deleted file mode 100644 index f9d8baeeb5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmTransientMappingTests.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.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.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlTransient; -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.iterators.ArrayIterator; - -public class OrmTransientMappingTests extends ContextModelTestCase -{ - public OrmTransientMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createTransientAnnotation() throws Exception{ - this.createAnnotationAndMembers("Transient", ""); - } - - - private ICompilationUnit createTestEntityTransientMapping() throws Exception { - createEntityAnnotation(); - createTransientAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.TRANSIENT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient"); - } - }); - } - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the resource model, verify context model updated - transientResource.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the resource model - transientResource.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transientMapping"); - OrmTransientMapping xmlTransientnMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - XmlTransient transientResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getTransients().get(0); - - assertEquals("transientMapping", xmlTransientnMapping.getName()); - assertEquals("transientMapping", transientResource.getName()); - - //set name in the context model, verify resource model updated - xmlTransientnMapping.setName("newName"); - assertEquals("newName", xmlTransientnMapping.getName()); - assertEquals("newName", transientResource.getName()); - - //set name to null in the context model - xmlTransientnMapping.setName(null); - assertNull(xmlTransientnMapping.getName()); - assertNull(transientResource.getName()); - } - - - public void testTransientMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormTransientMapping.getName()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormTransientMapping.getName()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormTransientMapping.getName()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityTransientMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmTransientMapping ormTransientMapping = (OrmTransientMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormTransientMapping.getName()); - } - - public void testTransientMorphToIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToVersionMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof VersionMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToTransientMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToEmbeddedIdMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToOneToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToOneMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } - - public void testTransientMorphToManyToManyMapping() throws Exception { - createTestEntityTransientMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY, "transient"); - - TransientMapping transientMapping = (TransientMapping) ormPersistentAttribute.getMapping(); - assertFalse(transientMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("transient", ormPersistentAttribute.getMapping().getName()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java deleted file mode 100644 index a053b9f8a0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmVersionMappingTests.java +++ /dev/null @@ -1,504 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.orm; - -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.BasicMapping; -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.TemporalType; -import org.eclipse.jpt.core.context.TransientMapping; -import org.eclipse.jpt.core.context.VersionMapping; -import org.eclipse.jpt.core.context.orm.OrmColumn; -import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.XmlVersion; -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.iterators.ArrayIterator; - -public class OrmVersionMappingTests extends ContextModelTestCase -{ - public OrmVersionMappingTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception { - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createVersionAnnotation() throws Exception{ - this.createAnnotationAndMembers("Version", ""); - } - - private void createColumnAnnotation() throws Exception{ - this.createAnnotationAndMembers("Column", - "String name() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";" + - "int length() default 255;" + - "int precision() default 0;" + - "int scale() default 0;"); - } - - private void createTemporalAnnotation() throws Exception{ - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - } - - private ICompilationUnit createTestEntityVersionMapping() throws Exception { - createEntityAnnotation(); - createVersionAnnotation(); - createColumnAnnotation(); - createTemporalAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.VERSION, JPA.COLUMN, JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version"); - sb.append(CR); - sb.append(" @Column(name=\"MY_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\", length=5, precision=6, scale=7)"); - sb.append(CR); - sb.append(" @Temporal(TemporalType.TIMESTAMP)"); - } - }); - } - - public void testUpdateName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the resource model, verify context model updated - versionResource.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the resource model - versionResource.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testModifyName() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertEquals("versionMapping", ormVersionMapping.getName()); - assertEquals("versionMapping", versionResource.getName()); - - //set name in the context model, verify resource model updated - ormVersionMapping.setName("newName"); - assertEquals("newName", ormVersionMapping.getName()); - assertEquals("newName", versionResource.getName()); - - //set name to null in the context model - ormVersionMapping.setName(null); - assertNull(ormVersionMapping.getName()); - assertNull(versionResource.getName()); - } - - public void testUpdateTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getTemporal()); - assertNull(versionResource.getTemporal()); - - //set temporal in the resource model, verify context model updated - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.DATE); - assertEquals(TemporalType.DATE, ormVersionMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIME); - assertEquals(TemporalType.TIME, ormVersionMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - - versionResource.setTemporal(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP); - assertEquals(TemporalType.TIMESTAMP, ormVersionMapping.getTemporal()); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - - //set temporal to null in the resource model - versionResource.setTemporal(null); - assertNull(ormVersionMapping.getTemporal()); - assertNull(versionResource.getTemporal()); - } - - public void testModifyTemporal() throws Exception { - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "versionMapping"); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - XmlVersion versionResource = ormResource().getEntityMappings().getEntities().get(0).getAttributes().getVersions().get(0); - - assertNull(ormVersionMapping.getTemporal()); - assertNull(versionResource.getTemporal()); - - //set temporal in the context model, verify resource model updated - ormVersionMapping.setTemporal(TemporalType.DATE); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.DATE, versionResource.getTemporal()); - assertEquals(TemporalType.DATE, ormVersionMapping.getTemporal()); - - ormVersionMapping.setTemporal(TemporalType.TIME); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIME, versionResource.getTemporal()); - assertEquals(TemporalType.TIME, ormVersionMapping.getTemporal()); - - ormVersionMapping.setTemporal(TemporalType.TIMESTAMP); - assertEquals(org.eclipse.jpt.core.resource.orm.TemporalType.TIMESTAMP, versionResource.getTemporal()); - assertEquals(TemporalType.TIMESTAMP, ormVersionMapping.getTemporal()); - - //set temporal to null in the context model - ormVersionMapping.setTemporal(null); - assertNull(versionResource.getTemporal()); - assertNull(ormVersionMapping.getTemporal()); - } - - //TODO test defaults - //TODO test overriding java mapping with a different mapping type in xml - - public void testVersionMappingNoUnderylingJavaAttribute() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "foo"); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("foo", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getTemporal()); - - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("foo", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - //@Basic(fetch=FetchType.LAZY, optional=false) - //@Column(name="MY_COLUMN", unique=true, nullable=false, insertable=false, updatable=false, - // columnDefinition="COLUMN_DEFINITION", table="MY_TABLE", length=5, precision=6, scale=7)"); - //@Column( - //@Lob - //@Temporal(TemporalType.TIMESTAMP) - //@Enumerated(EnumType.STRING) - public void testVirtualMappingMetadataCompleteFalse() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormVersionMapping.getName()); - assertEquals(TemporalType.TIMESTAMP, ormVersionMapping.getTemporal()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertEquals("MY_COLUMN", ormColumn.getSpecifiedName()); - assertEquals(Boolean.TRUE, ormColumn.getSpecifiedUnique()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedNullable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedInsertable()); - assertEquals(Boolean.FALSE, ormColumn.getSpecifiedUpdatable()); - assertEquals("COLUMN_DEFINITION", ormColumn.getColumnDefinition()); - assertEquals("MY_TABLE", ormColumn.getSpecifiedTable()); - assertEquals(Integer.valueOf(5), ormColumn.getSpecifiedLength()); - assertEquals(Integer.valueOf(6), ormColumn.getSpecifiedPrecision()); - assertEquals(Integer.valueOf(7), ormColumn.getSpecifiedScale()); - } - - public void testVirtualMappingMetadataCompleteTrue() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE); - assertEquals(2, ormPersistentType.virtualAttributesSize()); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next(); - - assertEquals(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey()); - - ormPersistentAttribute.makeSpecified(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY); - ormPersistentAttribute= ormPersistentType.specifiedAttributes().next(); - - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - assertEquals("id", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getTemporal()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertEquals("id", ormColumn.getName()); - assertEquals(Boolean.FALSE, ormColumn.getUnique()); - assertEquals(Boolean.TRUE, ormColumn.getNullable()); - assertEquals(Boolean.TRUE, ormColumn.getInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getTable()); - assertEquals(Integer.valueOf(255), ormColumn.getLength()); - assertEquals(Integer.valueOf(0), ormColumn.getPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getScale()); - } - - public void testSpecifiedMapping() throws Exception { - createTestEntityVersionMapping(); - - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "id"); - assertEquals(1, ormPersistentType.virtualAttributesSize()); - - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next(); - OrmVersionMapping ormVersionMapping = (OrmVersionMapping) ormPersistentAttribute.getMapping(); - - assertEquals("id", ormVersionMapping.getName()); - assertNull(ormVersionMapping.getTemporal()); - - OrmColumn ormColumn = ormVersionMapping.getColumn(); - assertNull(ormColumn.getSpecifiedName()); - assertNull(ormColumn.getSpecifiedUnique()); - assertNull(ormColumn.getSpecifiedNullable()); - assertNull(ormColumn.getSpecifiedInsertable()); - assertNull(ormColumn.getSpecifiedUpdatable()); - assertNull(ormColumn.getColumnDefinition()); - assertNull(ormColumn.getSpecifiedTable()); - assertNull(ormColumn.getSpecifiedLength()); - assertNull(ormColumn.getSpecifiedPrecision()); - assertNull(ormColumn.getSpecifiedScale()); - - assertEquals("id", ormColumn.getDefaultName()); - assertEquals(Boolean.FALSE, ormColumn.getDefaultUnique()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultNullable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultInsertable()); - assertEquals(Boolean.TRUE, ormColumn.getDefaultUpdatable()); - assertEquals(null, ormColumn.getColumnDefinition()); - assertEquals(TYPE_NAME, ormColumn.getDefaultTable()); - assertEquals(Integer.valueOf(255), ormColumn.getDefaultLength()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultPrecision()); - assertEquals(Integer.valueOf(0), ormColumn.getDefaultScale()); - } - - public void testVersionMorphToIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof IdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((IdMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((IdMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToBasicMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof BasicMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - assertEquals(TemporalType.TIME, ((BasicMapping) ormPersistentAttribute.getMapping()).getTemporal()); - assertEquals("FOO", ((BasicMapping) ormPersistentAttribute.getMapping()).getColumn().getSpecifiedName()); - } - - public void testVersionMorphToTransientMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof TransientMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToEmbeddedIdMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof EmbeddedIdMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToOneToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof OneToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToOneMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToOneMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - - public void testVersionMorphToManyToManyMapping() throws Exception { - createTestEntityVersionMapping(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.addSpecifiedPersistentAttribute(MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY, "version"); - - VersionMapping versionMapping = (VersionMapping) ormPersistentAttribute.getMapping(); - assertFalse(versionMapping.isDefault()); - versionMapping.getColumn().setSpecifiedName("FOO"); - versionMapping.setTemporal(TemporalType.TIME); - assertFalse(versionMapping.isDefault()); - - ormPersistentAttribute.setSpecifiedMappingKey(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY); - assertEquals(1, ormPersistentType.specifiedAttributesSize()); - assertEquals(ormPersistentAttribute, ormPersistentType.specifiedAttributes().next()); - assertTrue(ormPersistentAttribute.getMapping() instanceof ManyToManyMapping); - assertEquals("version", ormPersistentAttribute.getMapping().getName()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java deleted file mode 100644 index c210d14c5d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmXmlTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.OrmXml; -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.OrmResource; -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; - -public class OrmXmlTests extends ContextModelTestCase -{ - public OrmXmlTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - xmlPersistenceUnit().setName("foo"); - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected PersistenceXml persistenceXml() { - return rootContext().getPersistenceXml(); - } - - protected OrmXml ormXml() { - return persistenceUnit().mappingFileRefs().next().getOrmXml(); - } - - public void testUpdateAddEntityMappings() throws Exception { - OrmResource ormResource = ormResource(); - ormResource.getContents().clear(); - ormResource.save(null); - - assertNull(ormXml().getEntityMappings()); - - ormResource.getContents().add(OrmFactory.eINSTANCE.createXmlEntityMappings()); - - assertNotNull(ormXml().getEntityMappings()); - - } - - public void testModifyAddEntityMappings() { - OrmResource ormResource = ormResource(); - ormResource.getContents().remove(ormResource.getEntityMappings()); - assertNull(ormResource.getEntityMappings()); - - OrmXml ormXml = ormXml(); - assertNull(ormXml.getEntityMappings()); - - ormXml.addEntityMappings(); - - assertNotNull(ormXml.getEntityMappings()); - - boolean exceptionThrown = false; - try { - ormXml.addEntityMappings(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue("IllegalStateException was not thrown", exceptionThrown); - } - - public void testUpdateRemoveEntityMappings() throws Exception { - OrmResource ormResource = ormResource(); - - assertNotNull(ormXml().getEntityMappings()); - - ormResource.getContents().clear(); - - assertNull(ormXml().getEntityMappings()); - } - - public void testModifyRemoveEntityMappings() { - OrmXml ormXml = ormXml(); - - assertNotNull(ormXml.getEntityMappings()); - - ormXml.removeEntityMappings(); - - assertNull(ormXml.getEntityMappings()); - - boolean exceptionThrown = false; - try { - ormXml.removeEntityMappings(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue("IllegalStateException was not thrown", exceptionThrown); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java deleted file mode 100644 index 0abf9ffcf9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitDefaultsTests.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.orm.PersistenceUnitDefaults; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata; -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; - -public class PersistenceUnitDefaultsTests extends ContextModelTestCase -{ - public PersistenceUnitDefaultsTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected PersistenceUnitDefaults persistenceUnitDefaults() { - return entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults(); - } - - public void testIsAllFeaturesUnset() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - ormResource().getEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitDefaults persistenceUnitDefaultsResource = OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults(); - persistenceUnitMetadata.setPersistenceUnitDefaults(persistenceUnitDefaultsResource); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(true); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCascadePersist(false); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setSchema("asdf"); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setSchema(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCatalog("asdf"); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setCatalog(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertFalse(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - - persistenceUnitDefaultsResource.setAccess(null); - assertTrue(persistenceUnitDefaultsResource.isAllFeaturesUnset()); - } - - public void testUpdateSchema() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifySchema2() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - } - - public void testModifySchema3() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set schema in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedSchema("MY_SCHEMA"); - assertEquals("MY_SCHEMA", persistenceUnitDefaults.getSchema()); - assertEquals("MY_SCHEMA", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getSchema()); - - //set schema to null in the context model - persistenceUnitDefaults.setSpecifiedSchema(null); - assertNull(persistenceUnitDefaults.getSchema()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCatalog() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCatalog2() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setSchema("MY_SCHEMA"); - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - } - - public void testModifyCatalog3() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set catalog in the context model, verify resource model modified - persistenceUnitDefaults.setSpecifiedCatalog("MY_CATALOG"); - assertEquals("MY_CATALOG", persistenceUnitDefaults.getCatalog()); - assertEquals("MY_CATALOG", ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getCatalog()); - - //set catalog to null in the context model - persistenceUnitDefaults.setSpecifiedCatalog(null); - assertNull(persistenceUnitDefaults.getCatalog()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - public void testUpdateCascadePersist() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the resource model, persistence-unit-defaults tag not removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyCascadePersist2() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCatalog("MY_CATALOG"); - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - } - - public void testModifyCascadePersist3() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set cascadePersist in the context model, verify resource model modified - persistenceUnitDefaults.setCascadePersist(true); - assertTrue(persistenceUnitDefaults.isCascadePersist()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().isCascadePersist()); - - //set cascadePersist to null in the context model - persistenceUnitDefaults.setCascadePersist(false); - assertFalse(persistenceUnitDefaults.isCascadePersist()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - - - public void testUpdateAccess() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(org.eclipse.jpt.core.resource.orm.AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.PROPERTY, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyAccess2() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set another element on the persistence-unit-defaults element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setCascadePersist(true); - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - } - - public void testModifyAccess3() throws Exception { - PersistenceUnitDefaults persistenceUnitDefaults = persistenceUnitDefaults(); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - //set another element on the persistence-unit-metadata element so only persistence-unit-defaults element gets removed - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - - //set access in the context model, verify resource model modified - persistenceUnitDefaults.setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnitDefaults.getAccess()); - assertEquals(org.eclipse.jpt.core.resource.orm.AccessType.FIELD, ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().getAccess()); - - //set access to null in the context model - persistenceUnitDefaults.setAccess(null); - assertNull(persistenceUnitDefaults.getAccess()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults()); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java deleted file mode 100644 index feada5432d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/PersistenceUnitMetadataTests.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.orm; - -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; -import org.eclipse.jpt.core.resource.orm.OrmFactory; -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; - -public class PersistenceUnitMetadataTests extends ContextModelTestCase -{ - public PersistenceUnitMetadataTests(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); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - protected PersistenceUnitMetadata persistenceUnitMetadata() { - return entityMappings().getPersistenceUnitMetadata(); - } - - public void testIsAllFeaturesUnset() throws Exception { - org.eclipse.jpt.core.resource.orm.XmlPersistenceUnitMetadata persistenceUnitMetadata = OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata(); - ormResource().getEntityMappings().setPersistenceUnitMetadata(persistenceUnitMetadata); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertFalse(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertTrue(persistenceUnitMetadata.isAllFeaturesUnset()); - - persistenceUnitMetadata.setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - assertFalse(persistenceUnitMetadata.isAllFeaturesUnset()); - } - - public void testUpdateXmlMappingMetadataComplete() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the resource model, verify context model updated - ormResource().getEntityMappings().setPersistenceUnitMetadata(OrmFactory.eINSTANCE.createXmlPersistenceUnitMetadata()); - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the resource model - ormResource().getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } - - public void testModifyXmlMappingMetadataComplete() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - } - - public void testModifyXmlMappingMetadataComplete2() throws Exception { - PersistenceUnitMetadata persistenceUnitMetadata = entityMappings().getPersistenceUnitMetadata(); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertNull(ormResource().getEntityMappings().getPersistenceUnitMetadata()); - - //set xmlMappingMetadataComplete in the context model, verify resource model modified - persistenceUnitMetadata.setXmlMappingMetadataComplete(true); - assertTrue(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertTrue(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - - //set xmlMappingMetadataComplete to null in the context model - //set another element on the persistence-unit-metadata element so it doesn't get removed - ormResource().getEntityMappings().getPersistenceUnitMetadata().setPersistenceUnitDefaults(OrmFactory.eINSTANCE.createXmlPersistenceUnitDefaults()); - persistenceUnitMetadata.setXmlMappingMetadataComplete(false); - assertFalse(persistenceUnitMetadata.isXmlMappingMetadataComplete()); - assertFalse(ormResource().getEntityMappings().getPersistenceUnitMetadata().isXmlMappingMetadataComplete()); - } -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java deleted file mode 100644 index fdf5a60c78..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/ClassRefTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class ClassRefTests extends ContextModelTestCase -{ - public ClassRefTests(String name) { - super(name); - } - - public void testUpdateClassName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add class ref - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - ClassRef classRef = persistenceUnit.specifiedClassRefs().next(); - - // test that class names are initially equal - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set xml class name to different name, test equality - xmlClassRef.setJavaClass("com.bar.Foo"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to empty string, test equality - xmlClassRef.setJavaClass(""); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to null, test equality - xmlClassRef.setJavaClass(null); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set name back to non-null, test equality - xmlClassRef.setJavaClass("com.foo.Bar"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - } - - public void testModifyClassName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add class ref - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - ClassRef classRef = persistenceUnit.specifiedClassRefs().next(); - - // test that class names are initially equal - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set context class name to different name, test equality - classRef.setClassName("com.bar.Foo"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to empty string, test equality - classRef.setClassName(""); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set class name to null, test equality - classRef.setClassName(null); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - - // set name back to non-null, test equality - classRef.setClassName("com.foo.Bar"); - - assertEquals(classRef.getClassName(), xmlClassRef.getJavaClass()); - } - - - public void testGetPersistentType() throws Exception { - createTestType(); - - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass(FULLY_QUALIFIED_TYPE_NAME); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - ClassRef classRef = classRef(); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, classRef.getJavaPersistentType().getName()); - - //test setting to a class that does not exist in the project - xmlClassRef.setJavaClass("com.foo.Bar"); - - classRef = classRef(); - assertNull(classRef.getJavaPersistentType()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java deleted file mode 100644 index 5dd87d2a34..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/JptCorePersistenceContextModelTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JptCorePersistenceContextModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCorePersistenceContextModelTests.class.getName()); - suite.addTestSuite(RootContextTests.class); - suite.addTestSuite(PersistenceXmlTests.class); - suite.addTestSuite(PersistenceTests.class); - suite.addTestSuite(PersistenceUnitTests.class); - suite.addTestSuite(MappingFileRefTests.class); - suite.addTestSuite(ClassRefTests.class); - return suite; - } - - private JptCorePersistenceContextModelTests() { - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java deleted file mode 100644 index 1854a15312..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/MappingFileRefTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class MappingFileRefTests extends ContextModelTestCase -{ - public MappingFileRefTests(String name) { - super(name); - } - - protected MappingFileRef mappingFileRef() { - return persistenceUnit().mappingFileRefs().next(); - } - - public void testUpdateFileName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add mapping file ref - XmlMappingFileRef xmlFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlFileRef.setFileName("foo.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlFileRef); - MappingFileRef fileRef = persistenceUnit.specifiedMappingFileRefs().next(); - - // test that file names are initially equal - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set xml to different file name, test equality - xmlFileRef.setFileName("bar.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to empty string, test equality - xmlFileRef.setFileName(""); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to null, test equality - xmlFileRef.setFileName(null); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name back to non-null, test equality - xmlFileRef.setFileName("baz.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - } - - public void testModifyFileName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add mapping file ref - XmlMappingFileRef xmlFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlFileRef.setFileName("foo.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlFileRef); - MappingFileRef fileRef = persistenceUnit.specifiedMappingFileRefs().next(); - - // test that file names are initially equal - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set context to different file name, test equality - fileRef.setFileName("bar.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to empty string, test equality - fileRef.setFileName(""); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name to null, test equality - fileRef.setFileName(null); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - - // set file name back to non-null, test equality - fileRef.setFileName("baz.xml"); - - assertEquals(fileRef.getFileName(), xmlFileRef.getFileName()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java deleted file mode 100644 index 4dc384a858..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceTests.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import org.eclipse.jpt.core.context.persistence.Persistence; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.resource.persistence.XmlPersistence; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class PersistenceTests extends ContextModelTestCase -{ - public PersistenceTests(String name) { - super(name); - } - - protected Persistence persistence() { - return rootContext().getPersistenceXml().getPersistence(); - } - - public void testUpdateAddPersistenceUnit() throws Exception { - PersistenceResource prm = persistenceResource(); - XmlPersistence xmlPersistence = prm.getPersistence(); - Persistence persistence = rootContext().getPersistenceXml().getPersistence(); - - // clear xml persistence units, test that it's clear in context - xmlPersistence.getPersistenceUnits().clear(); - - assertEquals(0, persistence.persistenceUnitsSize()); - - // add xml persistence unit, test that it's added to context - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(1, persistence.persistenceUnitsSize()); - - // add another, test that it *isn't* add to context - xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test2"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(1, persistence.persistenceUnitsSize()); - } - - public void testModifyAddPersistencUnit() { - XmlPersistence xmlPersistence = xmlPersistence(); - Persistence persistence = persistence(); - - // clear xml persistence units, test that it's clear in context - xmlPersistence.getPersistenceUnits().clear(); - assertEquals(0, persistence.persistenceUnitsSize()); - - // add persistence unit, test that it's added to resource - persistence.addPersistenceUnit(); - - assertEquals(1, persistence.persistenceUnitsSize()); - - // add another, test that we get an exception - boolean exception = false; - try { - persistence.addPersistenceUnit(); - } - catch (IllegalStateException e) { - exception = true; - } - - assertTrue(exception); - } - - public void testUpdateRemovePersistenceUnit() throws Exception { - PersistenceResource prm = persistenceResource(); - XmlPersistence xmlPersistence = prm.getPersistence(); - Persistence persistence = rootContext().getPersistenceXml().getPersistence(); - - // add a persistence unit and test that there are two existing xml and - // one context persistence unit - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(2, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove persistence unit from xml, test that context remains unchanged - xmlPersistenceUnit = xmlPersistence.getPersistenceUnits().get(0); - xmlPersistence.getPersistenceUnits().remove(xmlPersistenceUnit); - - assertEquals(1, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove another one from xml, text that it's now removed from context - xmlPersistenceUnit = xmlPersistence.getPersistenceUnits().get(0); - xmlPersistence.getPersistenceUnits().remove(xmlPersistenceUnit); - - assertEquals(0, xmlPersistence.getPersistenceUnits().size()); - assertEquals(0, persistence.persistenceUnitsSize()); - } - - public void testModifyRemovePersistenceUnit() { - XmlPersistence xmlPersistence = xmlPersistence(); - Persistence persistence = persistence(); - - // add a persistence unit and test that there are two existing xml and - // one context persistence unit - XmlPersistenceUnit xmlPersistenceUnit = PersistenceFactory.eINSTANCE.createXmlPersistenceUnit(); - xmlPersistenceUnit.setName("test"); - xmlPersistence.getPersistenceUnits().add(xmlPersistenceUnit); - - assertEquals(2, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove persistence unit, test that it's removed from resource and that - // a *new* persistence unit representing the previously unrepresented one - // is present - persistence.removePersistenceUnit(0); - - assertEquals(1, xmlPersistence.getPersistenceUnits().size()); - assertEquals(1, persistence.persistenceUnitsSize()); - - // remove new persistence unit, test that it's removed from resource and - // context - persistence.removePersistenceUnit(0); - - assertEquals(0, xmlPersistence.getPersistenceUnits().size()); - assertEquals(0, persistence.persistenceUnitsSize()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java deleted file mode 100644 index 08cd41c918..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceUnitTests.java +++ /dev/null @@ -1,1126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.context.persistence; - -import java.io.IOException; -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.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.persistence.ClassRef; -import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.context.persistence.PersistenceUnitTransactionType; -import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.orm.OrmResource; -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.XmlPersistenceUnit; -import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnitTransactionType; -import org.eclipse.jpt.core.resource.persistence.XmlProperties; -import org.eclipse.jpt.core.resource.persistence.XmlProperty; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class PersistenceUnitTests extends ContextModelTestCase -{ - - protected static final String INNER_CLASS_NAME = "InnerAnnotationTestType"; - protected static final String FULLY_QUALIFIED_INNER_CLASS_NAME = PACKAGE_NAME + "." + TYPE_NAME + "." + INNER_CLASS_NAME; - - public PersistenceUnitTests(String name) { - super(name); - } - - public void testUpdateName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that names are initially equal - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to different name, test equality - xmlPersistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to empty string, test equality - xmlPersistenceUnit.setName(""); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to null, test equality - xmlPersistenceUnit.setName(null); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name back to non-null, test equality - xmlPersistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - } - - public void testModifyName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that names are initially equal - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to different name, test equality - persistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to empty string, test equality - persistenceUnit.setName(""); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name to null, test equality - persistenceUnit.setName(null); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - - // set name back to non-null, test equality - persistenceUnit.setName("newName"); - - assertEquals(xmlPersistenceUnit.getName(), persistenceUnit.getName()); - } - - public void testUpdateTransactionType() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // 1 - initial value is default - assertNull(xmlPersistenceUnit.getTransactionType()); - assertNull(persistenceUnit.getSpecifiedTransactionType()); - - // 2 - set value, context changed - xmlPersistenceUnit.setTransactionType(XmlPersistenceUnitTransactionType.JTA); - - assertEquals(PersistenceUnitTransactionType.JTA, persistenceUnit.getSpecifiedTransactionType()); - - xmlPersistenceUnit.setTransactionType(XmlPersistenceUnitTransactionType.RESOURCE_LOCAL); - - assertEquals(PersistenceUnitTransactionType.RESOURCE_LOCAL, persistenceUnit.getSpecifiedTransactionType()); - - // 3 - unset value, context changed - xmlPersistenceUnit.setTransactionType(null); - - assertNull(persistenceUnit.getSpecifiedTransactionType()); - } - - public void testModifyTransactionType() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // 1 - initial value is default - assertNull(xmlPersistenceUnit.getTransactionType()); - assertNull(persistenceUnit.getSpecifiedTransactionType()); - - // 2 - set context value, resource changed - persistenceUnit.setSpecifiedTransactionType(PersistenceUnitTransactionType.JTA); - - assertEquals(XmlPersistenceUnitTransactionType.JTA, xmlPersistenceUnit.getTransactionType()); - - persistenceUnit.setSpecifiedTransactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL); - - assertEquals(XmlPersistenceUnitTransactionType.RESOURCE_LOCAL, xmlPersistenceUnit.getTransactionType()); - - // 3 - set context value to default, resource unset - persistenceUnit.setSpecifiedTransactionType(null); - - assertNull(persistenceUnit.getSpecifiedTransactionType()); - assertNull(xmlPersistenceUnit.getTransactionType()); - } - - public void testUpdateDescription() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that descriptions are initially equal - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to different description, test equality - xmlPersistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to empty string, test equality - xmlPersistenceUnit.setDescription(""); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to null, test equality - xmlPersistenceUnit.setDescription(null); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description back to non-null, test equality - xmlPersistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - } - - public void testModifyDescription() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that descriptions are initially equal - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to different description, test equality - persistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to empty string, test equality - persistenceUnit.setDescription(""); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description to null, test equality - persistenceUnit.setDescription(null); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - - // set description back to non-null, test equality - persistenceUnit.setDescription("newDescription"); - - assertEquals(xmlPersistenceUnit.getDescription(), persistenceUnit.getDescription()); - } - - public void testUpdateProvider() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that providers are initially equal - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to different provider, test equality - xmlPersistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to empty string, test equality - xmlPersistenceUnit.setProvider(""); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to null, test equality - xmlPersistenceUnit.setProvider(null); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider back to non-null, test equality - xmlPersistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - } - - public void testModifyProvider() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that providers are initially equal - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to different provider, test equality - persistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to empty string, test equality - persistenceUnit.setProvider(""); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider to null, test equality - persistenceUnit.setProvider(null); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - - // set provider back to non-null, test equality - persistenceUnit.setProvider("newProvider"); - - assertEquals(xmlPersistenceUnit.getProvider(), persistenceUnit.getProvider()); - } - - public void testUpdateJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that jtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to different jtaDataSource, test equality - xmlPersistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to empty string, test equality - xmlPersistenceUnit.setJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to null, test equality - xmlPersistenceUnit.setJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource back to non-null, test equality - xmlPersistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - } - - public void testModifyJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that jtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to different jtaDataSource, test equality - persistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to empty string, test equality - persistenceUnit.setJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource to null, test equality - persistenceUnit.setJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - - // set jtaDataSource back to non-null, test equality - persistenceUnit.setJtaDataSource("newJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getJtaDataSource(), persistenceUnit.getJtaDataSource()); - } - - public void testUpdateNonJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that nonJtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to different nonJtaDataSource, test equality - xmlPersistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to empty string, test equality - xmlPersistenceUnit.setNonJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to null, test equality - xmlPersistenceUnit.setNonJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource back to non-null, test equality - xmlPersistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - } - - public void testModifyNonJtaDataSource() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that nonJtaDataSources are initially equal - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to different nonJtaDataSource, test equality - persistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to empty string, test equality - persistenceUnit.setNonJtaDataSource(""); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource to null, test equality - persistenceUnit.setNonJtaDataSource(null); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - - // set nonJtaDataSource back to non-null, test equality - persistenceUnit.setNonJtaDataSource("newNonJtaDataSource"); - - assertEquals(xmlPersistenceUnit.getNonJtaDataSource(), persistenceUnit.getNonJtaDataSource()); - } - - public void testUpdateJarFileRefs1() { - // TODO - } - - public void testUpdateJarFileRefs2() { - // TODO - } - - public void testUpdateImpliedMappingFileRef1() throws Exception { - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that there is one initially - OrmResource ormResource = ormResource(); - assertTrue(ormResource.exists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - - // remove orm.xml - deleteResource(ormResource); - - assertFalse(ormResource.exists()); - assertNull(persistenceUnit.getImpliedMappingFileRef()); - } - - public void testUpdateImpliedMappingFileRef2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test that there is one initially - OrmResource ormResource = ormResource(); - assertTrue(ormResource.exists()); - assertNotNull(persistenceUnit.getImpliedMappingFileRef()); - - // add specified orm.xml - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("META-INF/orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(1, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - assertTrue(ormResource.exists()); - assertNull(persistenceUnit.getImpliedMappingFileRef()); - } - - public void testUpdateSpecifiedMappingFileRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(0, persistenceUnit.specifiedMappingFileRefsSize()); - - // add mapping file ref, test that it's added to context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(1, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - // add another ... - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(2, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - } - - public void testUpdateSpecifiedMappingFileRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two mapping file refs and test that there are two existing in xml and context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(xmlPersistenceUnit.getMappingFiles().size(), 2); - assertEquals(2, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - // remove mapping file ref from xml, test that it's removed from context - xmlMappingFileRef = xmlPersistenceUnit.getMappingFiles().get(0); - xmlPersistenceUnit.getMappingFiles().remove(xmlMappingFileRef); - - assertEquals(1, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - // remove another one ... - xmlMappingFileRef = xmlPersistenceUnit.getMappingFiles().get(0); - xmlPersistenceUnit.getMappingFiles().remove(xmlMappingFileRef); - - assertEquals(0, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - } - - public void testModifySpecifiedMappingFileRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(0, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - // add mapping file ref, test that it's added to resource - persistenceUnit.addSpecifiedMappingFileRef().setFileName("foo"); - - assertEquals(1, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - - // add another ... - persistenceUnit.addSpecifiedMappingFileRef().setFileName("bar"); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - assertEquals("bar", xmlPersistenceUnit.getMappingFiles().get(1).getFileName()); - - assertEquals(2, xmlPersistenceUnit.getMappingFiles().size()); - - // add another, testing order - persistenceUnit.addSpecifiedMappingFileRef(0).setFileName("baz"); - assertEquals(3, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals("baz", xmlPersistenceUnit.getMappingFiles().get(0).getFileName()); - assertEquals("foo", xmlPersistenceUnit.getMappingFiles().get(1).getFileName()); - assertEquals("bar", xmlPersistenceUnit.getMappingFiles().get(2).getFileName()); - } - - public void testModifySpecifiedMappingFileRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two mapping file refs and test that there are two existing in xml and context - XmlMappingFileRef xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - xmlMappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - xmlMappingFileRef.setFileName("orm2.xml"); - xmlPersistenceUnit.getMappingFiles().add(xmlMappingFileRef); - - assertEquals(2, xmlPersistenceUnit.getMappingFiles().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.specifiedMappingFileRefs())); - - // remove mapping file ref from context, test that it's removed from xml - persistenceUnit.removeSpecifiedMappingFileRef(0); - - assertEquals(1, xmlPersistenceUnit.getMappingFiles().size()); - - // remove another one ... - persistenceUnit.removeSpecifiedMappingFileRef(0); - - assertEquals(0, xmlPersistenceUnit.getMappingFiles().size()); - } - - public void testUpdateClassRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - assertEquals(0, persistenceUnit.specifiedClassRefsSize()); - - // add mapping file ref, test that it's added to context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(1, persistenceUnit.specifiedClassRefsSize()); - - // add another ... - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, persistenceUnit.specifiedClassRefsSize()); - } - - public void testUpdateClassRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two class refs and test that there are two existing in xml and context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.specifiedClassRefs())); - - // remove class ref from xml, test that it's removed from context - xmlClassRef = xmlPersistenceUnit.getClasses().get(0); - xmlPersistenceUnit.getClasses().remove(xmlClassRef); - - assertEquals(1, CollectionTools.size(persistenceUnit.specifiedClassRefs())); - - // remove another one ... - xmlClassRef = xmlPersistenceUnit.getClasses().get(0); - xmlPersistenceUnit.getClasses().remove(xmlClassRef); - - assertEquals(0, CollectionTools.size(persistenceUnit.specifiedClassRefs())); - } - - public void testModifyClassRefs1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - assertEquals(0, persistenceUnit.specifiedClassRefsSize()); - - // add class ref, test that it's added to context - persistenceUnit.addSpecifiedClassRef().setClassName("Foo"); - - try { - persistenceResource().save(null); - } - catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertEquals(1, xmlPersistenceUnit.getClasses().size()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - - // add another ... - persistenceUnit.addSpecifiedClassRef().setClassName("Bar"); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - assertEquals("Bar", xmlPersistenceUnit.getClasses().get(1).getJavaClass()); - - - persistenceUnit.addSpecifiedClassRef(0).setClassName("Baz"); - - assertEquals(3, xmlPersistenceUnit.getClasses().size()); - assertEquals("Baz", xmlPersistenceUnit.getClasses().get(0).getJavaClass()); - assertEquals("Foo", xmlPersistenceUnit.getClasses().get(1).getJavaClass()); - assertEquals("Bar", xmlPersistenceUnit.getClasses().get(2).getJavaClass()); - } - - public void testModifyClassRefs2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two class refs and test that there are two existing in xml and context - XmlJavaClassRef xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Bar"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - xmlClassRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - xmlClassRef.setJavaClass("com.foo.Baz"); - xmlPersistenceUnit.getClasses().add(xmlClassRef); - - assertEquals(2, xmlPersistenceUnit.getClasses().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.specifiedClassRefs())); - - // remove class ref from context, test that it's removed from xml - persistenceUnit.removeSpecifiedClassRef(0); - - assertEquals(1, xmlPersistenceUnit.getClasses().size()); - - // remove another one ... - persistenceUnit.removeSpecifiedClassRef(0); - - assertEquals(0, xmlPersistenceUnit.getClasses().size()); - } - - public void testImpliedClassRefs() throws Exception { - createTestEntityWithPersistentInnerClass(); - ListIterator<ClassRef> classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, classRefs.next().getClassName()); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - - jpaProject().setDiscoversAnnotatedClasses(true); - classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, classRefs.next().getClassName()); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - assertFalse(classRefs.hasNext()); - - - removeXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, classRefs.next().getClassName()); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - assertFalse(classRefs.hasNext()); - - addXmlClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertFalse(classRefs.hasNext()); - - removeXmlClassRef(FULLY_QUALIFIED_INNER_CLASS_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertEquals(FULLY_QUALIFIED_INNER_CLASS_NAME, classRefs.next().getClassName()); - assertFalse(classRefs.hasNext()); - - entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_INNER_CLASS_NAME); - classRefs = persistenceUnit().impliedClassRefs(); - assertFalse(classRefs.hasNext()); - } - - public void testUpdateExcludeUnlistedClasses() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // 1 - initial value is default - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 2 - set value, context changed - xmlPersistenceUnit.setExcludeUnlistedClasses(Boolean.TRUE); - - assertEquals(Boolean.TRUE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertTrue(persistenceUnit.isExcludeUnlistedClasses()); - assertEquals(Boolean.TRUE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - xmlPersistenceUnit.setExcludeUnlistedClasses(Boolean.FALSE); - - assertEquals(Boolean.FALSE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertEquals(Boolean.FALSE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 3 - unset value, context changed - xmlPersistenceUnit.setExcludeUnlistedClasses(null); - - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - } - - public void testModifyExcludeUnlistedClasses() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // 1 - initial value is default - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 2 - set value, resource changed - persistenceUnit.setSpecifiedExcludeUnlistedClasses(Boolean.TRUE); - - assertEquals(Boolean.TRUE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertTrue(persistenceUnit.isExcludeUnlistedClasses()); - assertEquals(Boolean.TRUE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - persistenceUnit.setSpecifiedExcludeUnlistedClasses(Boolean.FALSE); - - assertEquals(Boolean.FALSE, persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertEquals(Boolean.FALSE, xmlPersistenceUnit.getExcludeUnlistedClasses()); - - // 3 - set context to default, resource unset - persistenceUnit.setSpecifiedExcludeUnlistedClasses(null); - - assertNull(persistenceUnit.getSpecifiedExcludeUnlistedClasses()); - assertFalse(persistenceUnit.isExcludeUnlistedClasses()); - assertNull(xmlPersistenceUnit.getExcludeUnlistedClasses()); - } - - public void testUpdateProperties1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertNull(xmlPersistenceUnit.getProperties()); - assertEquals(0, CollectionTools.size(persistenceUnit.properties())); - - // add "properties", test that there's no real change to context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - assertEquals(0, CollectionTools.size(persistenceUnit.properties())); - - // add property, test that it's added to context - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(1, CollectionTools.size(persistenceUnit.properties())); - - // add another ... - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, CollectionTools.size(persistenceUnit.properties())); - } - - public void testUpdateProperties2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two properties and test that there are two existing in xml and context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.properties())); - - // remove property from xml, test that it's removed from context - xmlProperty = xmlProperties.getProperties().get(0); - xmlProperties.getProperties().remove(xmlProperty); - - assertEquals(1, CollectionTools.size(persistenceUnit.properties())); - - // remove another one ... - xmlProperty = xmlProperties.getProperties().get(0); - xmlProperties.getProperties().remove(xmlProperty); - - assertEquals(0, CollectionTools.size(persistenceUnit.properties())); - } - - public void testModifyProperties1() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // test there are none initially - assertNull(xmlPersistenceUnit.getProperties()); - assertEquals(0, persistenceUnit.propertiesSize()); - - // add property, test that it's added to resource - persistenceUnit.addProperty().setName("foo"); - - assertNotNull(xmlPersistenceUnit.getProperties()); - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - - // add another ... - persistenceUnit.addProperty().setName("bar"); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - assertEquals("bar", xmlPersistenceUnit.getProperties().getProperties().get(1).getName()); - - // add another testing order - persistenceUnit.addProperty(0).setName("baz"); - - assertEquals(3, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals("baz", xmlPersistenceUnit.getProperties().getProperties().get(0).getName()); - assertEquals("foo", xmlPersistenceUnit.getProperties().getProperties().get(1).getName()); - assertEquals("bar", xmlPersistenceUnit.getProperties().getProperties().get(2).getName()); - } - - public void testModifyProperties2() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two properties and test that there are two existing in xml and context - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("foo"); - xmlProperty.setValue("bar"); - xmlProperties.getProperties().add(xmlProperty); - xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperty.setName("FOO"); - xmlProperty.setValue("BAR"); - xmlProperties.getProperties().add(xmlProperty); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.properties())); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("foo"); - - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove another one. test that properties object is nulled - persistenceUnit.removeProperty("FOO", "BAR"); - - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties3() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two properties and test that there are two existing in xml and context - persistenceUnit.putProperty("foo", "bar", false); - persistenceUnit.putProperty("FOO", "BAR", false); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, CollectionTools.size(persistenceUnit.properties())); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("foo", "bar"); - - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove another one, test that properties object is nulled - persistenceUnit.removeProperty("FOO"); - - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties4() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two properties and test that there are two existing in xml and context - persistenceUnit.putProperty("foo", "bar", false); - persistenceUnit.putProperty("FOO", "BAR", false); - - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(2, persistenceUnit.propertiesSize()); - - // modify a property, test its value - persistenceUnit.putProperty("foo", "", false); - assertEquals("", persistenceUnit.getProperty("foo").getValue()); - - persistenceUnit.putProperty("foo", "BAR", false); - assertEquals("BAR", persistenceUnit.getProperty("foo").getValue()); - - // remove property that doesn't from context, test that the resource is unchanged - persistenceUnit.removeProperty("notExist"); - assertEquals(2, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove property from context, test that it's removed from resource - persistenceUnit.removeProperty("FOO"); - assertNull(persistenceUnit.getProperty("FOO")); - assertEquals(1, xmlPersistenceUnit.getProperties().getProperties().size()); - - // remove by setting value to null, test that properties object is nulled - persistenceUnit.putProperty("notExist", null, false); - assertNull(persistenceUnit.getProperty("notExist")); - - persistenceUnit.putProperty("foo", null, false); - assertNull(persistenceUnit.getProperty("foo")); - assertNull(xmlPersistenceUnit.getProperties()); - } - - public void testModifyProperties5() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // testing duplicate keys, add four properties and test that there are four existing in xml and context - persistenceUnit.putProperty("FOO", "BAR", false); - persistenceUnit.putProperty("foo", "bar 3", true); - persistenceUnit.putProperty("foo", "bar 2", true); - persistenceUnit.putProperty("foo", "bar 1", true); - - assertEquals(4, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(4, CollectionTools.size(persistenceUnit.properties())); - - // modify a property, test its value - persistenceUnit.replacePropertyValue("foo", "bar 2", "bar two"); - - Property property = persistenceUnit.getProperty("foo", "bar two"); - assertEquals("bar two", property.getValue()); - - // remove a property, test that there are four existing in xml and context - persistenceUnit.removeProperty("foo", "bar 1"); - assertEquals(3, xmlPersistenceUnit.getProperties().getProperties().size()); - assertEquals(3, CollectionTools.size(persistenceUnit.properties())); - } - - public void testAccessProperty() { - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add two properties and try to access it. - persistenceUnit.putProperty("foo", "bar", false); - persistenceUnit.putProperty("FOO", "BAR", false); - - Property property = persistenceUnit.getProperty("foo"); - assertNotNull(property); - assertEquals("bar", property.getValue()); - assertTrue(persistenceUnit.containsProperty("FOO")); - assertEquals("BAR", persistenceUnit.getProperty("FOO").getValue()); - assertNull(persistenceUnit.getProperty("notExist")); - } - - public void testUpdatePropertyName() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add property for testing - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperties.getProperties().add(xmlProperty); - Property property = persistenceUnit.properties().next(); - - // test that names are initially equal - assertEquals(xmlProperty.getName(), property.getName()); - - // set name to different name, test equality - xmlProperty.setName("newName"); - - assertEquals(xmlProperty.getName(), property.getName()); - - // set name to empty string, test equality - xmlProperty.setName(""); - - assertEquals(xmlProperty.getName(), property.getName()); - - // set name to null, test equality - xmlProperty.setName(null); - - assertEquals(xmlProperty.getName(), property.getName()); - - // set name back to non-null, test equality - xmlProperty.setName("newName"); - - assertEquals(xmlProperty.getName(), property.getName()); - } - - public void testUpdatePropertyValue() { - XmlPersistenceUnit xmlPersistenceUnit = xmlPersistenceUnit(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - // add property for testing - XmlProperties xmlProperties = PersistenceFactory.eINSTANCE.createXmlProperties(); - xmlPersistenceUnit.setProperties(xmlProperties); - XmlProperty xmlProperty = PersistenceFactory.eINSTANCE.createXmlProperty(); - xmlProperties.getProperties().add(xmlProperty); - Property property = persistenceUnit.properties().next(); - - // test that values are initially equal - assertEquals(xmlProperty.getValue(), property.getValue()); - - // set value to different value, test equality - xmlProperty.setValue("newValue"); - - assertEquals(xmlProperty.getValue(), property.getValue()); - - // set value to empty string, test equality - xmlProperty.setValue(""); - - assertEquals(xmlProperty.getValue(), property.getValue()); - - // set value to null, test equality - xmlProperty.setValue(null); - - assertEquals(xmlProperty.getValue(), property.getValue()); - - // set value back to non-null, test equality - xmlProperty.setValue("newValue"); - - assertEquals(xmlProperty.getValue(), property.getValue()); - } - - - public void testGetDefaultAccess() throws Exception { - createOrmXmlFile(); - PersistenceUnit persistenceUnit = persistenceUnit(); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, persistenceUnit.getDefaultAccess()); - - entityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, persistenceUnit.getDefaultAccess()); - } - - protected void createOrmXmlFile() throws Exception { - XmlMappingFileRef mappingFileRef = PersistenceFactory.eINSTANCE.createXmlMappingFileRef(); - mappingFileRef.setFileName(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); - xmlPersistenceUnit().getMappingFiles().add(mappingFileRef); - persistenceResource().save(null); - } - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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").append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithPersistentInnerClass() throws Exception { - createEntityAnnotation(); - - 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").append(CR); - } - - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append("@Entity").append(CR); - sb.append(" public static class " + INNER_CLASS_NAME + " {}").append(CR); - } - }); - } - - public void testPersistentType() throws Exception { - PersistenceUnit persistenceUnit = persistenceUnit(); - createTestEntity(); - - //persistentType not listed in persistence.xml and discoverAnnotatedClasses is false - //still find the persistentType because of changes for bug 190317 - assertFalse(jpaProject().discoversAnnotatedClasses()); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType not listed in persistence.xml, discover annotated classes set to true - jpaProject().setDiscoversAnnotatedClasses(true); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - //test persistentType list as class in persistence.xml - jpaProject().setDiscoversAnnotatedClasses(false); - XmlJavaClassRef classRef = PersistenceFactory.eINSTANCE.createXmlJavaClassRef(); - classRef.setJavaClass(FULLY_QUALIFIED_TYPE_NAME); - xmlPersistenceUnit().getClasses().add(classRef); - assertNotNull(persistenceUnit.getPersistentType(FULLY_QUALIFIED_TYPE_NAME)); - - - //test persistentType from orm.xml file that is specified in the persistence.xml - createOrmXmlFile(); - OrmPersistentType ormPersistentType = entityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, "model.Foo"); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - assertEquals(ormPersistentType, persistenceUnit.getPersistentType("model.Foo")); - - //test persistentType from orm.xml file that is implied(not specified) in the persistence.xml - xmlPersistenceUnit().getMappingFiles().remove(0); - assertNotNull(persistenceUnit.getPersistentType("model.Foo")); - } - -//TODO -// String getDefaultSchema(); -// String getDefaultCatalog(); -// AccessType getDefaultAccess(); -// boolean getDefaultCascadePersist(); - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java deleted file mode 100644 index 343f7f2ca6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/PersistenceXmlTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import org.eclipse.jpt.core.context.persistence.PersistenceXml; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class PersistenceXmlTests extends ContextModelTestCase -{ - public PersistenceXmlTests(String name) { - super(name); - } - - protected PersistenceXml persistenceXml() { - return rootContext().getPersistenceXml(); - } - - public void testUpdateAddPersistence() throws Exception { - PersistenceResource prm = persistenceResource(); - prm.getContents().clear(); - prm.save(null); - - assertNull(persistenceXml().getPersistence()); - - prm.getContents().add(PersistenceFactory.eINSTANCE.createXmlPersistence()); - - assertNotNull(persistenceXml().getPersistence()); - - } - - public void testModifyAddPersistence() { - PersistenceResource prm = persistenceResource(); - prm.getContents().remove(prm.getPersistence()); - assertNull(prm.getPersistence()); - - PersistenceXml persistenceXml = persistenceXml(); - - persistenceXml.addPersistence(); - - assertNotNull(persistenceXml.getPersistence()); - - boolean exceptionThrown = false; - try { - persistenceXml.addPersistence(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue(exceptionThrown); - } - - public void testUpdateRemovePersistence() throws Exception { - PersistenceResource prm = persistenceResource(); - - assertNotNull(persistenceXml().getPersistence()); - - prm.getContents().clear(); - - assertNull(persistenceXml().getPersistence()); - } - - public void testModifyRemovePersistence() { - PersistenceXml persistenceXml = persistenceXml(); - - assertNotNull(persistenceXml.getPersistence()); - - persistenceXml.removePersistence(); - - assertNull(persistenceXml.getPersistence()); - - boolean exceptionThrown = false; - try { - persistenceXml.removePersistence(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue(exceptionThrown); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextTests.java deleted file mode 100644 index 6e719084f2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/persistence/RootContextTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.persistence; - -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; - -public class RootContextTests extends ContextModelTestCase -{ - public RootContextTests(String name) { - super(name); - } - - public void testModifyAddPersistenceXml() throws Exception { - PersistenceResource pr = persistenceResource(); - deleteResource(pr); - - assertFalse(pr.exists()); - - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContext(); - assertNull(baseJpaContent.getPersistenceXml()); - - baseJpaContent.addPersistenceXml(); - - assertNotNull(baseJpaContent.getPersistenceXml()); - - boolean exceptionThrown = false; - try { - baseJpaContent.addPersistenceXml(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue(exceptionThrown); - } - - public void testModifyRemovePersistenceXml() throws Exception { - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContext(); - - assertNotNull(baseJpaContent.getPersistenceXml()); - - baseJpaContent.removePersistenceXml(); - waitForWorkspaceJobs(); - - assertNull(baseJpaContent.getPersistenceXml()); - - boolean exceptionThrown = false; - try { - baseJpaContent.removePersistenceXml(); - } - catch (IllegalStateException ise) { - exceptionThrown = true; - } - - assertTrue(exceptionThrown); - } - - public void testUpdateAddPersistenceXml() throws Exception { - PersistenceResource pr = persistenceResource(); - deleteResource(pr); - - assertFalse(pr.exists()); - - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContext(); - assertNull(baseJpaContent.getPersistenceXml()); - - pr.getContents().add(PersistenceFactory.eINSTANCE.createXmlPersistence()); - pr.save(null); - assertNotNull(baseJpaContent.getPersistenceXml()); - } - - public void testUpdateRemovePersistenceXml() throws Exception { - PersistenceResource pr = persistenceResource(); - JpaRootContextNode baseJpaContent = getJavaProject().getJpaProject().getRootContext(); - - assertNotNull(baseJpaContent.getPersistenceXml()); - - deleteResource(pr); - - assertNull(baseJpaContent.getPersistenceXml()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java deleted file mode 100644 index 556195eaf8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JpaModelTests.java +++ /dev/null @@ -1,227 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.model; - -import junit.framework.TestCase; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.GenericJpaModel; -import org.eclipse.jpt.core.internal.JpaModelManager; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestFacetedProject; -import org.eclipse.jpt.core.tests.internal.projects.TestPlatformProject; -import org.eclipse.jpt.utility.internal.ClassTools; - -public class JpaModelTests extends TestCase { - - /** carriage return */ - public static final String CR = System.getProperty("line.separator"); - - public JpaModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - if (this.debug()) { - this.printName(); - } - ProjectUtility.deleteAllProjects(); - } - - private boolean debug() { - Boolean debug = (Boolean) ClassTools.staticFieldValue(JpaModelManager.class, "DEBUG"); - return debug.booleanValue(); - } - - private void printName() { - String name = this.getName(); - System.out.println(); - System.out.println(); - this.printNameBorder(name); - System.out.println(name); - this.printNameBorder(name); - } - - private void printNameBorder(String name) { - for (int i = name.length(); i-- > 0; ) { - System.out.print('='); - } - System.out.println(); - } - - @Override - protected void tearDown() throws Exception { - ProjectUtility.deleteAllProjects(); - super.tearDown(); - } - - /** - * Builds a project with the java and utility facets installed, and with - * pre-existing entities added. - */ - private TestFacetedProject buildTestProject() throws Exception { - TestFacetedProject testProject = TestFacetedProject.buildFacetedProject(ClassTools.shortClassNameForObject(this), true); - testProject.installFacet("jst.java", "5.0"); - testProject.installFacet("jst.utility", "1.0"); - testProject.createFile( - new Path("src/test.pkg/TestEntity.java"), - "package test.pkg; @Entity public class TestEntity {}"); - testProject.createFile( - new Path("src/test.pkg/TestEntity2.java"), - "package test.pkg; @Entity public class TestEntity2 {}"); - return testProject; - } - - private IFile file(TestPlatformProject p, String path) { - return p.getProject().getFile(new Path(path)); - } - - public void testJpaModel() { - assertNotNull(JptCorePlugin.getJpaModel()); - } - - public void testFacetInstallUninstall() throws Exception { - TestFacetedProject testProject = this.buildTestProject(); - assertNull(JptCorePlugin.getJpaProject(testProject.getProject())); - - testProject.installFacet("jpt.jpa", "1.0"); - assertEquals(1, JptCorePlugin.getJpaModel().jpaProjectsSize()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNotNull(jpaProject); -// assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity2.java"))); - // persistence.xml and orm.xml are created in the background, so they probably - // won't be there yet... -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/persistence.xml"))); -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/orm.xml"))); - - testProject.uninstallFacet("jpt.jpa", "1.0"); - assertEquals(0, JptCorePlugin.getJpaModel().jpaProjectsSize()); - jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNull(jpaProject); - } - - public void testProjectCloseReopen() throws Exception { - TestFacetedProject testProject = this.buildTestProject(); - testProject.installFacet("jpt.jpa", "1.0"); - - testProject.getProject().close(null); - assertFalse(testProject.getProject().isOpen()); - JpaProject jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNull(jpaProject); - - testProject.getProject().open(null); - jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNotNull(jpaProject); -// assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity2.java"))); - // persistence.xml and orm.xml are created in the background, so they probably - // won't be there yet... -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/persistence.xml"))); -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/orm.xml"))); - } - - public void testProjectDeleteReimport() throws Exception { - TestFacetedProject testProject = this.buildTestProject(); - testProject.installFacet("jpt.jpa", "1.0"); - JpaProject jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNotNull(jpaProject); - assertEquals(1, JptCorePlugin.getJpaModel().jpaProjectsSize()); - - testProject.getProject().delete(false, true, null); - jpaProject = JptCorePlugin.getJpaProject(testProject.getProject()); - assertNull(jpaProject); - assertEquals(0, JptCorePlugin.getJpaModel().jpaProjectsSize()); - assertEquals(0, ResourcesPlugin.getWorkspace().getRoot().getProjects().length); - - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testProject.getProject().getName()); - project.create(null); - assertEquals(1, ResourcesPlugin.getWorkspace().getRoot().getProjects().length); - project.open(null); - - assertTrue(project.isOpen()); - assertTrue(JptCorePlugin.projectHasJpaFacet(project)); - jpaProject = JptCorePlugin.getJpaProject(project); - assertNotNull(jpaProject); -// assertEquals(4, jpaProject.jpaFilesSize()); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity.java"))); - assertNotNull(jpaProject.getJpaFile(this.file(testProject, "src/test.pkg/TestEntity2.java"))); - // persistence.xml and orm.xml are created in the background, so they probably - // won't be there yet... -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/persistence.xml"))); -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/orm.xml"))); - } - - //TODO - Commented out this test, since it was failing in the I-Build and we're not sure why. - //See bug 221757 -// public void testEditFacetSettingsFile() throws Exception { -// TestFacetedProject testProject = this.buildTestProject(); -// assertNull(JptCorePlugin.jpaProject(testProject.getProject())); -// -// // add the JPA facet by modifying the facet settings file directly -// IFile facetSettingsFile = this.file(testProject, ".settings/org.eclipse.wst.common.project.facet.core.xml"); -// InputStream inStream = new BufferedInputStream(facetSettingsFile.getContents()); -// int fileSize = inStream.available(); -// byte[] buf = new byte[fileSize]; -// inStream.read(buf); -// inStream.close(); -// -// String oldDocument = new String(buf); -// String oldString = "<installed facet=\"jst.utility\" version=\"1.0\"/>"; -// String newString = oldString + CR + " " + "<installed facet=\"jpt.jpa\" version=\"1.0\"/>"; -// String newDocument = oldDocument.replaceAll(oldString, newString); -// -// facetSettingsFile.setContents(new ByteArrayInputStream(newDocument.getBytes()), false, false, null); -// -// assertEquals(1, JptCorePlugin.jpaModel().jpaProjectsSize()); -// JpaProject jpaProject = JptCorePlugin.jpaProject(testProject.getProject()); -// assertNotNull(jpaProject); -// // persistence.xml and orm.xml do not get created in this situation (?) -// assertEquals(2, jpaProject.jpaFilesSize()); -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/test.pkg/TestEntity.java"))); -// assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/test.pkg/TestEntity2.java"))); -// // assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/persistence.xml"))); -// // assertNotNull(jpaProject.jpaFile(this.file(testProject, "src/META-INF/orm.xml"))); -// -// // now remove the JPA facet -// facetSettingsFile.setContents(new ByteArrayInputStream(oldDocument.getBytes()), false, false, null); -//// TODO moved this stuff to the error console until we can figure out why it fails intermittently ~bjv -//// assertEquals(0, JptCorePlugin.jpaModel().jpaProjectsSize()); -//// jpaProject = JptCorePlugin.jpaProject(testProject.getProject()); -//// assertNull(jpaProject); -// int size = JptCorePlugin.jpaModel().jpaProjectsSize(); -// if (size != 0) { -// System.err.println("bogus size: " + size); -// System.err.println("bogus project: " + JptCorePlugin.jpaProject(testProject.getProject())); -// } -// } - - /** - * make sure the DEBUG constants are 'false' before checking in the code - */ - public void testDEBUG() { - this.verifyDEBUG(JpaModelManager.class); - this.verifyDEBUG(GenericJpaModel.class); - } - - private void verifyDEBUG(Class<?> clazz) { - assertFalse("Recompile with \"DEBUG = false\": " + clazz.getName(), - ((Boolean) ClassTools.staticFieldValue(clazz, "DEBUG")).booleanValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java deleted file mode 100644 index 59be1a1135..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/model/JptCoreModelTests.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.model; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptCoreModelTests { - - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreModelTests.class.getPackage().getName()); - suite.addTestSuite(JpaModelTests.class); - return suite; - } - - private JptCoreModelTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java deleted file mode 100644 index e8a0ee9a99..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/BaseJpaPlatformTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -public class BaseJpaPlatformTests extends TestCase -{ - protected TestJpaProject jpaProject; - - protected static final String PROJECT_NAME = "PlatformTestProject"; - protected static final String PACKAGE_NAME = "platform.test"; - protected static final String PERSISTENCE_XML_LOCATION = "src/META-INF/persistence.xml"; - protected static final String ORM_XML_LOCATION = "src/META-INF/orm.xml"; - - - public BaseJpaPlatformTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - ProjectUtility.deleteAllProjects(); - jpaProject = this.buildJpaProject(PROJECT_NAME, false); // false = no auto-build - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJpaProject(projectName, autoBuild); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - ProjectUtility.deleteAllProjects(); - jpaProject = null; - super.tearDown(); - } - -// public void testPersistentTypes() throws CoreException, IOException { -// IFile persistenceXmlIFile = jpaProject.getProject().getFile(PERSISTENCE_XML_LOCATION); -// IJpaFile persistenceXmlJpaFile = jpaProject.getJpaProject().getJpaFile(persistenceXmlIFile); -// PersistenceXmlRootContentNode persistenceRoot = (PersistenceXmlRootContentNode) persistenceXmlJpaFile.getContent(); -// XmlPersistence persistence = persistenceRoot.getPersistence(); -// -// IFile ormXmlIFile = jpaProject.getProject().getFile(ORM_XML_LOCATION); -// IJpaFile ormXmlJpaFile = jpaProject.getJpaProject().getJpaFile(ormXmlIFile); -// XmlRootContentNode ormRoot = (XmlRootContentNode) ormXmlJpaFile.getContent(); -// EntityMappingsInternal entityMappings = ormRoot.getEntityMappings(); -// -// // add xml persistent type -// XmlEntityInternal xmlEntity = OrmFactory.eINSTANCE.createXmlEntityInternal(); -// xmlEntity.setSpecifiedName("XmlEntity"); -// entityMappings.getTypeMappings().add(xmlEntity); -// entityMappings.eResource().save(null); -// assertEquals(1, CollectionTools.size(jpaProject.getJpaProject().getPlatform().persistentTypes(PROJECT_NAME))); -// -// // add java persistent type -// jpaProject.createType(PACKAGE_NAME, "JavaEntity.java", -// "@Entity public class JavaEntity {}" -// ); -// XmlJavaClassRef javaClassRef = PersistenceFactory.eINSTANCE.createJavaClassRef(); -// javaClassRef.setJavaClass(PACKAGE_NAME + ".JavaEntity"); -// persistence.getPersistenceUnits().get(0).getClasses().add(javaClassRef); -// persistence.eResource().save(null); -// -// assertEquals(2, CollectionTools.size(jpaProject.getJpaProject().getPlatform().persistentTypes(PROJECT_NAME))); -// } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java deleted file mode 100644 index 6e6ea5cc26..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformExtensionTests.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - -import junit.framework.TestCase; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatform; -import org.eclipse.jpt.utility.internal.CollectionTools; - -public class JpaPlatformExtensionTests extends TestCase -{ - public static final String TEST_PLATFORM_ID = TestJpaPlatform.ID; - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - - public JpaPlatformExtensionTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - verifyExtensionTestProjectExists(); - } - - public static void verifyExtensionTestProjectExists() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint extensionPoint = - registry.getExtensionPoint(JptCorePlugin.PLUGIN_ID, "jpaPlatform"); - IExtension[] extensions = extensionPoint.getExtensions(); - boolean extensionFound = false; - for (IExtension extension : extensions) { - if (extension.getContributor().getName().equals(ExtensionTestPlugin.PLUGIN_ID)) { - extensionFound = true; - } - } - if (!extensionFound) { - throw new RuntimeException("Missing Extension " + TEST_PLATFORM_ID + ". The ExtensionTestProject plugin must be in your testing workspace."); - } - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testAllJpaPlatformIds() { - assertTrue(CollectionTools.size(JpaPlatformRegistry.instance().jpaPlatformIds()) >= 2); - } - - public void testJpaPlatformLabel() { - assertEquals(TEST_PLATFORM_LABEL, JpaPlatformRegistry.instance().getJpaPlatformLabel(TEST_PLATFORM_ID)); - } - - public void testJpaPlatform() { - assertNotNull(JpaPlatformRegistry.instance().getJpaPlatform(TEST_PLATFORM_ID)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java deleted file mode 100644 index de87fb36aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/platform/JpaPlatformTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.platform; - - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JpaPlatform; -import org.eclipse.jpt.core.MappingKeys; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestAttributeMapping; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestAttributeMappingProvider; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestTypeMapping; -import org.eclipse.jpt.core.tests.extension.resource.JavaTestTypeMappingProvider; -import org.eclipse.jpt.core.tests.extension.resource.TestJavaBasicMapping; -import org.eclipse.jpt.core.tests.extension.resource.TestJavaEntity; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaFactory; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatform; -import org.eclipse.jpt.core.tests.internal.context.ContextModelTestCase; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IActionConfigFactory; - -public class JpaPlatformTests extends ContextModelTestCase -{ - protected TestJpaProject testProject; - - protected static final String PROJECT_NAME = "ExtensionTestProject"; - protected static final String PACKAGE_NAME = "extension.test"; - - public static final String TEST_PLUGIN_CLASS = ExtensionTestPlugin.class.getName(); - public static final String TEST_PLUGIN_ID = "org.eclipse.jpt.core.tests.extension.resource"; - - public static final String TEST_PLATFORM_CLASS_NAME = TestJpaPlatform.class.getName(); - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - public static final String TEST_JPA_FACTORY = TestJpaFactory.class.getName(); - public static final String TEST_TYPE_MAPPING_PROVIDER_CLASS = JavaTestTypeMappingProvider.class.getName(); - public static final String TEST_ATTRIBUTE_MAPPING_PROVIDER_CLASS = JavaTestAttributeMappingProvider.class.getName(); - - public JpaPlatformTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - JpaPlatformExtensionTests.verifyExtensionTestProjectExists(); - } - - @Override - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return super.buildJpaProject(PROJECT_NAME, autoBuild, this.buildConfig()); - } - - protected IDataModel buildConfig() throws Exception { - IActionConfigFactory configFactory = new JpaFacetDataModelProvider(); - IDataModel config = (IDataModel) configFactory.create(); - config.setProperty(JpaFacetDataModelProperties.PLATFORM_ID, TestJpaPlatform.ID); - return config; - } - - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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").append(CR); - } - }); - } - - - protected JpaPlatform jpaPlatform() { - return this.jpaProject().getJpaPlatform(); - } - - public void testJpaFactory() { - assertTrue(jpaPlatform().getJpaFactory().getClass().getName().equals(TEST_JPA_FACTORY)); - } - - public void testBuildJavaTypeMappingFromMappingKey() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaTypeMapping javaTypeMapping = jpaProject().getJpaPlatform().buildJavaTypeMappingFromMappingKey(JavaTestTypeMapping.TEST_TYPE_MAPPING_KEY, javaPersistentType()); - assertTrue(javaTypeMapping instanceof JavaTestTypeMapping); - - javaTypeMapping = jpaPlatform().buildJavaTypeMappingFromMappingKey(MappingKeys.ENTITY_TYPE_MAPPING_KEY, javaPersistentType()); - assertTrue(javaTypeMapping instanceof TestJavaEntity); - } - - public void testBuildJavaAttributeMappingFromMappingKey() throws Exception { - createTestEntity(); - addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); - - JavaAttributeMapping javaAttributeMapping = jpaProject().getJpaPlatform().buildJavaAttributeMappingFromMappingKey(JavaTestAttributeMapping.TEST_ATTRIBUTE_MAPPING_KEY, javaPersistentType().getAttributeNamed("name")); - assertTrue(javaAttributeMapping instanceof JavaTestAttributeMapping); - - javaAttributeMapping = jpaPlatform().buildJavaAttributeMappingFromMappingKey(MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY, javaPersistentType().getAttributeNamed("name")); - assertTrue(javaAttributeMapping instanceof TestJavaBasicMapping); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestFacetedProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestFacetedProject.java deleted file mode 100644 index 4517f2b67a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestFacetedProject.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 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.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -/** - * This builds and holds a "faceted" project. - * Support for installing facets. - */ -public class TestFacetedProject extends TestPlatformProject { - private final IFacetedProject facetedProject; - - - // ********** builders ***************************** - - public static TestFacetedProject buildFacetedProject(String baseProjectName, boolean autoBuild) - throws CoreException { - return new TestFacetedProject(uniqueProjectName(baseProjectName), autoBuild); - } - - - // ********** constructors/initialization ********** - - public TestFacetedProject(String projectName) throws CoreException { - this(projectName, true); - } - - public TestFacetedProject(String projectName, boolean autoBuild) throws CoreException { - super(projectName, autoBuild); - this.facetedProject = this.createFacetedProject(); - } - - private IFacetedProject createFacetedProject() throws CoreException { - return ProjectFacetsManager.create(this.getProject(), true, null); // true = "convert if necessary" - } - - - // ********** public methods ********** - - public IFacetedProject getFacetedProject() { - return this.facetedProject; - } - - public void installFacet(String facetName, String versionName) throws CoreException { - this.installFacet(facetName, versionName, null); - } - - public void uninstallFacet(String facetName, String versionName) throws CoreException { - this.uninstallFacet(facetName, versionName, null); - } - - /** - * if 'config' is null, the JPA project will be built with the defaults - * defined in JpaFacetDataModelProvider#getDefaultProperty(String) - */ - public void installFacet(String facetName, String versionName, IDataModel config) throws CoreException { - this.facetedProject.installProjectFacet(this.facetVersion(facetName, versionName), config, null); - } - - public void uninstallFacet(String facetName, String versionName, IDataModel config) throws CoreException { - this.facetedProject.uninstallProjectFacet(this.facetVersion(facetName, versionName), config, null); - } - - private IProjectFacetVersion facetVersion(String facetName, String versionName) { - return ProjectFacetsManager.getProjectFacet(facetName).getVersion(versionName); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java deleted file mode 100644 index d9f77d393d..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * This builds and holds a "Java" project. - * Support for adding packages and types. - * - * "Java" projects aren't required to be "faceted" projects, but for JPA - * testing they are. - */ -public class TestJavaProject extends TestFacetedProject { - private final IJavaProject javaProject; - private final IPackageFragmentRoot sourceFolder; - - - // ********** builders ***************************** - - public static TestJavaProject buildJavaProject(String baseProjectName, boolean autoBuild) - throws CoreException { - return new TestJavaProject(uniqueProjectName(baseProjectName), autoBuild); - } - - - // ********** constructors/initialization ********** - - public TestJavaProject(String projectName) throws CoreException { - this(projectName, false); - } - - public TestJavaProject(String projectName, boolean autoBuild) throws CoreException { - super(projectName, autoBuild); - this.installFacet("jst.java", "5.0"); - this.javaProject = JavaCore.create(this.getProject()); - this.sourceFolder = this.javaProject.getPackageFragmentRoot(this.getProject().getFolder("src")); - } - - protected void addJar(String jarPath) throws JavaModelException { - this.addClasspathEntry(JavaCore.newLibraryEntry(new Path(jarPath), null, null)); - } - - private void addClasspathEntry(IClasspathEntry entry) throws JavaModelException { - this.javaProject.setRawClasspath(CollectionTools.add(this.javaProject.getRawClasspath(), entry), null); - } - - - // ********** public methods ********** - - public IPackageFragment createPackage(String packageName) throws CoreException { - return this.sourceFolder.createPackageFragment(packageName, false, null); // false = "no force" - } - - /** - * The source should NOT contain a package declaration; - * it will be added here. - */ - public ICompilationUnit createCompilationUnit(String packageName, String compilationUnitName, String source) throws CoreException { - return this.createCompilationUnit(this.createPackage(packageName), compilationUnitName, new SimpleSourceWriter(source)); - } - - /** - * The source should NOT contain a package declaration; - * it will be added here. - */ - public ICompilationUnit createCompilationUnit(String packageName, String compilationUnitName, SourceWriter sourceWriter) throws CoreException { - return this.createCompilationUnit(this.createPackage(packageName), compilationUnitName, sourceWriter); - } - - /** - * The source should NOT contain a package declaration; - * it will be added here. - */ - public ICompilationUnit createCompilationUnit(IPackageFragment packageFragment, String compilationUnitName, SourceWriter sourceWriter) throws CoreException { - StringBuilder sb = new StringBuilder(2000); - sb.append("package ").append(packageFragment.getElementName()).append(";").append(CR); - sb.append(CR); - sourceWriter.appendSourceTo(sb); - String source = sb.toString(); - return packageFragment.createCompilationUnit(compilationUnitName, source, false, null); // false = "no force" - } - - - // ********** member classes ********** - - public interface SourceWriter { - void appendSourceTo(StringBuilder sb); - } - - public class SimpleSourceWriter implements SourceWriter { - private final String source; - public SimpleSourceWriter(String source) { - super(); - this.source = source; - } - public void appendSourceTo(StringBuilder sb) { - sb.append(source); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java deleted file mode 100644 index d9622a4101..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJpaProject.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.projects; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.SynchronousJpaProjectUpdater; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * This builds and holds a "JPA" project. - * Support for adding packages and types. - * - * The JPA project's settings (platform, database connection, etc.) can be - * controlled by building a data model and passing it into the constructor. - */ -public class TestJpaProject extends TestJavaProject { - private final JpaProject jpaProject; - - public static final String JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.jpa.jar"; - - - // ********** builders ********** - - public static TestJpaProject buildJpaProject(String baseProjectName, boolean autoBuild, IDataModel jpaConfig) - throws CoreException { - return new TestJpaProject(uniqueProjectName(baseProjectName), autoBuild, jpaConfig); - } - - public static TestJpaProject buildJpaProject(String baseProjectName, boolean autoBuild) - throws CoreException { - return buildJpaProject(baseProjectName, autoBuild, null); - } - - // ********** constructors/initialization ********** - - public TestJpaProject(String projectName) throws CoreException { - this(projectName, false); - } - - public TestJpaProject(String projectName, boolean autoBuild) throws CoreException { - this(projectName, autoBuild, null); - } - - public TestJpaProject(String projectName, boolean autoBuild, IDataModel jpaConfig) throws CoreException { - super(projectName, autoBuild); - this.installFacet("jst.utility", "1.0"); - this.installFacet("jpt.jpa", "1.0", jpaConfig); - this.addJar(this.jarName()); - this.jpaProject = JptCorePlugin.getJpaProject(this.getProject()); - this.jpaProject.setUpdater(new SynchronousJpaProjectUpdater(this.jpaProject)); - } - - protected String jarName() { - String jarName = System.getProperty(JAR_NAME_SYSTEM_PROPERTY); - if (jarName == null) { - throw new RuntimeException("missing Java system property: \"" + JAR_NAME_SYSTEM_PROPERTY + "\""); - } - return jarName; - } - - - // ********** public methods ********** - - public JpaProject getJpaProject() { - return this.jpaProject; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestPlatformProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestPlatformProject.java deleted file mode 100644 index 8f6f562a62..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestPlatformProject.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.projects; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceDescription; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jpt.utility.internal.CollectionTools; - -/** - * This builds and holds a "general" Eclipse project. - * Support for adding natures, folders, and files. - */ -public class TestPlatformProject { - private final IProject project; - - /** carriage return */ - public static final String CR = System.getProperty("line.separator"); - - - // ********** builders ********** - - public static TestPlatformProject buildPlatformProject(String baseProjectName, boolean autoBuild) - throws CoreException { - return new TestPlatformProject(uniqueProjectName(baseProjectName), autoBuild); - } - - public static String uniqueProjectName(String baseProjectName) { - return baseProjectName + String.valueOf(System.currentTimeMillis()).substring(7); - } - - - // ********** constructors/initialization ********** - - public TestPlatformProject(String projectName, boolean autoBuild) throws CoreException { - super(); - this.setAutoBuild(autoBuild); // workspace-wide setting - this.project = this.buildPlatformProject(projectName); - } - - private void setAutoBuild(boolean autoBuild) throws CoreException { - IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription(); - description.setAutoBuilding(autoBuild); - ResourcesPlugin.getWorkspace().setDescription(description); - } - - private IProject buildPlatformProject(String projectName) throws CoreException { - IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - p.create(null); - p.open(null); - return p; - } - - - // ********** public methods ********** - - public IProject getProject() { - return this.project; - } - - public void addProjectNature(String natureID) throws CoreException { - IProjectDescription description = this.project.getDescription(); - description.setNatureIds(CollectionTools.add(description.getNatureIds(), natureID)); - this.project.setDescription(description, null); - } - - public void removeProjectNature(String natureID) throws CoreException { - IProjectDescription description = this.project.getDescription(); - description.setNatureIds(CollectionTools.removeAllOccurrences(description.getNatureIds(), natureID)); - this.project.setDescription(description, null); - } - - /** - * Create a folder with the specified name directly under the project. - */ - public IFolder createFolder(String folderName) throws CoreException { - return this.createFolder(this.project, new Path(folderName)); - } - - /** - * Create a folder in the specified container with the specified name. - */ - public IFolder createFolder(IContainer container, String folderName) throws CoreException { - return this.createFolder(container, new Path(folderName)); - } - - /** - * Create a folder in the specified container with the specified path. - */ - public IFolder createFolder(IContainer container, IPath folderPath) throws CoreException { - IFolder folder = container.getFolder(folderPath); - if ( ! folder.exists()) { - folder.create(false, true, null); // false = "no force"; true = "local" - } - return folder; - } - - /** - * Create a file with the specified name and content directly under the project. - */ - public IFile createFile(String fileName, String content) throws CoreException { - return this.createFile(this.project, fileName, content); - } - - /** - * Create a file in the specified container with the specified name and content. - */ - public IFile createFile(IContainer container, String fileName, String content) throws CoreException { - return createFile(container, new Path(fileName), content); - } - - /** - * Create a file in the project with the specified [relative] path - * and content. - */ - public IFile createFile(IPath filePath, String content) throws CoreException { - return this.createFile(this.project, filePath, content); - } - - /** - * Create a file in the specified container with the specified path and content. - */ - public IFile createFile(IContainer container, IPath filePath, String content) throws CoreException { - return this.createFile(container, filePath, new ByteArrayInputStream(content.getBytes())); - } - - /** - * Create a file in the specified container with the specified path and contents. - */ - public IFile createFile(IContainer container, IPath filePath, InputStream content) throws CoreException { - int pathCount = filePath.segmentCount() - 1; - for (int i = 0; i < pathCount; i++) { - container = container.getFolder(new Path(filePath.segment(i))); - if ( ! container.exists()) { - ((IFolder) container).create(true, true, null); // true = "force"; true = "local" - } - } - - IFile file = container.getFile(new Path(filePath.lastSegment())); - if (file.exists()) { - file.delete(true, null); // true = "force" - } - file.create(content, true, null); // true = "force" - return file; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java deleted file mode 100644 index ccc705abd2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/JptCoreResourceModelTests.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.resource; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import org.eclipse.jpt.core.tests.internal.resource.java.JptJavaResourceTests; - -public class JptCoreResourceModelTests extends TestCase -{ - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreResourceModelTests.class.getName()); - suite.addTest(JptJavaResourceTests.suite(all)); - if (all) { - suite.addTestSuite(OrmModelTests.class); - suite.addTestSuite(PersistenceModelTests.class); - } - return suite; - } - - private JptCoreResourceModelTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/OrmModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/OrmModelTests.java deleted file mode 100644 index ae285fe380..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/OrmModelTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit; -import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -public class OrmModelTests extends TestCase -{ - static final String BASE_PROJECT_NAME = OrmModelTests.class.getSimpleName(); - - TestJpaProject jpaProject; - - - public OrmModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - ProjectUtility.deleteAllProjects(); - jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - jpaProject = null; - super.tearDown(); - } - - public void testModelLoad() { - OrmArtifactEdit artifactEdit = OrmArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - assertNotNull(artifactEdit); - OrmResource resource = artifactEdit.getResource("META-INF/orm.xml"); - assertNotNull(resource); - } - - public void testModelLoad2() { - OrmArtifactEdit artifactEdit = OrmArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - assertNotNull(artifactEdit); - OrmResource resource = artifactEdit.getResource("META-INF/orm.xml"); - assertNotNull(resource); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/PersistenceModelTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/PersistenceModelTests.java deleted file mode 100644 index 803de6cd5a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/PersistenceModelTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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 - *******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.resource.persistence.PersistenceArtifactEdit; -import org.eclipse.jpt.core.resource.persistence.PersistenceResource; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -public class PersistenceModelTests extends TestCase -{ - static final String BASE_PROJECT_NAME = PersistenceModelTests.class.getSimpleName(); - - TestJpaProject jpaProject; - - - public PersistenceModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - ProjectUtility.deleteAllProjects(); - jpaProject = TestJpaProject.buildJpaProject(BASE_PROJECT_NAME, false); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - jpaProject = null; - super.tearDown(); - } - - public void testModelLoad() { - PersistenceArtifactEdit artifactEdit = PersistenceArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - assertNotNull(artifactEdit); - PersistenceResource resource = artifactEdit.getResource("META-INF/persistence.xml"); - assertNotNull(resource); - } - - public void testModelLoad2() { - PersistenceArtifactEdit artifactEdit = PersistenceArtifactEdit.getArtifactEditForRead(jpaProject.getProject()); - assertNotNull(artifactEdit); - PersistenceResource resource = artifactEdit.getResource("META-INF/persistence.xml"); - assertNotNull(resource); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java deleted file mode 100644 index eb2ee78333..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverrideTests.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -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.utility.internal.iterators.ArrayIterator; - -public class AssociationOverrideTests extends JavaResourceModelTestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - - public AssociationOverrideTests(String name) { - super(name); - } - - private void createAssociationOverrideAnnotation() throws Exception { - createJoinColumnAnnotation(); - this.createAnnotationAndMembers("AssociationOverride", - "String name(); " + - "JoinColumn[] joinColumns(); "); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - createAssociationOverrideAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ASSOCIATION_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - createAssociationOverrideAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverride(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - } - - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertNull(associationOverride.joinColumnAt(2).getName()); - - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name=\"BAR\"),@JoinColumn(name=\"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator<JoinColumnAnnotation> joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn})", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns=@JoinColumn)", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@AssociationOverride", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name=\"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn, @JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"foo\"), @JoinColumn})", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java deleted file mode 100644 index 2703566784..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AssociationOverridesTests.java +++ /dev/null @@ -1,345 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.AssociationOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AssociationOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class AssociationOverridesTests extends JavaResourceModelTestCase { - - private static final String ASSOCIATION_OVERRIDE_NAME = "MY_ASSOCIATION_OVERRIDE"; - - public AssociationOverridesTests(String name) { - super(name); - } - - private void createAssociationOverrideAnnotation() throws Exception { - createJoinColumnAnnotation(); - this.createAnnotationAndMembers("AssociationOverride", - "String name(); " + - "Column column(); "); - } - - private void createAssociationOverridesAnnotation() throws Exception { - createAssociationOverrideAnnotation(); - this.createAnnotationAndMembers("AssociationOverrides", - "AssociationOverride[] value();"); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - - } - - private ICompilationUnit createTestAssociationOverrideOnField() throws Exception { - createAssociationOverridesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\"))"); - } - }); - } - private ICompilationUnit createTestAssociationOverrideWithJoinColumns() throws Exception { - createAssociationOverridesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn}))"); - } - }); - } - - private ICompilationUnit createTestAssociationOverride() throws Exception { - createAssociationOverridesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ASSOCIATION_OVERRIDE, JPA.JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@AssociationOverride(name=\"FOO\", joinColumns=@JoinColumn(name=\"FOO\", columnDefinition=\"BAR\", referencedColumnName=\"BAZ\"))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.nestedAnnotations().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.nestedAnnotations().next(); - - assertNotNull(associationOverride); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName("Foo"); - assertEquals("Foo", associationOverride.getName()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AssociationOverridesAnnotation associationOverrides = (AssociationOverridesAnnotation) attributeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES); - AssociationOverrideAnnotation associationOverride = associationOverrides.nestedAnnotations().next(); - assertEquals(ASSOCIATION_OVERRIDE_NAME, associationOverride.getName()); - - associationOverride.setName(null); - assertNull(associationOverride.getName()); - - assertSourceDoesNotContain("@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AssociationOverride", cu); - assertSourceContains("@AssociationOverrides", cu); - } - - public void testAddAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name=\"FOO\", joinColumns = @JoinColumn(name=\"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testAddAssociationOverrideToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name=\"FOO\", joinColumns = @JoinColumn(name=\"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name=\"BAR\")})", cu); - - associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(0, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAZ"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name=\"BAZ\"),@AssociationOverride(name=\"FOO\", joinColumns = @JoinColumn(name=\"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")), @AssociationOverride(name=\"BAR\")})", cu); - - Iterator<JavaResourceNode> associationOverrides = typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertEquals("BAZ", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("FOO", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - assertEquals("BAR", ((AssociationOverrideAnnotation) associationOverrides.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ASSOCIATION_OVERRIDES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES))); - } - - public void testRemoveAssociationOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAssociationOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) typeResource.addAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - associationOverride.setName("BAR"); - assertSourceContains("@AssociationOverrides({@AssociationOverride(name=\"FOO\", joinColumns = @JoinColumn(name=\"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\")),@AssociationOverride(name=\"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES); - assertSourceContains("@AssociationOverride(name=\"FOO\", joinColumns = @JoinColumn(name=\"FOO\", columnDefinition = \"BAR\", referencedColumnName = \"BAZ\"))", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(0, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0); - associationOverride.addJoinColumn(1); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - associationOverride.addJoinColumn(0).setName("FOO"); - associationOverride.addJoinColumn(1); - associationOverride.addJoinColumn(0).setName("BAR"); - - - Iterator<JoinColumnAnnotation> joinColumns = associationOverride.joinColumns(); - assertEquals("BAR", joinColumns.next().getName()); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns = {@JoinColumn(name=\"BAR\"),@JoinColumn(name=\"FOO\"), @JoinColumn}))", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - associationOverride.addJoinColumn(0).setName("FOO"); - - Iterator<JoinColumnAnnotation> joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertEquals("BAR", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(1); - joinColumns = associationOverride.joinColumns(); - assertEquals("FOO", joinColumns.next().getName()); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn}))", cu); - - associationOverride.removeJoinColumn(0); - joinColumns = associationOverride.joinColumns(); - assertNull(joinColumns.next().getName()); - assertEquals(false, joinColumns.hasNext()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns=@JoinColumn))", cu); - - - associationOverride.setName(null); - associationOverride.removeJoinColumn(0); - assertSourceDoesNotContain("@AssociationOverride", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - - associationOverride.moveJoinColumn(2, 0); - assertEquals("BAR", associationOverride.joinColumnAt(0).getName()); - assertNull(associationOverride.joinColumnAt(1).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name=\"FOO\")}))", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - associationOverride.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn}))", cu); - associationOverride.moveJoinColumn(0, 2); - assertNull(associationOverride.joinColumnAt(0).getName()); - assertEquals("FOO", associationOverride.joinColumnAt(1).getName()); - assertEquals("BAR", associationOverride.joinColumnAt(2).getName()); - assertEquals(3, associationOverride.joinColumnsSize()); - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn, @JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")}))", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestAssociationOverrideWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AssociationOverrideAnnotation associationOverride = (AssociationOverrideAnnotation) attributeResource.annotations(JPA.ASSOCIATION_OVERRIDE, JPA.ASSOCIATION_OVERRIDES).next(); - - assertEquals(2, associationOverride.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = associationOverride.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@AssociationOverrides(@AssociationOverride(name=\"" + ASSOCIATION_OVERRIDE_NAME + "\", joinColumns={@JoinColumn(name=\"foo\"), @JoinColumn}))", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java deleted file mode 100644 index e09c06b77f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverrideTests.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class AttributeOverrideTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE"; - - public AttributeOverrideTests(String name) { - super(name); - } - - private void createAttributeOverrideAnnotation() throws Exception { - this.createAnnotationAndMembers("AttributeOverride", - "String name(); " + - "Column column(); "); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; " + - "int length() default 255; " + - "int precision() default 0; " + - "int scale() default 0;"); - } - - private ICompilationUnit createTestAttributeOverrideOnField() throws Exception { - createAttributeOverrideAnnotation(); - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestAttributeOverrideWithColumnOnField() throws Exception { - createAttributeOverrideAnnotation(); - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ATTRIBUTE_OVERRIDE, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name=\"" + COLUMN_NAME + "\"))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - } - - public void testGetNullColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNotNull(attributeOverride); - assertNull(column); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName("Foo"); - assertEquals("Foo", attributeOverride.getName()); - assertSourceContains("@AttributeOverride(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName(null); - assertNull(attributeOverride.getName()); - - assertSourceDoesNotContain("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AttributeOverride", cu); - } - - public void testColumnGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testColumnSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - - column.setName("Foo"); - - assertSourceContains("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name=\"Foo\"))", cu); - - column.setName(null); - assertNull(attributeOverride.getColumn()); - assertSourceContains("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - } - - public void testAddColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNull(column); - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNull(column); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java deleted file mode 100644 index 1712d914ba..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/AttributeOverridesTests.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.AttributeOverridesAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class AttributeOverridesTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String ATTRIBUTE_OVERRIDE_NAME = "MY_ATTRIBUTE_OVERRIDE"; - - public AttributeOverridesTests(String name) { - super(name); - } - - private void createAttributeOverrideAnnotation() throws Exception { - createColumnAnnotation(); - this.createAnnotationAndMembers("AttributeOverride", - "String name(); " + - "Column column(); "); - } - - private void createAttributeOverridesAnnotation() throws Exception { - createAttributeOverrideAnnotation(); - this.createAnnotationAndMembers("AttributeOverrides", - "AttributeOverride[] value();"); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; " + - "int length() default 255; " + - "int precision() default 0; " + - "int scale() default 0;"); - } - - private ICompilationUnit createTestAttributeOverrideOnField() throws Exception { - createAttributeOverridesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverrides(@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestAttributeOverrideWithColumnOnField() throws Exception { - createAttributeOverridesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES, JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@AttributeOverrides(@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name=\"" + COLUMN_NAME + "\")))"); - } - }); - } - - private ICompilationUnit createTestAttributeOverride() throws Exception { - createAttributeOverridesAnnotation(); - 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"); - sb.append(CR); - sb.append("@AttributeOverride(name=\"FOO\", column=@Column(name=\"FOO\", columnDefinition=\"BAR\", table=\"BAZ\", unique=false, nullable=false, insertable=false, updatable=false, length=1, precision=1, scale=1))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.nestedAnnotations().next(); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - } - - public void testGetNullColumn() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.nestedAnnotations().next(); - ColumnAnnotation column = attributeOverride.getColumn(); - assertNotNull(attributeOverride); - assertNull(column); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.nestedAnnotations().next(); - - assertNotNull(attributeOverride); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName("Foo"); - assertEquals("Foo", attributeOverride.getName()); - assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.nestedAnnotations().next(); - assertEquals(ATTRIBUTE_OVERRIDE_NAME, attributeOverride.getName()); - - attributeOverride.setName(null); - assertNull(attributeOverride.getName()); - - assertSourceDoesNotContain("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - assertSourceContains("@AttributeOverride", cu); - assertSourceContains("@AttributeOverrides", cu); - } - - public void testColumnGetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverridesAnnotation attributeOverrides = (AttributeOverridesAnnotation) attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES); - AttributeOverrideAnnotation attributeOverride = attributeOverrides.nestedAnnotations().next(); - - ColumnAnnotation column = attributeOverride.getColumn(); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testColumnSetName() throws Exception { - ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - - ColumnAnnotation column = attributeOverride.getColumn(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName("Foo"); - - assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\", column = @Column(name=\"Foo\")))", cu); - - column.setName(null); - assertNull(attributeOverride.getColumn()); - assertSourceContains("@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")", cu); - } - - public void testAddAttributeOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\", column = @Column(name=\"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testAddAttributeOverrideToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\", column = @Column(name=\"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name=\"BAR\")})", cu); - - attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAZ\"),@AttributeOverride(name=\"FOO\", column = @Column(name=\"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)), @AttributeOverride(name=\"BAR\")})", cu); - - Iterator<JavaResourceNode> attributeOverrides = typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertEquals("BAZ", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("FOO", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - assertEquals("BAR", ((AttributeOverrideAnnotation) attributeOverrides.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(typeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testRemoveAttributeOverrideCopyExisting() throws Exception { - ICompilationUnit cu = createTestAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) typeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\", column = @Column(name=\"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1)),@AttributeOverride(name=\"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverride(name=\"FOO\", column = @Column(name=\"FOO\", columnDefinition = \"BAR\", table = \"BAZ\", unique = false, nullable = false, insertable = false, updatable = false, length = 1, precision = 1, scale = 1))", cu); - } - //not sure i want to test this api, how can we keep ContainerAnnotation.add, move, remove from being public? - //users should go throught AbstractJavapersistenceResource. this gets confusing because you would handle it differently - //for non top-level annotations -// public void testAdd() throws Exception { -// ICompilationUnit cu = this.createTestType(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// assertNull(attributeOverrides); -// -// attributeResource.addAnnotation(JPA.ATTRIBUTE_OVERRIDES); -// attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// assertNotNull(attributeOverrides); -// -// assertSourceContains("@AttributeOverrides"); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(0); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"Foo\"))"); -// -// AttributeOverride barAttributeOverride = attributeOverrides.add(0); -// barAttributeOverride.setName("Bar"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"Bar\"), @AttributeOverride(name=\"Foo\")})"); -// -// } -// -// public void testMove() throws Exception { -// ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(1); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\"), @AttributeOverride(name=\"Foo\")})"); -// -// attributeOverrides.move(0, 1); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"Foo\"), @AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\")})"); -// } -// -// public void testRemove() throws Exception { -// ICompilationUnit cu = this.createTestAttributeOverrideWithColumnOnField(); -// JavaPersistentTypeResource typeResource = buildJavaTypeResource(cu); -// JavaPersistentAttributeResource attributeResource = typeResource.fields().next(); -// AttributeOverrides attributeOverrides = (AttributeOverrides) attributeResource.annotation(JPA.ATTRIBUTE_OVERRIDES); -// -// AttributeOverride fooAttributeOverride = attributeOverrides.add(1); -// fooAttributeOverride.setName("Foo"); -// -// assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"" + ATTRIBUTE_OVERRIDE_NAME + "\"), @AttributeOverride(name=\"Foo\")})"); -// -// attributeOverrides.remove(0); -// -// assertSourceContains("@AttributeOverrides(@AttributeOverride(name=\"Foo\"))"); -// -// attributeOverrides.remove(0); -// -// assertSourceContains("@AttributeOverrides()"); -// -// } - - - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java deleted file mode 100644 index 608c6ef248..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/BasicTests.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.FetchType; -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.utility.internal.iterators.ArrayIterator; - -public class BasicTests extends JavaResourceModelTestCase { - - public BasicTests(String name) { - super(name); - } - - private ICompilationUnit createTestBasic() throws Exception { - this.createAnnotationAndMembers("Basic", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.BASIC); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic"); - } - }); - } - - private ICompilationUnit createTestBasicWithOptional() throws Exception { - this.createAnnotationAndMembers("Basic", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.BASIC); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(optional=true)"); - } - }); - } - - private ICompilationUnit createTestBasicWithFetch() throws Exception { - this.createAnnotationAndMembers("Basic", "boolean optional() default true; FetchType fetch() default FetchType.EAGER;"); - this.createEnumAndMembers("FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.BASIC, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Basic(fetch=FetchType.EAGER)"); - } - }); - } - - public void testBasic() throws Exception { - ICompilationUnit cu = this.createTestBasic(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertNotNull(basic); - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertTrue(basic.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertTrue(basic.getOptional()); - - basic.setOptional(false); - assertFalse(basic.getOptional()); - - assertSourceContains("@Basic(optional=false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestBasicWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertTrue(basic.getOptional()); - - basic.setOptional(null); - assertNull(basic.getOptional()); - - assertSourceContains("@Basic", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - - basic.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, basic.getFetch()); - - assertSourceContains("@Basic(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestBasicWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - BasicAnnotation basic = (BasicAnnotation) attributeResource.getMappingAnnotation(JPA.BASIC); - assertEquals(FetchType.EAGER, basic.getFetch()); - - basic.setFetch(null); - assertNull(basic.getFetch()); - - assertSourceContains("@Basic", cu); - assertSourceDoesNotContain("fetch", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java deleted file mode 100644 index a812d8438f..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ColumnTests.java +++ /dev/null @@ -1,423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.utility.internal.iterators.ArrayIterator; - -public class ColumnTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public ColumnTests(String name) { - super(name); - } - - private void createColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("Column", - "String name() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; " + - "int length() default 255; " + - "int precision() default 0; " + - "int scale() default 0;"); - } - - private ICompilationUnit createTestColumn() throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - } - }); - } - - private ICompilationUnit createTestColumnWithName() throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithTable() throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(table=\"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithColumnDefinition() throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestColumnWithBooleanElement(final String booleanElement) throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(" + booleanElement + "=true)"); - } - }); - } - - private ICompilationUnit createTestColumnWithIntElement(final String intElement) throws Exception { - createColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(" + intElement + "=5)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@Column(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@Column(table=\"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@Column(columnDefinition=\"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUnique()); - - assertSourceContains("@Column(unique=false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getNullable()); - - assertSourceContains("@Column(nullable=false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getInsertable()); - - assertSourceContains("@Column(insertable=false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Boolean.TRUE, column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(Boolean.FALSE); - assertEquals(Boolean.FALSE, column.getUpdatable()); - - assertSourceContains("@Column(updatable=false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetLength() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("length"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getLength()); - } - - public void testSetLength() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getLength()); - - column.setLength(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getLength()); - - assertSourceContains("@Column(length=5)", cu); - - column.setLength(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("precision"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getPrecision()); - } - - public void testSetPrecision() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertEquals(null, column.getPrecision()); - - column.setPrecision(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getPrecision()); - - assertSourceContains("@Column(precision=5)", cu); - - column.setPrecision(null); - assertSourceDoesNotContain("@Column", cu); - } - - public void testGetScale() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("scale"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertEquals(Integer.valueOf(5), column.getScale()); - } - - public void testSetScale() throws Exception { - ICompilationUnit cu = this.createTestColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - - assertNotNull(column); - assertNull(column.getScale()); - - column.setScale(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getScale()); - - assertSourceContains("@Column(scale=5)", cu); - - column.setScale(null); - assertSourceDoesNotContain("@Column", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java deleted file mode 100644 index 8aa31a5cfa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorColumnTests.java +++ /dev/null @@ -1,225 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.DiscriminatorColumnAnnotation; -import org.eclipse.jpt.core.resource.java.DiscriminatorType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class DiscriminatorColumnTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - - public DiscriminatorColumnTests(String name) { - super(name); - } - - private void createDiscriminatorColumnAnnotation() throws Exception { - this.createEnumAndMembers("DiscriminatorType", "STRING, CHAR, INTEGER"); - this.createAnnotationAndMembers("DiscriminatorColumn", - "String name() default \"DTYPE\"; " + - "DiscriminatorType discriminatorType() default STRING; " + - "String columnDefinition() default \"\"; " + - "int length() default 31;"); - } - - private ICompilationUnit createTestDiscriminatorColumn() throws Exception { - createDiscriminatorColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithName() throws Exception { - createDiscriminatorColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithColumnDefinition() throws Exception { - createDiscriminatorColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorColumnWithDiscriminatorType() throws Exception { - createDiscriminatorColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_COLUMN, JPA.DISCRIMINATOR_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(discriminatorType=DiscriminatorType.CHAR)"); - } - }); - } - - private ICompilationUnit createTestColumnWithIntElement(final String intElement) throws Exception { - createDiscriminatorColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorColumn(" + intElement + "=5)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getDiscriminatorType()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@DiscriminatorColumn(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@DiscriminatorColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@DiscriminatorColumn(columnDefinition=\"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@DiscriminatorColumn", cu); - } - - public void testGetLength() throws Exception { - ICompilationUnit cu = this.createTestColumnWithIntElement("length"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertEquals(Integer.valueOf(5), column.getLength()); - } - - public void testSetLength() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNotNull(column); - assertNull(column.getLength()); - - column.setLength(Integer.valueOf(5)); - assertEquals(Integer.valueOf(5), column.getLength()); - - assertSourceContains("@DiscriminatorColumn(length=5)", cu); - - column.setLength(null); - assertSourceDoesNotContain("@DiscriminatorColumn", cu); - } - - public void testGetDiscriminatorType() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumnWithDiscriminatorType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - assertEquals(DiscriminatorType.CHAR, column.getDiscriminatorType()); - } - - public void testSetDiscriminatorType() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - DiscriminatorColumnAnnotation column = (DiscriminatorColumnAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_COLUMN); - - assertNull(column.getDiscriminatorType()); - - column.setDiscriminatorType(DiscriminatorType.INTEGER); - assertEquals(DiscriminatorType.INTEGER, column.getDiscriminatorType()); - - assertSourceContains("@DiscriminatorColumn(discriminatorType=INTEGER)", cu); - - column.setDiscriminatorType(null); - assertSourceDoesNotContain("@DiscriminatorColumn", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java deleted file mode 100644 index db386b45e3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/DiscriminatorValueTests.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.DiscriminatorValueAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class DiscriminatorValueTests extends JavaResourceModelTestCase { - - public DiscriminatorValueTests(String name) { - super(name); - } - - private ICompilationUnit createTestDiscriminatorValue() throws Exception { - this.createAnnotationAndMembers("DiscriminatorValue", "String value() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorValue"); - } - }); - } - - private ICompilationUnit createTestDiscriminatorValueWithValue() throws Exception { - this.createAnnotationAndMembers("DiscriminatorValue", "String value() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.DISCRIMINATOR_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@DiscriminatorValue(value=\"discriminator\")"); - } - }); - } - - public void testDiscriminatorValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - assertNotNull(discriminatorValue); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValueWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - assertEquals("discriminator", discriminatorValue.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestDiscriminatorValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - DiscriminatorValueAnnotation discriminatorValue = (DiscriminatorValueAnnotation) typeResource.getAnnotation(JPA.DISCRIMINATOR_VALUE); - - discriminatorValue.setValue("foo"); - - assertSourceContains("@DiscriminatorValue(\"foo\")", cu); - - discriminatorValue.setValue(null); - - assertSourceDoesNotContain("@DiscriminatorValue", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java deleted file mode 100644 index f4ab8532d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddableTests.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class EmbeddableTests extends JavaResourceModelTestCase { - - public EmbeddableTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbeddable() throws Exception { - this.createAnnotationAndMembers("Embeddable", ""); - 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"); - } - }); - } - - private ICompilationUnit createTestEmbeddableAndEntity() throws Exception { - this.createAnnotationAndMembers("Embeddable", ""); - this.createAnnotationAndMembers("Entity", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDABLE, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append("@Embeddable"); - } - }); - } - - public void testEmbeddable() throws Exception { - ICompilationUnit cu = this.createTestEmbeddable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EmbeddableAnnotation); - } - - public void testEmbeddableAndEntity() throws Exception { - ICompilationUnit cu = this.createTestEmbeddableAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EmbeddableAnnotation); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(JPA.ENTITY); - assertNotNull(entity); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java deleted file mode 100644 index c5b90335b7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedIdTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.EmbeddedIdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class EmbeddedIdTests extends JavaResourceModelTestCase { - - public EmbeddedIdTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbeddedId() throws Exception { - this.createAnnotationAndMembers("EmbeddedId", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED_ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@EmbeddedId"); - } - }); - } - - public void testEmbeddedId() throws Exception { - ICompilationUnit cu = this.createTestEmbeddedId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EmbeddedIdAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java deleted file mode 100644 index db922e4ca2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EmbeddedTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.EmbeddedAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class EmbeddedTests extends JavaResourceModelTestCase { - - public EmbeddedTests(String name) { - super(name); - } - - private ICompilationUnit createTestEmbedded() throws Exception { - this.createAnnotationAndMembers("Embedded", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - } - }); - } - - public void testEmbedded() throws Exception { - ICompilationUnit cu = this.createTestEmbedded(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EmbeddedAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java deleted file mode 100644 index b2fcc69c28..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EntityTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class EntityTests extends JavaResourceModelTestCase { - - private static final String ENTITY_NAME = "Foo"; - - public EntityTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - 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 createTestEntityWithName() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - 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(name=\"" + ENTITY_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestMappedSuperclassAndEntity() throws Exception { - this.createAnnotationAndMembers("MappedSuperclass", ""); - this.createAnnotationAndMembers("Entity", "String name();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - sb.append("@Entity"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(JPA.ENTITY); - assertTrue(entity != null); - assertEquals(ENTITY_NAME, entity.getName()); - } - - public void testGetNameNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(JPA.ENTITY); - assertTrue(entity != null); - assertNull(entity.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(JPA.ENTITY); - assertNull(entity.getName()); - entity.setName("Foo"); - assertEquals("Foo", entity.getName()); - - assertSourceContains("@Entity(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestEntityWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - EntityAnnotation entity = (EntityAnnotation) typeResource.getMappingAnnotation(JPA.ENTITY); - assertEquals(ENTITY_NAME, entity.getName()); - - entity.setName(null); - assertNull(entity.getName()); - - assertSourceContains("@Entity", cu); - assertSourceDoesNotContain("@Entity(name=\"Foo\")", cu); - } - - public void testMappedSuperclassAndEntity() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclassAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EntityAnnotation); - - MappedSuperclassAnnotation mappedSuperclass = (MappedSuperclassAnnotation) typeResource.getMappingAnnotation(JPA.MAPPED_SUPERCLASS); - assertNotNull(mappedSuperclass); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java deleted file mode 100644 index cd7dd1ef49..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/EnumeratedTests.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.EnumType; -import org.eclipse.jpt.core.resource.java.EnumeratedAnnotation; -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.utility.internal.iterators.ArrayIterator; - -public class EnumeratedTests extends JavaResourceModelTestCase { - - public EnumeratedTests(String name) { - super(name); - } - - private ICompilationUnit createTestEnumerated() throws Exception { - this.createAnnotationAndMembers("Enumerated", "EnumType value();"); - this.createEnumAndMembers("EnumType", "ORDINAL, STRING"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENUMERATED); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated"); - } - }); - } - - private ICompilationUnit createTestEnumeratedWithValue() throws Exception { - this.createAnnotationAndMembers("Enumerated", "EnumType value();"); - this.createEnumAndMembers("EnumType", "ORDINAL, STRING"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENUMERATED, JPA.ENUM_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Enumerated(EnumType.ORDINAL)"); - } - }); - } - - public void testEnumerated() throws Exception { - ICompilationUnit cu = this.createTestEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - assertNotNull(enumerated); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestEnumeratedWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - assertEquals(EnumType.ORDINAL, enumerated.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestEnumerated(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - EnumeratedAnnotation enumerated = (EnumeratedAnnotation) attributeResource.getAnnotation(JPA.ENUMERATED); - - enumerated.setValue(EnumType.STRING); - - assertSourceContains("@Enumerated(STRING)", cu); - - enumerated.setValue(null); - - assertSourceDoesNotContain("@Enumerated", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java deleted file mode 100644 index 7420cddd33..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/GeneratedValueTests.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; -import org.eclipse.jpt.core.resource.java.GenerationType; -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.utility.internal.iterators.ArrayIterator; - -public class GeneratedValueTests extends JavaResourceModelTestCase { - - private static final String GENERATOR = "MY_GENERATOR"; - public GeneratedValueTests(String name) { - super(name); - } - - private void createGenerationTypeEnum() throws Exception { - this.createEnumAndMembers("GenerationType", "TABLE, SEQUENCE, IDENTITY, AUTO;"); - } - - private void createGeneratedValueAnnotation() throws Exception { - this.createAnnotationAndMembers("GeneratedValue", "GenerationType strategy() default AUTO; String generator() default \"\""); - createGenerationTypeEnum(); - } - - private ICompilationUnit createTestGeneratedValue() throws Exception { - createGeneratedValueAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue"); - } - }); - } - - private ICompilationUnit createTestGeneratedValueWithGenerator() throws Exception { - createGeneratedValueAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue(generator=\"" + GENERATOR + "\")"); - } - }); - } - - private ICompilationUnit createTestGeneratedValueWithStrategy() throws Exception { - createGeneratedValueAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.GENERATED_VALUE, JPA.GENERATION_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@GeneratedValue(strategy=GenerationType.SEQUENCE)"); - } - }); - } - - public void testGeneratedValue() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertNotNull(generatedValue); - } - - public void testGetGenerator() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithGenerator(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GENERATOR, generatedValue.getGenerator()); - } - - public void testSetGenerator() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithGenerator(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GENERATOR, generatedValue.getGenerator()); - - generatedValue.setGenerator("foo"); - assertEquals("foo", generatedValue.getGenerator()); - - assertSourceContains("@GeneratedValue(generator=\"foo\")", cu); - - generatedValue.setGenerator(null); - assertNull(generatedValue.getGenerator()); - - assertSourceDoesNotContain("generator", cu); - assertSourceContains("@GeneratedValue", cu); - } - - public void testGetStrategy() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GenerationType.SEQUENCE, generatedValue.getStrategy()); - } - - public void testSetStrategy() throws Exception { - ICompilationUnit cu = this.createTestGeneratedValueWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - GeneratedValueAnnotation generatedValue = (GeneratedValueAnnotation) attributeResource.getAnnotation(JPA.GENERATED_VALUE); - assertEquals(GenerationType.SEQUENCE, generatedValue.getStrategy()); - - generatedValue.setStrategy(GenerationType.TABLE); - assertEquals(GenerationType.TABLE, generatedValue.getStrategy()); - - assertSourceContains("@GeneratedValue(strategy=TABLE)", cu); - - generatedValue.setStrategy(null); - assertNull(generatedValue.getStrategy()); - assertSourceDoesNotContain("strategy", cu); - assertSourceContains("@GeneratedValue", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java deleted file mode 100644 index d88f43bd6b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdClassTests.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.IdClassAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class IdClassTests extends JavaResourceModelTestCase { - - private static final String ID_CLASS_VALUE = "MyClass"; - - public IdClassTests(String name) { - super(name); - } - - private void createIdClassAnnotation() throws Exception { - this.createAnnotationAndMembers("IdClass", "Class value();"); - } - - private ICompilationUnit createTestIdClass() throws Exception { - createIdClassAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ID_CLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@IdClass"); - } - }); - } - - private ICompilationUnit createTestIdClassWithValue() throws Exception { - createIdClassAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ID_CLASS); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@IdClass(" + ID_CLASS_VALUE + ".class)"); - } - }); - } - - public void testIdClass() throws Exception { - ICompilationUnit cu = this.createTestIdClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertNotNull(idClass); - assertNull(idClass.getValue()); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertEquals(ID_CLASS_VALUE, idClass.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertEquals(ID_CLASS_VALUE, idClass.getValue()); - - idClass.setValue("foo"); - assertEquals("foo", idClass.getValue()); - - assertSourceContains("@IdClass(foo.class)", cu); - - idClass.setValue(null); - - assertSourceDoesNotContain("@IdClass", cu); - - idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertNull(idClass); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestIdClassWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - IdClassAnnotation idClass = (IdClassAnnotation) typeResource.getAnnotation(JPA.ID_CLASS); - assertNotNull(idClass.getValue()); - assertEquals("MyClass", idClass.getFullyQualifiedClass()); //bug 196200 changed this - - - idClass.setValue(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, idClass.getFullyQualifiedClass()); - assertSourceContains("@IdClass(" + TYPE_NAME + ".class)", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java deleted file mode 100644 index 721454d21c..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/IdTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class IdTests extends JavaResourceModelTestCase { - - public IdTests(String name) { - super(name); - } - - private ICompilationUnit createTestId() throws Exception { - this.createAnnotationAndMembers("Id", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ID); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - public void testId() throws Exception { - ICompilationUnit cu = this.createTestId(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof IdAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java deleted file mode 100644 index a2058e6d22..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/InheritanceTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.InheritanceAnnotation; -import org.eclipse.jpt.core.resource.java.InheritanceType; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class InheritanceTests extends JavaResourceModelTestCase { - - public InheritanceTests(String name) { - super(name); - } - - private ICompilationUnit createTestInheritance() throws Exception { - this.createAnnotationAndMembers("Inheritance", "InheritanceType strategy() default SINGLE_TABLE;"); - this.createEnumAndMembers("InheritanceType", "SINGLE_TABLE, JOINED, TABLE_PER_CLASS"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.INHERITANCE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Inheritance"); - } - }); - } - - private ICompilationUnit createTestInheritanceWithStrategy() throws Exception { - this.createAnnotationAndMembers("Inheritance", "InheritanceType strategy() default SINGLE_TABLE;"); - this.createEnumAndMembers("InheritanceType", "SINGLE_TABLE, JOINED, TABLE_PER_CLASS"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.INHERITANCE, JPA.INHERITANCE_TYPE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Inheritance(strategy=InheritanceType.JOINED)"); - } - }); - } - - public void testInheritance() throws Exception { - ICompilationUnit cu = this.createTestInheritance(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - assertNotNull(inheritance); - } - - public void testGetStrategy() throws Exception { - ICompilationUnit cu = this.createTestInheritanceWithStrategy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - assertEquals(InheritanceType.JOINED, inheritance.getStrategy()); - } - - public void testSetStrategy() throws Exception { - ICompilationUnit cu = this.createTestInheritance(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - InheritanceAnnotation inheritance = (InheritanceAnnotation) typeResource.getAnnotation(JPA.INHERITANCE); - inheritance.setStrategy(InheritanceType.TABLE_PER_CLASS); - - assertSourceContains("@Inheritance(strategy=TABLE_PER_CLASS)", cu); - - inheritance.setStrategy(null); - - assertSourceDoesNotContain("@Inheritance", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java deleted file mode 100644 index 4df0a87c68..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JPTToolsTests.java +++ /dev/null @@ -1,517 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.IMethodBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.JPTTools; -import org.eclipse.jpt.core.utility.jdt.FieldAttribute; -import org.eclipse.jpt.core.utility.jdt.MethodAttribute; -import org.eclipse.jpt.core.utility.jdt.Type; - -public class JPTToolsTests extends JavaResourceModelTestCase { - - public JPTToolsTests(String name) { - super(name); - } - - private ICompilationUnit createTestTypeFieldWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " String foo;").append(CR); - sb.append(CR); - } - }); - } - - protected FieldAttribute fooField(ICompilationUnit cu) { - return this.buildField("foo", cu); - } - - - private ICompilationUnit createTestTypeGetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " int getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeInvalidMethodName() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int foo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeConstructor() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public " + TYPE_NAME + "() {").append(CR); - sb.append(" super();").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeVoidMethodReturnType() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public void getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - -// private ICompilationUnit createTestTypeInvalidMethodReturnType() throws Exception { -// return this.createTestType(new DefaultAnnotationWriter() { -// -// @Override -// public Iterator<String> imports() { -// return new ArrayIterator<String>("com.foo.Foo"); -// } -// @Override -// public void appendGetIdMethodAnnotationTo(StringBuffer sb) { -// sb.append(CR); -// sb.append(" public Foo getFoo() {").append(CR); -// sb.append(" return null;").append(CR); -// sb.append(" }").append(CR); -// sb.append(CR); -// sb.append(" public void setFoo(Foo id) {").append(CR); -// sb.append(" this.id = id;").append(CR); -// sb.append(" }").append(CR); -// sb.append(CR); -// } -// }); -// } - - private ICompilationUnit createTestTypeIsMethod() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public boolean isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(boolean id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeIsMethodReturnInt() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeIsAndGetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" " + modifier + " boolean isFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" " + modifier + " boolean getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" public void setFoo(boolean id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeSetMethodWithModifier(final String modifier) throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public int getFoo() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" " + modifier + " void setFoo(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeWithMemberTypes() throws Exception { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" public static class FooStatic {}").append(CR); - sb.append(CR); - sb.append(" public class FooNotStatic {}").append(CR); - sb.append(CR); - sb.append(" public @interface MyAnnotation {}").append(CR); - sb.append(CR); - sb.append(" public enum MyEnum {}").append(CR); - } - }); - } - - protected MethodAttribute fooMethod(ICompilationUnit cu) { - return this.buildMethod("getFoo", cu); - } - - //private String foo; - persistable - public void testFieldIsPersistable1() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private"); - FieldAttribute fieldAttribute = fooField(cu); - IVariableBinding variableBinding = fieldAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.fieldIsPersistable(variableBinding)); - } - - //private static String foo; - not persistable - public void testFieldIsPersistable2() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private static"); - FieldAttribute fieldAttribute = fooField(cu); - IVariableBinding variableBinding = fieldAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.fieldIsPersistable(variableBinding)); - } - - //private transient String foo; - not persistable - public void testFieldIsPersistable3() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private transient"); - FieldAttribute fieldAttribute = fooField(cu); - IVariableBinding variableBinding = fieldAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.fieldIsPersistable(variableBinding)); - } - - //private final String foo; - persistable - public void testFieldIsPersistable4() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("private final"); - FieldAttribute fieldAttribute = fooField(cu); - IVariableBinding variableBinding = fieldAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.fieldIsPersistable(variableBinding)); - } - - //public String foo; - persistable - public void testFieldIsPersistable5() throws Exception { - ICompilationUnit cu = createTestTypeFieldWithModifier("public"); - FieldAttribute fieldAttribute = fooField(cu); - IVariableBinding variableBinding = fieldAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.fieldIsPersistable(variableBinding)); - } - - - //public int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter1() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - - } - - //protected int getFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter2() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("protected"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter3() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier(""); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //private int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter4() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("private"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public static int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter5() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public static"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public final int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter6() throws Exception { - ICompilationUnit cu = createTestTypeGetMethodWithModifier("public final"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter7() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - - } - - //protected void setFoo(int foo) {} - persistable - public void testMethodIsPersistablePropertyGetter8() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("protected"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //void setFoo(int foo) {} - not persistable - public void testMethodIsPersistablePropertyGetter9() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier(""); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //private void setFoo(int foo) {} - not persistable - public void testMethodIsPersistablePropertyGetter10() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("private"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public static void setFoo(int foo) {} - not persistable - public void testMethodIsPersistablePropertyGetter11() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public static"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public final void setFoo(int foo) {} - not persistable - public void testMethodIsPersistablePropertyGetter12() throws Exception { - ICompilationUnit cu = createTestTypeSetMethodWithModifier("public final"); - MethodAttribute methodAttribute = fooMethod(cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - } - - //public boolean isFoo() {} - persistable - public void testMethodIsPersistablePropertyGetter13() throws Exception { - ICompilationUnit cu = createTestTypeIsMethod(); - MethodAttribute methodAttribute = this.buildMethod("isFoo", cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - - } - - //public int isFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter14() throws Exception { - ICompilationUnit cu = createTestTypeIsMethodReturnInt(); - MethodAttribute methodAttribute = this.buildMethod("isFoo", cu); - IMethodBinding methodBinding = methodAttribute.getBinding(JDTTools.buildASTRoot(cu)); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(methodBinding)); - - } - - //public int isFoo() {} - persistable - //public int getFoo() {} - not persistable - public void testMethodIsPersistablePropertyGetter15() throws Exception { - ICompilationUnit cu = createTestTypeIsAndGetMethodWithModifier("public"); - MethodAttribute isFooMethod = this.buildMethod("isFoo", cu); - MethodAttribute getFooMethod = this.buildMethod("getFoo", cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertTrue(JPTTools.methodIsPersistablePropertyGetter(isFooMethod.getBinding(astRoot))); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(getFooMethod.getBinding(astRoot))); - } - - //public int foo() {} - not persistable - public void testMethodIsPersistablePropertyGetter16() throws Exception { - ICompilationUnit cu = createTestTypeInvalidMethodName(); - MethodAttribute fooMethod = this.buildMethod("foo", cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(fooMethod.getBinding(astRoot))); - } - - //public void getFoo() {} - not persistable - void return type - public void testMethodIsPersistablePropertyGetter17() throws Exception { - ICompilationUnit cu = createTestTypeVoidMethodReturnType(); - MethodAttribute fooMethod = this.buildMethod("getFoo", cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(fooMethod.getBinding(astRoot))); - } - - //TODO - //**getFooMethod.binding(CompliationUnit) is returning null, not sure why and don't know how to test - //**this if it is returning null there instead of returning null for IMethodBinding.getReturnType() -// //public Foo getFoo() {} - not persistable - Foo does not resolve -// public void testMethodIsPersistablePropertyGetter18() throws Exception { -// ICompilationUnit cu = createTestTypeInvalidMethodReturnType(); -// MethodAttribute getFooMethod = this.buildMethod("getFoo"); -// -// CompilationUnit astRoot = JDTTools.buildASTRoot(cu); -// assertFalse(JPTTools.methodIsPersistablePropertyGetter(fooMethod.binding(astRoot))); -// } - - //method with parameters - not persistable - public void testMethodIsPersistablePropertyGetter19() throws Exception { - ICompilationUnit cu = createTestType(); - MethodAttribute setIdMethod = idSetMethod(cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(setIdMethod.getBinding(astRoot))); - } - - //constructor - not persistable - public void testMethodIsPersistablePropertyGetter20() throws Exception { - ICompilationUnit cu = createTestTypeConstructor(); - MethodAttribute constructor = buildMethod(TYPE_NAME, cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(constructor.getBinding(astRoot))); - } - - //no corresponding set method - not persistable - public void testMethodIsPersistablePropertyGetter21() throws Exception { - ICompilationUnit cu = createTestType(); - MethodAttribute getNameMethod = nameGetMethod(cu); - - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.methodIsPersistablePropertyGetter(getNameMethod.getBinding(astRoot))); - } - - //public class AnnotationTestType - public void cuIsPersistable() throws Exception { - ICompilationUnit cu = createTestType(); - Type type = testType(cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertTrue(JPTTools.typeIsPersistable(type.getBinding(astRoot))); - } - - //public final class MyFinal - public void cuIsPersistable2() throws Exception { - ICompilationUnit cu = this.javaProject.createCompilationUnit("finals", "MyFinal.java", "public final class MyFinal { }"); - Type type = buildType("MyFinal", cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.typeIsPersistable(type.getBinding(astRoot))); - } - - //public interface MyInterface - public void cuIsPersistable3() throws Exception { - ICompilationUnit cu = this.javaProject.createCompilationUnit("interfaces", "MyInterface.java", "public interface MyInterface { }"); - Type type = buildType("MyInterface", cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.typeIsPersistable(type.getBinding(astRoot))); - } - - //enum not persistable - public void cuIsPersistable4() throws Exception { - ICompilationUnit cu = this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - Type type = buildType("TestEnum", cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.typeIsPersistable(type.getBinding(astRoot))); - } - - //annotation not persistable - public void cuIsPersistable5() throws Exception { - ICompilationUnit cu = this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - Type type = buildType("TestAnnotation", cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.typeIsPersistable(type.getBinding(astRoot))); - } - - //public static member type is persistable - public void cuIsPersistable6() throws Exception { - ICompilationUnit cu = this.createTestTypeWithMemberTypes(); - Type testType = this.testType(cu); - Type memberType = this.buildType(testType, "FooStatic", 1, cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertTrue(JPTTools.typeIsPersistable(memberType.getBinding(astRoot))); - } - - //non-static member type is not persistable - public void cuIsPersistable7() throws Exception { - ICompilationUnit cu = this.createTestTypeWithMemberTypes(); - Type testType = this.testType(cu); - Type memberType = this.buildType(testType, "FooNotStatic", 1, cu); - CompilationUnit astRoot = JDTTools.buildASTRoot(cu); - assertFalse(JPTTools.typeIsPersistable(memberType.getBinding(astRoot))); - } - //TODO still need to test typeIsPersistable() returns false for local and anonymous classes - - -} - diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java deleted file mode 100644 index 9a038055ab..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.internal.GenericJpaProject; -import org.eclipse.jpt.core.internal.SimpleJpaProjectConfig; -import org.eclipse.jpt.core.internal.resource.java.JavaResourceModelImpl; -import org.eclipse.jpt.core.internal.utility.jdt.NullAnnotationEditFormatter; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase; -import org.eclipse.jpt.utility.CommandExecutorProvider; -import org.eclipse.jpt.utility.internal.StringTools; - -public class JavaResourceModelTestCase extends AnnotationTestCase -{ - private JavaElementChangeListener javaElementChangeListener; - protected JavaResourceModel javaResourceModel; - - - public JavaResourceModelTestCase(String name) { - super(name); - } - @Override - protected void setUp() throws Exception { - super.setUp(); - this.javaElementChangeListener = new JavaElementChangeListener(); - JavaCore.addElementChangedListener(this.javaElementChangeListener); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - JavaCore.removeElementChangedListener(this.javaElementChangeListener); - this.javaElementChangeListener = null; - } - - /** - * Forward the Java element change event back to the JPA model manager. - */ - private class JavaElementChangeListener implements IElementChangedListener { - JavaElementChangeListener() { - super(); - } - public void elementChanged(ElementChangedEvent event) { - if (JavaResourceModelTestCase.this.javaResourceModel != null) { - JavaResourceModelTestCase.this.javaResourceModel.javaElementChanged(event); - } - } - @Override - public String toString() { - return StringTools.buildToStringFor(this); - } - } - - protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - return this.javaProject.createCompilationUnit("javax.persistence", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - protected ICompilationUnit createEnumAndMembers(String enumName, String enumBody) throws Exception { - return this.javaProject.createCompilationUnit("javax.persistence", enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } - - //build up a dummy JpaProject that does not have JpaFiles in it and does not update from java changes - protected JpaProject buildJpaProject() throws CoreException { - return new TestJpaProject(this.buildJpaProjectConfig(this.javaProject.getProject())); - } - - protected class TestJpaProject extends GenericJpaProject { - protected TestJpaProject(JpaProject.Config config) throws CoreException { - super(config); - this.setUpdater(Updater.Null.instance());// ignore all updates, since there is no context model - } - - @Override - protected IResourceProxyVisitor buildInitialResourceProxyVisitor() { - return new IResourceProxyVisitor() { - public boolean visit(IResourceProxy proxy) throws CoreException { - return false; // ignore all the files in the Eclipse project - } - }; - } - - @Override - protected JpaRootContextNode buildRootContextNode() { - return null; // no root context - } - } - - private JpaProject.Config buildJpaProjectConfig(IProject project) { - SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); - config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); - config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); - config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); - return config; - } - - protected JavaResourcePersistentType buildJavaTypeResource(ICompilationUnit cu) - throws CoreException { - this.javaResourceModel = buildJavaResourceModel(cu); - this.javaResourceModel.resolveTypes(); - return this.javaResourceModel.getJpaCompilationUnit().getPersistentType(); - } - - protected JavaResourceModel buildJavaResourceModel(ICompilationUnit cu) throws CoreException { - if (this.javaResourceModel != null) { - throw new IllegalStateException(); - } - IFile file = (IFile) cu.getResource(); - JpaProject jpaProject = buildJpaProject(); - return new JavaResourceModelImpl( - file, - jpaProject.getJpaPlatform().getAnnotationProvider(), - CommandExecutorProvider.Default.instance(), - NullAnnotationEditFormatter.instance()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java deleted file mode 100644 index b14feb7030..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentAttributeTests.java +++ /dev/null @@ -1,905 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.IdImpl; -import org.eclipse.jpt.core.internal.resource.java.OneToOneImpl; -import org.eclipse.jpt.core.resource.java.AttributeOverrideAnnotation; -import org.eclipse.jpt.core.resource.java.BasicAnnotation; -import org.eclipse.jpt.core.resource.java.ColumnAnnotation; -import org.eclipse.jpt.core.resource.java.IdAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.OneToManyAnnotation; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.core.utility.jdt.Member.Editor; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - - -public class JavaResourcePersistentAttributeTests extends JavaResourceModelTestCase { - - public JavaResourcePersistentAttributeTests(String name) { - super(name); - } - - private ICompilationUnit createTestEntity() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - - 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 createTestEntityWithNonResolvingField() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - - 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private Foo foo;").append(CR); - sb.append(CR); - } - }); - } - private ICompilationUnit createTestEntityWithNonResolvingMethod() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - - 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("private Foo foo;").append(CR); - sb.append(CR); - sb.append(" @Id"); - sb.append(CR); - sb.append(" public Foo getFoo() {").append(CR); - sb.append(" return this.foo;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - sb.append(CR); - sb.append(" public void setFoo(Foo foo) {").append(CR); - sb.append(" this.foo = foo;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - } - }); - } - - private ICompilationUnit createTestEntityMultipleVariableDeclarationsPerLine() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Column", "String name();"); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" "); - sb.append("@Id"); - sb.append(CR); - sb.append(" "); - sb.append("@Column(name=\"baz\")"); - sb.append(" private String foo, bar;").append(CR); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestEntityWithIdAndBasic() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Id", ""); - this.createAnnotationAndMembers("Basic", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.BASIC); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append("@Basic"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Column", "String name();"); - this.createAnnotationAndMembers("Id", "String name();"); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.ID, JPA.COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append(" "); - sb.append("@Column"); - } - }); - } - - private ICompilationUnit createTestEntityWithColumn() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Column", "String name(); String table();"); - 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"FOO\", table=\"MY_TABLE\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithIdColumnGeneratedValue() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Column", "String name(); String table();"); - this.createAnnotationAndMembers("GeneratedValue", ""); - this.createAnnotationAndMembers("Id", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.COLUMN, JPA.ID, JPA.GENERATED_VALUE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - sb.append(CR); - sb.append("@Column"); - sb.append(CR); - sb.append("@GeneratedValue"); - } - }); - } - - - private ICompilationUnit createTestEntityMultipleColumns() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - this.createAnnotationAndMembers("Column", "String name();"); - 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column(name=\"FOO\")"); - sb.append(CR); - sb.append("@Column(name=\"BAR\")"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWithAttributeOverride() throws Exception { - this.createAnnotationAndMembers("Embedded", "String name();"); - this.createAnnotationAndMembers("AttributeOverride", "String name();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverride(name=\"FOO\")"); - } - }); - } - private ICompilationUnit createTestEmbeddedWithAttributeOverrides() throws Exception { - this.createAnnotationAndMembers("Embedded", "String name();"); - this.createAnnotationAndMembers("AttributeOverride", "String name();"); - this.createAnnotationAndMembers("AttributeOverrides", "AttributeOverride[] value();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides(@AttributeOverride(name=\"FOO\"))"); - } - }); - } - private ICompilationUnit createTestEmbeddedWithAttributeOverridesEmpty() throws Exception { - this.createAnnotationAndMembers("Embedded", "String name();"); - this.createAnnotationAndMembers("AttributeOverrides", "AttributeOverride[] value();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides()"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWith2AttributeOverrides() throws Exception { - this.createAnnotationAndMembers("Embedded", "String name();"); - this.createAnnotationAndMembers("AttributeOverride", "String name();"); - this.createAnnotationAndMembers("AttributeOverrides", "AttributeOverride[] value();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverrides({@AttributeOverride(name=\"FOO\"), @AttributeOverride(name=\"BAR\")})"); - } - }); - } - - private ICompilationUnit createTestEmbeddedWithAttributeOverrideAndAttributeOverrides() throws Exception { - this.createAnnotationAndMembers("Embedded", "String name();"); - this.createAnnotationAndMembers("AttributeOverride", "String name();"); - this.createAnnotationAndMembers("AttributeOverrides", "AttributeOverride[] value();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.EMBEDDED, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Embedded"); - sb.append(CR); - sb.append("@AttributeOverride(name=\"FOO\")"); - sb.append(CR); - sb.append("@AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\")})"); - } - }); - } - - private ICompilationUnit createTestTypePublicAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public String foo;"); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypePackageAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" String foo;"); - sb.append(CR); - } - }); - } - - private ICompilationUnit createTestTypeFinalAttribute() throws Exception { - - return this.createTestType(new DefaultAnnotationWriter() { - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(CR); - sb.append(" public final String foo;"); - sb.append(CR); - } - }); - } - - public void testJavaAttributeAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(1, attributeResource.annotationsSize()); - } - - public void testJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNotNull(attributeResource.getAnnotation(JPA.COLUMN)); - } - - public void testJavaAttributeAnnotationNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNull(attributeResource.getAnnotation(JPA.TABLE)); - } - - //This will result in a compilation error, but we assume the first column found - public void testDuplicateAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityMultipleColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - ColumnAnnotation columnResource = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("FOO", columnResource.getName()); - } - - public void testRemoveColumn() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - attributeResource.removeAnnotation(JPA.COLUMN); - - assertSourceDoesNotContain("@Column", cu); - } - - public void testRemoveColumnName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ColumnAnnotation columnResource = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - columnResource.setTable(null); - assertSourceContains("@Column(name=\"FOO\")", cu); - - columnResource.setName(null); - assertSourceDoesNotContain("@Column", cu); - - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testMultipleAttributeMappings() throws Exception { - ICompilationUnit cu = this.createTestEntityWithIdAndBasic(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(2, attributeResource.mappingAnnotationsSize()); - assertEquals(0, attributeResource.annotationsSize()); - assertNotNull(attributeResource.getMappingAnnotation(JPA.BASIC)); - assertNotNull(attributeResource.getMappingAnnotation(JPA.ID)); - - JavaResourceNode javaAttributeMappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(javaAttributeMappingAnnotation instanceof BasicAnnotation); - assertSourceContains("@Basic", cu); - assertSourceContains("@Id", cu); - - this.createAnnotationAndMembers("OneToMany", ""); - attributeResource.setMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(1, attributeResource.mappingAnnotationsSize()); - javaAttributeMappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(javaAttributeMappingAnnotation instanceof OneToManyAnnotation); - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("@Basic", cu); - } - - public void testSetJavaAttributeMappingAnnotation() throws Exception { - ICompilationUnit cu = createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(0, attributeResource.mappingAnnotationsSize()); - - this.createAnnotationAndMembers("Id", ""); - attributeResource.setMappingAnnotation(JPA.ID); - assertTrue(attributeResource.getMappingAnnotation() instanceof IdAnnotation); - assertSourceContains("@Id", cu); - } - - public void testSetJavaAttributeMappingAnnotation2() throws Exception { - ICompilationUnit cu = createTestEntityWithColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNull(attributeResource.getMappingAnnotation()); - - this.createAnnotationAndMembers("Id", ""); - attributeResource.setMappingAnnotation(JPA.ID); - assertTrue(attributeResource.getMappingAnnotation() instanceof IdAnnotation); - - assertSourceContains("@Id", cu); - assertSourceContains("@Column", cu); - } - - public void testSetJavaAttributeMappingAnnotation3() throws Exception { - ICompilationUnit cu = createTestEntityWithIdColumnGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertTrue(attributeResource.getMappingAnnotation() instanceof IdAnnotation); - - this.createAnnotationAndMembers("Basic", ""); - attributeResource.setMappingAnnotation(JPA.BASIC); - assertTrue(attributeResource.getMappingAnnotation() instanceof BasicAnnotation); - - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@GeneratedValue", cu); //not supported by Basic - assertSourceContains("@Column", cu); //common between Id and Basic - } - - public void testSetJavaAttributeMappingAnnotationNull() throws Exception { - ICompilationUnit cu = createTestEntityWithIdColumnGeneratedValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertTrue(attributeResource.getMappingAnnotation() instanceof IdAnnotation); - - attributeResource.setMappingAnnotation(null); - assertNull(attributeResource.getMappingAnnotation()); - - assertSourceDoesNotContain("@Id", cu); - assertSourceContains("@GeneratedValue", cu); //not supported by Basic - assertSourceContains("@Column", cu); //common between Id and Basic - } - - public void testAddJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertSourceDoesNotContain("@Column", cu); - attributeResource.addAnnotation(JPA.COLUMN); - assertSourceContains("@Column", cu); - } - - public void testRemoveJavaAttributeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertSourceContains("@Column", cu); - attributeResource.removeAnnotation(JPA.COLUMN); - assertSourceDoesNotContain("@Column", cu); - } - - //update source code to change from @Id to @OneToOne and make sure @Column is not removed - public void testChangeAttributeMappingInSource() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - final JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - idField(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - ((IdImpl) attributeResource.getMappingAnnotation()).getDeclarationAnnotationAdapter().removeAnnotation(declaration); - } - }); - - this.createAnnotationAndMembers("OneToOne", ""); - cu.createImport("javax.persistence.OneToOne", null, new NullProgressMonitor()); - - idField(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - OneToOneImpl.DECLARATION_ANNOTATION_ADAPTER.newMarkerAnnotation(declaration); - } - }); - - assertNotNull(attributeResource.getAnnotation(JPA.COLUMN)); - assertNull(attributeResource.getMappingAnnotation(JPA.ID)); - assertNotNull(attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE)); - assertSourceContains("@Column", cu); - } - - public void testJavaAttributeAnnotationsNestable() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(1, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - - assertEquals("FOO", attributeOverride.getName()); - } - - public void testJavaAttributeAnnotationsNoNestable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(0, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testJavaAttributeAnnotationsContainerNoNestable() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverridesEmpty(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertEquals(0, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testJavaAttributeAnnotationsNestableAndContainer() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrideAndAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverrideResource = (AttributeOverrideAnnotation) attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES).next(); - assertEquals("BAR", attributeOverrideResource.getName()); - } - - // -->> @AttributeOverride(name="FOO") - public void testAddJavaAttributeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("FOO"); - assertSourceContains("@AttributeOverride(name=\"FOO\")", cu); - } - - // @Embedded -->> @Embedded - // @AttributeOverride(name="FOO") @AttributeOverrides({@AttributeOverride(name="FOO"), @AttributeOverride(name="BAR")}) - public void testAddJavaAttributeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - this.createAnnotationAndMembers("AttributeOverrides", "String name();"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"),@AttributeOverride(name=\"BAR\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - // @Embedded - // @AttributeOverrides(@AttributeOverride(name="FOO")) - // || - // \/ - // @Embedded - // @AttributeOverrides({@AttributeOverride(name="FOO"), @AttributeOverride(name="BAR")}) - public void testAddJavaAttributeAnnotationNestableContainer3() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"),@AttributeOverride(name=\"BAR\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - public void testAddJavaAttributeAnnotationNestableContainer5() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride.setName("BAR"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAR\"),@AttributeOverride(name=\"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - } - - // @Embedded - // @SecondaryTable(name=\"FOO\") - // @AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\")}) - // || - // \/ - // @Embedded - // @AttributeOverride(name=\"FOO\") - // @AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\"), @AttributeOverride(name=\"BOO\")}) - public void testAddJavaAttributeAnnotationNestableContainer4() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrideAndAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - AttributeOverrideAnnotation attributeOverride = (AttributeOverrideAnnotation) attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\"),", cu); - assertSourceContains("@AttributeOverride})", cu); - attributeOverride.setName("BOO"); - - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDE)); - assertNotNull(attributeResource.getAnnotation(JPA.ATTRIBUTE_OVERRIDES)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES))); - - Iterator<JavaResourceNode> attributeOverrideAnnotations = attributeResource.annotations(JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BAR", attributeOverride.getName()); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BAZ", attributeOverride.getName()); - attributeOverride = (AttributeOverrideAnnotation) attributeOverrideAnnotations.next(); - assertEquals("BOO", attributeOverride.getName()); - - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"BAZ\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BOO\")})", cu); - } - - //@Entity - //@AttributeOverride(name="FOO") - public void testRemoveJavaAttributeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverride(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride", cu); - } - - - //@Entity - //@SecondaryTables(@SecondaryTable(name="FOO")) - public void testRemoveJavaAttributeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWithAttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride", cu); - assertSourceDoesNotContain("@AttributeOverrides", cu); - } - - public void testRemoveJavaAttributeAnnotationIndex() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - attributeResource.removeAnnotation(0, JPA.ATTRIBUTE_OVERRIDE , JPA.ATTRIBUTE_OVERRIDES); - - assertSourceDoesNotContain("@AttributeOverride(name=\"FOO\"", cu); - assertSourceContains("@AttributeOverride(name=\"BAR\"", cu); - assertSourceDoesNotContain("@AttributeOverrides", cu); - } - - public void testRemoveJavaAttributeAnnotationIndex2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation)attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"), @AttributeOverride(name=\"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BAZ\")})", cu); - - attributeResource.removeAnnotation(1, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"), @AttributeOverride(name=\"BAZ\")})", cu); - } - - public void testMoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation)attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"), @AttributeOverride(name=\"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BAZ\")})", cu); - - - attributeResource.move(0, 2, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAZ\"), @AttributeOverride(name=\"FOO\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BAR\")})", cu); - } - - public void testMoveJavaTypeAnnotation2() throws Exception { - ICompilationUnit cu = createTestEmbeddedWith2AttributeOverrides(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - AttributeOverrideAnnotation newAnnotation = (AttributeOverrideAnnotation) attributeResource.addAnnotation(2, JPA.ATTRIBUTE_OVERRIDE, JPA.ATTRIBUTE_OVERRIDES); - newAnnotation.setName("BAZ"); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"FOO\"), @AttributeOverride(name=\"BAR\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BAZ\")})", cu); - - attributeResource.move(1, 0, JPA.ATTRIBUTE_OVERRIDES); - assertSourceContains("@AttributeOverrides({@AttributeOverride(name=\"BAR\"), @AttributeOverride(name=\"FOO\"),", cu); - assertSourceContains("@AttributeOverride(name=\"BAZ\")})", cu); - } - - //more detailed tests in JPTToolsTests - public void testIsPersistableField() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - assertTrue(attributeResource.isPersistable()); - } - - public void testIsPersistableField2() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "fields"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertTrue(attributeResource.isForField()); - assertTrue(attributeResource.isPersistable()); //bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - this.javaResourceModel.resolveTypes(); - - assertTrue(attributeResource.isPersistable()); - } - - public void testGetQualifiedTypeName() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "fields"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertEquals("test.Foo", attributeResource.getQualifiedTypeName()); //bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - this.javaResourceModel.resolveTypes(); - - assertEquals("test.Foo", attributeResource.getQualifiedTypeName()); - } - - - //more detailed tests in JPTToolsTests - public void testIsPersistableMethod() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.properties().next(); - - assertTrue(attributeResource.isPersistable()); - } - - public void testIsPersistableMethod2() throws Exception { - ICompilationUnit cu = createTestEntityWithNonResolvingMethod(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - @SuppressWarnings("unchecked") - List<JavaResourcePersistentAttribute> attributes = (List<JavaResourcePersistentAttribute>) ClassTools.fieldValue(typeResource, "methods"); - JavaResourcePersistentAttribute attributeResource = attributes.get(0); - - assertEquals("foo", attributeResource.getName()); - assertTrue(attributeResource.isForProperty()); - assertTrue(attributeResource.isPersistable());//bug 196200 changed this - - this.javaProject.createCompilationUnit("test", "Foo.java", "public class Foo {}"); - this.javaResourceModel.resolveTypes(); - - assertTrue(attributeResource.isPersistable()); - } - - //this tests that we handle mutliple variable declarations in one line. - //The annotations should apply to all fields defined. This is not really a useful - //thing to do with JPA beyond the most basic things that use default column names - public void testMultipleVariableDeclarationsPerLine() throws Exception { - ICompilationUnit cu = createTestEntityMultipleVariableDeclarationsPerLine(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(4, CollectionTools.size(typeResource.fields())); - Iterator<JavaResourcePersistentAttribute> fields = typeResource.fields(); - JavaResourcePersistentAttribute attributeResource = fields.next(); - ColumnAnnotation column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("baz", column.getName()); - - attributeResource = fields.next(); - column = (ColumnAnnotation) attributeResource.getAnnotation(JPA.COLUMN); - assertEquals("baz", column.getName()); - } - - public void testIsPublic() throws Exception { - ICompilationUnit cu = createTestTypePublicAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.attributes().next(); - - assertTrue(attribute.isPublic()); - } - - public void testIsPublicFalse() throws Exception { - ICompilationUnit cu = createTestTypePackageAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.attributes().next(); - - assertFalse(attribute.isPublic()); - } - - public void testIsFinal() throws Exception { - ICompilationUnit cu = createTestTypeFinalAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.attributes().next(); - - assertTrue(attribute.isFinal()); - } - - public void testIsFinalFalse() throws Exception { - ICompilationUnit cu = createTestTypePackageAttribute(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attribute = typeResource.attributes().next(); - - assertFalse(attribute.isFinal()); - } - - //TODO add tests for JPTTools static methods -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java deleted file mode 100644 index ac64ff8f55..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourcePersistentTypeTests.java +++ /dev/null @@ -1,999 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.List; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.internal.resource.java.EmbeddableImpl; -import org.eclipse.jpt.core.internal.resource.java.EntityImpl; -import org.eclipse.jpt.core.resource.java.AccessType; -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.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; -import org.eclipse.jpt.core.utility.jdt.Member.Editor; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JavaResourcePersistentTypeTests extends JavaResourceModelTestCase { - - public JavaResourcePersistentTypeTests(String name) { - super(name); - } - - private void createEntityAnnotation() throws Exception{ - this.createAnnotationAndMembers("Entity", "String name() default \"\";"); - } - - private void createEmbeddableAnnotation() throws Exception{ - this.createAnnotationAndMembers("Embeddable", ""); - } - - private void createMappedSuperclassAnnotation() throws Exception{ - this.createAnnotationAndMembers("MappedSuperclass", ""); - } - - private void createSecondaryTableAnnotation() throws Exception{ - this.createAnnotationAndMembers("SecondaryTable", "String name();"); - } - - private void createSecondaryTablesAnnotation() throws Exception{ - this.createAnnotationAndMembers("SecondaryTables", ""); - } - - - private ICompilationUnit createTestEntity() throws Exception { - createEntityAnnotation(); - - 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 createTestInvalidAnnotations() throws Exception { - this.createAnnotationAndMembers("Foo", "String name();"); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>("javax.persistence.Foo"); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Foo"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Foo"); - } - }); - } - - private ICompilationUnit createTestEntityWithMemberEmbeddable() throws Exception { - createEntityAnnotation(); - createEmbeddableAnnotation(); - - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - } - - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" @Embeddable"); - sb.append(CR); - sb.append(" public static class Foo { }").append(CR); - - } - }); - } - - private ICompilationUnit createTestEntityDuplicates() throws Exception { - createEntityAnnotation(); - - 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(name=\"FirstEntity\")").append(CR); - sb.append("@Entity(name=\"SecondEntity\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithEmbeddable() throws Exception { - createEntityAnnotation(); - createEmbeddableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.EMBEDDABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@Embeddable"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedField() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 createTestEntityAnnotatedNonPersistableMethod() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - - 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 appendGetNameMethodAnnotationTo(StringBuilder sb) { - sb.append("@Id"); - } - }); - } - - private ICompilationUnit createTestEntityAnnotatedPersistableMethodNonPersistableField() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Id", ""); - this.createAnnotationAndMembers("Column", ""); - - 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"); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - sb.append(" private transient int notPersistable;").append(CR); - sb.append(CR); - - } - @Override - public void appendGetIdMethodAnnotationTo(StringBuilder sb) { - sb.append("@Column"); - } - }); - } - private ICompilationUnit createTestEntityNoPersistableFields() throws Exception { - createEntityAnnotation(); - - 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"); - } - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.delete(sb.indexOf("private int id;"), sb.indexOf("private int id;") + "private int id;".length()); - sb.delete(sb.indexOf("private String name;"), sb.indexOf("private String name;") + "private String name;".length()); - } - }); - } - -// private ICompilationUnit createTestEntityLarge(final int i) throws Exception { -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator<String> imports() { -// return new ArrayIterator<String>(JPA.ENTITY + i); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity" + i); -// sb.append(CR); -// } -// @Override -// public String typeName() { -// return TYPE_NAME + i; -// } -// }); -// } -// -// public void testLarge() throws Exception { -// for (int i = START; i <= END; i++) { -// this.createAnnotationAndMembers("Entity" +i, "String name();"); -// } -// -// List<ICompilationUnit> cus = new ArrayList<ICompilationUnit>(); -// for (int i = START; i <= END; i++) { -// cus.add(createTestEntityLarge(i)); -// } -// long start = System.currentTimeMillis(); -// List<JavaPersistentTypeResource> typeResources = new ArrayList<JavaPersistentTypeResource>(); -// for (int i = 0; i < END; i++) { -// typeResources.add(buildJavaTypeResource(cus.get(i))); -// } -// long end = System.currentTimeMillis(); -// -// System.out.println(end-start + "ms"); -// for (int i = 0; i < END; i++) { -// assertEquals(1, CollectionTools.size(typeResources.get(i).javaTypeMappingAnnotations())); -// assertNotNull(typeResources.get(i).javaTypeMappingAnnotation(JPA.ENTITY + (i+1))); -// } -// -// -//// assertEquals(0, CollectionTools.size(typeResource.javaTypeAnnotations())); -// } - - - - private ICompilationUnit createTestEntityWithTable() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Table", "String name(); String schema();"); - 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"); - sb.append(CR); - sb.append("@Table(name=\"FOO\", schema=\"BAR\")"); - } - }); - } - -// private ICompilationUnit createTestEntityWithTableAndIdClass() throws Exception { -// createEntityAnnotation(); -// this.createAnnotationAndMembers("Table", "String name(); String schema();"); -// this.createAnnotationAndMembers("IdClass", "Class value();"); -// return this.createTestType(new DefaultAnnotationWriter() { -// @Override -// public Iterator<String> imports() { -// return new ArrayIterator<String>(JPA.ENTITY, JPA.TABLE, JPA.ID_CLASS); -// } -// @Override -// public void appendTypeAnnotationTo(StringBuilder sb) { -// sb.append("@Entity"); -// sb.append(CR); -// sb.append("@Table"); -// sb.append(CR); -// sb.append("@IdClass"); -// } -// }); -// } -// - - private ICompilationUnit createTestEntityMultipleTables() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("Table", "String name(); String schema();"); - 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"); - sb.append(CR); - sb.append("@Table(name=\"FOO\")"); - sb.append(CR); - sb.append("@Table(name=\"BAR\")"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTable() throws Exception { - createEntityAnnotation(); - createSecondaryTableAnnotation(); - 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"); - sb.append(CR); - sb.append("@SecondaryTable(name=\"FOO\")"); - } - }); - } - private ICompilationUnit createTestEntityWithEmptySecondaryTables() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name();"); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - 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"); - sb.append(CR); - sb.append("@SecondaryTables()"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTables() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name();"); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - 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"); - sb.append(CR); - sb.append("@SecondaryTables(@SecondaryTable(name=\"FOO\"))"); - } - }); - } - - private ICompilationUnit createTestEntityWith2SecondaryTables() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name();"); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - 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"); - sb.append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})"); - } - }); - } - - private ICompilationUnit createTestEntityWithSecondaryTableAndSecondaryTables() throws Exception { - createEntityAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name();"); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value();"); - 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"); - sb.append(CR); - sb.append("@SecondaryTable(name=\"FOO\")"); - sb.append(CR); - sb.append("@SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\")})"); - } - }); - } - - private ICompilationUnit createTestEntityWithMemberTypes() throws Exception { - createEntityAnnotation(); - - 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"); - } - @Override - public void appendMemberTypeTo(StringBuilder sb) { - sb.append(" static class FooStatic {}").append(CR); - sb.append(CR); - sb.append(" class FooNotStatic {}").append(CR); - sb.append(CR); - sb.append(" @interface MyAnnotation {}").append(CR); - sb.append(CR); - sb.append(" enum MyEnum {}").append(CR); - } - }); - } - - public void testJavaTypeAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(1, typeResource.annotationsSize()); - } - - public void testJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNotNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testJavaTypeAnnotationNull() throws Exception { - ICompilationUnit cu = this.createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - //This will result in a compilation error, but we assume the first table found - public void testDuplicateAnnotations() throws Exception { - ICompilationUnit cu = this.createTestEntityMultipleTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals("FOO", tableResource.getName()); - } - - public void testRemoveTable() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - typeResource.removeAnnotation(JPA.TABLE); - - assertSourceDoesNotContain("@Table", cu); - } - - public void testRemoveTableName() throws Exception { - ICompilationUnit cu = this.createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation tableResource = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - tableResource.setSchema(null); - assertSourceContains("@Table(name=\"FOO\")", cu); - - tableResource.setName(null); - assertSourceDoesNotContain("@Table", cu); - - assertNull(typeResource.getAnnotation(JPA.TABLE)); - } - - public void testMultipleTypeMappings() throws Exception { - ICompilationUnit cu = this.createTestEntityWithEmbeddable(); - createMappedSuperclassAnnotation(); - - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(2, typeResource.mappingAnnotationsSize()); - assertEquals(0, typeResource.annotationsSize()); - assertNotNull(typeResource.getMappingAnnotation(JPA.EMBEDDABLE)); - assertNotNull(typeResource.getMappingAnnotation(JPA.ENTITY)); - - JavaResourceNode javaTypeMappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(javaTypeMappingAnnotation instanceof EmbeddableAnnotation); - assertSourceContains("@Entity", cu); - assertSourceContains("@Embeddable", cu); - - typeResource.setMappingAnnotation(JPA.MAPPED_SUPERCLASS); - assertEquals(1, typeResource.mappingAnnotationsSize()); - javaTypeMappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(javaTypeMappingAnnotation instanceof MappedSuperclassAnnotation); - assertSourceDoesNotContain("@Entity", cu); - assertSourceContains("@MappedSuperclass", cu); - assertSourceDoesNotContain("@Embeddable", cu); - } - - public void testSetJavaTypeMappingAnnotation() throws Exception { - createEntityAnnotation(); - ICompilationUnit cu = createTestType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(0, typeResource.mappingAnnotationsSize()); - - typeResource.setMappingAnnotation(JPA.ENTITY); - assertTrue(typeResource.getMappingAnnotation() instanceof EntityAnnotation); - assertSourceContains("@Entity", cu); - } - - public void testSetJavaTypeMappingAnnotation2() throws Exception { - ICompilationUnit cu = createTestEntityWithTable(); - createEmbeddableAnnotation(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertTrue(typeResource.getMappingAnnotation() instanceof EntityAnnotation); - - typeResource.setMappingAnnotation(JPA.EMBEDDABLE); - assertTrue(typeResource.getMappingAnnotation() instanceof EmbeddableAnnotation); - - assertSourceDoesNotContain("@Entity", cu); - assertSourceContains("@Table", cu); - } - - public void testAddJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertSourceDoesNotContain("@Table", cu); - typeResource.addAnnotation(JPA.TABLE); - - assertSourceContains("@Table", cu); - } - - public void testRemoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertSourceContains("@Table", cu); - typeResource.removeAnnotation(JPA.TABLE); - assertSourceDoesNotContain("@Table", cu); - } - - //update source code to change from @Entity to @Embeddable and make sure @Table is not removed - public void testChangeTypeMappingInSource() throws Exception { - ICompilationUnit cu = createTestEntityWithTable(); - final JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - testType(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - ((EntityImpl) typeResource.getMappingAnnotation()).getDeclarationAnnotationAdapter().removeAnnotation(declaration); - } - }); - - this.createAnnotationAndMembers("Embeddable", "String name();"); - cu.createImport("javax.persistence.Embeddable", null, new NullProgressMonitor()); - - this.testType(cu).edit(new Editor() { - public void edit(ModifiedDeclaration declaration) { - EmbeddableImpl.DECLARATION_ANNOTATION_ADAPTER.newMarkerAnnotation(declaration); - } - }); - - assertNotNull(typeResource.getAnnotation(JPA.TABLE)); - assertNull(typeResource.getMappingAnnotation(JPA.ENTITY)); - assertNotNull(typeResource.getMappingAnnotation(JPA.EMBEDDABLE)); - assertSourceContains("@Table", cu); - } - - public void testJavaTypeAnnotationsNestable() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(1, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals("FOO", secondaryTableResource.getName()); - } - - public void testJavaTypeAnnotationsNoNestable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(0, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testJavaTypeAnnotationsContainerNoNestable() throws Exception { - ICompilationUnit cu = createTestEntityWithEmptySecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertEquals(0, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testJavaTypeAnnotationsNestableAndContainer() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTableAndSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - assertEquals("BAR", secondaryTableResource.getName()); - } - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") - public void testAddJavaTypeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("FOO"); - assertSourceContains("@SecondaryTable(name=\"FOO\")", cu); - } - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddJavaTypeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - createSecondaryTablesAnnotation(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"),@SecondaryTable(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - // @Entity - // @SecondaryTables(@SecondaryTable(name="FOO")) - // || - // \/ - // @Entity - // @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddJavaTypeAnnotationNestableContainer3() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"),@SecondaryTable(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddJavaTypeAnnotationNestableContainer5() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAR\"),@SecondaryTable(name=\"FOO\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddJavaTypeAnnotationNestableContainer6() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAR\"),@SecondaryTable(name=\"FOO\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAZ\"),@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"FOO\")})", cu); - - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - // @Entity - // @SecondaryTable(name=\"FOO\") - // @SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\")}) - // || - // \/ - // @Entity - // @SecondaryTable(name=\"FOO\") - // @SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\"), @SecondaryTable(name=\"BOO\")}) - public void testAddJavaTypeAnnotationNestableContainer4() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTableAndSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - SecondaryTableAnnotation secondaryTableResource = (SecondaryTableAnnotation) typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\"), @SecondaryTable})", cu); - secondaryTableResource.setName("BOO"); - - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - - Iterator<JavaResourceNode> secondaryTableAnnotations = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BAR", secondaryTableResource.getName()); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BAZ", secondaryTableResource.getName()); - secondaryTableResource = (SecondaryTableAnnotation) secondaryTableAnnotations.next(); - assertEquals("BOO", secondaryTableResource.getName()); - - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\"), @SecondaryTable(name=\"BOO\")})", cu); - } - - //@Entity - //@SecondaryTable(name="FOO") - public void testRemoveJavaTypeAnnotationNestableContainer() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - - //@Entity - //@SecondaryTables(@SecondaryTable(name="FOO")) - public void testRemoveJavaTypeAnnotationNestableContainer2() throws Exception { - ICompilationUnit cu = createTestEntityWithSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable", cu); - assertSourceDoesNotContain("@SecondaryTables", cu); - } - - public void testRemoveJavaTypeAnnotationIndex() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - typeResource.removeAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - - assertSourceDoesNotContain("@SecondaryTable(name=\"FOO\"", cu); - assertSourceContains("@SecondaryTable(name=\"BAR\"", cu); - assertSourceDoesNotContain("@SecondaryTables", cu); - } - - public void testRemoveJavaTypeAnnotationIndex2() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ", cu); - - typeResource.removeAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAZ\")})", cu); - } - - public void testMoveJavaTypeAnnotation() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\")})", cu); - - typeResource.move(0, 2, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAZ\"), @SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})", cu); - } - - public void testMoveJavaTypeAnnotation2() throws Exception { - ICompilationUnit cu = createTestEntityWith2SecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation newAnnotation = (SecondaryTableAnnotation)typeResource.addAnnotation(2, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - newAnnotation.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\")})", cu); - - typeResource.move(2, 0, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAR\"), @SecondaryTable(name=\"BAZ\"), @SecondaryTable(name=\"FOO\")})", cu); - } - - public void testNestedTypes() throws Exception { - ICompilationUnit cu = createTestEntityWithMemberTypes(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals("only persistable types should be returned by nestedTypes()", 1, CollectionTools.size(persistentType.nestedTypes())); - - @SuppressWarnings("unchecked") - List<JavaResourcePersistentType> nestedTypes = (List<JavaResourcePersistentType>) ClassTools.fieldValue(persistentType, "nestedTypes"); - - assertEquals("enums and interfaces should be ignored", 2, CollectionTools.size(nestedTypes)); - - } - - public void testDuplicateEntityAnnotations() throws Exception { - ICompilationUnit cu = createTestEntityDuplicates(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - EntityAnnotation javaTypeMappingAnnotation = (EntityAnnotation) persistentType.getMappingAnnotation(JPA.ENTITY); - assertEquals("FirstEntity", javaTypeMappingAnnotation.getName()); - - assertEquals(1, persistentType.mappingAnnotationsSize()); - - javaTypeMappingAnnotation = (EntityAnnotation) persistentType.getMappingAnnotation(); - assertEquals("FirstEntity", javaTypeMappingAnnotation.getName()); - - } - - - public void testAttributes() throws Exception { - // TODO - } - - public void testFields() throws Exception { - // TODO - } - - public void testProperties() throws Exception { - // TODO - } - - public void testGetAccessNoAttributesAnnotated() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertNull(persistentType.getAccess()); - } - - public void testGetAccessFieldsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedField(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.FIELD, persistentType.getAccess()); - } - - public void testGetAccessMethodsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.PROPERTY, persistentType.getAccess()); - } - - public void testGetAccessFieldsAndMethodsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedFieldAndMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.FIELD, persistentType.getAccess()); - } - - public void testGetAccessNonPersistableMethodAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedNonPersistableMethod(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertNull(persistentType.getAccess()); - } - - public void testGetAccessPersistableMethodAndNonPersistableFieldAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityAnnotatedPersistableMethodNonPersistableField(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.PROPERTY, persistentType.getAccess()); - } - - public void testGetAccessNoPersistableFieldsAnnotated() throws Exception { - ICompilationUnit cu = createTestEntityNoPersistableFields(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals(AccessType.PROPERTY, persistentType.getAccess()); - } - - //TODO more tests here with superclasses other than Object. - //1. Test where the superclass does not resolve - //2. Test a superclass that does resolve - //3. What about a superclass that is a class file in a jar?? - //4. - public void testGetSuperclassQualifiedName() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertEquals("java.lang.Object", persistentType.getSuperClassQualifiedName()); - - } - - //more detailed tests in JPTToolsTests - public void testIsPersistable() throws Exception { - ICompilationUnit cu = createTestEntity(); - JavaResourcePersistentType persistentType = buildJavaTypeResource(cu); - - assertTrue(persistentType.isPersistable()); - } - - public void testAnnotatedMemberType() throws Exception { - ICompilationUnit cu = this.createTestEntityWithMemberEmbeddable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertNotNull(typeResource.getMappingAnnotation(JPA.ENTITY)); - assertNull(typeResource.getMappingAnnotation(JPA.EMBEDDABLE)); - - JavaResourcePersistentType nestedType = typeResource.nestedTypes().next(); - assertNull(nestedType.getMappingAnnotation(JPA.ENTITY)); - assertNotNull(nestedType.getMappingAnnotation(JPA.EMBEDDABLE)); - } - - public void testInvalidAnnotations() throws Exception { - ICompilationUnit cu = this.createTestInvalidAnnotations(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - assertEquals(0, typeResource.mappingAnnotationsSize()); - assertEquals(0, typeResource.annotationsSize()); - - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - assertEquals(0, attributeResource.mappingAnnotationsSize()); - assertEquals(0, attributeResource.annotationsSize()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java deleted file mode 100644 index 1f4a193f60..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnTests.java +++ /dev/null @@ -1,369 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.utility.internal.iterators.ArrayIterator; - -public class JoinColumnTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public JoinColumnTests(String name) { - super(name); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\"; " + - "String referencedColumnName() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; "); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(table=\"" + COLUMN_TABLE + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(referencedColumnName=\"" + COLUMN_REFERENCED_COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - createJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(" + booleanElement + "=true)"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@JoinColumn(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@JoinColumn(table=\"Foo\")", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@JoinColumn(referencedColumnName=\"Foo\")", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@JoinColumn(columnDefinition=\"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertTrue(column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(false); - assertFalse(column.getUnique()); - - assertSourceContains("@JoinColumn(unique=false)", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertTrue(column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(false); - assertFalse(column.getNullable()); - - assertSourceContains("@JoinColumn(nullable=false)", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertTrue(column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(false); - assertFalse(column.getInsertable()); - - assertSourceContains("@JoinColumn(insertable=false)", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertTrue(column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.getAnnotation(JPA.JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(false); - assertFalse(column.getUpdatable()); - - assertSourceContains("@JoinColumn(updatable=false)", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java deleted file mode 100644 index e7c734357b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinColumnsTests.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JoinColumnsTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_TABLE = "MY_TABLE"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public JoinColumnsTests(String name) { - super(name); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", - "String name() default \"\"; " + - "String referencedColumnName() default \"\"; " + - "boolean unique() default false; " + - "boolean nullable() default true; " + - "boolean insertable() default true; " + - "boolean updatable() default true; " + - "String columnDefinition() default \"\"; " + - "String table() default \"\"; "); - } - - private void createJoinColumnsAnnotation() throws Exception { - createJoinColumnAnnotation(); - this.createAnnotationAndMembers("JoinColumns", - "JoinColumn[] value();"); - } - - private ICompilationUnit createTestJoinColumns() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn)"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithName() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(name=\"" + COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithTable() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(table=\"" + COLUMN_TABLE + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithReferencedColumnName() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(referencedColumnName=\"" + COLUMN_REFERENCED_COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithColumnDefinition() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\"))"); - } - }); - } - - private ICompilationUnit createTestJoinColumnWithBooleanElement(final String booleanElement) throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumns(@JoinColumn(" + booleanElement + "=true))"); - } - }); - } - - private ICompilationUnit createTestJoinColumn() throws Exception { - createJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getNullable()); - assertNull(column.getInsertable()); - assertNull(column.getUnique()); - assertNull(column.getUpdatable()); - assertNull(column.getTable()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@JoinColumns(@JoinColumn(name=\"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_TABLE, column.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getTable()); - - column.setTable("Foo"); - assertEquals("Foo", column.getTable()); - - assertSourceContains("@JoinColumns(@JoinColumn(table=\"Foo\"))", cu); - - - column.setTable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@JoinColumns(@JoinColumn(referencedColumnName=\"Foo\"))", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@JoinColumns(@JoinColumn(columnDefinition=\"Foo\"))", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("unique"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getUnique()); - } - - public void testSetUnique() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUnique()); - - column.setUnique(false); - assertFalse(column.getUnique()); - - assertSourceContains("@JoinColumns(@JoinColumn(unique=false))", cu); - - column.setUnique(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("nullable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getNullable()); - } - - public void testSetNullable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getNullable()); - - column.setNullable(false); - assertFalse(column.getNullable()); - - assertSourceContains("@JoinColumns(@JoinColumn(nullable=false))", cu); - - column.setNullable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("insertable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getInsertable()); - } - - public void testSetInsertable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getInsertable()); - - column.setInsertable(false); - assertFalse(column.getInsertable()); - - assertSourceContains("@JoinColumns(@JoinColumn(insertable=false))", cu); - - column.setInsertable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - } - - public void testGetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumnWithBooleanElement("updatable"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertTrue(column.getUpdatable()); - } - - public void testSetUpdatable() throws Exception { - ICompilationUnit cu = this.createTestJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - JoinColumnAnnotation column = (JoinColumnAnnotation) attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getUpdatable()); - - column.setUpdatable(false); - assertFalse(column.getUpdatable()); - - assertSourceContains("@JoinColumns(@JoinColumn(updatable=false))", cu); - - column.setUpdatable(null); - assertSourceDoesNotContain("@JoinColumn", cu); - assertSourceDoesNotContain("@JoinColumns", cu); - } - - - public void testAddJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name=\"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.JOIN_COLUMNS)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS))); - } - - public void testAddJoinColumnToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name=\"FOO\")})", cu); - - joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("BAZ"); - assertSourceContains("@JoinColumns({@JoinColumn(name=\"BAZ\"),@JoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"), @JoinColumn(name=\"FOO\")})", cu); - - Iterator<JavaResourceNode> joinColumns = attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - assertEquals("BAZ", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("BAR", ((JoinColumnAnnotation) joinColumns.next()).getName()); - assertEquals("FOO", ((JoinColumnAnnotation) joinColumns.next()).getName()); - - assertNull(attributeResource.getAnnotation(JPA.JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.JOIN_COLUMNS)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS))); - } - - - public void testRemoveJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinColumnAnnotation joinColumn = (JoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@JoinColumns({@JoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\"),@JoinColumn(name=\"FOO\")})", cu); - - attributeResource.removeAnnotation(1, JPA.JOIN_COLUMN, JPA.JOIN_COLUMNS); - assertSourceContains("@JoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", table = \"TABLE\", unique = false, nullable = false, insertable = false, updatable = false, referencedColumnName = \"REF_NAME\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java deleted file mode 100644 index 6f7b41f8c1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JoinTableTests.java +++ /dev/null @@ -1,685 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.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.resource.java.JoinTableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class JoinTableTests extends JavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public JoinTableTests(String name) { - super(name); - } - - private void createJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name() default \"\";" + - "String referencedColumnName() default \"\";" + - "boolean unique() default false;" + - "boolean nullable() default true;" + - "boolean insertable() default true;" + - "boolean updatable() default true;" + - "String columnDefinition() default \"\";" + - "String table() default \"\";"); - - } - - private void createUniqueConstraintAnnotation() throws Exception { - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - } - - private void createJoinTableAnnotation() throws Exception { - createJoinColumnAnnotation(); - createUniqueConstraintAnnotation(); - this.createAnnotationAndMembers("JoinTable", "String name() default \"\"; String catalog() default \"\"; String schema() default \"\";JoinColumn[] joinColumns() default {}; JoinColumn[] inverseJoinColumns() default {}; UniqueConstraint[] uniqueConstraints() default {};"); - } - - private ICompilationUnit createTestJoinTable() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithName() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithSchema() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE); - } - - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(schema=\"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithCatalog() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(catalog=\"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithUniqueConstraints() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithJoinColumns() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(joinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn})"); - } - }); - } - - private ICompilationUnit createTestJoinTableWithInverseJoinColumns() throws Exception { - createJoinTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.JOIN_TABLE, JPA.JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@JoinTable(inverseJoinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@JoinTable(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@JoinTable(catalog=\"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@JoinTable(schema=\"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, table.uniqueConstraintsSize()); - - table.removeUniqueConstraint(1); - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(2, table.uniqueConstraintsSize()); - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - assertEquals("BAZ", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals(1, table.uniqueConstraintsSize()); - assertSourceContains("@JoinTable(uniqueConstraints=@UniqueConstraint(columnNames={\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - assertEquals(0, table.uniqueConstraintsSize()); - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@JoinTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"})})", cu); - } - - public void testJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.joinColumnsSize()); - } - - public void testJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addJoinColumn(0); - table.addJoinColumn(1); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.joinColumnsSize()); - } - - public void testAddJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addJoinColumn(0).setName("FOO"); - table.addJoinColumn(1); - table.addJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"BAR\"),@JoinColumn(name=\"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addJoinColumn(0).setName("FOO"); - - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertEquals("BAR", table.joinColumnAt(1).getName()); - assertNull(table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - - table.removeJoinColumn(1); - assertEquals("FOO", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals(2, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn})", cu); - - table.removeJoinColumn(0); - assertNull(table.joinColumnAt(0).getName()); - assertEquals(1, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns=@JoinColumn)", cu); - - - table.removeJoinColumn(0); - assertEquals(0, table.joinColumnsSize()); - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testMoveJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - table.moveJoinColumn(2, 0); - assertEquals("BAR", table.joinColumnAt(0).getName()); - assertNull(table.joinColumnAt(1).getName()); - assertEquals("FOO", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn, @JoinColumn(name=\"FOO\")})", cu); - } - - public void testMoveJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - JoinColumnAnnotation joinColumn = table.joinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setUnique(Boolean.FALSE); - joinColumn.setNullable(Boolean.FALSE); - joinColumn.setInsertable(Boolean.FALSE); - joinColumn.setUpdatable(Boolean.FALSE); - joinColumn.setColumnDefinition("COLUMN_DEF"); - joinColumn.setTable("TABLE"); - - table.addJoinColumn(0).setName("FOO"); - - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\"), @JoinColumn})", cu); - - - table.moveJoinColumn(0, 2); - assertNull(table.joinColumnAt(0).getName()); - assertEquals("FOO", table.joinColumnAt(1).getName()); - assertEquals("BAR", table.joinColumnAt(2).getName()); - assertEquals(3, table.joinColumnsSize()); - assertSourceContains("@JoinTable(joinColumns={@JoinColumn, @JoinColumn(name=\"FOO\"), @JoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", unique = false, nullable = false, insertable = false, updatable = false, columnDefinition = \"COLUMN_DEF\", table = \"TABLE\")})", cu); - } - - public void testSetJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.joinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.joinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@JoinTable(joinColumns={@JoinColumn(name=\"foo\"), @JoinColumn})", cu); - } - - public void testInverseJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(0, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - - table.addInverseJoinColumn(0); - table.addInverseJoinColumn(1); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testInverseJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.inverseJoinColumnsSize()); - } - - public void testAddInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - table.addInverseJoinColumn(0).setName("FOO"); - table.addInverseJoinColumn(1); - table.addInverseJoinColumn(0).setName("BAR"); - - assertEquals("BAR", table.inverseJoinColumnAt(0).getName()); - assertEquals("FOO", table.inverseJoinColumnAt(1).getName()); - assertNull(table.inverseJoinColumnAt(2).getName()); - assertSourceContains("@JoinTable(inverseJoinColumns={@JoinColumn(name=\"BAR\"),@JoinColumn(name=\"FOO\"), @JoinColumn})", cu); - } - - public void testRemoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(2).setName("FOO"); - - Iterator<JoinColumnAnnotation> inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(1); - assertSourceContains("@JoinTable(inverseJoinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn(name=\"FOO\")})", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceContains("@JoinTable(inverseJoinColumns=@JoinColumn(name=\"FOO\"))", cu); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertFalse(inverseJoinColumns.hasNext()); - - table.removeInverseJoinColumn(0); - assertSourceDoesNotContain("@JoinTable", cu); - } - - public void testMoveInverseJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(0).setName("FOO"); - - Iterator<JoinColumnAnnotation> inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(2, 0); - inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns={@JoinColumn(name=\"BAR\"), @JoinColumn, @JoinColumn(name=\"FOO\")})", cu); - } - - public void testMoveInverseJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - table.addInverseJoinColumn(1).setName("FOO"); - - Iterator<JoinColumnAnnotation> inverseJoinColumns = table.inverseJoinColumns(); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - assertNull(inverseJoinColumns.next().getName()); - - table.moveInverseJoinColumn(0, 2); - inverseJoinColumns = table.inverseJoinColumns(); - assertNull(inverseJoinColumns.next().getName()); - assertEquals("BAR", inverseJoinColumns.next().getName()); - assertEquals("FOO", inverseJoinColumns.next().getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns={@JoinColumn, @JoinColumn(name=\"BAR\"), @JoinColumn(name=\"FOO\")})", cu); - } - - public void testSetInverseJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestJoinTableWithInverseJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JoinTableAnnotation table = (JoinTableAnnotation) attributeResource.getAnnotation(JPA.JOIN_TABLE); - - assertEquals(2, table.inverseJoinColumnsSize()); - - JoinColumnAnnotation joinColumn = table.inverseJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@JoinTable(inverseJoinColumns={@JoinColumn(name=\"foo\"), @JoinColumn})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaCompilationUnitTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaCompilationUnitTests.java deleted file mode 100644 index 955fd27e8e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JpaCompilationUnitTests.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceModel; -import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; -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.jpt.utility.internal.iterators.ArrayIterator; - -public class JpaCompilationUnitTests extends AnnotationTestCase { - - public JpaCompilationUnitTests(String name) { - super(name); - } - - @Override - protected TestJavaProject buildJavaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJpaProject(projectName, autoBuild); // false = no auto-build - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("javax.persistence", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - private ICompilationUnit createTestEntity() throws Exception { - this.createAnnotationAndMembers("Entity", "String name();"); - - 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"); - } - }); - } - - protected JpaCompilationUnit getJpaCompilationUnitResource(ICompilationUnit testCompilationUnit) throws CoreException { - JpaProject jpaProject = ((TestJpaProject) this.javaProject).getJpaProject(); - JpaFile jpaFile = jpaProject.getJpaFile((IFile) testCompilationUnit.getResource()); - JavaResourceModel javaResourceModel = (JavaResourceModel) jpaFile.getResourceModel(); - return javaResourceModel.getJpaCompilationUnit(); - } - - public void testGetPersistentType() throws Exception { - ICompilationUnit compilationUnit = this.createTestEntity(); - JpaCompilationUnit jpaCompilationUnit = getJpaCompilationUnitResource(compilationUnit); - - assertTrue(jpaCompilationUnit.getPersistentType().getMappingAnnotation() instanceof EntityAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java deleted file mode 100644 index 781a0606dd..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JptJavaResourceTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptJavaResourceTests { - - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptJavaResourceTests.class.getName()); - if (all) { - suite.addTestSuite(JpaCompilationUnitTests.class); - } - suite.addTestSuite(JavaResourcePersistentTypeTests.class); - suite.addTestSuite(JavaResourcePersistentAttributeTests.class); - suite.addTestSuite(JPTToolsTests.class); - - suite.addTestSuite(AssociationOverrideTests.class); - suite.addTestSuite(AssociationOverridesTests.class); - suite.addTestSuite(AttributeOverrideTests.class); - suite.addTestSuite(AttributeOverridesTests.class); - suite.addTestSuite(BasicTests.class); - suite.addTestSuite(ColumnTests.class); - suite.addTestSuite(DiscriminatorValueTests.class); - suite.addTestSuite(DiscriminatorColumnTests.class); - suite.addTestSuite(EmbeddableTests.class); - suite.addTestSuite(EmbeddedTests.class); - suite.addTestSuite(EmbeddedIdTests.class); - suite.addTestSuite(EntityTests.class); - suite.addTestSuite(EnumeratedTests.class); - suite.addTestSuite(GeneratedValueTests.class); - suite.addTestSuite(IdClassTests.class); - suite.addTestSuite(IdTests.class); - suite.addTestSuite(InheritanceTests.class); - suite.addTestSuite(JoinColumnTests.class); - suite.addTestSuite(JoinColumnsTests.class); - suite.addTestSuite(JoinTableTests.class); - suite.addTestSuite(LobTests.class); - suite.addTestSuite(ManyToManyTests.class); - suite.addTestSuite(ManyToOneTests.class); - suite.addTestSuite(MapKeyTests.class); - suite.addTestSuite(MappedSuperclassTests.class); - suite.addTestSuite(NamedNativeQueryTests.class); - suite.addTestSuite(NamedNativeQueriesTests.class); - suite.addTestSuite(NamedQueryTests.class); - suite.addTestSuite(NamedQueriesTests.class); - suite.addTestSuite(OneToManyTests.class); - suite.addTestSuite(OneToOneTests.class); - suite.addTestSuite(OrderByTests.class); - suite.addTestSuite(PrimaryKeyJoinColumnTests.class); - suite.addTestSuite(PrimaryKeyJoinColumnsTests.class); - suite.addTestSuite(QueryHintTests.class); - suite.addTestSuite(SecondaryTableTests.class); - suite.addTestSuite(SecondaryTablesTests.class); - suite.addTestSuite(SequenceGeneratorTests.class); - suite.addTestSuite(TableGeneratorTests.class); - suite.addTestSuite(TableTests.class); - suite.addTestSuite(TemporalTests.class); - suite.addTestSuite(TransientTests.class); - suite.addTestSuite(VersionTests.class); - - return suite; - } - - private JptJavaResourceTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java deleted file mode 100644 index da2298d6aa..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/LobTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.utility.internal.iterators.ArrayIterator; - -public class LobTests extends JavaResourceModelTestCase { - - public LobTests(String name) { - super(name); - } - - private ICompilationUnit createTestLob() throws Exception { - this.createAnnotationAndMembers("Lob", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.LOB); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Lob"); - } - }); - } - - public void testLob() throws Exception { - ICompilationUnit cu = this.createTestLob(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - LobAnnotation lob = (LobAnnotation) attributeResource.getAnnotation(JPA.LOB); - assertNotNull(lob); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java deleted file mode 100644 index fd6b1a3c2a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToManyTests.java +++ /dev/null @@ -1,406 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -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.utility.internal.iterators.ArrayIterator; - -public class ManyToManyTests extends JavaResourceModelTestCase { - - public ManyToManyTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToMany() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "FetchType fetch() default FetchType.LAZY; CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithFetch() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "FetchType fetch() default FetchType.LAZY;"); - this.createEnumAndMembers("FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(fetch=FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithTargetEntity() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "Class targetEntity() default void.class; "); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(targetEntity=AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMappedBy() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "String mappedBy() default\"\";"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(mappedBy=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithCascade() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade=CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithMultipleCascade() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade={CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToManyWithDuplicateCascade() throws Exception { - this.createAnnotationAndMembers("ManyToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToMany(cascade={CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToMany() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertNotNull(manyToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToMany.getFetch()); - - assertSourceContains("@ManyToMany(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(FetchType.EAGER, manyToMany.getFetch()); - - manyToMany.setFetch(null); - assertNull(manyToMany.getFetch()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity=Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(TYPE_NAME, manyToMany.getTargetEntity()); - - manyToMany.setTargetEntity(null); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToMany.getFullyQualifiedTargetEntity()); - - manyToMany.setTargetEntity("Foo"); - - assertSourceContains("@ManyToMany(targetEntity=Foo.class)", cu); - - assertEquals("Foo", manyToMany.getTargetEntity()); - - assertEquals("Foo", manyToMany.getFullyQualifiedTargetEntity()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals(null, manyToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertNull(manyToMany.getMappedBy()); - manyToMany.setMappedBy("bar"); - assertEquals("bar", manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany(mappedBy=\"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertEquals("foo", manyToMany.getMappedBy()); - - manyToMany.setMappedBy(null); - assertNull(manyToMany.getMappedBy()); - - assertSourceContains("@ManyToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertSourceContains("@ManyToMany(cascade=ALL)", cu); - - assertTrue(manyToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(true); - assertSourceContains("@ManyToMany(cascade=MERGE)", cu); - - assertTrue(manyToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadePersist()); - - manyToMany.setCascadePersist(true); - assertSourceContains("@ManyToMany(cascade=PERSIST)", cu); - - assertTrue(manyToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeRemove(true); - assertSourceContains("@ManyToMany(cascade=REMOVE)", cu); - - assertTrue(manyToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertFalse(manyToMany.isCascadeRefresh()); - - manyToMany.setCascadeRefresh(true); - assertSourceContains("@ManyToMany(cascade=REFRESH)", cu); - - assertTrue(manyToMany.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeAll()); - - manyToMany.setCascadeAll(true); - assertTrue(manyToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToMany(cascade=CascadeType.ALL)", cu); - - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToMany.setCascadeAll(false); - assertFalse(manyToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); //TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToMany.isCascadeMerge()); - - manyToMany.setCascadeMerge(false); - assertFalse(manyToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToManyAnnotation manyToMany = (ManyToManyAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_MANY); - assertTrue(manyToMany.isCascadeMerge()); - assertTrue(manyToMany.isCascadeRemove()); - - manyToMany.setCascadeMerge(false); - assertSourceContains("@ManyToMany(cascade=REMOVE)", cu); - - manyToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java deleted file mode 100644 index 5355950212..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/ManyToOneTests.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -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.ManyToOneAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class ManyToOneTests extends JavaResourceModelTestCase { - - public ManyToOneTests(String name) { - super(name); - } - - private ICompilationUnit createTestManyToOne() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "FetchType fetch() default FetchType.LAZY; CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithFetch() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "FetchType fetch() default FetchType.LAZY;"); - this.createEnumAndMembers("FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(fetch=FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithTargetEntity() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "Class targetEntity() default void.class;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(targetEntity=AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithOptional() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(optional=true)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithCascade() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade=CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithMultipleCascade() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade={CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestManyToOneWithDuplicateCascade() throws Exception { - this.createAnnotationAndMembers("ManyToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MANY_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@ManyToOne(cascade={CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testManyToOne() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertNotNull(manyToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, manyToOne.getFetch()); - - assertSourceContains("@ManyToOne(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(FetchType.EAGER, manyToOne.getFetch()); - - manyToOne.setFetch(null); - assertNull(manyToOne.getFetch()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity=Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(TYPE_NAME, manyToOne.getTargetEntity()); - - manyToOne.setTargetEntity(null); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, manyToOne.getFullyQualifiedTargetEntity()); - - manyToOne.setTargetEntity("Foo"); - - assertSourceContains("@ManyToOne(targetEntity=Foo.class)", cu); - - assertEquals("Foo", manyToOne.getTargetEntity()); - - assertEquals("Foo", manyToOne.getFullyQualifiedTargetEntity());//bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, manyToOne.getOptional()); - - assertSourceContains("@ManyToOne(optional=false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertEquals(Boolean.TRUE, manyToOne.getOptional()); - - manyToOne.setOptional(null); - assertNull(manyToOne.getOptional()); - - assertSourceContains("@ManyToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertSourceContains("@ManyToOne(cascade=ALL)", cu); - - assertTrue(manyToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(true); - assertSourceContains("@ManyToOne(cascade=MERGE)", cu); - - assertTrue(manyToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadePersist()); - - manyToOne.setCascadePersist(true); - assertSourceContains("@ManyToOne(cascade=PERSIST)", cu); - - assertTrue(manyToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeRemove(true); - assertSourceContains("@ManyToOne(cascade=REMOVE)", cu); - - assertTrue(manyToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestManyToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertFalse(manyToOne.isCascadeRefresh()); - - manyToOne.setCascadeRefresh(true); - assertSourceContains("@ManyToOne(cascade=REFRESH)", cu); - - assertTrue(manyToOne.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeAll()); - - manyToOne.setCascadeAll(true); - assertTrue(manyToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@ManyToOne(cascade=CascadeType.ALL)", cu); - - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - manyToOne.setCascadeAll(false); - assertFalse(manyToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(manyToOne.isCascadeMerge()); - - manyToOne.setCascadeMerge(false); - assertFalse(manyToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestManyToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - ManyToOneAnnotation manyToOne = (ManyToOneAnnotation) attributeResource.getMappingAnnotation(JPA.MANY_TO_ONE); - assertTrue(manyToOne.isCascadeMerge()); - assertTrue(manyToOne.isCascadeRemove()); - - manyToOne.setCascadeMerge(false); - assertSourceContains("@ManyToOne(cascade=REMOVE)", cu); - - manyToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java deleted file mode 100644 index 3c8c893276..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MapKeyTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.MapKeyAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class MapKeyTests extends JavaResourceModelTestCase { - - public MapKeyTests(String name) { - super(name); - } - - private ICompilationUnit createTestMapKey() throws Exception { - this.createAnnotationAndMembers("MapKey", "String name() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAP_KEY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKey"); - } - }); - } - - private ICompilationUnit createTestMapKeyWithName() throws Exception { - this.createAnnotationAndMembers("MapKey", "String name() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAP_KEY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@MapKey(name=\"key\")"); - } - }); - } - - public void testMapKey() throws Exception { - ICompilationUnit cu = this.createTestMapKey(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - assertNotNull(mapKey); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestMapKeyWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - assertEquals("key", mapKey.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestMapKey(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - MapKeyAnnotation mapKey = (MapKeyAnnotation) attributeResource.getAnnotation(JPA.MAP_KEY); - - mapKey.setName("foo"); - - assertSourceContains("@MapKey(name=\"foo\")", cu); - - mapKey.setName(null); - - assertSourceContains("@MapKey", cu); - assertSourceDoesNotContain("@MapKey(name=\"foo\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java deleted file mode 100644 index 4fa66cf2cc..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/MappedSuperclassTests.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.EntityAnnotation; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.MappedSuperclassAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class MappedSuperclassTests extends JavaResourceModelTestCase { - - public MappedSuperclassTests(String name) { - super(name); - } - - private ICompilationUnit createTestMappedSuperclass() throws Exception { - this.createAnnotationAndMembers("MappedSuperclass", ""); - 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 createTestMappedSuperclassAndEntity() throws Exception { - this.createAnnotationAndMembers("MappedSuperclass", ""); - this.createAnnotationAndMembers("Entity", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.MAPPED_SUPERCLASS, JPA.ENTITY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@MappedSuperclass"); - sb.append("@Entity"); - } - }); - } - - public void testMappedSuperclass() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof MappedSuperclassAnnotation); - } - - public void testMappedSuperclassAndEntity() throws Exception { - ICompilationUnit cu = this.createTestMappedSuperclassAndEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - JavaResourceNode mappingAnnotation = typeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof EntityAnnotation); - - MappedSuperclassAnnotation mappedSuperclass = (MappedSuperclassAnnotation) typeResource.getMappingAnnotation(JPA.MAPPED_SUPERCLASS); - assertNotNull(mappedSuperclass); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java deleted file mode 100644 index 0afd0c7bf1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueriesTests.java +++ /dev/null @@ -1,441 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -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.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class NamedNativeQueriesTests extends JavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - private static final String QUERY_RESULT_CLASS = "Result"; - private static final String QUERY_RESULT_SET_MAPPING = "resultSetMapping"; - - public NamedNativeQueriesTests(String name) { - super(name); - } - - private void createNamedNativeQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedNativeQuery", "String name(); " + - "String query();" + - "QueryHint[] hints() default{};"); - } - - private void createNamedNativeQueriesAnnotation() throws Exception { - createNamedNativeQueryAnnotation(); - this.createAnnotationAndMembers("NamedNativeQueries", - "NamedNativeQuery[] value();"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", "String name(); " + - "String value();"); - } - - private ICompilationUnit createTestNamedNativeQueries() throws Exception { - createNamedNativeQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery)"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithName() throws Exception { - return createTestNamedNativeQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedNativeQueryWithQuery() throws Exception { - return createTestNamedNativeQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultSetMapping() throws Exception { - return createTestNamedNativeQueryWithStringElement("resultSetMapping", QUERY_RESULT_SET_MAPPING); - } - - - private ICompilationUnit createTestNamedNativeQueryWithStringElement(final String elementName, final String value) throws Exception { - createNamedNativeQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(" + elementName + "=\"" + value + "\"))"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultClass() throws Exception { - createNamedNativeQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(resultClass=" + QUERY_RESULT_CLASS + ".class))"); - } - }); - } - private ICompilationUnit createTestNamedNativeQueryWithQueryHints() throws Exception { - createNamedNativeQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERIES, JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQueries(@NamedNativeQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint}))"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQuery() throws Exception { - createNamedNativeQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(name=\"foo\", query=\"bar\", hints=@QueryHint(name=\"BAR\", value=\"FOO\"), resultClass=Foo.class, resultSetMapping=\"mapping\")"); - } - }); - } - - public void testNamedNativeQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedNativeQuery(name=\"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedNativeQuery(query=\"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - } - - public void testSetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - - namedQuery.setResultClass("foo"); - assertEquals("foo", namedQuery.getResultClass()); - - assertSourceContains("@NamedNativeQuery(resultClass=foo.class)", cu); - - namedQuery.setResultClass(null); - assertNull(namedQuery.getResultClass()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertNotNull(namedQuery.getResultClass()); - assertEquals("Result", namedQuery.getFullyQualifiedResultClass());//bug 196200 changed this - - namedQuery.setResultClass(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, namedQuery.getFullyQualifiedResultClass()); - assertSourceContains("@NamedNativeQuery(resultClass=" + TYPE_NAME + ".class)", cu); - } - - public void testGetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - } - - public void testSetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - - namedQuery.setResultSetMapping("foo"); - assertEquals("foo", namedQuery.getResultSetMapping()); - - assertSourceContains("@NamedNativeQuery(resultSetMapping=\"foo\")", cu); - - namedQuery.setResultSetMapping(null); - assertNull(namedQuery.getResultSetMapping()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedNativeQuery(hints={@QueryHint(name=\"BAR\"),@QueryHint(name=\"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints={@QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")}))", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints=@QueryHint(name=\"BAR\", value=\"FOO\")))", cu); - - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint, @QueryHint(name=\"BAZ\")}))", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueriesAnnotation namedQueries = (NamedNativeQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES); - NamedNativeQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQueries(@NamedNativeQuery(hints={@QueryHint, @QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")}))", cu); - } - - public void testAddNamedNativeQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES))); - } - - public void testAddNamedNativeQueryToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name=\"BAR\")})", cu); - - namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAZ"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name=\"BAZ\"),@NamedNativeQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"), @NamedNativeQuery(name=\"BAR\")})", cu); - - Iterator<JavaResourceNode> namedQueries = typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - assertEquals("BAZ", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - assertEquals("foo", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - assertEquals("BAR", ((NamedNativeQueryAnnotation) namedQueries.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERIES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES))); - } - - public void testRemoveNamedNativeQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedNativeQueries({@NamedNativeQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\"),@NamedNativeQuery(name=\"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.NAMED_NATIVE_QUERY, JPA.NAMED_NATIVE_QUERIES); - assertSourceContains("@NamedNativeQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"), resultClass = Foo.class, resultSetMapping = \"mapping\")", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java deleted file mode 100644 index 00529df8d2..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedNativeQueryTests.java +++ /dev/null @@ -1,355 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedNativeQueryAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class NamedNativeQueryTests extends JavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - private static final String QUERY_RESULT_CLASS = "Result"; - private static final String QUERY_RESULT_SET_MAPPING = "resultSetMapping"; - - public NamedNativeQueryTests(String name) { - super(name); - } - - private void createNamedNativeQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedNativeQuery", "String name(); " + - "String query();" + - "QueryHint[] hints() default{};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", "String name(); " + - "String value();"); - } - - private ICompilationUnit createTestNamedNativeQuery() throws Exception { - createNamedNativeQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithName() throws Exception { - return createTestNamedNativeQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedNativeQueryWithQuery() throws Exception { - return createTestNamedNativeQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultSetMapping() throws Exception { - return createTestNamedNativeQueryWithStringElement("resultSetMapping", QUERY_RESULT_SET_MAPPING); - } - - - private ICompilationUnit createTestNamedNativeQueryWithStringElement(final String elementName, final String value) throws Exception { - createNamedNativeQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(" + elementName + "=\"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestNamedNativeQueryWithResultClass() throws Exception { - createNamedNativeQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(resultClass=" + QUERY_RESULT_CLASS + ".class)"); - } - }); - } - private ICompilationUnit createTestNamedNativeQueryWithQueryHints() throws Exception { - createNamedNativeQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_NATIVE_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedNativeQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint})"); - } - }); - } - - public void testNamedNativeQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedNativeQuery(name=\"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedNativeQuery(query=\"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - } - - public void testSetResultClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_CLASS, namedQuery.getResultClass()); - - namedQuery.setResultClass("foo"); - assertEquals("foo", namedQuery.getResultClass()); - - assertSourceContains("@NamedNativeQuery(resultClass=foo.class)", cu); - - namedQuery.setResultClass(null); - assertNull(namedQuery.getResultClass()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testGetFullyQualifiedClass() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultClass(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertNotNull(namedQuery.getResultClass()); - assertEquals("Result", namedQuery.getFullyQualifiedResultClass());//bug 196200 changed this - - namedQuery.setResultClass(TYPE_NAME); - - assertEquals(FULLY_QUALIFIED_TYPE_NAME, namedQuery.getFullyQualifiedResultClass()); - assertSourceContains("@NamedNativeQuery(resultClass=" + TYPE_NAME + ".class)", cu); - } - - public void testGetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - } - - public void testSetResultSetMapping() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithResultSetMapping(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - assertEquals(QUERY_RESULT_SET_MAPPING, namedQuery.getResultSetMapping()); - - namedQuery.setResultSetMapping("foo"); - assertEquals("foo", namedQuery.getResultSetMapping()); - - assertSourceContains("@NamedNativeQuery(resultSetMapping=\"foo\")", cu); - - namedQuery.setResultSetMapping(null); - assertNull(namedQuery.getResultSetMapping()); - - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - assertEquals(2, namedQuery.hintsSize()); - } - - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedNativeQuery(hints={@QueryHint(name=\"BAR\"),@QueryHint(name=\"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints={@QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")})", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints=@QueryHint(name=\"BAR\", value=\"FOO\"))", cu); - - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedNativeQuery", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint, @QueryHint(name=\"BAZ\")})", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedNativeQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedNativeQueryAnnotation namedQuery = (NamedNativeQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_NATIVE_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedNativeQuery(hints={@QueryHint, @QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java deleted file mode 100644 index 77208998b3..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueriesTests.java +++ /dev/null @@ -1,351 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class NamedQueriesTests extends JavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - - public NamedQueriesTests(String name) { - super(name); - } - - private void createNamedQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedQuery", "String name(); " + - "String query();" + - "QueryHint[] hints() default{};"); - } - - private void createNamedQueriesAnnotation() throws Exception { - createNamedQueryAnnotation(); - this.createAnnotationAndMembers("NamedQueries", - "NamedQuery[] value();"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", "String name(); " + - "String value();"); - } - - private ICompilationUnit createTestNamedQueries() throws Exception { - createNamedQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERIES, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery)"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithName() throws Exception { - return createTestNamedQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedQueryWithQuery() throws Exception { - return createTestNamedQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedQueryWithStringElement(final String elementName, final String value) throws Exception { - createNamedQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERIES, JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery(" + elementName + "=\"" + value + "\"))"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - createNamedQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERIES, JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQueries(@NamedQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint}))"); - } - }); - } - - - private ICompilationUnit createTestNamedQuery() throws Exception { - createNamedQueriesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(name=\"foo\", query=\"bar\", hints=@QueryHint(name=\"BAR\", value=\"FOO\"))"); - } - }); - } - - public void testNamedQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedQuery(name=\"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedQuery", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedQuery(query=\"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedQuery", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueries(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - namedQuery.addHint(0).setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - - assertSourceContains("@NamedQuery(hints={@QueryHint(name=\"BAR\"),@QueryHint(name=\"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints={@QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")}))", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints=@QueryHint(name=\"BAR\", value=\"FOO\")))", cu); - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedQueries", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint, @QueryHint(name=\"BAZ\")}))", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueriesAnnotation namedQueries = (NamedQueriesAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERIES); - NamedQueryAnnotation namedQuery = namedQueries.nestedAnnotations().next(); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQueries(@NamedQuery(hints={@QueryHint, @QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")}))", cu); - } - - public void testAddNamedQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\")),@NamedQuery(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.NAMED_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_QUERIES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES))); - } - - public void testAddNamedQueryToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\")),@NamedQuery(name=\"BAR\")})", cu); - - - namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(0, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAZ"); - assertSourceContains("@NamedQueries({@NamedQuery(name=\"BAZ\"),@NamedQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\")), @NamedQuery(name=\"BAR\")})", cu); - - Iterator<JavaResourceNode> namedQueries = typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - assertEquals("BAZ", ((NamedQueryAnnotation) namedQueries.next()).getName()); - assertEquals("foo", ((NamedQueryAnnotation) namedQueries.next()).getName()); - assertEquals("BAR", ((NamedQueryAnnotation) namedQueries.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.NAMED_QUERY)); - assertNotNull(typeResource.getAnnotation(JPA.NAMED_QUERIES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.NAMED_QUERY, JPA.NAMED_QUERIES))); - } - - public void testRemoveNamedQueryCopyExisting() throws Exception { - ICompilationUnit cu = createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.addAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - namedQuery.setName("BAR"); - assertSourceContains("@NamedQueries({@NamedQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\")),@NamedQuery(name=\"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.NAMED_QUERY, JPA.NAMED_QUERIES); - assertSourceContains("@NamedQuery(name=\"foo\", query = \"bar\", hints = @QueryHint(name=\"BAR\", value = \"FOO\"))", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java deleted file mode 100644 index 51fd90e940..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/NamedQueryTests.java +++ /dev/null @@ -1,273 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class NamedQueryTests extends JavaResourceModelTestCase { - - private static final String QUERY_NAME = "myQuery"; - private static final String QUERY_QUERY = "SELECT name FROM Employee"; - - public NamedQueryTests(String name) { - super(name); - } - - private void createNamedQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedQuery", "String name(); " + - "String query();" + - "QueryHint[] hints() default{};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", "String name(); " + - "String value();"); - } - - private ICompilationUnit createTestNamedQuery() throws Exception { - createNamedQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithName() throws Exception { - return createTestNamedQueryWithStringElement("name", QUERY_NAME); - } - - private ICompilationUnit createTestNamedQueryWithQuery() throws Exception { - return createTestNamedQueryWithStringElement("query", QUERY_QUERY); - } - - private ICompilationUnit createTestNamedQueryWithStringElement(final String elementName, final String value) throws Exception { - createNamedQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERY); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(" + elementName + "=\"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - createNamedQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint})"); - } - }); - } - - public void testNamedQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertNotNull(namedQuery); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_NAME, namedQuery.getName()); - - namedQuery.setName("foo"); - assertEquals("foo", namedQuery.getName()); - - assertSourceContains("@NamedQuery(name=\"foo\")", cu); - - namedQuery.setName(null); - assertNull(namedQuery.getName()); - - assertSourceDoesNotContain("@NamedQuery", cu); - } - - public void testGetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - } - - public void testSetQuery() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - assertEquals(QUERY_QUERY, namedQuery.getQuery()); - - namedQuery.setQuery("foo"); - assertEquals("foo", namedQuery.getQuery()); - - assertSourceContains("@NamedQuery(query=\"foo\")", cu); - - namedQuery.setQuery(null); - assertNull(namedQuery.getQuery()); - - assertSourceDoesNotContain("@NamedQuery", cu); - } - - public void testHints() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - assertEquals(0, namedQuery.hintsSize()); - } - - public void testHints2() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - namedQuery.addHint(0); - namedQuery.addHint(1); - - assertEquals(2, namedQuery.hintsSize()); - } - - public void testHints3() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - assertEquals(2, namedQuery.hintsSize()); - - ListIterator<QueryHintAnnotation> iterator = namedQuery.hints(); - assertEquals("BAR", iterator.next().getName()); - assertNull(iterator.next().getName()); - } - - public void testAddHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQuery(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - - namedQuery.addHint(0).setName("FOO"); - namedQuery.addHint(1); - QueryHintAnnotation queryHint = namedQuery.addHint(0); - queryHint.setName("BAR"); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals("FOO", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertSourceContains("@NamedQuery(hints={@QueryHint(name=\"BAR\"),@QueryHint(name=\"FOO\"), @QueryHint})", cu); - } - - public void testRemoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.removeHint(2); - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertEquals(2, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints={@QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")})", cu); - - namedQuery.removeHint(0); - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertEquals(1, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints=@QueryHint(name=\"BAR\", value=\"FOO\"))", cu); - - namedQuery.removeHint(0); - assertEquals(0, namedQuery.hintsSize()); - assertSourceDoesNotContain("@NamedQuery", cu); - } - - public void testMoveHint() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(2, 0); - - assertEquals("BAR", namedQuery.hintAt(0).getName()); - assertNull(namedQuery.hintAt(1).getName()); - assertEquals("BAZ", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints={@QueryHint(name=\"BAR\", value=\"FOO\"), @QueryHint, @QueryHint(name=\"BAZ\")})", cu); - } - - public void testMoveHint2() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - namedQuery.addHint(0).setName("BAZ"); - - assertEquals("BAZ", namedQuery.hintAt(0).getName()); - assertEquals("BAR", namedQuery.hintAt(1).getName()); - assertNull(namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - - namedQuery.moveHint(0, 2); - - assertNull(namedQuery.hintAt(0).getName()); - assertEquals("BAZ", namedQuery.hintAt(1).getName()); - assertEquals("BAR", namedQuery.hintAt(2).getName()); - assertEquals(3, namedQuery.hintsSize()); - assertSourceContains("@NamedQuery(hints={@QueryHint, @QueryHint(name=\"BAZ\"), @QueryHint(name=\"BAR\", value=\"FOO\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java deleted file mode 100644 index eda0b0e0e6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToManyTests.java +++ /dev/null @@ -1,408 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -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.OneToManyAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class OneToManyTests extends JavaResourceModelTestCase { - - public OneToManyTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToMany() throws Exception { - this.createAnnotationAndMembers("OneToMany", "FetchType fetch() default FetchType.LAZY; CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithFetch() throws Exception { - this.createAnnotationAndMembers("OneToMany", "FetchType fetch() default FetchType.LAZY;"); - this.createEnumAndMembers("FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(fetch=FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithTargetEntity() throws Exception { - this.createAnnotationAndMembers("OneToMany", "Class targetEntity() default void.class;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(targetEntity=AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMappedBy() throws Exception { - this.createAnnotationAndMembers("OneToMany", "String mappedBy() default\"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(mappedBy=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithCascade() throws Exception { - this.createAnnotationAndMembers("OneToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade=CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithMultipleCascade() throws Exception { - this.createAnnotationAndMembers("OneToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade={CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToManyWithDuplicateCascade() throws Exception { - this.createAnnotationAndMembers("OneToMany", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_MANY, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToMany(cascade={CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToMany() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertNotNull(oneToMany); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToMany.getFetch()); - - assertSourceContains("@OneToMany(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(FetchType.EAGER, oneToMany.getFetch()); - - oneToMany.setFetch(null); - assertNull(oneToMany.getFetch()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity=Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(TYPE_NAME, oneToMany.getTargetEntity()); - - oneToMany.setTargetEntity(null); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToMany.getFullyQualifiedTargetEntity()); - - oneToMany.setTargetEntity("Foo"); - - assertSourceContains("@OneToMany(targetEntity=Foo.class)", cu); - - assertEquals("Foo", oneToMany.getTargetEntity()); - - assertEquals("Foo", oneToMany.getFullyQualifiedTargetEntity()); //bug 196200 changed this - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - } - - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals(null, oneToMany.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertNull(oneToMany.getMappedBy()); - oneToMany.setMappedBy("bar"); - assertEquals("bar", oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany(mappedBy=\"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertEquals("foo", oneToMany.getMappedBy()); - - oneToMany.setMappedBy(null); - assertNull(oneToMany.getMappedBy()); - - assertSourceContains("@OneToMany", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertSourceContains("@OneToMany(cascade=ALL)", cu); - - assertTrue(oneToMany.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(true); - assertSourceContains("@OneToMany(cascade=MERGE)", cu); - - assertTrue(oneToMany.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadePersist()); - - oneToMany.setCascadePersist(true); - assertSourceContains("@OneToMany(cascade=PERSIST)", cu); - - assertTrue(oneToMany.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeRemove(true); - assertSourceContains("@OneToMany(cascade=REMOVE)", cu); - - assertTrue(oneToMany.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToMany(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertFalse(oneToMany.isCascadeRefresh()); - - oneToMany.setCascadeRefresh(true); - assertSourceContains("@OneToMany(cascade=REFRESH)", cu); - - assertTrue(oneToMany.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeAll()); - - oneToMany.setCascadeAll(true); - assertTrue(oneToMany.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToMany(cascade=CascadeType.ALL)", cu); - - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToMany.setCascadeAll(false); - assertFalse(oneToMany.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToMany.isCascadeMerge()); - - oneToMany.setCascadeMerge(false); - assertFalse(oneToMany.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToManyWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToManyAnnotation oneToMany = (OneToManyAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_MANY); - assertTrue(oneToMany.isCascadeMerge()); - assertTrue(oneToMany.isCascadeRemove()); - - oneToMany.setCascadeMerge(false); - assertSourceContains("@OneToMany(cascade=REMOVE)", cu); - - oneToMany.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java deleted file mode 100644 index dd0e044629..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OneToOneTests.java +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.FetchType; -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.utility.internal.iterators.ArrayIterator; - -public class OneToOneTests extends JavaResourceModelTestCase { - - public OneToOneTests(String name) { - super(name); - } - - private ICompilationUnit createTestOneToOne() throws Exception { - this.createAnnotationAndMembers("OneToOne", "FetchType fetch() default FetchType.LAZY; CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithFetch() throws Exception { - this.createAnnotationAndMembers("OneToOne", "FetchType fetch() default FetchType.LAZY;"); - this.createEnumAndMembers("FetchType", "EAGER, LAZY"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE, JPA.FETCH_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(fetch=FetchType.EAGER)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithTargetEntity() throws Exception { - this.createAnnotationAndMembers("OneToOne", "Class targetEntity() default void.class;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(targetEntity=AnnotationTestType.class)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithOptional() throws Exception { - this.createAnnotationAndMembers("OneToOne", "boolean optional() default true;"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(optional=true)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMappedBy() throws Exception { - this.createAnnotationAndMembers("OneToOne", "String mappedBy() default\"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(mappedBy=\"foo\")"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithCascade() throws Exception { - this.createAnnotationAndMembers("OneToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade=CascadeType.ALL)"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithMultipleCascade() throws Exception { - this.createAnnotationAndMembers("OneToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade={CascadeType.MERGE, CascadeType.REMOVE})"); - } - }); - } - - private ICompilationUnit createTestOneToOneWithDuplicateCascade() throws Exception { - this.createAnnotationAndMembers("OneToOne", "CascadeType[] cascade() default = {};"); - this.createEnumAndMembers("CascadeType", "ALL, PERSIST, MERGE, REMOVE, REFRESH"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ONE_TO_ONE, JPA.CASCADE_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OneToOne(cascade={CascadeType.MERGE, CascadeType.MERGE})"); - } - }); - } - - public void testOneToOne() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertNotNull(oneToOne); - } - - public void testGetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - } - - public void testSetFetch() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(FetchType.LAZY); - assertEquals(FetchType.LAZY, oneToOne.getFetch()); - - assertSourceContains("@OneToOne(fetch=LAZY)", cu); - } - - public void testSetFetchNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithFetch(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(FetchType.EAGER, oneToOne.getFetch()); - - oneToOne.setFetch(null); - assertNull(oneToOne.getFetch()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("fetch", cu); - } - - - public void testGetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - } - - public void testSetTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity=Foo.class)", cu); - } - - public void testSetTargetEntityNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(TYPE_NAME, oneToOne.getTargetEntity()); - - oneToOne.setTargetEntity(null); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("targetEntity", cu); - } - - - public void testGetFullyQualifiedTargetEntity() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithTargetEntity(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(FULLY_QUALIFIED_TYPE_NAME, oneToOne.getFullyQualifiedTargetEntity()); - - oneToOne.setTargetEntity("Foo"); - - assertSourceContains("@OneToOne(targetEntity=Foo.class)", cu); - - assertEquals("Foo", oneToOne.getTargetEntity()); - - assertEquals("Foo", oneToOne.getFullyQualifiedTargetEntity()); //bug 196200 changed this - } - - public void testGetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - } - - public void testSetOptional() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(Boolean.FALSE); - assertEquals(Boolean.FALSE, oneToOne.getOptional()); - - assertSourceContains("@OneToOne(optional=false)", cu); - } - - public void testSetOptionalNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithOptional(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(Boolean.TRUE, oneToOne.getOptional()); - - oneToOne.setOptional(null); - assertNull(oneToOne.getOptional()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("optional", cu); - } - - public void testGetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - } - - public void testGetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals(null, oneToOne.getMappedBy()); - } - - public void testSetMappedBy() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertNull(oneToOne.getMappedBy()); - oneToOne.setMappedBy("bar"); - assertEquals("bar", oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne(mappedBy=\"bar\")", cu); - } - - public void testSetMappedByNull() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMappedBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertEquals("foo", oneToOne.getMappedBy()); - - oneToOne.setMappedBy(null); - assertNull(oneToOne.getMappedBy()); - - assertSourceContains("@OneToOne", cu); - assertSourceDoesNotContain("mappedBy", cu); - } - - public void testSetCascadeAll() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertSourceContains("@OneToOne(cascade=ALL)", cu); - - assertTrue(oneToOne.isCascadeAll()); - } - - public void testSetCascadeMerge() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(true); - assertSourceContains("@OneToOne(cascade=MERGE)", cu); - - assertTrue(oneToOne.isCascadeMerge()); - } - - public void testSetCascadePersist() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadePersist()); - - oneToOne.setCascadePersist(true); - assertSourceContains("@OneToOne(cascade=PERSIST)", cu); - - assertTrue(oneToOne.isCascadePersist()); - } - - public void testSetCascadeRemove() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeRemove(true); - assertSourceContains("@OneToOne(cascade=REMOVE)", cu); - - assertTrue(oneToOne.isCascadeRemove()); - } - - public void testSetCascadeRefresh() throws Exception { - ICompilationUnit cu = this.createTestOneToOne(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertFalse(oneToOne.isCascadeRefresh()); - - oneToOne.setCascadeRefresh(true); - assertSourceContains("@OneToOne(cascade=REFRESH)", cu); - - assertTrue(oneToOne.isCascadeRefresh()); - } - - public void testCascadeMoreThanOnce() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeAll()); - - oneToOne.setCascadeAll(true); - assertTrue(oneToOne.isCascadeAll()); - //a second CascadeType.All should not have been added - assertSourceContains("@OneToOne(cascade=CascadeType.ALL)", cu); - - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - - //test setting cascadeAll to false again, should just do nothing - oneToOne.setCascadeAll(false); - assertFalse(oneToOne.isCascadeAll()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testDuplicateCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithDuplicateCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false);//TODO should the resource model handle this and remove both MERGE - //settings instead of having to set it false twice? - assertTrue(oneToOne.isCascadeMerge()); - - oneToOne.setCascadeMerge(false); - assertFalse(oneToOne.isCascadeMerge()); - - assertSourceDoesNotContain("cascade", cu); - } - - public void testMultipleCascade() throws Exception { - ICompilationUnit cu = this.createTestOneToOneWithMultipleCascade(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OneToOneAnnotation oneToOne = (OneToOneAnnotation) attributeResource.getMappingAnnotation(JPA.ONE_TO_ONE); - assertTrue(oneToOne.isCascadeMerge()); - assertTrue(oneToOne.isCascadeRemove()); - - oneToOne.setCascadeMerge(false); - assertSourceContains("@OneToOne(cascade=REMOVE)", cu); - - oneToOne.setCascadeRemove(false); - assertSourceDoesNotContain("cascade", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java deleted file mode 100644 index e0c6799995..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/OrderByTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.OrderByAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class OrderByTests extends JavaResourceModelTestCase { - - public OrderByTests(String name) { - super(name); - } - - private ICompilationUnit createTestOrderBy() throws Exception { - this.createAnnotationAndMembers("OrderBy", "String value() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ORDER_BY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderBy"); - } - }); - } - - private ICompilationUnit createTestOrderByWithValue() throws Exception { - this.createAnnotationAndMembers("OrderBy", "String value() default \"\";"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ORDER_BY); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@OrderBy(value=\"key\")"); - } - }); - } - - public void testOrderBy() throws Exception { - ICompilationUnit cu = this.createTestOrderBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - assertNotNull(orderBy); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestOrderByWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - assertEquals("key", orderBy.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestOrderBy(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - OrderByAnnotation orderBy = (OrderByAnnotation) attributeResource.getAnnotation(JPA.ORDER_BY); - - orderBy.setValue("foo"); - - assertSourceContains("@OrderBy(\"foo\")", cu); - - orderBy.setValue(null); - - assertSourceContains("@OrderBy", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java deleted file mode 100644 index 40819510d0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnTests.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class PrimaryKeyJoinColumnTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public PrimaryKeyJoinColumnTests(String name) { - super(name); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", - "String name() default \"\"; " + - "String referencedColumnName() default \"\"; " + - "String columnDefinition() default \"\"; "); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumn() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithName() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(name=\"" + COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithReferencedColumnName() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(referencedColumnName=\"" + COLUMN_REFERENCED_COLUMN_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithColumnDefinition() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@PrimaryKeyJoinColumn(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - - - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@PrimaryKeyJoinColumn(referencedColumnName=\"Foo\")", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@PrimaryKeyJoinColumn(columnDefinition=\"Foo\")", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java deleted file mode 100644 index a0a2d00e71..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/PrimaryKeyJoinColumnsTests.java +++ /dev/null @@ -1,268 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class PrimaryKeyJoinColumnsTests extends JavaResourceModelTestCase { - - private static final String COLUMN_NAME = "MY_COLUMN"; - private static final String COLUMN_COLUMN_DEFINITION = "COLUMN_DEFINITION"; - private static final String COLUMN_REFERENCED_COLUMN_NAME = "MY_REF_COLUMN_NAME"; - - public PrimaryKeyJoinColumnsTests(String name) { - super(name); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", - "String name() default \"\"; " + - "String referencedColumnName() default \"\"; " + - "String columnDefinition() default \"\";"); - } - - private void createPrimaryKeyJoinColumnsAnnotation() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - this.createAnnotationAndMembers("PrimaryKeyJoinColumns", - "PrimaryKeyJoinColumn[] value();"); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumns() throws Exception { - createPrimaryKeyJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn)"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithName() throws Exception { - createPrimaryKeyJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(name=\"" + COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithReferencedColumnName() throws Exception { - createPrimaryKeyJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(referencedColumnName=\"" + COLUMN_REFERENCED_COLUMN_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumnWithColumnDefinition() throws Exception { - createPrimaryKeyJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(columnDefinition=\"" + COLUMN_COLUMN_DEFINITION + "\"))"); - } - }); - } - - private ICompilationUnit createTestPrimaryKeyJoinColumn() throws Exception { - createPrimaryKeyJoinColumnsAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\")"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertEquals(COLUMN_NAME, column.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertNotNull(column); - assertNull(column.getName()); - assertNull(column.getReferencedColumnName()); - assertNull(column.getColumnDefinition()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getName()); - - column.setName("Foo"); - assertEquals("Foo", column.getName()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(name=\"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertEquals(COLUMN_NAME, column.getName()); - - column.setName(null); - assertNull(column.getName()); - - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - - public void testGetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithReferencedColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_REFERENCED_COLUMN_NAME, column.getReferencedColumnName()); - } - - public void testSetReferencedColumnName() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getReferencedColumnName()); - - column.setReferencedColumnName("Foo"); - assertEquals("Foo", column.getReferencedColumnName()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(referencedColumnName=\"Foo\"))", cu); - - - column.setReferencedColumnName(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - - public void testGetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumnWithColumnDefinition(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - assertEquals(COLUMN_COLUMN_DEFINITION, column.getColumnDefinition()); - } - - public void testSetColumnDefinition() throws Exception { - ICompilationUnit cu = this.createTestPrimaryKeyJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - PrimaryKeyJoinColumnAnnotation column = (PrimaryKeyJoinColumnAnnotation) attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS).next(); - - assertNotNull(column); - assertNull(column.getColumnDefinition()); - - column.setColumnDefinition("Foo"); - assertEquals("Foo", column.getColumnDefinition()); - - assertSourceContains("@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(columnDefinition=\"Foo\"))", cu); - - - column.setColumnDefinition(null); - assertSourceDoesNotContain("@PrimaryKeyJoinColumn", cu); - } - - - public void testAddPrimaryKeyJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - - assertNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMNS)); - assertEquals(2, CollectionTools.size(attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS))); - } - public void testAddPrimaryKeyJoinColumnToBeginningOfList() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - - joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(0, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("BAZ"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name=\"BAZ\"),@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"), @PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - - Iterator<JavaResourceNode> pkJoinColumns = attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - assertEquals("BAZ", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("BAR", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - assertEquals("FOO", ((PrimaryKeyJoinColumnAnnotation) pkJoinColumns.next()).getName()); - - assertNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMN)); - assertNotNull(attributeResource.getAnnotation(JPA.PRIMARY_KEY_JOIN_COLUMNS)); - assertEquals(3, CollectionTools.size(attributeResource.annotations(JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS))); - } - - public void testRemovePrimaryKeyJoinColumnCopyExisting() throws Exception { - ICompilationUnit cu = createTestPrimaryKeyJoinColumn(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - PrimaryKeyJoinColumnAnnotation joinColumn = (PrimaryKeyJoinColumnAnnotation) attributeResource.addAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - joinColumn.setName("FOO"); - assertSourceContains("@PrimaryKeyJoinColumns({@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\"),@PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - - attributeResource.removeAnnotation(1, JPA.PRIMARY_KEY_JOIN_COLUMN, JPA.PRIMARY_KEY_JOIN_COLUMNS); - assertSourceContains("@PrimaryKeyJoinColumn(name=\"BAR\", columnDefinition = \"COLUMN_DEF\", referencedColumnName = \"REF_NAME\")", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java deleted file mode 100644 index 65d72116c9..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/QueryHintTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation; -import org.eclipse.jpt.core.resource.java.QueryHintAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class QueryHintTests extends JavaResourceModelTestCase { - - private static final String QUERY_HINT_NAME = "myHint"; - private static final String QUERY_HINT_VALUE = "myValue"; - - public QueryHintTests(String name) { - super(name); - } - - private void createNamedQueryAnnotation() throws Exception { - createQueryHintAnnotation(); - this.createAnnotationAndMembers("NamedQuery", "String name(); " + - "String query();" + - "QueryHint[] hints() default{};"); - } - - private void createQueryHintAnnotation() throws Exception { - this.createAnnotationAndMembers("QueryHint", "String name(); " + - "String value();"); - } - - private ICompilationUnit createTestNamedQueryWithQueryHints() throws Exception { - createNamedQueryAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.NAMED_QUERY, JPA.QUERY_HINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@NamedQuery(hints={@QueryHint(name=\"" + QUERY_HINT_NAME + "\", value=\"" + QUERY_HINT_VALUE + "\"), @QueryHint})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - QueryHintAnnotation queryHint = namedQuery.hints().next(); - assertEquals(QUERY_HINT_NAME, queryHint.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestNamedQueryWithQueryHints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - NamedQueryAnnotation namedQuery = (NamedQueryAnnotation) typeResource.getAnnotation(JPA.NAMED_QUERY); - QueryHintAnnotation queryHint = namedQuery.hints().next(); - assertEquals(QUERY_HINT_NAME, queryHint.getName()); - - queryHint.setName("foo"); - assertEquals("foo", queryHint.getName()); - - assertSourceContains("@QueryHint(name=\"foo\", value=\"" + QUERY_HINT_VALUE + "\")", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java deleted file mode 100644 index 9128356b53..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTableTests.java +++ /dev/null @@ -1,459 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.UniqueConstraintAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class SecondaryTableTests extends JavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public SecondaryTableTests(String name) { - super(name); - } - - private void createUniqueConstraintAnnotation() throws Exception { - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", "String name() default \"\"; String referencedColumnName() default \"\";String columnDefinition() default \"\";"); - } - - private void createSecondaryTableAnnotation() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - createUniqueConstraintAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name() default \"\"; " + - "String catalog() default \"\";" + - "String schema() default \"\";" + - "PrimaryKeyJoinColumn[] pkJoinColumns() default {};" + - "UniqueConstraint[] uniqueConstraints() default {};"); - } - - private ICompilationUnit createTestSecondaryTable() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithName() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithSchema() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(schema=\"" + SCHEMA_NAME + "\")"); - } - }); - } - private ICompilationUnit createTestSecondaryTableWithCatalog() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(catalog=\"" + CATALOG_NAME + "\")"); - } - }); - } - - - private ICompilationUnit createTestSecondaryTableWithUniqueConstraints() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithPkJoinColumns() throws Exception { - createSecondaryTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"), @PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\")})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@SecondaryTable(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@SecondaryTable(catalog=\"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@SecondaryTable(schema=\"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.removeUniqueConstraint(1); - Iterator<UniqueConstraintAnnotation> uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAR", uniqueConstraints.next().columnNames().next()); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - assertSourceContains("@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - uniqueConstraints = table.uniqueConstraints(); - assertEquals("BAZ", uniqueConstraints.next().columnNames().next()); - assertFalse(uniqueConstraints.hasNext()); - assertSourceContains("@SecondaryTable(uniqueConstraints=@UniqueConstraint(columnNames={\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - uniqueConstraints = table.uniqueConstraints(); - assertFalse(uniqueConstraints.hasNext()); - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - - secondaryTable.moveUniqueConstraint(2, 0); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - assertSourceContains("@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - - secondaryTable.moveUniqueConstraint(0, 2); - assertEquals("BAZ", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertEquals(3, secondaryTable.uniqueConstraintsSize()); - assertSourceContains("@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"})})", cu); - } - - - public void testPkJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(0, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.addPkJoinColumn(0); - table.addPkJoinColumn(1); - - assertEquals(2, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.pkJoinColumnsSize()); - } - - public void testAddPkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - - table.addPkJoinColumn(0).setName("FOO"); - table.addPkJoinColumn(0); - table.addPkJoinColumn(0).setName("BAR");//test adding a pkJoinColumn in front of 2 other joinColumns - - assertEquals("BAR", table.pkJoinColumnAt(0).getName()); - assertNull(table.pkJoinColumnAt(1).getName()); - assertEquals("FOO", table.pkJoinColumnAt(2).getName()); - - assertEquals(3, table.pkJoinColumnsSize()); - assertSourceContains("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"),@PrimaryKeyJoinColumn, @PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - } - - public void testRemovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - table.removePkJoinColumn(1); - assertSourceContains("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"), @PrimaryKeyJoinColumn(name=\"BAZ\")})", cu); - - table.removePkJoinColumn(0); - assertSourceContains("@SecondaryTable(pkJoinColumns=@PrimaryKeyJoinColumn(name=\"BAZ\"))", cu); - - - table.removePkJoinColumn(0); - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testMovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(2, 0); - assertSourceContains("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\"), @PrimaryKeyJoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\")})", cu); - } - - public void testMovePkJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(0, 2); - assertSourceContains("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAZ\"), @PrimaryKeyJoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\"), @PrimaryKeyJoinColumn(name=\"FOO\")})", cu); - } - - public void testSetPkJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - - assertEquals(3, table.pkJoinColumnsSize()); - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"foo\"), @PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\")})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java deleted file mode 100644 index 807daefd6e..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SecondaryTablesTests.java +++ /dev/null @@ -1,532 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.PrimaryKeyJoinColumnAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTableAnnotation; -import org.eclipse.jpt.core.resource.java.SecondaryTablesAnnotation; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class SecondaryTablesTests extends JavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public SecondaryTablesTests(String name) { - super(name); - } - - - private void createUniqueConstraintAnnotation() throws Exception { - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - } - - private void createPrimaryKeyJoinColumnAnnotation() throws Exception { - this.createAnnotationAndMembers("PrimaryKeyJoinColumn", "String name() default \"\"; String referencedColumnName() default \"\";String columnDefinition() default \"\";"); - } - - private void createSecondaryTableAnnotation() throws Exception { - createPrimaryKeyJoinColumnAnnotation(); - createUniqueConstraintAnnotation(); - this.createAnnotationAndMembers("SecondaryTable", "String name() default \"\"; " + - "String catalog() default \"\"; " + - "String schema() default \"\";" + - "PrimaryKeyJoinColumn[] pkJoinColumns() default {};" + - "UniqueConstraint[] uniqueConstraints() default {};"); - - } - private void createSecondaryTablesAnnotation() throws Exception { - createSecondaryTableAnnotation(); - this.createAnnotationAndMembers("SecondaryTables", "SecondaryTable[] value()"); - } - - private ICompilationUnit createTestSecondaryTables() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable)"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithName() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(name=\"" + TABLE_NAME + "\"))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTableWithSchema() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(schema=\"" + SCHEMA_NAME + "\"))"); - } - }); - } - private ICompilationUnit createTestSecondaryTableWithCatalog() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(catalog=\"" + CATALOG_NAME + "\"))"); - } - }); - } - - - private ICompilationUnit createTestSecondaryTableWithUniqueConstraints() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint}))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTable() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.ENTITY, JPA.SECONDARY_TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Entity"); - sb.append(CR); - sb.append("@SecondaryTable(name=\"FOO\", catalog=\"BAR\", schema=\"BAZ\", uniqueConstraints=@UniqueConstraint(columnNames={\"BAR\"}))"); - } - }); - } - - private ICompilationUnit createTestSecondaryTablesWithPkJoinColumns() throws Exception { - createSecondaryTablesAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SECONDARY_TABLES, JPA.SECONDARY_TABLE, JPA.PRIMARY_KEY_JOIN_COLUMN); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"), @PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\")}))"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLE); - assertNull(table); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - assertNotNull(secondaryTables); - - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertEquals(TABLE_NAME, secondaryTable.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertNull(secondaryTable.getName()); - assertNull(secondaryTable.getCatalog()); - assertNull(secondaryTable.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - - assertNull(secondaryTable.getName()); - - secondaryTable.setName("Foo"); - assertEquals("Foo", secondaryTable.getName()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(name=\"Foo\"))", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertEquals(TABLE_NAME, secondaryTable.getName()); - - secondaryTable.setName(null); - assertNull(secondaryTable.getName()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertEquals(CATALOG_NAME, secondaryTable.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertNull(secondaryTable.getCatalog()); - - secondaryTable.setCatalog("Foo"); - assertEquals("Foo", secondaryTable.getCatalog()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(catalog=\"Foo\"))", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertEquals(CATALOG_NAME, secondaryTable.getCatalog()); - - secondaryTable.setCatalog(null); - assertNull(secondaryTable.getCatalog()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertNotNull(secondaryTable); - assertEquals(SCHEMA_NAME, secondaryTable.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertNull(secondaryTable.getSchema()); - - secondaryTable.setSchema("Foo"); - assertEquals("Foo", secondaryTable.getSchema()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(schema=\"Foo\"))", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - assertEquals(SCHEMA_NAME, secondaryTable.getSchema()); - - secondaryTable.setSchema(null); - assertNull(secondaryTable.getSchema()); - - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - - assertEquals(0, secondaryTable.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - - secondaryTable.addUniqueConstraint(0); - secondaryTable.addUniqueConstraint(1); - - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - - assertEquals(2, secondaryTable.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - secondaryTable.addUniqueConstraint(1); - secondaryTable.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, secondaryTable.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint}))", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - secondaryTable.removeUniqueConstraint(2); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint(columnNames={\"BAR\"})})", cu); - - secondaryTable.removeUniqueConstraint(0); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints=@UniqueConstraint(columnNames={\"BAR\"}))", cu); - - secondaryTable.removeUniqueConstraint(0); - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(2).columnNames().hasNext()); - - secondaryTable.moveUniqueConstraint(2, 0); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(1).columnNames().hasNext()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint, @UniqueConstraint(columnNames=\"FOO\")}))", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTablesAnnotation secondaryTables = (SecondaryTablesAnnotation) typeResource.getAnnotation(JPA.SECONDARY_TABLES); - SecondaryTableAnnotation secondaryTable = secondaryTables.nestedAnnotationAt(0); - secondaryTable.addUniqueConstraint(0).addColumnName("FOO"); - - assertEquals("FOO", secondaryTable.uniqueConstraintAt(0).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertFalse(secondaryTable.uniqueConstraintAt(2).columnNames().hasNext()); - - secondaryTable.moveUniqueConstraint(0, 2); - assertFalse(secondaryTable.uniqueConstraintAt(0).columnNames().hasNext()); - assertEquals("FOO", secondaryTable.uniqueConstraintAt(1).columnNames().next()); - assertEquals("BAR", secondaryTable.uniqueConstraintAt(2).columnNames().next()); - assertSourceContains("@SecondaryTables(@SecondaryTable(uniqueConstraints={@UniqueConstraint, @UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint(columnNames={\"BAR\"})}))", cu); - } - - - // @Entity -->> @Entity - // @SecondaryTable(name="FOO") @SecondaryTables({@SecondaryTable(name="FOO"), @SecondaryTable(name="BAR")}) - public void testAddSecondaryTableCopyExisting() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames=\"BAR\")),@SecondaryTable(name=\"BAR\")})", cu); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(2, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testAddSecondaryTable() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames=\"BAR\")),@SecondaryTable(name=\"BAR\")})", cu); - - secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(0, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAZ"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"BAZ\"),@SecondaryTable(name=\"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames=\"BAR\")), @SecondaryTable(name=\"BAR\")})", cu); - - Iterator<JavaResourceNode> secondaryTables = typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertEquals("BAZ", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("FOO", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - assertEquals("BAR", ((SecondaryTableAnnotation) secondaryTables.next()).getName()); - - assertNull(typeResource.getAnnotation(JPA.SECONDARY_TABLE)); - assertNotNull(typeResource.getAnnotation(JPA.SECONDARY_TABLES)); - assertEquals(3, CollectionTools.size(typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES))); - } - - public void testRemoveSecondaryTableCopyExisting() throws Exception { - ICompilationUnit cu = createTestSecondaryTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SecondaryTableAnnotation secondaryTable = (SecondaryTableAnnotation) typeResource.addAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - secondaryTable.setName("BAR"); - assertSourceContains("@SecondaryTables({@SecondaryTable(name=\"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames=\"BAR\")),@SecondaryTable(name=\"BAR\")})", cu); - - typeResource.removeAnnotation(1, JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES); - assertSourceContains("@SecondaryTable(name=\"FOO\", catalog = \"BAR\", schema = \"BAZ\", uniqueConstraints = @UniqueConstraint(columnNames=\"BAR\"))", cu); - } - - - public void testPkJoinColumns() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(0, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.addPkJoinColumn(0); - table.addPkJoinColumn(1); - - assertEquals(2, table.pkJoinColumnsSize()); - } - - public void testPkJoinColumns3() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(3, table.pkJoinColumnsSize()); - } - - public void testAddPkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTables(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.addPkJoinColumn(0).setName("FOO"); - table.addPkJoinColumn(1); - table.addPkJoinColumn(0).setName("BAR"); - - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"),@PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn}))", cu); - } - - public void testRemovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - table.removePkJoinColumn(1); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAR\"), @PrimaryKeyJoinColumn(name=\"BAZ\")}))", cu); - - table.removePkJoinColumn(0); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns=@PrimaryKeyJoinColumn(name=\"BAZ\")))", cu); - - table.removePkJoinColumn(0); - assertSourceDoesNotContain("@SecondaryTable", cu); - } - - public void testMovePkJoinColumn() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(2, 0); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\"), @PrimaryKeyJoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\")}))", cu); - } - - public void testMovePkJoinColumn2() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumnAt(0); - joinColumn.setReferencedColumnName("REF_NAME"); - joinColumn.setColumnDefinition("COLUMN_DEF"); - table.movePkJoinColumn(0, 2); - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"BAZ\"), @PrimaryKeyJoinColumn(name=\"BAR\", referencedColumnName = \"REF_NAME\", columnDefinition = \"COLUMN_DEF\"), @PrimaryKeyJoinColumn(name=\"FOO\")}))", cu); - } - - public void testSetPkJoinColumnName() throws Exception { - ICompilationUnit cu = this.createTestSecondaryTablesWithPkJoinColumns(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - SecondaryTableAnnotation table = (SecondaryTableAnnotation) typeResource.annotations(JPA.SECONDARY_TABLE, JPA.SECONDARY_TABLES).next(); - - assertEquals(3, table.pkJoinColumnsSize()); - - PrimaryKeyJoinColumnAnnotation joinColumn = table.pkJoinColumns().next(); - - assertEquals("BAR", joinColumn.getName()); - - joinColumn.setName("foo"); - assertEquals("foo", joinColumn.getName()); - - assertSourceContains("@SecondaryTables(@SecondaryTable(pkJoinColumns={@PrimaryKeyJoinColumn(name=\"foo\"), @PrimaryKeyJoinColumn(name=\"FOO\"), @PrimaryKeyJoinColumn(name=\"BAZ\")}))", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java deleted file mode 100644 index e209c4cd53..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/SequenceGeneratorTests.java +++ /dev/null @@ -1,242 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.SequenceGeneratorAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class SequenceGeneratorTests extends JavaResourceModelTestCase { - - private static final String GENERATOR_NAME = "MY_GENERATOR"; - private static final String GENERATOR_SEQUENCE_NAME = "MY_SEQUENCE"; - private static final Integer GENERATOR_ALLOCATION_SIZE = Integer.valueOf(5); - private static final Integer GENERATOR_INITIAL_VALUE = Integer.valueOf(5); - - public SequenceGeneratorTests(String name) { - super(name); - } - - private void createSequenceGeneratorAnnotation() throws Exception { - this.createAnnotationAndMembers("SequenceGenerator", "String name(); " + - "String sequenceName() default \"\"" + - "int initialValue() default 1" + - "int allocationSize() default 50"); - } - - private ICompilationUnit createTestSequenceGeneratorOnField() throws Exception { - createSequenceGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorOnType() throws Exception { - createSequenceGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorWithName() throws Exception { - return createTestSequenceGeneratorWithStringElement("name", GENERATOR_NAME); - } - - private ICompilationUnit createTestSequenceGeneratorWithSequenceName() throws Exception { - return createTestSequenceGeneratorWithStringElement("sequenceName", GENERATOR_SEQUENCE_NAME); - } - - private ICompilationUnit createTestSequenceGeneratorWithStringElement(final String elementName, final String value) throws Exception { - createSequenceGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator(" + elementName + "=\"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestSequenceGeneratorWithAllocationSize() throws Exception { - return createTestSequenceGeneratorWithIntElement("allocationSize", GENERATOR_ALLOCATION_SIZE); - } - - private ICompilationUnit createTestSequenceGeneratorWithInitialValue() throws Exception { - return createTestSequenceGeneratorWithIntElement("initialValue", GENERATOR_INITIAL_VALUE); - } - - private ICompilationUnit createTestSequenceGeneratorWithIntElement(final String elementName, final int value) throws Exception { - createSequenceGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.SEQUENCE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@SequenceGenerator(" + elementName + "=" + value + ")"); - } - }); - } - - public void testSequenceGeneratorOnField() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertNotNull(sequenceGenerator); - } - - public void testSequenceGeneratorOnType() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) typeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertNotNull(sequenceGenerator); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_NAME, sequenceGenerator.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_NAME, sequenceGenerator.getName()); - - sequenceGenerator.setName("foo"); - assertEquals("foo", sequenceGenerator.getName()); - - assertSourceContains("@SequenceGenerator(name=\"foo\")", cu); - - sequenceGenerator.setName(null); - assertNull(sequenceGenerator.getName()); - - assertSourceDoesNotContain("@SequenceGenerator", cu); - } - - public void testGetSequenceName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSequenceName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SEQUENCE_NAME, sequenceGenerator.getSequenceName()); - } - - public void testSetSequenceName() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithSequenceName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_SEQUENCE_NAME, sequenceGenerator.getSequenceName()); - - sequenceGenerator.setSequenceName("foo"); - assertEquals("foo", sequenceGenerator.getSequenceName()); - - assertSourceContains("@SequenceGenerator(sequenceName=\"foo\")", cu); - - sequenceGenerator.setSequenceName(null); - assertNull(sequenceGenerator.getSequenceName()); - - assertSourceDoesNotContain("@SequenceGenerator", cu); - } - - public void testGetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, sequenceGenerator.getAllocationSize()); - } - - public void testSetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, sequenceGenerator.getAllocationSize()); - - sequenceGenerator.setAllocationSize(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), sequenceGenerator.getAllocationSize()); - - assertSourceContains("@SequenceGenerator(allocationSize=500)", cu); - - sequenceGenerator.setAllocationSize(null); - - assertSourceDoesNotContain("@SequenceGenerator", cu); - - sequenceGenerator.setAllocationSize(Integer.valueOf(0)); - assertSourceContains("@SequenceGenerator(allocationSize=0)", cu); - } - - public void testGetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, sequenceGenerator.getInitialValue()); - } - - public void testSetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestSequenceGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - SequenceGeneratorAnnotation sequenceGenerator = (SequenceGeneratorAnnotation) attributeResource.getAnnotation(JPA.SEQUENCE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, sequenceGenerator.getInitialValue()); - - sequenceGenerator.setInitialValue(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), sequenceGenerator.getInitialValue()); - - assertSourceContains("@SequenceGenerator(initialValue=500)", cu); - - sequenceGenerator.setInitialValue(null); - - assertSourceDoesNotContain("@SequenceGenerator", cu); - - sequenceGenerator.setInitialValue(Integer.valueOf(0)); - assertSourceContains("@SequenceGenerator(initialValue=0)", cu); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java deleted file mode 100644 index b12c6387f8..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableGeneratorTests.java +++ /dev/null @@ -1,521 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.TableGeneratorAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TableGeneratorTests extends JavaResourceModelTestCase { - - private static final String GENERATOR_NAME = "MY_GENERATOR"; - private static final String GENERATOR_TABLE = "MY_TABLE"; - private static final String GENERATOR_CATALOG = "MY_CATALOG"; - private static final String GENERATOR_SCHEMA = "MY_SCHEMA"; - private static final String GENERATOR_PK_COLUMN_NAME = "MY_PK_COLUMN_NAME"; - private static final String GENERATOR_VALUE_COLUMN_NAME = "MY_VALUE_COLUMN_NAME"; - private static final String GENERATOR_PK_COLUMN_VALUE = "MY_PK_COLUMN_VALUE"; - private static final Integer GENERATOR_ALLOCATION_SIZE = Integer.valueOf(5); - private static final Integer GENERATOR_INITIAL_VALUE = Integer.valueOf(5); - - public TableGeneratorTests(String name) { - super(name); - } - - private void createTableGeneratorAnnotation() throws Exception { - this.createAnnotationAndMembers("TableGenerator", "String name(); " + - "String table() default \"\"" + - "String catalog() default \"\"" + - "String schema() default \"\"" + - "String pkColumnName() default \"\"" + - "String valueColumnName() default \"\"" + - "String pkColumnValue() default \"\"" + - "int initialValue() default 0" + - "int allocationSize() default 50" + - "UniqueConstraint[] uniqueConstraints() default{}"); - } - - private ICompilationUnit createTestTableGeneratorOnField() throws Exception { - createTableGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorOnType() throws Exception { - createTableGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE_GENERATOR); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithName() throws Exception { - return createTestTableGeneratorWithStringElement("name", GENERATOR_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithTable() throws Exception { - return createTestTableGeneratorWithStringElement("table", GENERATOR_TABLE); - } - - private ICompilationUnit createTestTableGeneratorWithCatalog() throws Exception { - return createTestTableGeneratorWithStringElement("catalog", GENERATOR_CATALOG); - } - - private ICompilationUnit createTestTableGeneratorWithSchema() throws Exception { - return createTestTableGeneratorWithStringElement("schema", GENERATOR_SCHEMA); - } - private ICompilationUnit createTestTableGeneratorWithPkColumnName() throws Exception { - return createTestTableGeneratorWithStringElement("pkColumnName", GENERATOR_PK_COLUMN_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithValueColumnName() throws Exception { - return createTestTableGeneratorWithStringElement("valueColumnName", GENERATOR_VALUE_COLUMN_NAME); - } - - private ICompilationUnit createTestTableGeneratorWithPkColumnValue() throws Exception { - return createTestTableGeneratorWithStringElement("pkColumnValue", GENERATOR_PK_COLUMN_VALUE); - } - - private ICompilationUnit createTestTableGeneratorWithStringElement(final String elementName, final String value) throws Exception { - createTableGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(" + elementName + "=\"" + value + "\")"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithAllocationSize() throws Exception { - return createTestTableGeneratorWithIntElement("allocationSize", GENERATOR_ALLOCATION_SIZE); - } - - private ICompilationUnit createTestTableGeneratorWithInitialValue() throws Exception { - return createTestTableGeneratorWithIntElement("initialValue", GENERATOR_INITIAL_VALUE); - } - - private ICompilationUnit createTestTableGeneratorWithIntElement(final String elementName, final int value) throws Exception { - createTableGeneratorAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE_GENERATOR); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(" + elementName + "=" + value + ")"); - } - }); - } - - private ICompilationUnit createTestTableGeneratorWithUniqueConstraints() throws Exception { - createTableGeneratorAnnotation(); - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE_GENERATOR, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@TableGenerator(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})"); - } - }); - } - - public void testTableGeneratorOnField() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertNotNull(tableGenerator); - } - - public void testTableGeneratorOnType() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnType(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) typeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertNotNull(tableGenerator); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_NAME, tableGenerator.getName()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_NAME, tableGenerator.getName()); - - tableGenerator.setName("foo"); - assertEquals("foo", tableGenerator.getName()); - - assertSourceContains("@TableGenerator(name=\"foo\")", cu); - - tableGenerator.setName(null); - assertNull(tableGenerator.getName()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetTable() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_TABLE, tableGenerator.getTable()); - } - - public void testSetTable() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_TABLE, tableGenerator.getTable()); - - tableGenerator.setTable("foo"); - assertEquals("foo", tableGenerator.getTable()); - - assertSourceContains("@TableGenerator(table=\"foo\")", cu); - - tableGenerator.setTable(null); - assertNull(tableGenerator.getTable()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_CATALOG, tableGenerator.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_CATALOG, tableGenerator.getCatalog()); - - tableGenerator.setCatalog("foo"); - assertEquals("foo", tableGenerator.getCatalog()); - - assertSourceContains("@TableGenerator(catalog=\"foo\")", cu); - - tableGenerator.setCatalog(null); - assertNull(tableGenerator.getCatalog()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, tableGenerator.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_SCHEMA, tableGenerator.getSchema()); - - tableGenerator.setSchema("foo"); - assertEquals("foo", tableGenerator.getSchema()); - - assertSourceContains("@TableGenerator(schema=\"foo\")", cu); - - tableGenerator.setSchema(null); - assertNull(tableGenerator.getSchema()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetPkColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_NAME, tableGenerator.getPkColumnName()); - } - - public void testSetPkColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_NAME, tableGenerator.getPkColumnName()); - - tableGenerator.setPkColumnName("foo"); - assertEquals("foo", tableGenerator.getPkColumnName()); - - assertSourceContains("@TableGenerator(pkColumnName=\"foo\")", cu); - - tableGenerator.setPkColumnName(null); - assertNull(tableGenerator.getPkColumnName()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetValueColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithValueColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_VALUE_COLUMN_NAME, tableGenerator.getValueColumnName()); - } - - public void testSetValueColumnName() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithValueColumnName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_VALUE_COLUMN_NAME, tableGenerator.getValueColumnName()); - - tableGenerator.setValueColumnName("foo"); - assertEquals("foo", tableGenerator.getValueColumnName()); - - assertSourceContains("@TableGenerator(valueColumnName=\"foo\")", cu); - - tableGenerator.setValueColumnName(null); - assertNull(tableGenerator.getValueColumnName()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetPkColumnValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_VALUE, tableGenerator.getPkColumnValue()); - } - - public void testSetPkColumnValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithPkColumnValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_PK_COLUMN_VALUE, tableGenerator.getPkColumnValue()); - - tableGenerator.setPkColumnValue("foo"); - assertEquals("foo", tableGenerator.getPkColumnValue()); - - assertSourceContains("@TableGenerator(pkColumnValue=\"foo\")", cu); - - tableGenerator.setPkColumnValue(null); - assertNull(tableGenerator.getPkColumnValue()); - - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testGetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, tableGenerator.getAllocationSize()); - } - - public void testSetAllocationSize() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithAllocationSize(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_ALLOCATION_SIZE, tableGenerator.getAllocationSize()); - - tableGenerator.setAllocationSize(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), tableGenerator.getAllocationSize()); - - assertSourceContains("@TableGenerator(allocationSize=500)", cu); - - tableGenerator.setAllocationSize(null); - - assertSourceDoesNotContain("@TableGenerator", cu); - - tableGenerator.setAllocationSize(Integer.valueOf(0)); - assertSourceContains("@TableGenerator(allocationSize=0)", cu); - } - - public void testGetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, tableGenerator.getInitialValue()); - } - - public void testSetInitialValue() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithInitialValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - assertEquals(GENERATOR_INITIAL_VALUE, tableGenerator.getInitialValue()); - - tableGenerator.setInitialValue(Integer.valueOf(500)); - assertEquals(Integer.valueOf(500), tableGenerator.getInitialValue()); - - assertSourceContains("@TableGenerator(initialValue=500)", cu); - - tableGenerator.setInitialValue(null); - - assertSourceDoesNotContain("@TableGenerator", cu); - - tableGenerator.setInitialValue(Integer.valueOf(0)); - assertSourceContains("@TableGenerator(initialValue=0)", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(0, tableGenerator.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.addUniqueConstraint(0); - tableGenerator.addUniqueConstraint(1); - - assertEquals(2, tableGenerator.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - assertEquals(3, tableGenerator.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorOnField(); - this.createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.addUniqueConstraint(0).addColumnName("FOO"); - tableGenerator.addUniqueConstraint(1); - tableGenerator.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", tableGenerator.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", tableGenerator.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, tableGenerator.uniqueConstraintAt(2).columnNamesSize()); - - assertEquals(3, tableGenerator.uniqueConstraintsSize()); - assertSourceContains("@TableGenerator(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint})", cu); - } - - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.removeUniqueConstraint(1); - assertSourceContains("@TableGenerator(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - tableGenerator.removeUniqueConstraint(0); - assertSourceContains("@TableGenerator(uniqueConstraints=@UniqueConstraint(columnNames={\"BAZ\"}))", cu); - - tableGenerator.removeUniqueConstraint(0); - assertSourceDoesNotContain("@TableGenerator", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.moveUniqueConstraint(2, 0); - assertSourceContains("@TableGenerator(uniqueConstraints={@UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTableGeneratorWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TableGeneratorAnnotation tableGenerator = (TableGeneratorAnnotation) attributeResource.getAnnotation(JPA.TABLE_GENERATOR); - - tableGenerator.moveUniqueConstraint(0, 2); - assertSourceContains("@TableGenerator(uniqueConstraints={@UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"})})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java deleted file mode 100644 index 5495c4dbe6..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TableTests.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import java.util.ListIterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TableAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TableTests extends JavaResourceModelTestCase { - - private static final String TABLE_NAME = "MY_TABLE"; - private static final String SCHEMA_NAME = "MY_SCHEMA"; - private static final String CATALOG_NAME = "MY_CATALOG"; - - public TableTests(String name) { - super(name); - } - - private void createTableAnnotation() throws Exception { - createUniqueConstraintAnnotation(); - this.createAnnotationAndMembers("Table", "String name() default \"\"; String catalog() default \"\"; String schema() default \"\"; UniqueConstraint[] uniqueConstraints() default {};"); - } - - private void createUniqueConstraintAnnotation() throws Exception { - createAnnotationAndMembers("UniqueConstraint", "String[] columnNames();"); - } - - private ICompilationUnit createTestTable() throws Exception { - createTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table"); - } - }); - } - - private ICompilationUnit createTestTableWithName() throws Exception { - createTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(name=\"" + TABLE_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithSchema() throws Exception { - createTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(schema=\"" + SCHEMA_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithCatalog() throws Exception { - createTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(catalog=\"" + CATALOG_NAME + "\")"); - } - }); - } - - private ICompilationUnit createTestTableWithUniqueConstraints() throws Exception { - createTableAnnotation(); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TABLE, JPA.UNIQUE_CONSTRAINT); - } - @Override - public void appendTypeAnnotationTo(StringBuilder sb) { - sb.append("@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"})})"); - } - }); - } - - public void testGetName() throws Exception { - ICompilationUnit cu = this.createTestTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(TABLE_NAME, table.getName()); - } - - public void testGetNull() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getName()); - assertNull(table.getCatalog()); - assertNull(table.getSchema()); - } - - public void testSetName() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getName()); - - table.setName("Foo"); - assertEquals("Foo", table.getName()); - - assertSourceContains("@Table(name=\"Foo\")", cu); - } - - public void testSetNameNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithName(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(TABLE_NAME, table.getName()); - - table.setName(null); - assertNull(table.getName()); - - assertSourceDoesNotContain("@Table", cu); - } - - public void testGetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(CATALOG_NAME, table.getCatalog()); - } - - public void testSetCatalog() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getCatalog()); - - table.setCatalog("Foo"); - assertEquals("Foo", table.getCatalog()); - - assertSourceContains("@Table(catalog=\"Foo\")", cu); - } - - public void testSetCatalogNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithCatalog(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(CATALOG_NAME, table.getCatalog()); - - table.setCatalog(null); - assertNull(table.getCatalog()); - - assertSourceDoesNotContain("@Table", cu); - } - - public void testGetSchema() throws Exception { - ICompilationUnit cu = this.createTestTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertEquals(SCHEMA_NAME, table.getSchema()); - } - - public void testSetSchema() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertNotNull(table); - assertNull(table.getSchema()); - - table.setSchema("Foo"); - assertEquals("Foo", table.getSchema()); - - assertSourceContains("@Table(schema=\"Foo\")", cu); - } - - public void testSetSchemaNull() throws Exception { - ICompilationUnit cu = this.createTestTableWithSchema(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - assertEquals(SCHEMA_NAME, table.getSchema()); - - table.setSchema(null); - assertNull(table.getSchema()); - - assertSourceDoesNotContain("@Table", cu); - } - - public void testUniqueConstraints() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(0, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0); - table.addUniqueConstraint(1); - - assertEquals(2, table.uniqueConstraintsSize()); - } - - public void testUniqueConstraints3() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - assertEquals(3, table.uniqueConstraintsSize()); - } - - public void testAddUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1); - table.addUniqueConstraint(0).addColumnName("BAR"); - - assertEquals("BAR", table.uniqueConstraintAt(0).columnNames().next()); - assertEquals("FOO", table.uniqueConstraintAt(1).columnNames().next()); - assertEquals(0, table.uniqueConstraintAt(2).columnNamesSize()); - - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"FOO\"), @UniqueConstraint})", cu); - } - - public void testAddUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(0); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.uniqueConstraintAt(1).addColumnName("BAZ"); - - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint,@UniqueConstraint(columnNames={ \"BAR\", \"BAZ\" }), @UniqueConstraint(columnNames=\"FOO\")})", cu); - - assertEquals("FOO", table.uniqueConstraintAt(2).columnNames().next()); - ListIterator<String> columnNames = table.uniqueConstraintAt(1).columnNames(); - assertEquals("BAR", columnNames.next()); - assertEquals("BAZ", columnNames.next()); - } - public void testRemoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.removeUniqueConstraint(1); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"BAZ\"})})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints=@UniqueConstraint(columnNames={\"BAZ\"}))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table", cu); - } - - public void testRemoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.addUniqueConstraint(2).addColumnName("BAZ"); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames=\"FOO\"),@UniqueConstraint(columnNames=\"BAR\"), @UniqueConstraint(columnNames=\"BAZ\")})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames=\"BAR\"),@UniqueConstraint(columnNames=\"BAZ\")})", cu); - - table.removeUniqueConstraint(0); - assertSourceContains("@Table(uniqueConstraints=@UniqueConstraint(columnNames=\"BAZ\"))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table", cu); - } - - public void testRemoveUniqueConstraint3() throws Exception { - ICompilationUnit cu = this.createTestTable(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - table.addUniqueConstraint(0).addColumnName("FOO"); - table.addUniqueConstraint(1).addColumnName("BAR"); - table.addUniqueConstraint(2).addColumnName("BAZ"); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames=\"FOO\"),@UniqueConstraint(columnNames=\"BAR\"), @UniqueConstraint(columnNames=\"BAZ\")})", cu); - - table.removeUniqueConstraint(2); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames=\"FOO\"),@UniqueConstraint(columnNames=\"BAR\")})", cu); - - table.removeUniqueConstraint(1); - assertSourceContains("@Table(uniqueConstraints=@UniqueConstraint(columnNames=\"FOO\"))", cu); - - table.removeUniqueConstraint(0); - assertSourceDoesNotContain("@Table", cu); - } - - public void testMoveUniqueConstraint() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.moveUniqueConstraint(2, 0); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"FOO\"}), @UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"})})", cu); - } - - public void testMoveUniqueConstraint2() throws Exception { - ICompilationUnit cu = this.createTestTableWithUniqueConstraints(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - TableAnnotation table = (TableAnnotation) typeResource.getAnnotation(JPA.TABLE); - - table.moveUniqueConstraint(0, 2); - assertSourceContains("@Table(uniqueConstraints={@UniqueConstraint(columnNames={\"BAZ\"}), @UniqueConstraint(columnNames={\"BAR\"}), @UniqueConstraint(columnNames={\"FOO\"})})", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java deleted file mode 100644 index 9aca8780ac..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TemporalTests.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -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.TemporalAnnotation; -import org.eclipse.jpt.core.resource.java.TemporalType; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TemporalTests extends JavaResourceModelTestCase { - - public TemporalTests(String name) { - super(name); - } - - private ICompilationUnit createTestTemporal() throws Exception { - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - this.createEnumAndMembers("TemporalType", "DATE, TIME, TIMESTAMP"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TEMPORAL); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal"); - } - }); - } - - private ICompilationUnit createTestTemporalWithValue() throws Exception { - this.createAnnotationAndMembers("Temporal", "TemporalType value();"); - this.createEnumAndMembers("TemporalType", "DATE, TIME, TIMESTAMP"); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TEMPORAL, JPA.TEMPORAL_TYPE); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Temporal(TemporalType.DATE)"); - } - }); - } - - public void testTemporal() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - assertNotNull(temporal); - } - - public void testGetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporalWithValue(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - assertEquals(TemporalType.DATE, temporal.getValue()); - } - - public void testSetValue() throws Exception { - ICompilationUnit cu = this.createTestTemporal(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - TemporalAnnotation temporal = (TemporalAnnotation) attributeResource.getAnnotation(JPA.TEMPORAL); - - temporal.setValue(TemporalType.TIME); - - assertSourceContains("@Temporal(TIME)", cu); - - temporal.setValue(null); - - assertSourceDoesNotContain("@Temporal", cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java deleted file mode 100644 index 89c7db53d4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/TransientTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.TransientAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class TransientTests extends JavaResourceModelTestCase { - - public TransientTests(String name) { - super(name); - } - - private ICompilationUnit createTestTransient() throws Exception { - this.createAnnotationAndMembers("Transient", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.TRANSIENT); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Transient"); - } - }); - } - - public void testTransient() throws Exception { - ICompilationUnit cu = this.createTestTransient(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof TransientAnnotation); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java deleted file mode 100644 index eef64e99f0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/VersionTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.resource.java; - -import java.util.Iterator; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.resource.java.JPA; -import org.eclipse.jpt.core.resource.java.JavaResourceNode; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; -import org.eclipse.jpt.core.resource.java.VersionAnnotation; -import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; - -public class VersionTests extends JavaResourceModelTestCase { - - public VersionTests(String name) { - super(name); - } - - private ICompilationUnit createTestVersion() throws Exception { - this.createAnnotationAndMembers("Version", ""); - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return new ArrayIterator<String>(JPA.VERSION); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append("@Version"); - } - }); - } - - public void testVersion() throws Exception { - ICompilationUnit cu = this.createTestVersion(); - JavaResourcePersistentType typeResource = buildJavaTypeResource(cu); - JavaResourcePersistentAttribute attributeResource = typeResource.fields().next(); - - JavaResourceNode mappingAnnotation = attributeResource.getMappingAnnotation(); - assertTrue(mappingAnnotation instanceof VersionAnnotation); - } -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java deleted file mode 100644 index 1b8d7a57a1..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/AnnotationTestCase.java +++ /dev/null @@ -1,519 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import java.io.File; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.NumberLiteral; -import org.eclipse.jdt.core.dom.SimpleName; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute; -import org.eclipse.jpt.core.internal.utility.jdt.JDTMethodAttribute; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.JDTType; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject; -import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter; -import org.eclipse.jpt.core.utility.jdt.Type; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -import junit.framework.TestCase; - -/** - * Provide an easy(?) way to build an annotated source file. - * The type must be created by calling one of the #createType() methods - * before calling any of the various helper methods (i.e. the type is *not* - * created during #setUp()). - */ -public abstract class AnnotationTestCase extends TestCase { - protected TestJavaProject javaProject; - - public static final String CR = System.getProperty("line.separator"); - public static final String SEP = File.separator; - public static final String PROJECT_NAME = "AnnotationTestProject"; - public static final String PACKAGE_NAME = "test"; - public static final String TYPE_NAME = "AnnotationTestType"; - public static final String FULLY_QUALIFIED_TYPE_NAME = PACKAGE_NAME + "." + TYPE_NAME; - public static final String FILE_NAME = TYPE_NAME + ".java"; - public static final IPath FILE_PATH = new Path("src" + SEP + PACKAGE_NAME + SEP + FILE_NAME); - - public static final String[] EMPTY_STRING_ARRAY = new String[0]; - - - // ********** TestCase behavior ********** - - protected AnnotationTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.deleteAllProjects(); - this.javaProject = this.buildJavaProject(false); // false = no auto-build - } - - protected void deleteAllProjects() throws Exception { - ProjectUtility.deleteAllProjects(); - } - - protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception { - return this.buildJavaProject(PROJECT_NAME, autoBuild); - } - - protected TestJavaProject buildJavaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJavaProject(projectName, autoBuild); - } - - @Override - protected void tearDown() throws Exception { -// this.dumpSource(); -// this.javaProject.dispose(); - TestTools.clear(this); - super.tearDown(); - } - - protected void dumpSource(ICompilationUnit cu) throws Exception { - System.out.println("*** " + this.getName() + " ****"); - System.out.println(this.getSource(cu)); - System.out.println(); - } - - - // ********** type creation ********** - - /** - * create an un-annotated type - */ - protected ICompilationUnit createTestType() throws CoreException { - return this.createTestType(new DefaultAnnotationWriter()); - } - - /** - * shortcut for simply adding an annotation to the 'id' field - */ - protected ICompilationUnit createTestType(final String annotationImport, final String idFieldAnnotation) throws CoreException { - return this.createTestType(new DefaultAnnotationWriter() { - @Override - public Iterator<String> imports() { - return (annotationImport == null) ? - EmptyIterator.<String>instance() - : - new SingleElementIterator<String>(annotationImport); - } - @Override - public void appendIdFieldAnnotationTo(StringBuilder sb) { - sb.append(idFieldAnnotation); - } - }); - } - - /** - * shortcut for simply adding a fully-qualified annotation to the 'id' field - */ - protected ICompilationUnit createTestType(final String idFieldAnnotation) throws CoreException { - return this.createTestType(null, idFieldAnnotation); - } - - - protected ICompilationUnit createTestType(AnnotationWriter annotationWriter) throws CoreException { - return this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, this.createSourceWriter(annotationWriter)); - } - - protected ICompilationUnit createTestType(String packageName, String fileName, String typeName, AnnotationWriter annotationWriter) throws CoreException { - return this.javaProject.createCompilationUnit(packageName, fileName, this.createSourceWriter(annotationWriter, typeName)); - } - - protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter) { - return new AnnotatedSourceWriter(annotationWriter); - } - - protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter, String typeName) { - return new AnnotatedSourceWriter(annotationWriter, typeName); - } - - protected void appendSourceTo(StringBuilder sb, AnnotationWriter annotationWriter, String typeName) { - sb.append(CR); - for (Iterator<String> stream = annotationWriter.imports(); stream.hasNext(); ) { - sb.append("import "); - sb.append(stream.next()); - sb.append(";"); - sb.append(CR); - } - sb.append(CR); - annotationWriter.appendTypeAnnotationTo(sb); - sb.append(CR); - sb.append("public class ").append(typeName).append(" "); - annotationWriter.appendExtendsImplementsTo(sb); - sb.append("{").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendIdFieldAnnotationTo(sb); - sb.append(CR); - sb.append(" private int id;").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendNameFieldAnnotationTo(sb); - sb.append(CR); - sb.append(" private String name;").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendGetIdMethodAnnotationTo(sb); - sb.append(CR); - sb.append(" public int getId() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendSetIdMethodAnnotationTo(sb); - sb.append(CR); - sb.append(" public void setId(int id) {").append(CR); - sb.append(" this.id = id;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendGetNameMethodAnnotationTo(sb); - sb.append(CR); - sb.append(" public String getName() {").append(CR); - sb.append(" return this.name;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - sb.append(" "); - annotationWriter.appendSetNameMethodAnnotationTo(sb); - sb.append(CR); - sb.append(" public void setTestField(String testField) {").append(CR); - sb.append(" this.testField = testField;").append(CR); - sb.append(" }").append(CR); - sb.append(CR); - annotationWriter.appendMemberTypeTo(sb); - sb.append(CR); - sb.append("}").append(CR); - annotationWriter.appendTopLevelTypesTo(sb); - sb.append(CR); - } - - - // ********** queries ********** - - protected TestJavaProject getJavaProject() { - return this.javaProject; - } - - protected JDTType testType(ICompilationUnit cu) { - return this.buildType(TYPE_NAME, cu); - } - - protected JDTType buildType(String name, ICompilationUnit cu) { - return this.buildType(name, 1, cu); - } - - protected JDTType buildType(String name, int occurrence, ICompilationUnit cu) { - return this.buildType(null, name, 1, cu); - } - - protected JDTType buildType(Type declaringType, String name, int occurrence, ICompilationUnit cu) { - return new JDTType(declaringType, name, occurrence, cu); - } - - protected JDTFieldAttribute idField(ICompilationUnit cu) { - return this.buildField("id", cu); - } - - protected JDTFieldAttribute nameField(ICompilationUnit cu) { - return this.buildField("name", cu); - } - - protected JDTFieldAttribute buildField(String name, ICompilationUnit cu) { - return this.buildField(name, 1, cu); - } - - protected JDTFieldAttribute buildField(String name, int occurrence, ICompilationUnit cu) { - return this.buildField(this.testType(cu), name, occurrence, cu); - } - - protected JDTFieldAttribute buildField(Type declaringType, String name, int occurrence, ICompilationUnit cu) { - return new JDTFieldAttribute(declaringType, name, occurrence, cu); - } - - protected JDTMethodAttribute idGetMethod(ICompilationUnit cu) { - return this.buildMethod("getId", cu); - } - - protected JDTMethodAttribute idSetMethod(ICompilationUnit cu) { - return this.buildMethod("setId", new String[] {"int"}, cu); - } - - protected JDTMethodAttribute nameGetMethod(ICompilationUnit cu) { - return this.buildMethod("getName", cu); - } - - protected JDTMethodAttribute buildMethod(String name, ICompilationUnit cu) { - return this.buildMethod(name, EMPTY_STRING_ARRAY, cu); - } - - protected JDTMethodAttribute buildMethod(String name, String[] parameterTypeNames, ICompilationUnit cu) { - return this.buildMethod(name, parameterTypeNames, 1, cu); - } - - protected JDTMethodAttribute buildMethod(String name, String[] parameterTypeNames, int occurrence, ICompilationUnit cu) { - return new JDTMethodAttribute(this.testType(cu), name, parameterTypeNames, occurrence, cu); - } - - protected JDTMethodAttribute buildMethod(Type declaringType, String name, String[] parameterTypeNames, int occurrence, ICompilationUnit cu) { - return new JDTMethodAttribute(declaringType, name, parameterTypeNames, occurrence, cu); - } - - protected String getSource(ICompilationUnit cu) throws JavaModelException { - return cu.getBuffer().getContents(); - } - - protected CompilationUnit buildASTRoot(ICompilationUnit cu) { - return JDTTools.buildASTRoot(cu); - } - - - // ********** test validation ********** - - protected void assertSourceContains(String s, ICompilationUnit cu) throws JavaModelException { - String source = this.getSource(cu); - boolean found = source.indexOf(s) > -1; - if ( ! found) { - String msg = "source does not contain the expected string: " + s + " (see System console)"; - System.out.println("*** " + this.getName() + " ****"); - System.out.println(msg); - System.out.println(source); - System.out.println(); - fail(msg); - } - } - - protected void assertSourceDoesNotContain(String s, ICompilationUnit cu) throws JavaModelException { - String source = this.getSource(cu); - int pos = source.indexOf(s); - if (pos != -1) { - String msg = "unexpected string in source (position: " + pos + "): " + s + " (see System console)"; - System.out.println("*** " + this.getName() + " ****"); - System.out.println(msg); - System.out.println(source); - System.out.println(); - fail(msg); - } - } - - - // ********** manipulate annotations ********** - - /** - * Return the *first* member value pair for the specified annotation element - * with the specified name. - * Return null if the annotation has no such element. - */ - protected MemberValuePair memberValuePair(NormalAnnotation annotation, String elementName) { - for (MemberValuePair pair : this.values(annotation)) { - if (pair.getName().getFullyQualifiedName().equals(elementName)) { - return pair; - } - } - return null; - } - - /** - * minimize the scope of the suppressed warnings - */ - @SuppressWarnings("unchecked") - protected List<MemberValuePair> values(NormalAnnotation na) { - return na.values(); - } - - /** - * check for null member value pair - */ - protected Expression value_(MemberValuePair pair) { - return (pair == null) ? null : pair.getValue(); - } - - /** - * Return the value of the *first* annotation element - * with the specified name. - * Return null if the annotation has no such element. - */ - protected Expression annotationElementValue(NormalAnnotation annotation, String elementName) { - return this.value_(this.memberValuePair(annotation, elementName)); - } - - /** - * Return the value of the *first* annotation element - * with the specified name. - * Return null if the annotation has no such element. - */ - protected Expression annotationElementValue(SingleMemberAnnotation annotation, String elementName) { - return elementName.equals("value") ? annotation.getValue() : null; - } - - /** - * Return the value of the *first* annotation element - * with the specified name. - * Return null if the annotation has no such element. - * (An element name of "value" will return the value of a single - * member annotation.) - */ - protected Expression annotationElementValue(Annotation annotation, String elementName) { - if (annotation.isNormalAnnotation()) { - return this.annotationElementValue((NormalAnnotation) annotation, elementName); - } - if (annotation.isSingleMemberAnnotation()) { - return this.annotationElementValue((SingleMemberAnnotation) annotation, elementName); - } - return null; - } - - /** - * Build a number literal and set its initial value to the specified literal. - */ - protected NumberLiteral newNumberLiteral(AST ast, int value) { - return ast.newNumberLiteral(Integer.toString(value)); - } - - /** - * Build a string literal and set its initial value. - */ - protected StringLiteral newStringLiteral(AST ast, String value) { - StringLiteral stringLiteral = ast.newStringLiteral(); - stringLiteral.setLiteralValue(value); - return stringLiteral; - } - - protected MemberValuePair newMemberValuePair(AST ast, SimpleName name, Expression value) { - MemberValuePair pair = ast.newMemberValuePair(); - pair.setName(name); - pair.setValue(value); - return pair; - } - - protected MemberValuePair newMemberValuePair(AST ast, String name, Expression value) { - return this.newMemberValuePair(ast, ast.newSimpleName(name), value); - } - - protected MemberValuePair newMemberValuePair(AST ast, String name, String value) { - return this.newMemberValuePair(ast, name, this.newStringLiteral(ast, value)); - } - - protected MemberValuePair newMemberValuePair(AST ast, String name, int value) { - return this.newMemberValuePair(ast, name, this.newNumberLiteral(ast, value)); - } - - /** - * Add the specified member value pair to the specified annotation. - * Return the resulting annotation. - */ - protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, MemberValuePair pair) { - this.values(annotation).add(pair); - return annotation; - } - - /** - * Add the specified member value pair to the specified annotation. - * Return the resulting annotation. - */ - protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, String name, int value) { - return this.addMemberValuePair(annotation, this.newMemberValuePair(annotation.getAST(), name, value)); - } - - /** - * Add the specified member value pair to the specified annotation. - * Return the resulting annotation. - */ - protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, String name, String value) { - return this.addMemberValuePair(annotation, this.newMemberValuePair(annotation.getAST(), name, value)); - } - - - // ********** member classes ********** - - public interface AnnotationWriter { - Iterator<String> imports(); - void appendTypeAnnotationTo(StringBuilder sb); - void appendExtendsImplementsTo(StringBuilder sb); - void appendIdFieldAnnotationTo(StringBuilder sb); - void appendNameFieldAnnotationTo(StringBuilder sb); - void appendGetIdMethodAnnotationTo(StringBuilder sb); - void appendSetIdMethodAnnotationTo(StringBuilder sb); - void appendGetNameMethodAnnotationTo(StringBuilder sb); - void appendSetNameMethodAnnotationTo(StringBuilder sb); - void appendMemberTypeTo(StringBuilder sb); - void appendTopLevelTypesTo(StringBuilder sb); - } - - public static class DefaultAnnotationWriter implements AnnotationWriter { - public Iterator<String> imports() {return EmptyIterator.instance();} - public void appendTypeAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendExtendsImplementsTo(StringBuilder sb) {/* do nothing */} - public void appendIdFieldAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendNameFieldAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendGetIdMethodAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendSetIdMethodAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendGetNameMethodAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendSetNameMethodAnnotationTo(StringBuilder sb) {/* do nothing */} - public void appendMemberTypeTo(StringBuilder sb) {/* do nothing */} - public void appendTopLevelTypesTo(StringBuilder sb) {/* do nothing */} - } - - public static class AnnotationWriterWrapper implements AnnotationWriter { - private final AnnotationWriter aw; - public AnnotationWriterWrapper(AnnotationWriter aw) { - super(); - this.aw = aw; - } - public Iterator<String> imports() {return aw.imports();} - public void appendTypeAnnotationTo(StringBuilder sb) {aw.appendTypeAnnotationTo(sb);} - public void appendExtendsImplementsTo(StringBuilder sb) {aw.appendExtendsImplementsTo(sb);} - public void appendIdFieldAnnotationTo(StringBuilder sb) {aw.appendIdFieldAnnotationTo(sb);} - public void appendNameFieldAnnotationTo(StringBuilder sb) {aw.appendNameFieldAnnotationTo(sb);} - public void appendGetIdMethodAnnotationTo(StringBuilder sb) {aw.appendGetIdMethodAnnotationTo(sb);} - public void appendSetIdMethodAnnotationTo(StringBuilder sb) {aw.appendSetIdMethodAnnotationTo(sb);} - public void appendGetNameMethodAnnotationTo(StringBuilder sb) {aw.appendGetNameMethodAnnotationTo(sb);} - public void appendSetNameMethodAnnotationTo(StringBuilder sb) {aw.appendSetNameMethodAnnotationTo(sb);} - public void appendMemberTypeTo(StringBuilder sb) {aw.appendMemberTypeTo(sb);} - public void appendTopLevelTypesTo(StringBuilder sb) {aw.appendTopLevelTypesTo(sb);} - } - - public class AnnotatedSourceWriter implements SourceWriter { - private AnnotationWriter annotationWriter; - private String typeName; - public AnnotatedSourceWriter(AnnotationWriter annotationWriter) { - this(annotationWriter, TYPE_NAME); - } - public AnnotatedSourceWriter(AnnotationWriter annotationWriter, String typeName) { - super(); - this.annotationWriter = annotationWriter; - this.typeName = typeName; - } - public void appendSourceTo(StringBuilder sb) { - AnnotationTestCase.this.appendSourceTo(sb, this.annotationWriter, typeName); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java deleted file mode 100644 index 10947d9ae4..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java +++ /dev/null @@ -1,730 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jpt.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; - -public class CombinationIndexedDeclarationAnnotationAdapterTests extends AnnotationTestCase { - - public CombinationIndexedDeclarationAnnotationAdapterTests(String name) { - super(name); - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - public void testAnnotation1() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isNormalAnnotation()); - } - - public void testAnnotation2() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotation3() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isNormalAnnotation()); - } - - public void testAnnotation4() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotation5() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isNormalAnnotation()); - String value = ((StringLiteral) ((MemberValuePair) ((NormalAnnotation) annotation).values().get(0)).getValue()).getLiteralValue(); - assertEquals("ADDRESS_ID2", value); - } - - public void testAnnotation6() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotation7() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isNormalAnnotation()); - String value = ((StringLiteral) ((MemberValuePair) ((NormalAnnotation) annotation).values().get(0)).getValue()).getLiteralValue(); - assertEquals("ADDRESS_ID2", value); - } - - public void testAnnotation8() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testRemoveAnnotation1() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumn", cu); - } - - public void testRemoveAnnotation2() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumns", cu); - this.assertSourceDoesNotContain("JoinColumn", cu); - } - - public void testRemoveAnnotation3() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumns", cu); - this.assertSourceDoesNotContain("ADDRESS_ID2", cu); - this.assertSourceContains("@JoinColumn(name=\"ADDRESS_ID1\")", cu); - } - - public void testRemoveAnnotation4() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumns", cu); - this.assertSourceDoesNotContain("ADDRESS_ID2", cu); - this.assertSourceContains("@JoinColumn(name=\"ADDRESS_ID1\")", cu); - } - - public void testRemoveAnnotation5() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "String comment(); JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(comment=\"test\",columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceContains("@annot.JoinColumns(comment=\"test\",columns=@annot.JoinColumn(name=\"ADDRESS_ID1\"))", cu); - } - - public void testRemoveAnnotation6() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(null)"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.removeAnnotation(); - this.assertSourceContains("@annot.JoinColumns(null)", cu); - } - - public void testRemoveAnnotation12() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID0\")"; - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("JoinColumns", cu); - } - - public void testRemoveAnnotation13() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null, @annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - this.assertSourceContains("@annot.JoinColumn", cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumn", cu); - } - - public void testRemoveAnnotation14() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), null})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID0\")"; - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation15() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})"); - String expected = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, null, @annot.JoinColumn(name=\"ADDRESS_ID3\")})"; - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation16() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})"); - String expected = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})"; - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 3); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation17() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null, null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - this.assertSourceContains("@annot.JoinColumn", cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("JoinColumn", cu); - } - - public void testNewMarkerAnnotation1() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("JoinColumn", cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("JoinColumn", cu); - this.assertSourceDoesNotContain("JoinColumns", cu); - } - - public void testNewMarkerAnnotation2() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn"); - this.assertSourceDoesNotContain("JoinColumns", cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@JoinColumns(columns={@JoinColumn,@JoinColumn})", cu); - } - - public void testNewMarkerAnnotation3() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn, @annot.JoinColumn})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn, @annot.JoinColumn," + CR + " @JoinColumn})", cu); - } - - public void testNewMarkerAnnotation4() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(77)"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("JoinColumn", cu); - this.assertSourceDoesNotContain("JoinColumns", cu); - this.assertSourceDoesNotContain("77", cu); - } - - public void testNewMarkerAnnotation5() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns=@annot.JoinColumn(77))"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.JoinColumns(columns=@JoinColumn)", cu); - this.assertSourceDoesNotContain("77", cu); - } - - public void testNewMarkerAnnotation6() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns=@annot.JoinColumn(77))"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn(77),@JoinColumn})", cu); - } - - public void testNewMarkerAnnotation7() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(77)"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@JoinColumns(columns={@JoinColumn(77),@JoinColumn})", cu); - } - - public void testNewMarkerAnnotation8() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(77),@annot.JoinColumn(88)})"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn(77),@JoinColumn})", cu); - } - - public void testNewMarkerAnnotation9() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"blah\",num=42)"); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@JoinColumns(columns={@JoinColumn(text=\"blah\", num=42),@JoinColumn})", cu); - } - - public void testNewMarkerAnnotation23() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"blah\",num=42)"); - String expected = "@JoinColumns(columns={@JoinColumn(text=\"blah\", num=42),null,@JoinColumn})"; - this.assertSourceDoesNotContain(expected, cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation24() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"blah\",num=42)"); - String expected1 = "@JoinColumns({"; - String expected2 = "@JoinColumn(text=\"blah\", num=42),null,"; - String expected3 = "@JoinColumn" + CR + " })"; - this.assertSourceDoesNotContain(expected1, cu); - this.assertSourceDoesNotContain(expected2, cu); - this.assertSourceDoesNotContain(expected3, cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected1, cu); - this.assertSourceContains(expected2, cu); - this.assertSourceContains(expected3, cu); - } - - public void testNewMarkerAnnotation25() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected1 = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, null,"; // the line gets split - String expected2 = "@JoinColumn})"; - this.assertSourceDoesNotContain(expected1, cu); - this.assertSourceDoesNotContain(expected2, cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 4); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected1, cu); - this.assertSourceContains(expected2, cu); - } - - public void testNewMarkerAnnotation26() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected1 = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, null,"; // the line gets split - String expected2 = "@JoinColumn})"; - this.assertSourceDoesNotContain(expected1, cu); - this.assertSourceDoesNotContain(expected2, cu); - DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 4); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected1, cu); - this.assertSourceContains(expected2, cu); - } - - public void testMoveAnnotation1() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID0\")"); - String expected = "@JoinColumns(columns={null,@JoinColumn(name=\"ADDRESS_ID0\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(1); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation2() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={null,@annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID1\")"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("JoinColumns", cu); - } - - public void testMoveAnnotation2a() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null,@annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID1\")"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 1); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("JoinColumns", cu); - } - - public void testMoveAnnotation3() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})"); - String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 3); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation4() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID4\")})"); - String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 3); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation5() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 2); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation6() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID0\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation7() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 3); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation8() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})"); - String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})"; - this.assertSourceDoesNotContain(expected, cu); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 3); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation9() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})"; - ICompilationUnit cu = this.createTestType(expected); // the source should be unchanged - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 0); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation10() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID0\")"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 2); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(1); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("@annot.JoinColumns", cu); - } - - public void testMoveAnnotation10a() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID0\")"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "value", 2); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(1); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("@annot.JoinColumns", cu); - } - - public void testMoveAnnotation11() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID0\")"); - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 1); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceDoesNotContain("JoinColumn", cu); - } - - public void testMoveAnnotation12() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})"); - String expected = "@JoinColumn(name=\"ADDRESS_ID2\")"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 2); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - this.assertSourceDoesNotContain("@annot.JoinColumns", cu); - } - - public void testMoveAnnotation13() throws Exception { - this.createAnnotationAndMembers("JoinColumn", "String name();"); - this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();"); - ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, @annot.JoinColumn(name=\"ADDRESS_ID3\")})"); - String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})"; - IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter( - "annot.JoinColumn", "annot.JoinColumns", "columns", 3); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), cidaa); - Annotation annotation = iaa.getAnnotation(JDTTools.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java deleted file mode 100644 index e3e909794a..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jpt.core.internal.utility.jdt.DefaultAnnotationEditFormatter; -import org.eclipse.jpt.utility.internal.ClassTools; - -public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase { - - - // ********** TestCase behavior ********** - - public DefaultAnnotationEditFormatterTests(String name) { - super(name); - } - - - // ********** tests ********** - - public void testCommaLength() throws Exception { - assertEquals(1, this.commaLength(",")); - assertEquals(1, this.commaLength(", ")); - assertEquals(1, this.commaLength(", ")); - - assertEquals(2, this.commaLength(" ,")); - assertEquals(2, this.commaLength(" , ")); - assertEquals(2, this.commaLength(" , ")); - - assertEquals(3, this.commaLength(" ,")); - assertEquals(3, this.commaLength(" , ")); - assertEquals(3, this.commaLength(" , ")); - - assertEquals(0, this.commaLength(" ,,,")); - assertEquals(0, this.commaLength(" ,,, ")); - assertEquals(0, this.commaLength(" , ,")); - - assertEquals(0, this.commaLength(" ,x")); - assertEquals(0, this.commaLength(" ,x ")); - assertEquals(0, this.commaLength(" , x")); - - assertEquals(0, this.commaLength("x ,")); - assertEquals(0, this.commaLength("x , ")); - assertEquals(0, this.commaLength("x , ")); - } - - private int commaLength(String s) { - Integer len = (Integer) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s); - return len.intValue(); - } - - public void testStringIsAnnotation() throws Exception { - assertTrue(this.stringIsAnnotation("@F")); - assertTrue(this.stringIsAnnotation("@Foo")); - assertTrue(this.stringIsAnnotation("@org.bar.Foo")); - - assertFalse(this.stringIsAnnotation("")); - assertFalse(this.stringIsAnnotation("@")); - assertFalse(this.stringIsAnnotation("Foo")); - assertFalse(this.stringIsAnnotation("Foo@")); - } - - private boolean stringIsAnnotation(String s) { - Boolean b = (Boolean) ClassTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s); - return b.booleanValue(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JDTToolsTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JDTToolsTests.java deleted file mode 100644 index f644cabc17..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JDTToolsTests.java +++ /dev/null @@ -1,87 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Name; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute; -import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; - -public class JDTToolsTests extends AnnotationTestCase { - - public JDTToolsTests(String name) { - super(name); - } - - private void createEnumAndMembers(String enumName, String enumBody) throws Exception { - this.javaProject.createCompilationUnit("enums", enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - public void testResolveEnum1() throws Exception { - this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - - ICompilationUnit cu = this.createTestType("@annot.TestAnnotation(foo=enums.TestEnum.BAZ)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo"); - JDTFieldAttribute field = this.idField(cu); - - String actual = JDTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu)))); - assertEquals("enums.TestEnum.BAZ", actual); - } - - public void testResolveEnum2() throws Exception { - this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - - ICompilationUnit cu = this.createTestType("static enums.TestEnum.BAZ", "@annot.TestAnnotation(foo=BAZ)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo"); - JDTFieldAttribute field = this.idField(cu); - - String actual = JDTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu)))); - assertEquals("enums.TestEnum.BAZ", actual); - } - - public void testResolveEnum3() throws Exception { - this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - - ICompilationUnit cu = this.createTestType("static enums.TestEnum.*", "@annot.TestAnnotation(foo=BAZ)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo"); - JDTFieldAttribute field = this.idField(cu); - - String actual = JDTTools.resolveEnum((Name)daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu)))); - assertEquals("enums.TestEnum.BAZ", actual); - } - - public void testResolveEnum4() throws Exception { - this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ"); - this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();"); - - ICompilationUnit cu = this.createTestType("enums.TestEnum", "@annot.TestAnnotation(foo=TestEnum.BAZ)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo"); - JDTFieldAttribute field = this.idField(cu); - - String actual = JDTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu)))); - assertEquals("enums.TestEnum.BAZ", actual); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JptCoreUtilityJdtTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JptCoreUtilityJdtTests.java deleted file mode 100644 index e95256f3e5..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/JptCoreUtilityJdtTests.java +++ /dev/null @@ -1,39 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptCoreUtilityJdtTests { - - public static Test suite() { - return suite(true); - } - - public static Test suite(boolean all) { - TestSuite suite = new TestSuite(JptCoreUtilityJdtTests.class.getPackage().getName()); - suite.addTestSuite(CombinationIndexedDeclarationAnnotationAdapterTests.class); - suite.addTestSuite(DefaultAnnotationEditFormatterTests.class); - suite.addTestSuite(JDTToolsTests.class); - suite.addTestSuite(MemberAnnotationElementAdapterTests.class); - suite.addTestSuite(NestedDeclarationAnnotationAdapterTests.class); - suite.addTestSuite(NestedIndexedDeclarationAnnotationAdapterTests.class); - suite.addTestSuite(SimpleDeclarationAnnotationAdapterTests.class); - suite.addTestSuite(TypeTests.class); - return suite; - } - - private JptCoreUtilityJdtTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java deleted file mode 100644 index 0f25f9bbb7..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java +++ /dev/null @@ -1,949 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import java.util.Arrays; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.internal.utility.jdt.ASTNodeTextRange; -import org.eclipse.jpt.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.BooleanExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.CharacterStringExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumArrayDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationElementAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NumberIntegerExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.PrimitiveTypeStringExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleTypeStringExpressionConverter; -import org.eclipse.jpt.core.internal.utility.jdt.StringExpressionConverter; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter; -import org.eclipse.jpt.core.utility.jdt.ExpressionConverter; - -public class MemberAnnotationElementAdapterTests extends AnnotationTestCase { - - public MemberAnnotationElementAdapterTests(String name) { - super(name); - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - private void createEnum(String enumName, String enumBody) throws Exception { - this.javaProject.createCompilationUnit("enums", enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); - } - - public void testValue1() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"xxx\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("xxx", aea.getValue()); - } - - public void testValue2() throws Exception { - this.createAnnotationAndMembers("Foo", "int bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=48)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Integer> daea = new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, "bar", NumberIntegerExpressionConverter.instance()); - AnnotationElementAdapter<Integer> aea = new MemberAnnotationElementAdapter<Integer>(this.idField(cu), daea); - assertEquals(Integer.valueOf(48), aea.getValue()); - } - - public void testValue3() throws Exception { - this.createAnnotationAndMembers("Foo", "char bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar='c')"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", CharacterStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("c", aea.getValue()); - } - - public void testValue4() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=false)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa, "bar", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValue5() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))"); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValue6() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(false)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa, BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValueNull1() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueNull2() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueNull3() throws Exception { - this.createAnnotationAndMembers("Baz", "String fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(jimmy=@annot.Baz))"); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa3, "fred"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueStringConcatenation() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"xxx\" + \"yyy\" + \"zzz\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("xxxyyyzzz", aea.getValue()); - } - - public void testValueStringConstant() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - // just a bit hacky: - ICompilationUnit cu = this.createTestType("private static final String FOO_BAR = \"xxx\"; @annot.Foo(bar=FOO_BAR + \"yyy\" + \"zzz\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("xxxyyyzzz", aea.getValue()); - } - - public void testValueNumberArithmetic() throws Exception { - this.createAnnotationAndMembers("Foo", "int bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=47 - 7 + 2 * 1 / 1)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar"); - AnnotationElementAdapter<Integer> aea = new MemberAnnotationElementAdapter<Integer>(this.idField(cu), daea); - assertEquals(Integer.valueOf(42), aea.getValue()); - } - - public void testValueNumberShift() throws Exception { - this.createAnnotationAndMembers("Foo", "int bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=2 << 2)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar"); - AnnotationElementAdapter<Integer> aea = new MemberAnnotationElementAdapter<Integer>(this.idField(cu), daea); - assertEquals(Integer.valueOf(8), aea.getValue()); - } - - public void testValueNumberConstant() throws Exception { - this.createAnnotationAndMembers("Foo", "int bar();"); - // just a bit hacky: - ICompilationUnit cu = this.createTestType("private static final int FOO_BAR = 77; @annot.Foo(bar=FOO_BAR)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar"); - AnnotationElementAdapter<Integer> aea = new MemberAnnotationElementAdapter<Integer>(this.idField(cu), daea); - assertEquals(Integer.valueOf(77), aea.getValue()); - } - - public void testValueCharacterConstant() throws Exception { - this.createAnnotationAndMembers("Foo", "char bar();"); - // just a bit hacky: - ICompilationUnit cu = this.createTestType("private static final char FOO_BAR = 'Q'; @annot.Foo(bar=FOO_BAR)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("Q", aea.getValue()); - } - - public void testValueCharacterCast() throws Exception { - this.createAnnotationAndMembers("Foo", "char bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(char) 0x41)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("A", aea.getValue()); - } - - public void testValueBooleanOperator1() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=7 > 2)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar"); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.TRUE, aea.getValue()); - } - - public void testValueBooleanOperator2() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=7 == 2)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar"); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValueBooleanOperator3() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(7 != 2) && false)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar"); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValueBooleanOperator4() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(7 != 2) ? false : true)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar"); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - } - - public void testValueInvalidValue1() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=77)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue2() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=bazzzz)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue3() throws Exception { - this.createAnnotationAndMembers("Foo", "boolean bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=bazzzz)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar"); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue4() throws Exception { - this.createAnnotationAndMembers("Foo", "char bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"bazzzz\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue5() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"java.lang.Object\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue6() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue7() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String value = "\"false\""; - String element = "fred=" + value; - String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(" + element + ")))"; - ICompilationUnit cu = this.createTestType(annotation); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueInvalidValue8() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={true, false})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {null, null}, aea.getValue())); - } - - public void testValueInvalidValue9() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=77)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {null}, aea.getValue())); - } - - public void testASTNode1() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - String value = "\"xxx\""; - String element = "bar=" + value; - String annotation = "@annot.Foo(" + element + ")"; - ICompilationUnit cu = this.createTestType(annotation); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - TextRange textRange = new ASTNodeTextRange(aea.getAstNode(this.buildASTRoot(cu))); - assertEquals(this.getSource(cu).indexOf(value), textRange.getOffset()); - assertEquals(value.length(), textRange.getLength()); - assertEquals(8, textRange.getLineNumber()); - } - - public void testASTNode2() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String value = "false"; - String element = "fred=" + value; - String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(" + element + ")))"; - ICompilationUnit cu = this.createTestType(annotation); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - assertEquals(Boolean.FALSE, aea.getValue()); - TextRange textRange = new ASTNodeTextRange(aea.getAstNode(this.buildASTRoot(cu))); - assertEquals(value.length(), textRange.getLength()); - } - - public void testASTNode3() throws Exception { - this.createAnnotationAndMembers("Foo", "String value();"); - String element = "\"xxx\""; - String annotation = "@annot.Foo(" + element + ")"; - ICompilationUnit cu = this.createTestType(annotation); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - TextRange textRange = new ASTNodeTextRange(aea.getAstNode(this.buildASTRoot(cu))); - assertEquals(this.getSource(cu).indexOf(element), textRange.getOffset()); - assertEquals(element.length(), textRange.getLength()); - } - - public void testASTNode4() throws Exception { - this.createAnnotationAndMembers("Foo", "String value();"); - String annotation = "@annot.Foo"; - ICompilationUnit cu = this.createTestType(annotation); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - TextRange textRange = new ASTNodeTextRange(aea.getAstNode(this.buildASTRoot(cu))); - assertEquals(this.getSource(cu).indexOf(annotation), textRange.getOffset()); - assertEquals(annotation.length(), textRange.getLength()); - } - - public void testSetValue1() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - String annotation = "@annot.Foo(bar=\"xxx\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue(null); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testSetValue2() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - String annotation = "@annot.Foo(bar=\"xxx\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar", false); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue(null); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@Foo", cu); - } - - public void testSetValue3() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - - aea.setValue(null); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceDoesNotContain("Foo", cu); - this.assertSourceDoesNotContain("Bar", cu); - } - - public void testSetValue3a() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar", false); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz", false); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - - aea.setValue(null); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@annot.Foo(@Bar)", cu); - } - - public void testSetValue4() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("xxx"); - this.assertSourceContains("@Foo(bar=\"xxx\")", cu); - } - - public void testSetValue5() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - - aea.setValue(Boolean.TRUE); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=true)))", cu); - } - - public void testSetValue6() throws Exception { - this.createAnnotationAndMembers("Baz", "boolean fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz"); - DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance()); - AnnotationElementAdapter<Boolean> aea = new MemberAnnotationElementAdapter<Boolean>(this.idField(cu), daea); - - aea.setValue(Boolean.TRUE); - this.assertSourceContains("@Foo(@Bar(jimmy=@Baz(fred=true)))", cu); - } - - public void testSetValue7() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - String annotation = "@annot.Foo(bar=\"xxx\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("yyy"); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@annot.Foo(bar=\"yyy\")", cu); - } - - public void testSetValue8() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar();"); - String annotation = "@annot.Foo"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("xxx"); - this.assertSourceContains("@Foo(bar=\"xxx\")", cu); - } - - public void testSetValue9() throws Exception { - this.createAnnotationAndMembers("Foo", "String value(); String bar();"); - String annotation = "@annot.Foo(\"zzz\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("xxx"); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@Foo(value=\"zzz\", bar=\"xxx\")", cu); - } - - public void testSetValue10() throws Exception { - this.createAnnotationAndMembers("Foo", "String bar(); String baz();"); - String annotation = "@annot.Foo(bar=\"xxx\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "baz"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("yyy"); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@annot.Foo(bar=\"xxx\", baz = \"yyy\")", cu); - } - - public void testSetValue11() throws Exception { - this.createAnnotationAndMembers("Baz", "int fred();"); - this.createAnnotationAndMembers("Bar", "annot.Baz[] jimmy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - String annotation = "@annot.Foo(@annot.Bar(jimmy={@annot.Baz(fred=0), @annot.Baz(fred=1), @annot.Baz(fred=2), @annot.Baz(fred=3)}))"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "jimmy", 2, "annot.Baz"); - DeclarationAnnotationElementAdapter<Integer> daea = new ConversionDeclarationAnnotationElementAdapter<Integer>(daa3, "fred", NumberIntegerExpressionConverter.instance()); - AnnotationElementAdapter<Integer> aea = new MemberAnnotationElementAdapter<Integer>(this.idField(cu), daea); - - assertEquals(Integer.valueOf(2), aea.getValue()); - aea.setValue(Integer.valueOf(48)); - this.assertSourceContains("@annot.Foo(@annot.Bar(jimmy={@annot.Baz(fred=0), @annot.Baz(fred=1), @annot.Baz(fred=48), @annot.Baz(fred=3)}))", cu); - } - - public void testSetValue12() throws Exception { - this.createAnnotationAndMembers("Foo", "String value();"); - String annotation = "@annot.Foo"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "value"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("xxx"); - this.assertSourceContains("@Foo(\"xxx\")", cu); - } - - public void testSetValue13() throws Exception { - this.createAnnotationAndMembers("Foo", "String value();"); - String annotation = "@annot.Foo(\"zzz\")"; - ICompilationUnit cu = this.createTestType(annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "value"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - - aea.setValue("xxx"); - this.assertSourceDoesNotContain(annotation, cu); - this.assertSourceContains("@annot.Foo(\"xxx\")", cu); - } - - public void testSimpleTypeLiteral1() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.lang.Object.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("java.lang.Object", aea.getValue()); - } - - public void testSimpleTypeLiteral2() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - aea.setValue("java.lang.Object"); - this.assertSourceContains("@Foo(bar=java.lang.Object.class)", cu); - } - - public void testSimpleTypeLiteral3() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=int.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testSimpleTypeLiteral4() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.util.Map.Entry.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("java.util.Map.Entry", aea.getValue()); - } - - public void testPrimitiveTypeLiteral1() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=int.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("int", aea.getValue()); - } - - public void testPrimitiveTypeLiteral2() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - aea.setValue("int"); - this.assertSourceContains("@Foo(bar=int.class)", cu); - } - - public void testPrimitiveTypeLiteral3() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.lang.Object.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testPrimitiveTypeLiteral4() throws Exception { - this.createAnnotationAndMembers("Foo", "Class bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=void.class)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance()); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("void", aea.getValue()); - } - - public void testValueEnum1() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.XXX)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("enums.TestEnum.XXX", aea.getValue()); - } - - public void testValueEnum2() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - ICompilationUnit cu = this.createTestType("static enums.TestEnum.XXX", "@annot.Foo(bar=XXX)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("enums.TestEnum.XXX", aea.getValue()); - } - - public void testValueEnum3() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertNull(aea.getValue()); - } - - public void testValueEnum4() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - ICompilationUnit cu = this.createTestType("enums.TestEnum", "@annot.Foo(bar=TestEnum.XXX)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - assertEquals("enums.TestEnum.XXX", aea.getValue()); - } - - public void testSetValueEnum1() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - String annotation = "@annot.Foo(bar=XXX)"; - ICompilationUnit cu = this.createTestType("static enums.TestEnum.XXX", annotation); - this.assertSourceContains(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - aea.setValue(null); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testSetValueEnum2() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();"); - String annotation = "@Foo(bar=XXX)"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String> aea = new MemberAnnotationElementAdapter<String>(this.idField(cu), daea); - aea.setValue("enums.TestEnum.XXX"); - this.assertSourceContains("import static enums.TestEnum.XXX;", cu); - this.assertSourceContains(annotation, cu); - } - - public void testValueStringArray() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={\"string0\", \"string1\"})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"string0", "string1"}, aea.getValue())); - } - - public void testValueStringArrayConcatenation() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={\"stri\" + \"ng0\", \"s\" + \"tring1\"})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"string0", "string1"}, aea.getValue())); - } - - public void testValueStringArrayEmpty() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[0], aea.getValue())); - } - - public void testValueStringArraySingleElement() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"string0\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"string0"}, aea.getValue())); - } - - public void testValueNullStringArray() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo()"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[0], aea.getValue())); - } - - public void testSetValueStringArray() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - String annotation = "@Foo(bar={\"string0\",\"string1\"})"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[] {"string0", "string1"}); - this.assertSourceContains(annotation, cu); - } - - public void testSetValueStringArrayEmptyRemove() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - String annotation = "@Foo"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[0]); - this.assertSourceDoesNotContain(annotation, cu); - } - - public void testSetValueStringArrayEmpty() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - String annotation = "@Foo(bar={})"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - ExpressionConverter<String[]> expressionConverter = new AnnotationStringArrayExpressionConverter(StringExpressionConverter.instance(), false); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", expressionConverter); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[0]); - this.assertSourceContains(annotation, cu); - } - - public void testSetValueStringArraySingleElement() throws Exception { - this.createAnnotationAndMembers("Foo", "String[] bar();"); - String annotation = "@Foo(bar=\"string0\")"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings()); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[] {"string0"}); - this.assertSourceContains(annotation, cu); - } - - public void testValueEnumArray() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={enums.TestEnum.XXX, enums.TestEnum.YYY})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX", "enums.TestEnum.YYY"}, aea.getValue())); - } - - public void testValueEnumArrayInvalidEntry() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={enums.TestEnum.XXX, 88})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX", null}, aea.getValue())); - } - - public void testValueEnumArrayEmpty() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar={})"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[0], aea.getValue())); - } - - public void testValueEnumArraySingleElement() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.XXX)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX"}, aea.getValue())); - } - - public void testValueEnumArraySingleElementInvalid() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"\")"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[] {null}, aea.getValue())); - } - - public void testValueNullEnumArray() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - ICompilationUnit cu = this.createTestType("@annot.Foo()"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - assertTrue(Arrays.equals(new String[0], aea.getValue())); - } - - public void testSetValueEnumArray() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - String annotation = "@Foo(bar={XXX,YYY})"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[] {"enums.TestEnum.XXX", "enums.TestEnum.YYY"}); - this.assertSourceContains("import static enums.TestEnum.XXX;", cu); - this.assertSourceContains("import static enums.TestEnum.YYY;", cu); - this.assertSourceContains(annotation, cu); - } - - public void testSetValueEnumArrayEmptyRemove() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - String annotation = "@Foo"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[0]); - this.assertSourceDoesNotContain(annotation, cu); - } - - public void testSetValueEnumArrayEmpty() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - String annotation = "@Foo(bar={})"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar", true, false); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[0]); - this.assertSourceContains(annotation, cu); - } - - public void testSetValueEnumArraySingleElement() throws Exception { - this.createEnum("TestEnum", "XXX, YYY, ZZZ"); - this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();"); - String annotation = "@Foo(bar=XXX)"; - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain(annotation, cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar"); - AnnotationElementAdapter<String[]> aea = new MemberAnnotationElementAdapter<String[]>(this.idField(cu), daea); - aea.setValue(new String[] {"enums.TestEnum.XXX"}); - this.assertSourceContains("import static enums.TestEnum.XXX;", cu); - this.assertSourceContains(annotation, cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java deleted file mode 100644 index ff46aa3ab0..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java +++ /dev/null @@ -1,764 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -public class NestedDeclarationAnnotationAdapterTests extends AnnotationTestCase { - - public NestedDeclarationAnnotationAdapterTests(String name) { - super(name); - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - public void testAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar)"); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - } - - public void testAnnotation2() throws Exception { - this.createAnnotationAndMembers("Baz", "String value();"); - this.createAnnotationAndMembers("Bar", "annot.Baz yana();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar(yana=@annot.Baz))"); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "nestedAnnotation", "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "yana", "annot.Baz"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa3); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - } - - public void testAnnotationNull1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo()"); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull2() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull3() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "String nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=\"annot.Bar\")"); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull4() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Bar2", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar2 nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar2)"); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testRemoveAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - String na = "@annot.Foo(nestedAnnotation=@annot.Bar)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation1a() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - String na = "@annot.Foo(nestedAnnotation=@annot.Bar)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar", false); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains("Foo", cu); - } - - public void testRemoveAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "String nestedAnnotation();"); - String na = "@annot.Foo(nestedAnnotation=\"annot.Bar\")"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Bar2", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar2 nestedAnnotation();"); - String na = "@annot.Foo(nestedAnnotation=@annot.Bar2)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation5() throws Exception { - this.createAnnotationAndMembers("Baz", "String value();"); - this.createAnnotationAndMembers("Bar", "annot.Baz nestedAnnotation2();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation1();"); - String na = "@annot.Foo(nestedAnnotation1=@annot.Bar(nestedAnnotation2=@annot.Baz))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daaFoo = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daaBar = new NestedDeclarationAnnotationAdapter(daaFoo, "nestedAnnotation1", "annot.Bar"); - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(daaBar, "nestedAnnotation2", "annot.Baz"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceDoesNotContain("Foo", cu); - this.assertSourceDoesNotContain("Bar", cu); - this.assertSourceDoesNotContain("Baz", cu); - } - - public void testRemoveAnnotation5a() throws Exception { - this.createAnnotationAndMembers("Baz", "String value();"); - this.createAnnotationAndMembers("Bar", "annot.Baz nestedAnnotation2();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation1();"); - String na = "@annot.Foo(nestedAnnotation1=@annot.Bar(nestedAnnotation2=@annot.Baz))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daaFoo = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daaBar = new NestedDeclarationAnnotationAdapter(daaFoo, "nestedAnnotation1", "annot.Bar", false); - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(daaBar, "nestedAnnotation2", "annot.Baz", false); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains("@annot.Foo(nestedAnnotation1=@Bar)", cu); - } - - public void testNewMarkerAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(nestedAnnotation=@Bar)", cu); - } - - public void testNewMarkerAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(@Bar)", cu); - } - - public void testNewMarkerAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotation=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotation=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "Object value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewSingleMemberAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation1(declaration); - } - }); - this.assertSourceContains("@Foo(nestedAnnotation=@Bar(\"test string literal\"))", cu); - } - - void editNewSingleMemberAnnotation1(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation2(declaration); - } - }); - this.assertSourceContains("@Foo(@Bar(\"test string literal\"))", cu); - } - - void editNewSingleMemberAnnotation2(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotation=@Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation3(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation3(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation4(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation4(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotation=@Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation5(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation5(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "Object value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation6(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation6(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String xxx();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation7(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation7(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewSingleMemberAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value(); String xxx();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar(\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation8(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation8(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewNormalAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation1(declaration); - } - }); - this.assertSourceContains("@Foo(nestedAnnotation=@Bar(yyy=\"test string literal\"))", cu); - } - - void editNewNormalAnnotation1(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation2(declaration); - } - }); - this.assertSourceContains("@Foo(@Bar(yyy=\"test string literal\"))", cu); - } - - void editNewNormalAnnotation2(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotation=@Bar(yyy=\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation3(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation3(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar(yyy=\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation4(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation4(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotation=@Bar(yyy=\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation5(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation5(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "Object value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar(yyy=\"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation6(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation6(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar nestedAnnotation();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar(yyy = \"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation7(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation7(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - - public void testNewNormalAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "String yyy();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar(yyy = \"test string literal\"))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation8(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation8(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "yyy", "test string literal"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java deleted file mode 100644 index 50c8a83abd..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java +++ /dev/null @@ -1,2219 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.NumberLiteral; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.MemberIndexedAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.IndexedDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -public class NestedIndexedDeclarationAnnotationAdapterTests extends AnnotationTestCase { - - public NestedIndexedDeclarationAnnotationAdapterTests(String name) { - super(name); - } - - private void createAnnotation(String annotationName) throws Exception { - this.createAnnotationAndMembers(annotationName, ""); - } - - private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }"); - } - - public void testAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar, @annot.Bar(\"two\")})"); - // 0 - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa.getAnnotation(astRoot); - assertNotNull(annotation); - assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - - // 1 - daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 1, "annot.Bar"); - aa = new MemberAnnotationAdapter(this.idField(cu), daa); - annotation = aa.getAnnotation(astRoot); - assertNotNull(annotation); - assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isSingleMemberAnnotation()); - } - - public void testAnnotation2() throws Exception { - this.createAnnotation("Baz"); - this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana=@annot.Baz))"); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Baz"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa3); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - } - - public void testAnnotation3() throws Exception { - this.createAnnotation("Baz"); - this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana={@annot.Baz}))"); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Baz"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa3); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa.getAnnotation(astRoot); - assertNotNull(annotation); - assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - - // name mismatch - daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Xyz"); - aa = new MemberAnnotationAdapter(this.idField(cu), daa3); - annotation = aa.getAnnotation(astRoot); - assertNull(annotation); - } - - public void testAnnotationNull1() throws Exception { - this.createAnnotation("Bar"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo()"); - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull2() throws Exception { - this.createAnnotation("Bar"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull3() throws Exception { - this.createAnnotation("Bar"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"annot.Bar\")"); - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull4() throws Exception { - this.createAnnotation("NotBar"); - this.createAnnotation("Bar"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull5() throws Exception { - this.createAnnotationAndMembers("Bar", "String value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar, @annot.Bar(\"two\")})"); - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull6() throws Exception { - this.createAnnotation("Xyz"); - this.createAnnotation("Baz"); - this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana={@annot.Baz}))"); - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar"); - DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Xyz"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa3); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testRemoveAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1)})"; - String expected = "@annot.Foo(nestedAnnotations={null, @annot.Bar(1)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={\"annot.Bar1\", \"annot.Bar2\", \"annot.Bar3\"})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation4() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.NotBar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.NotBar(0), @annot.NotBar(1)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations=@annot.Bar)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - assertNull(aa.getAnnotation(this.buildASTRoot(cu))); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation5a() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations=@annot.Bar)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar", false); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertTrue(aa1.getAnnotation(this.buildASTRoot(cu)).isMarkerAnnotation()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains("import annot.Foo;", cu); - this.assertSourceContains("@Foo", cu); - } - - public void testRemoveAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations=\"annot.Bar\")"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation7() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.NotBar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations=@annot.NotBar)"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.removeAnnotation(); - this.assertSourceContains(na, cu); - } - - public void testRemoveAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1), @annot.Bar(2), @annot.Bar(3)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertTrue(aa1.getAnnotation(astRoot).isNormalAnnotation()); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1), null, @annot.Bar(3)})", cu); - } - - public void testRemoveAnnotation9() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1), @annot.Bar(2), @annot.Bar(3)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertTrue(aa1.getAnnotation(astRoot).isSingleMemberAnnotation()); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains("@annot.Foo({@annot.Bar(0), @annot.Bar(1), null, @annot.Bar(3)})", cu); - } - - public void testRemoveAnnotation10() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1)})"; - String expected = "@annot.Foo({null, @annot.Bar(1)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 0, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation11() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1)})"; - String expected = "@annot.Foo(@annot.Bar(0))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 1, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation12() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2)})"; - String expected = "@annot.Foo(@annot.Bar(0))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation13() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({null, @annot.Bar(1)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 1, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation14() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), null})"; - String expected = "@annot.Foo(@annot.Bar(0))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation15() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})"; - String expected = "@annot.Foo({@annot.Bar(0), null, null, @annot.Bar(3)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation16() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})"; - String expected = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 3, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation17() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2)})"; - String expected = "@annot.Foo(nestedAnnotations=@annot.Bar(0))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "nestedAnnotations").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation18() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={null, @annot.Bar(1)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 1, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testRemoveAnnotation19() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), null})"; - String expected = "@annot.Foo(nestedAnnotations=@annot.Bar(0))"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "nestedAnnotations").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation20() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})"; - String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, null, @annot.Bar(3)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testRemoveAnnotation21() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})"; - String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2)})"; - ICompilationUnit cu = this.createTestType(na); - this.assertSourceDoesNotContain(expected, cu); - this.assertSourceContains(na, cu); - - DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa1 = new MemberAnnotationAdapter(this.idField(cu), daa1); - DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 3, "annot.Bar"); - AnnotationAdapter aa2 = new MemberAnnotationAdapter(this.idField(cu), daa2); - CompilationUnit astRoot = this.buildASTRoot(cu); - Annotation annotation = aa2.getAnnotation(astRoot); - assertNotNull(annotation); - - aa2.removeAnnotation(); - assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType()); - this.assertSourceDoesNotContain(na, cu); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(nestedAnnotations=@Bar)", cu); - } - - public void testNewMarkerAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("Foo", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(@Bar)", cu); - } - - public void testNewMarkerAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotations=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotations=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation9() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - assertNull(aa.getAnnotation(this.buildASTRoot(cu))); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(nestedAnnotations={null,null,null,null,null,@Bar})", cu); - } - - public void testNewMarkerAnnotation10() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - this.assertSourceDoesNotContain("Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@Foo(value=\"something\", nestedAnnotations={null,null,null,null,null,@Bar})", cu); - } - - public void testNewMarkerAnnotation11() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - String expected = "@annot.Foo({@Bar, \"two\"})"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation12() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - this.assertSourceDoesNotContain("Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("Bar})", cu); // split line - } - - public void testNewMarkerAnnotation13() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - String expected = "@annot.Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation14() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - this.assertSourceDoesNotContain("Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar})", cu); - } - - public void testNewMarkerAnnotation15() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)"); - String expected = "@annot.Foo(@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation16() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))"); - String expected = "@annot.Foo({@annot.Bar(55),@Bar})"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation17() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - String expected = "@annot.Foo(nestedAnnotations={@Bar})"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation18() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - this.assertSourceDoesNotContain("Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("Bar})", cu); // split line - } - - public void testNewMarkerAnnotation19() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"something\")"); - String expected = "@annot.Foo(nestedAnnotations=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation20() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - String expected = "@annot.Foo(nestedAnnotations=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation21() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar})", cu); - } - - public void testNewMarkerAnnotation22() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(88))"); - String expected = "@annot.Foo(nestedAnnotations=@Bar)"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation23() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(88))"); - String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(88),null,@Bar})"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 2, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation24() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(88))"); - String expected = "@annot.Foo({@annot.Bar(88),null,@Bar})"; - this.assertSourceDoesNotContain(expected, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected, cu); - } - - public void testNewMarkerAnnotation25() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar(88), @annot.Bar(77)})"); - String expected1 = "@annot.Foo(nestedAnnotations={@annot.Bar(88), @annot.Bar(77), null, null,"; // the line gets split - String expected2 = "@Bar})"; - this.assertSourceDoesNotContain(expected1, cu); - this.assertSourceDoesNotContain(expected2, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 4, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected1, cu); - this.assertSourceContains(expected2, cu); - } - - public void testNewMarkerAnnotation26() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(88), @annot.Bar(77)})"); - String expected1 = "@annot.Foo({@annot.Bar(88), @annot.Bar(77), null, null,"; // the line gets split - String expected2 = "@Bar})"; - this.assertSourceDoesNotContain(expected1, cu); - this.assertSourceDoesNotContain(expected2, cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 4, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - aa.newMarkerAnnotation(); - this.assertSourceContains(expected1, cu); - this.assertSourceContains(expected2, cu); - } - - public void testNewSingleMemberAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation1(declaration); - } - }); - this.assertSourceContains("@Foo(nestedAnnotations=@Bar(88))", cu); - } - - void editNewSingleMemberAnnotation1(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation2(declaration); - } - }); - this.assertSourceContains("@Foo(@Bar(88))", cu); - } - - void editNewSingleMemberAnnotation2(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotations=@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation3(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation3(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation4(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation4(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotations=@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation5(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation5(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation6(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation6(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation7(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation7(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation8(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation8(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation9() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@Foo(nestedAnnotations={null,null,null,null,null,@Bar(MISSING)})", cu); // ??? - } - - public void testNewSingleMemberAnnotation10() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@Foo(value=\"something\", nestedAnnotations={null,null,null,null,null,@Bar(MISSING)})", cu); // ??? - } - - public void testNewSingleMemberAnnotation11() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - String expected = "@annot.Foo({@Bar(88), \"two\"})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation11(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation11(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation12() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@Bar(MISSING)})", cu); // split line - } - - public void testNewSingleMemberAnnotation13() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - String expected = "@annot.Foo(@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation13(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation13(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation14() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar(MISSING)})", cu); - } - - public void testNewSingleMemberAnnotation15() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)"); - String expected = "@annot.Foo(@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation15(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation15(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation16() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))"); - String expected = "@annot.Foo({@annot.Bar(55),@Bar(88)})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation16(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation16(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation17() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - String expected = "@annot.Foo(nestedAnnotations={@Bar(88)})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation17(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation17(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation18() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@Bar(MISSING)})", cu); // ??? - } - - public void testNewSingleMemberAnnotation19() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"something\")"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation19(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation19(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation20() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation20(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation20(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewSingleMemberAnnotation21() throws Exception { - this.createAnnotationAndMembers("NotBar", "int value();"); - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newSingleMemberAnnotation(); - this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar(MISSING)})", cu); - } - - public void testNewSingleMemberAnnotation22() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(77))"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation22(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewSingleMemberAnnotation22(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - SingleMemberAnnotation annotation = daa.newSingleMemberAnnotation(declaration); - NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral(); - numberLiteral.setToken("88"); - annotation.setValue(numberLiteral); - } - - public void testNewNormalAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation1(declaration); - } - }); - this.assertSourceContains("@Foo(nestedAnnotations=@Bar(xxx=88))", cu); - } - - void editNewNormalAnnotation1(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation2(declaration); - } - }); - this.assertSourceContains("@Foo(@Bar(xxx=88))", cu); - } - - void editNewNormalAnnotation2(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(nestedAnnotations=@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation3(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation3(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - String expected = "@Foo(@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation4(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation4(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@Foo(value=\"something\", nestedAnnotations=@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation5(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation5(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - String expected = "@annot.Foo(@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation6(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation6(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String xxx();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar(xxx = 88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation7(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation7(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value(); String xxx();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")"); - String expected = "@annot.Foo(xxx=\"something\", value = @Bar(xxx = 88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation8(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation8(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation9() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String xxx();"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@Foo(nestedAnnotations={null,null,null,null,null,@Bar()})", cu); - } - - public void testNewNormalAnnotation10() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@Foo(value=\"something\", nestedAnnotations={null,null,null,null,null,@Bar()})", cu); - } - - public void testNewNormalAnnotation11() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - String expected = "@annot.Foo({@Bar(xxx=88), \"two\"})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation11(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation11(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation12() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@Bar()})", cu); // split line - } - - public void testNewNormalAnnotation13() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - String expected = "@annot.Foo(@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation13(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation13(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation14() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(7)"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar()})", cu); - } - - public void testNewNormalAnnotation15() throws Exception { - this.createAnnotationAndMembers("NotBar", "int xxx();"); - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)"); - String expected = "@annot.Foo(@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation15(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation15(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation16() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))"); - String expected = "@annot.Foo({@annot.Bar(55),@Bar(xxx=88)})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation16(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation16(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation17() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - String expected = "@annot.Foo(nestedAnnotations={@Bar(xxx=88)})"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation17(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation17(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation18() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@Bar()})", cu); // split line - } - - public void testNewNormalAnnotation19() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"something\")"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation19(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation19(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation20() throws Exception { - this.createAnnotationAndMembers("NotBar", "int xxx();"); - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation20(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation20(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testNewNormalAnnotation21() throws Exception { - this.createAnnotationAndMembers("NotBar", "int xxx();"); - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)"); - this.assertSourceDoesNotContain("@Bar", cu); - - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newNormalAnnotation(); - this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar()})", cu); - } - - public void testNewNormalAnnotation22() throws Exception { - this.createAnnotationAndMembers("Bar", "int xxx();"); - this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(77))"); - String expected = "@annot.Foo(nestedAnnotations=@Bar(xxx=88))"; - this.assertSourceDoesNotContain(expected, cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation22(declaration); - } - }); - this.assertSourceContains(expected, cu); - } - - void editNewNormalAnnotation22(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar"); - NormalAnnotation annotation = daa.newNormalAnnotation(declaration); - this.addMemberValuePair(annotation, "xxx", 88); - } - - public void testMoveAnnotation1() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(00))"); - String expected = "@annot.Foo({null,@annot.Bar(00)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(1); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation2() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({null, @annot.Bar(11)})"); - String expected = "@annot.Foo(@annot.Bar(11))"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation3() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), @annot.Bar(33)})"); - String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11), @annot.Bar(22)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation4() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), @annot.Bar(33), @annot.Bar(44)})"); - String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation5() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})"); - String expected = "@annot.Foo({@annot.Bar(00), @annot.Bar(11), null, @annot.Bar(22)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation6() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})"); - String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22), @annot.Bar(00)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation7() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})"); - String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation8() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})"); - String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})"; - this.assertSourceDoesNotContain(expected, cu); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation9() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22)})"; - ICompilationUnit cu = this.createTestType(expected); // the source should be unchanged - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(3); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation10() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11)})"); - String expected = "@annot.Foo(@annot.Bar(00))"; - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - iaa.moveAnnotation(1); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation11() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(00))"); - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceDoesNotContain("Foo", cu); - } - - public void testMoveAnnotation12() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), null, @annot.Bar(22)})"); - String expected = "@annot.Foo(@annot.Bar(22))"; - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - - public void testMoveAnnotation13() throws Exception { - this.createAnnotationAndMembers("Bar", "int value();"); - this.createAnnotationAndMembers("Foo", "annot.Bar[] value();"); - ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), null, @annot.Bar(33)})"); - String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11)})"; - - IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter( - new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar"); - IndexedAnnotationAdapter iaa = new MemberIndexedAnnotationAdapter(this.idField(cu), idaa); - Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - iaa.moveAnnotation(0); - this.assertSourceContains(expected, cu); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java deleted file mode 100644 index a091ff3a53..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java +++ /dev/null @@ -1,205 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.Annotation; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.MemberValuePair; -import org.eclipse.jdt.core.dom.NormalAnnotation; -import org.eclipse.jdt.core.dom.NumberLiteral; -import org.eclipse.jdt.core.dom.SingleMemberAnnotation; -import org.eclipse.jdt.core.dom.StringLiteral; -import org.eclipse.jpt.core.internal.utility.jdt.MemberAnnotationAdapter; -import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter; -import org.eclipse.jpt.core.utility.jdt.Member; -import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration; - -public class SimpleDeclarationAnnotationAdapterTests extends AnnotationTestCase { - - public SimpleDeclarationAnnotationAdapterTests(String name) { - super(name); - } - - private void createAnnotation(String annotationName) throws Exception { - this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " {}"); - } - - public void testAnnotation1() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.Foo", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - } - - public void testAnnotation2() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo(1) @annot.Foo(2)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("annot.Foo", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isSingleMemberAnnotation()); - Expression value = ((SingleMemberAnnotation) annotation).getValue(); - assertEquals(ASTNode.NUMBER_LITERAL, value.getNodeType()); - assertEquals("1", ((NumberLiteral) value).getToken()); - } - - public void testAnnotation3() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("annot.Foo", "@Foo"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - assertEquals("Foo", annotation.getTypeName().getFullyQualifiedName()); - assertTrue(annotation.isMarkerAnnotation()); - } - - public void testAnnotationNull1() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType(); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - } - - public void testAnnotationNull2() throws Exception { - this.createAnnotation("Foo"); - this.createAnnotation("Fop"); - ICompilationUnit cu = this.createTestType("@annot.Fop"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - this.assertSourceContains("@annot.Fop", cu); - } - - public void testAnnotationNull3() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - // un-qualified name - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - this.assertSourceContains("@annot.Foo", cu); - } - - public void testRemoveAnnotation1() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo"); - this.assertSourceContains("@annot.Foo", cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("@annot.Foo", cu); - } - - public void testRemoveAnnotation2() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo(1) @annot.Foo(2)"); - this.assertSourceContains("@annot.Foo(1) @annot.Foo(2)", cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.removeAnnotation(); - this.assertSourceDoesNotContain("@annot.Foo(1)", cu); - this.assertSourceContains("@annot.Foo(2)", cu); - } - - public void testNewMarkerAnnotation1() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@annot.Foo", cu); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("import annot.Foo;", cu); - this.assertSourceContains("@Foo", cu); - } - - public void testNewMarkerAnnotation2() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType("@annot.Foo(88)"); - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - AnnotationAdapter aa = new MemberAnnotationAdapter(this.idField(cu), daa); - Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu)); - assertNotNull(annotation); - - aa.newMarkerAnnotation(); - this.assertSourceContains("import annot.Foo;", cu); - this.assertSourceContains("@Foo", cu); - this.assertSourceDoesNotContain("@annot.Foo(88)", cu); - } - - public void testNewSingleMemberAnnotation() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - SimpleDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation(declaration); - } - }); - this.assertSourceContains("import annot.Foo;", cu); - this.assertSourceContains("@Foo(\"test string literal\")", cu); - } - - void editNewSingleMemberAnnotation(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newSingleMemberAnnotation(declaration); - StringLiteral stringLiteral = annotation.getAST().newStringLiteral(); - stringLiteral.setLiteralValue("test string literal"); - annotation.setValue(stringLiteral); - } - - public void testNewNormalAnnotation() throws Exception { - this.createAnnotation("Foo"); - ICompilationUnit cu = this.createTestType(); - this.assertSourceDoesNotContain("@Foo", cu); - this.idField(cu).edit(new Member.Editor() { - public void edit(ModifiedDeclaration declaration) { - SimpleDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation(declaration); - } - }); - this.assertSourceContains("import annot.Foo;", cu); - this.assertSourceContains("@Foo(bar=\"test string literal\")", cu); - } - - void editNewNormalAnnotation(ModifiedDeclaration declaration) { - DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo"); - NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration); - assertNull(annotation); - annotation = daa.newNormalAnnotation(declaration); - MemberValuePair mvp = this.newMemberValuePair(annotation.getAST(), "bar", "test string literal"); - this.values(annotation).add(mvp); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/TypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/TypeTests.java deleted file mode 100644 index 8efb3bef1b..0000000000 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/utility/jdt/TypeTests.java +++ /dev/null @@ -1,51 +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 - ******************************************************************************/ -package org.eclipse.jpt.core.tests.internal.utility.jdt; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; - -public class TypeTests extends AnnotationTestCase { - - public TypeTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - protected ICompilationUnit createCompilationUnit(String source) throws CoreException { - return this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, source); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void test1() throws Exception { - ICompilationUnit jdtCompilationUnit = this.createCompilationUnit(this.buildTest1Source()); - assertNotNull(jdtCompilationUnit); - } - - private String buildTest1Source() { - StringBuilder sb = new StringBuilder(); - sb.append("public class ").append(TYPE_NAME).append(" {").append(CR); - sb.append(" private int id;").append(CR); - sb.append(" public int getId() {").append(CR); - sb.append(" return this.id;").append(CR); - sb.append(" }").append(CR); - sb.append("}").append(CR); - return sb.toString(); - } - -} |