diff options
Diffstat (limited to 'jpa_diagram_editor')
8 files changed, 1 insertions, 1274 deletions
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RefactorAttributeTypeFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RefactorAttributeTypeFeatureTest.java deleted file mode 100644 index 4f600313fb..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RefactorAttributeTypeFeatureTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Date; -import java.util.List; - -import org.easymock.EasyMock; -import org.eclipse.core.resources.IFile; -import org.eclipse.graphiti.features.context.ICustomContext; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RefactorAttributeTypeFeature; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory; -import org.junit.Before; -import org.junit.Test; - -public class RefactorAttributeTypeFeatureTest { - - private IJPAEditorFeatureProvider featureProvider; - private ICustomContext context; - final String TEST_PROJECT = "Test"+(new Date()).getTime(); - private JpaProject jpaProject = null; - private JPACreateFactory factory = null; - private IFile entity; - - @Before - public void setUp() throws Exception{ - factory = JPACreateFactory.instance(); - jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis()); - assertNotNull(jpaProject); - entity = factory.createEntity(jpaProject, "org.eclipse.Ent"); - Thread.sleep(2000); - factory.addAttributes(entity, "att", "java.lang.String", "", "att", false); - - } - - @Test - public void testRefactorAttributeTypeFeature(){ - PictogramElement[] elements = new PictogramElement[1]; - PictogramElement element = EasyMock.createNiceMock(PictogramElement.class); - replay(element); - elements[0] = element; - - featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class); - expect(featureProvider.getBusinessObjectForPictogramElement(element)).andReturn(null); - replay(featureProvider); - - context = EasyMock.createMock(ICustomContext.class); - expect(context.getPictogramElements()).andReturn(elements); - replay(context); - - RefactorAttributeTypeFeature feature = new RefactorAttributeTypeFeature(featureProvider); - feature.execute(context); - } - - @Test - public void testAttributeUtils(){ - PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpaProject); - JavaPersistentType jpt = (JavaPersistentType)pu.getPersistentType("org.eclipse.Ent"); - JavaPersistentAttribute at = jpt.getAttributeNamed("id"); - List<String> lst = JpaArtifactFactory.instance().getAnnotationStrings(at); - assertEquals(1, lst.size()); - assertTrue(lst.contains("@Id")); - String typeName1 = JPAEditorUtil.getAttributeTypeName(at); - assertEquals("int", typeName1); - String typeName2 = JPAEditorUtil.getAttributeTypeName(at.getResourceAttribute()); - assertEquals("int", typeName2); - } - -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java deleted file mode 100644 index 34e3ba1189..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.ui; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.easymock.EasyMock; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.graphiti.dt.IDiagramTypeProvider; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.platform.IDiagramEditor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.jpa.core.JpaFile; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JpaStructureNode; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.ui.JPAEditorMatchingStrategy; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.IModelIntegrationUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPADiagramEditorInput; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.PartInitException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class ModelIntegrationTest { - - private static final String CODE_GENERATED = "CODE_GENERATED"; - private IJPAEditorFeatureProvider featureProvider; - final String TEST_PROJECT = "Test"; - private JpaProject jpaProject = null; - private JPACreateFactory factory = null; - IEclipseFacade eclipseFacade = null; - private String testProjectName = TEST_PROJECT + "_" + System.currentTimeMillis(); - IFile entityFile = null; - - @Before - public void setUp() throws Exception { - factory = JPACreateFactory.instance(); - jpaProject = factory.createJPAProject(testProjectName); - assertNotNull(jpaProject); - entityFile = factory.createEntity(jpaProject, "org.eclipse.Entity1"); - Thread.sleep(2000); - featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class); - expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entityFile)); - expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entityFile)).anyTimes(); - } - - @Test - public void testJPAEditorMatchingStrategyWithEntityFileEditorInputTrue() { - IEditorReference editorRef = EasyMock.createMock(IEditorReference.class); - IFileEditorInput input = EasyMock.createMock(IFileEditorInput.class); - expect(input.getFile()).andStubReturn(entityFile); - expect(input.getName()).andStubReturn(CODE_GENERATED); - ICompilationUnit cu = createCompilationUnitFrom(entityFile); - - IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class); - JavaPersistentType inputJptType = (JavaPersistentType) JPACreateFactory.getPersistentType(entityFile); - expect(ut.getJPType(cu)).andStubReturn(inputJptType); - expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut); - Diagram d = EasyMock.createMock(Diagram.class); - IJPADiagramEditorInput dEdInput = EasyMock.createMock(IJPADiagramEditorInput.class); - try { - expect(editorRef.getEditorInput()).andStubReturn(dEdInput); - } catch (PartInitException e) { - e.printStackTrace(); - } - expect(dEdInput.getDiagram()).andStubReturn(d); - IDiagramTypeProvider dtp = EasyMock.createMock(IDiagramTypeProvider.class); - expect(featureProvider.getDiagramTypeProvider()).andStubReturn(dtp); - IModelIntegrationUtil moinIntUtil = EasyMock.createMock(IModelIntegrationUtil.class); - expect(featureProvider.getMoinIntegrationUtil()).andStubReturn(moinIntUtil); - expect(moinIntUtil.getProjectByDiagram(d)).andStubReturn(jpaProject); - PictogramElement pe = EasyMock.createMock(PictogramElement.class); - expect(featureProvider.getPictogramElementForBusinessObject(inputJptType)).andStubReturn(pe); - IDiagramEditor dEd = EasyMock.createMock(IDiagramEditor.class); - expect(dtp.getDiagramEditor()).andStubReturn(dEd); - dEd.setPictogramElementForSelection(pe); - - JPAEditorMatchingStrategy str = new JPAEditorMatchingStrategy(featureProvider); - - EasyMock.replay(editorRef, d, dtp, pe, dEd, moinIntUtil, dEdInput, ut, input, featureProvider); - assertTrue(str.matches(editorRef, input)); - } - - @Test - public void testJPAEditorMatchingStrategyWithEntityFileEditorInputFalse() { - IEditorReference editorRef = EasyMock.createMock(IEditorReference.class); - IFileEditorInput input = EasyMock.createMock(IFileEditorInput.class); - expect(input.getFile()).andStubReturn(entityFile); - expect(input.getName()).andStubReturn(CODE_GENERATED); - ICompilationUnit cu = createCompilationUnitFrom(entityFile); - - IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class); - JavaPersistentType inputJptType = (JavaPersistentType) JPACreateFactory.getPersistentType(entityFile); - expect(ut.getJPType(cu)).andStubReturn(inputJptType); - expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut); - Diagram d = EasyMock.createMock(Diagram.class); - IJPADiagramEditorInput dEdInput = EasyMock.createMock(IJPADiagramEditorInput.class); - try { - expect(editorRef.getEditorInput()).andStubReturn(dEdInput); - } catch (PartInitException e) { - e.printStackTrace(); - } - expect(dEdInput.getDiagram()).andStubReturn(d); - IDiagramTypeProvider dtp = EasyMock.createMock(IDiagramTypeProvider.class); - expect(featureProvider.getDiagramTypeProvider()).andStubReturn(dtp); - IModelIntegrationUtil moinIntUtil = EasyMock.createMock(IModelIntegrationUtil.class); - expect(featureProvider.getMoinIntegrationUtil()).andStubReturn(moinIntUtil); - JpaProject anotherJpaProject = EasyMock.createMock(JpaProject.class); - expect(moinIntUtil.getProjectByDiagram(d)).andStubReturn(anotherJpaProject); - PictogramElement pe = EasyMock.createMock(PictogramElement.class); - expect(featureProvider.getPictogramElementForBusinessObject(inputJptType)).andStubReturn(pe); - IDiagramEditor dEd = EasyMock.createMock(IDiagramEditor.class); - expect(dtp.getDiagramEditor()).andStubReturn(dEd); - dEd.setPictogramElementForSelection(pe); - - JPAEditorMatchingStrategy str = new JPAEditorMatchingStrategy(featureProvider); - - EasyMock.replay(editorRef, d, dtp, pe, dEd, moinIntUtil, anotherJpaProject, dEdInput, ut, input, featureProvider); - assertFalse(str.matches(editorRef, input)); - } - - @Test - public void testJPAEditorMatchingStrategyWithJPADiagramEditorInputTrue() { - IEditorReference editorRef = EasyMock.createMock(IEditorReference.class); - expect(editorRef.getPartName()).andStubReturn("ProjectName"); - IJPADiagramEditorInput input = EasyMock.createMock(IJPADiagramEditorInput.class); - expect(input.getProjectName()).andStubReturn("ProjectName"); - JPAEditorMatchingStrategy str = new JPAEditorMatchingStrategy(featureProvider); - EasyMock.replay(editorRef, input, featureProvider); - assertTrue(str.matches(editorRef, input)); - } - - @Test - public void testJPAEditorMatchingStrategyWithJPADiagramEditorInputFalse() { - IEditorReference editorRef = EasyMock.createMock(IEditorReference.class); - expect(editorRef.getPartName()).andStubReturn("ProjectName"); - IJPADiagramEditorInput input = EasyMock.createMock(IJPADiagramEditorInput.class); - expect(input.getProjectName()).andStubReturn("DifferentProjectName"); - JPAEditorMatchingStrategy str = new JPAEditorMatchingStrategy(featureProvider); - EasyMock.replay(editorRef, input, featureProvider); - assertFalse(str.matches(editorRef, input)); - } - - -// @Test -// public void testJPAEditorMatchingStrategyWithFileEditorInput() { -// IEditorReference editorRef = EasyMock.createMock(IEditorReference.class); -// IFileEditorInput input = EasyMock.createMock(IFileEditorInput.class); -// IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class); -// expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut); -// JavaPersistentType jpt = EasyMock.createMock(JavaPersistentType.class); -// ICompilationUnit cu = JavaCore.createCompilationUnitFrom(entityFile); -// expect(ut.getJPType(cu)).andStubReturn(jpt); -// PersistenceUnit pu = EasyMock.createMock(PersistenceUnit.class); -// expect(jpt.getPersistenceUnit()).andStubReturn(pu); -// expect(pu.getJpaProject()).andStubReturn(jpaProject); -// expect(input.getFile()).andStubReturn(entityFile); -// expect(input.getName()).andStubReturn(entityFile.getName()); -// JPAEditorMatchingStrategy str = new JPAEditorMatchingStrategy(featureProvider); -// EasyMock.replay(editorRef, input, ut, jpt, pu, featureProvider); -// assertFalse(str.matches(editorRef, input)); -// } - - - - public ICompilationUnit createCompilationUnitFrom(IFile file) { - return JavaCore.createCompilationUnitFrom(file); - } - - @After - public void tearDown() throws Exception { - deleteAllProjects(); - } - - private void deleteAllProjects() throws Exception { - IProgressMonitor monitor= new NullProgressMonitor(); - ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - IProject project = jpaProject.getProject(); - project.close(monitor); - project.close(monitor); - project.delete(true, true, monitor); - } - } , monitor); - } - -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java deleted file mode 100644 index 4c8dfe3d51..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import org.easymock.EasyMock; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.util.BasicInternalEList; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer; -import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory; -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleListener; - - -@SuppressWarnings("unchecked") -public class ModelIntegrationUtilTest { - - @Test - public void getMOINNoResourceFolderTest() { - IProject project = EasyMock.createMock(IProject.class); - //EList rr = new BasicInternalEList(String.class); - EasyMock.expect(project.getProjectRelativePath()).andStubReturn(new Path("src")); - EasyMock.replay(project); - IPath p = ModelIntegrationUtil.getEMFResourceFolderPath(project); - assertNotNull(p); - assertEquals(2, p.segmentCount()); - assertEquals(p.segment(0), "src"); - } - - @SuppressWarnings("rawtypes") - @Test - public void getMOINSrcResourceFolderTest() { - IProject project = EasyMock.createMock(IProject.class); - EList rr = new BasicInternalEList(String.class); - rr.add("src"); - EasyMock.expect(project.getProjectRelativePath()).andStubReturn(new Path("src")); - EasyMock.replay(project); - IPath p = ModelIntegrationUtil.getEMFResourceFolderPath(project); - assertNotNull(p); - assertEquals(2, p.segmentCount()); - assertEquals(p.segment(0), "src"); - } - - @Test - public void copyExistingXMIContentAndDeleteFileTest() throws Exception { - Bundle b = EasyMock.createMock(Bundle.class); - BundleContext bc = EasyMock.createMock(BundleContext.class); - EasyMock.expect(bc.getBundle()).andStubReturn(b); - EasyMock.expect(b.getSymbolicName()).andStubReturn("jpa_editor"); - bc.addBundleListener(EasyMock.isA(BundleListener.class)); - EasyMock.replay(bc, b); - - JPADiagramEditorPlugin p = new JPADiagramEditorPlugin(); - p.start(bc); - - IPreferenceStore store = JPADiagramEditorPlugin.getDefault().getPreferenceStore(); - store.putValue(JPAEditorPreferenceInitializer.PROPERTY_DIAGRAM_FOLDER, "diagrams"); - store.getString(JPAEditorPreferenceInitializer.PROPERTY_DIAGRAM_FOLDER); - - JPACreateFactory factory = JPACreateFactory.instance(); - JpaProject jpaProject = factory.createJPAProject("Test_" + System.currentTimeMillis()); - assertNotNull(jpaProject); - ModelIntegrationUtil.copyExistingXMIContentAndDeleteFile(jpaProject.getProject(), "diagram_name", null); - } -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferenceInitializerTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferenceInitializerTest.java deleted file mode 100644 index f34965d054..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferenceInitializerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.preferences; - -import static org.junit.Assert.*; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceStore; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer; -import org.junit.Test; - -public class JPAEditorPreferenceInitializerTest { - @Test - public void testInitializeDefaultPreferences() { - IPreferenceStore store = new PreferenceStore(); - AbstractPreferenceInitializer fixture = new JPAEditorPreferenceInitializer( - store); - fixture.initializeDefaultPreferences(); - String pack = store - .getDefaultString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_PACKAGE); - assertEquals(JPAEditorPreferenceInitializer.PROPERTY_VAL_ENTITY_PACKAGE, pack); - } - -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferencesPageTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferencesPageTest.java deleted file mode 100644 index 718896e8c3..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferencesPageTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.preferences; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferenceInitializer; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.preferences.JPAEditorPreferencesPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class JPAEditorPreferencesPageTest { - - private IPreferenceStore store; - private String oldValue; - - @Before - public void setUp() { - store = JPADiagramEditorPlugin.getDefault().getPreferenceStore(); - oldValue = store - .getString(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_PACKAGE); - } - - @After - public void tearDown() { - store.setValue(JPAEditorPreferenceInitializer.PROPERTY_ENTITY_PACKAGE, - oldValue); - } - - /* - @Test - public void testCheckState() { - JPAEditorPreferencesPage page = createControl(); - assertNull(page.getErrorMessage()); - } - - @Test - public void testCheckStateErrorMessage() { - store.setValue(JPAEditorPreferenceInitializer.DEFAULT_ENTITY_PACKAGE, - "d omd"); - JPAEditorPreferencesPage page = createControl(); - assertNotNull(page.getErrorMessage()); - } - - @Test - public void testCheckStateWarningMessage() { - store.setValue(JPAEditorPreferenceInitializer.DEFAULT_ENTITY_PACKAGE, - "CapitalLetter"); - JPAEditorPreferencesPage page = createControl(); - assertNull(page.getMessage()); - assertTrue(page.isValid()); - } - */ - - @Test - public void testInit() { - JPAEditorPreferencesPage page = new JPAEditorPreferencesPage(); - page.init(null); - } - - @SuppressWarnings("unused") - private JPAEditorPreferencesPage createControl() { - JPAEditorPreferencesPage page = new JPAEditorPreferencesPage(); - Composite composite = new Composite(Display.getDefault() - .getActiveShell(), SWT.NONE); - page.createControl(composite); - return page; - } -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorToolBehaviorProviderTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorToolBehaviorProviderTest.java deleted file mode 100644 index a987680cdb..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorToolBehaviorProviderTest.java +++ /dev/null @@ -1,252 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2010 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Kiril Mitov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.provider; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertEquals; - -import org.easymock.EasyMock; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.graphiti.dt.IDiagramTypeProvider; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.IDoubleClickContext; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.tb.IDecorator; -import org.eclipse.graphiti.tb.IToolBehaviorProvider; -import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.modelintegration.ui.JPAEditorMatchingStrategy; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.JPAEditorToolBehaviorProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IStaticIDE; -import org.eclipse.ui.PartInitException; -import org.junit.Before; -import org.junit.Test; - -public class JPAEditorToolBehaviorProviderTest { - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - } - - @Test - public void testGetRenderingDecoratorsPictogramElementError() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - IMarker marker = replayMarker(IMarker.SEVERITY_ERROR, "Error message"); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[] { marker }); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(1, decorators.length); - assertEquals("Error message", decorators[0].getMessage()); - } - - @Test - public void testGetRenderingDecoratorsPictogramElementWarning() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - - IMarker marker = replayMarker(IMarker.SEVERITY_WARNING, "Warning message"); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[] { marker }); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(1, decorators.length); - assertEquals("Warning message", decorators[0].getMessage()); - } - - @Test - public void testGetRenderingDecoratorsPictogramElementInfo() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - IMarker marker = replayMarker(IMarker.SEVERITY_INFO, "Info message"); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[] { marker }); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(1, decorators.length); - assertEquals("Info message", decorators[0].getMessage()); - } - - @Test - public void testGetRenderingDecoratorsPictogramElementNoMarkers() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[0]); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(0, decorators.length); - } - - @Test - public void testGetRenderingDecoratorsPictogramElementTwoMarkers() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - IMarker warningMarker = replayMarker(IMarker.SEVERITY_WARNING, "warning"); - IMarker errorMarker = replayMarker(IMarker.SEVERITY_ERROR, "error"); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[] { errorMarker, warningMarker }); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(1, decorators.length); - assertEquals("error", decorators[0].getMessage()); - } - - @Test - public void testGetRenderingDecoratorsPictogramElementLocation() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - IMarker marker = replayMarker(IMarker.SEVERITY_ERROR, "Error message"); - JavaPersistentType jpt = replayJptWithMarker(new IMarker[] { marker }); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp); - IDecorator[] decorators = provider.getDecorators(pe); - assertEquals(1, decorators.length); - assertEquals(80, ((ImageDecorator) decorators[0]).getX()); - assertEquals(80, ((ImageDecorator) decorators[0]).getY()); - } - - @Test - public void testGetDoubleClickOnJptFeature() throws PartInitException, CoreException { - PictogramElement pe = replayPictogramElement(100, 100); - IFile file = replayResource(); - JavaPersistentType jpt = replayJpt(pe, file); - IDiagramTypeProvider dtp = replayDiagramProvider(pe, jpt); - - IEclipseFacade facade = EasyMock.createMock(IEclipseFacade.class); - IStaticIDE ide = EasyMock.createMock(IStaticIDE.class); - expect(facade.getIDE()).andStubReturn(ide); - ide.openEditor(file); - replay(facade, ide); - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp, facade); - - IDoubleClickContext context = replayDoubleClickContext(pe); - provider.getDoubleClickFeature(context); - verify(ide); - } - - @Test - public void testGetDoubleClickOnJpaFeature() throws Exception { - PictogramElement pe = replayPictogramElement(100, 100); - IFile file = replayResource(); - JavaPersistentAttribute jpa = replayJpa(pe, file); - IDiagramTypeProvider dtp = replayDiagramProviderForJpa(pe, jpa); - - IEclipseFacade eclipseFacade = EasyMock.createMock(IEclipseFacade.class); - IStaticIDE ide = EasyMock.createMock(IStaticIDE.class); - expect(eclipseFacade.getIDE()).andStubReturn(ide); - ide.openEditor(file); - replay(eclipseFacade, ide); - IToolBehaviorProvider provider = new JPAEditorToolBehaviorProvider(dtp, eclipseFacade); - - IDoubleClickContext context = replayDoubleClickContext(pe); - provider.getDoubleClickFeature(context); - verify(ide); - } - - private IDiagramTypeProvider replayDiagramProvider(PictogramElement pe, JavaPersistentType jpt) { - IFeatureProvider featureProvider = EasyMock.createMock(IFeatureProvider.class); - expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(jpt); - IDiagramTypeProvider dtp = EasyMock.createMock(IDiagramTypeProvider.class); - expect(dtp.getFeatureProvider()).andStubReturn(featureProvider); - replay(dtp, featureProvider); - return dtp; - } - - private IMarker replayMarker(int severity, String message) throws CoreException { - IMarker marker = EasyMock.createMock(IMarker.class); - expect(marker.getAttribute(IMarker.SEVERITY)).andStubReturn(severity); - expect(marker.getAttribute(IMarker.MESSAGE)).andStubReturn(message); - replay(marker); - return marker; - } - - private JavaPersistentType replayJptWithMarker(IMarker[] markers) throws CoreException { - JavaPersistentType jpt = EasyMock.createMock(JavaPersistentType.class); - IFile file = EasyMock.createMock(IFile.class); - expect(file.exists()).andReturn(true); - expect(file.findMarkers(null, true, IResource.DEPTH_INFINITE)).andStubReturn(markers); - expect(jpt.getResource()).andStubReturn(file); - replay(file, jpt); - return jpt; - } - - private IFile replayResource() throws CoreException { - IFile file = EasyMock.createMock(IFile.class); - file.setSessionProperty(new QualifiedName(null, JPAEditorMatchingStrategy.DOUBLE_CLICK), "true"); - EasyMock.expectLastCall().asStub(); - expect(file.getType()).andStubReturn(IResource.FILE); - replay(file); - return file; - } - - private IDoubleClickContext replayDoubleClickContext(PictogramElement pe){ - IDoubleClickContext context = EasyMock.createMock(IDoubleClickContext.class); - expect(context.getPictogramElements()).andStubReturn(new PictogramElement[] {pe}); - replay(context); - return context; - } - - private JavaPersistentType replayJpt(PictogramElement pe, IFile file){ - IFeatureProvider featureProvider = EasyMock.createMock(IFeatureProvider.class); - JavaPersistentType jpt = EasyMock.createMock(JavaPersistentType.class); - expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(jpt); - expect(jpt.getResource()).andReturn(file); - replay(jpt, featureProvider); - return jpt; - } - - private JavaPersistentAttribute replayJpa(PictogramElement pe, IFile file){ - IFeatureProvider featureProvider = EasyMock.createMock(IFeatureProvider.class); - JavaPersistentAttribute jpa = EasyMock.createMock(JavaPersistentAttribute.class); - expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(jpa); - expect(jpa.getResource()).andReturn(file); - replay(jpa, featureProvider); - return jpa; - } - - private IDiagramTypeProvider replayDiagramProviderForJpa(PictogramElement pe, JavaPersistentAttribute jpa) { - IFeatureProvider featureProvider = EasyMock.createMock(IFeatureProvider.class); - expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(jpa); - IDiagramTypeProvider dtp = EasyMock.createMock(IDiagramTypeProvider.class); - expect(dtp.getFeatureProvider()).andStubReturn(featureProvider); - replay(dtp, featureProvider); - return dtp; - } - - private PictogramElement replayPictogramElement(int width, int height) { - PictogramElement pe = EasyMock.createMock(PictogramElement.class); - GraphicsAlgorithm algo = EasyMock.createMock(GraphicsAlgorithm.class); - expect(algo.getWidth()).andStubReturn(width); - expect(algo.getHeight()).andStubReturn(height); - expect(pe.getGraphicsAlgorithm()).andStubReturn(algo); - replay(pe, algo); - return pe; - } - -} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java deleted file mode 100644 index f313512e5d..0000000000 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java +++ /dev/null @@ -1,492 +0,0 @@ -/******************************************************************************* - * <copyright> - * - * Copyright (c) 2005, 2011 SAP AG. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Stefan Dimov - initial API, implementation and documentation - * - * </copyright> - * - *******************************************************************************/ -package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.relation; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.Set; - -import org.easymock.EasyMock; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType; -import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; -import org.eclipse.jpt.jpa.core.JpaFile; -import org.eclipse.jpt.jpa.core.JpaProject; -import org.eclipse.jpt.jpa.core.JpaStructureNode; -import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType; -import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.AbstractRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToManyUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.ManyToOneUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToManyUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneBiDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.OneToOneUniDirRelation; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IEclipseFacade; -import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; -import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory; -import org.junit.Before; -import org.junit.Test; - -public class CreateRelationsInFieldAnnotatedEntitiesTest { - - private IJPAEditorFeatureProvider featureProvider; - final String TEST_PROJECT = "Test"; - private JpaProject jpaProject = null; - private JPACreateFactory factory = null; - IEclipseFacade eclipseFacade = null; - - @Before - public void setUp() throws Exception { - factory = JPACreateFactory.instance(); - jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis()); - assertNotNull(jpaProject); - IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1"); - Thread.sleep(2000); - featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class); - expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity)); - expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes(); - replay(featureProvider); - } - - public ICompilationUnit createCompilationUnitFrom(IFile file) { - return JavaCore.createCompilationUnitFrom(file); - } - - - @Test - public void testCreateOneToOneUnidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address", - true, - cu1, - createCompilationUnitFrom((IFile)t2.getResource())); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("OneToOne")); - assertNull(((OwnableRelationshipMappingAnnotation)ownerAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - IType javaType = cu1.findPrimaryType(); - IField f = javaType.getField("address"); - assertTrue(f.exists()); - - } - - @Test - public void testCreateOneToOneBidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - ICompilationUnit cu2 = createCompilationUnitFrom((IFile)t2.getResource()); - AbstractRelation rel = new OneToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", - true, - cu1, - cu2); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("OneToOne")); - assertNull(((OwnableRelationshipMappingAnnotation)ownerAt.getMapping()).getMappedBy()); - - JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer"); - assertNotNull(inverseAt); - annotations = JpaArtifactFactory.instance().getAnnotationNames(inverseAt); - assertTrue(annotations.contains("OneToOne")); - assertEquals("address", ((OwnableRelationshipMappingAnnotation)inverseAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - assertTrue(cu2.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - IType javaType2 = cu2.findPrimaryType(); - IField f2 = javaType2.getField("customer"); - assertTrue(f2.exists()); - - } - - @Test - public void testCreateOneToManyUnidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new OneToManyUniDirRelation(featureProvider, t1, t2, "address", - true, - cu1, - createCompilationUnitFrom((IFile)t2.getResource())); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("OneToMany")); - assertNull(((OwnableRelationshipMappingAnnotation)ownerAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - - } - - @Test - public void testCreateManyToOneUnidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address", - true, - cu1, - createCompilationUnitFrom((IFile)t2.getResource())); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("ManyToOne")); - - assertTrue(cu1.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - - } - - - @Test - public void testCreateManyToOneBidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - ICompilationUnit cu2 = createCompilationUnitFrom((IFile)t2.getResource()); - AbstractRelation rel = new ManyToOneBiDirRelation(featureProvider, t1, t2, "address", "customer", - true, - cu1, - cu2); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("ManyToOne")); - - JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer"); - assertNotNull(inverseAt); - annotations = JpaArtifactFactory.instance().getAnnotationNames(inverseAt); - assertTrue(annotations.contains("OneToMany")); - assertEquals("address", ((OwnableRelationshipMappingAnnotation)inverseAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - assertTrue(cu2.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - IType javaType2 = cu2.findPrimaryType(); - IField f2 = javaType2.getField("customer"); - assertTrue(f2.exists()); - - } - - @Test - public void testCreateManyToManyUnidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - AbstractRelation rel = new ManyToManyUniDirRelation(featureProvider, t1, t2, "address", - true, - cu1, - createCompilationUnitFrom((IFile)t2.getResource())); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("ManyToMany")); - assertNull(((OwnableRelationshipMappingAnnotation)ownerAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - - } - - @Test - public void testCreateManyToManyBidirRelation() throws Exception { - assertNotNull(jpaProject); - IFile customerFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer"); - - IFile addressFile = factory.createFieldAnnotatedEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address"); - - jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor()); - - assertTrue(customerFile.exists()); - JavaResourceAbstractType customerType = jpaProject.getJavaResourceType("com.test.Customer"); - assertNotNull(customerType); - - - JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - while (t1 == null) { - Thread.sleep(200); - t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName()); - } - - assertTrue(addressFile.exists()); - JavaResourceAbstractType addressType = jpaProject.getJavaResourceType("com.Address"); - assertNotNull(customerType); - - - JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - while (t2 == null) { - Thread.sleep(200); - t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName()); - } - ICompilationUnit cu1 = createCompilationUnitFrom((IFile)t1.getResource()); - ICompilationUnit cu2 = createCompilationUnitFrom((IFile)t2.getResource()); - AbstractRelation rel = new ManyToManyBiDirRelation(featureProvider, t1, t2, "address", "customer", - true, - cu1, - cu2); - assertNotNull(rel); - assertSame(t1, rel.getOwner()); - assertSame(t2, rel.getInverse()); - assertEquals("address", rel.getOwnerAttributeName()); - JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address"); - assertNotNull(ownerAt); - Set<String> annotations = JpaArtifactFactory.instance().getAnnotationNames(ownerAt); - assertTrue(annotations.contains("ManyToMany")); - assertNull(((OwnableRelationshipMappingAnnotation)ownerAt.getMapping()).getMappedBy()); - - JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer"); - assertNotNull(inverseAt); - annotations = JpaArtifactFactory.instance().getAnnotationNames(inverseAt); - assertTrue(annotations.contains("ManyToMany")); - assertEquals("address", ((OwnableRelationshipMappingAnnotation)inverseAt.getMapping()).getMappedBy()); - - assertTrue(cu1.isWorkingCopy()); - assertTrue(cu2.isWorkingCopy()); - - IType javaType1 = cu1.findPrimaryType(); - IField f1 = javaType1.getField("address"); - assertTrue(f1.exists()); - IType javaType2 = cu2.findPrimaryType(); - IField f2 = javaType2.getField("customer"); - assertTrue(f2.exists()); - - } - - -} - - diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml index 98ad18889a..f5e7a14f2e 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml @@ -31,7 +31,7 @@ <property name="plugin-name" value="${plugin-name}"/> <property name="classname" value="org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.AllJpaEditorTests" /> <property name="plugin-path" value="${eclipse-home}/plugins/${plugin-name}"/> - <property name="extraVMargs" value="-Dorg.eclipse.jpt.jpa.jar=${testDir}/${jpt-persistence-jar} -Dorg.eclipse.jpt.eclipselink.jar=${testDir}/${jpt-eclipselink-jar}"/> + <property name="extraVMargs" value="-Dorg.eclipse.jpt.jpa.jar=${testDir}/${jpt-persistence204-jar} -Dorg.eclipse.jpt.eclipselink.jar=${testDir}/${jpt-eclipselink-jar}"/> </ant> </target> |