Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortle2011-03-08 17:59:19 +0000
committertle2011-03-08 17:59:19 +0000
commit6cd0cd26dd033571cbf1fe67487db7a9392b934c (patch)
treea067d9e466785b804d01e3d25a36c86da7aabf3c
parentcb5165a134aac7e53b4d9255f7850bafa6680841 (diff)
downloadwebtools.dali-6cd0cd26dd033571cbf1fe67487db7a9392b934c.tar.gz
webtools.dali-6cd0cd26dd033571cbf1fe67487db7a9392b934c.tar.xz
webtools.dali-6cd0cd26dd033571cbf1fe67487db7a9392b934c.zip
Tests plugin renamed.
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.classpath14
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.cvsignore7
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.project28
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF38
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/about.html34
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/build.properties7
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/plugin.properties14
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/AllJpaEditorTests.java80
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java442
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java61
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java171
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddAttributeFeatureTest.java188
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddJPAEntityFeatureTest.java276
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java329
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java119
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java229
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java573
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DeleteRelationFeatureTest.java76
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DirectEditAttributeFeatureTest.java114
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/LayoutEntityFeatureTest.java60
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/OpenMiniatureViewFeatureTest.java63
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RefactorAttributeTypeFeatureTest.java99
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RemoveAttributeFeatureTest.java112
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java121
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/UpdateAttributeFeatureTest.java120
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java148
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java238
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java59
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferenceInitializerTest.java38
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferencesPageTest.java86
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorFeatureProviderTest.java169
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorToolBehaviorProviderTest.java252
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java621
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java509
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java319
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java123
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/IEditor.java22
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPAEditorUtilTest.java402
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPASolverTest.java167
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JpaArtifactFactoryTest.java204
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/URLEscaper.java18
-rw-r--r--jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml48
42 files changed, 6798 insertions, 0 deletions
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.classpath b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.classpath
new file mode 100644
index 0000000000..696bd754b7
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.classpath
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/common/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/common/utility/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/jpa/core/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/jpt/jpa/ui/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/**"/>
+ </accessrules>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.cvsignore b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.cvsignore
new file mode 100644
index 0000000000..f478745caa
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.cvsignore
@@ -0,0 +1,7 @@
+bin
+@dot
+build.xml
+temp.folder
+tests.jar
+javaCompiler...args
+.settings
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.project b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.project
new file mode 100644
index 0000000000..fd5f56209d
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.jpadiagrameditor.ui.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..dff0365381
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,38 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-Vendor: %providerName
+Bundle-SymbolicName: org.eclipse.jpt.jpadiagrameditor.ui.tests;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPAEditorTestsActivator
+Bundle-ActivationPolicy: lazy
+Bundle-Localization: plugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.easymock;bundle-version="[2.4.0,3.0.0)",
+ org.eclipse.emf.ecore.xmi;bundle-version="[2.5.0,3.0.0)",
+ org.eclipse.emf.transaction;bundle-version="[1.4.0,2.0.0)",
+ org.eclipse.gef;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.graphiti;bundle-version="[0.8.0,1.0.0)",
+ org.eclipse.graphiti.ui;bundle-version="[0.8.0,1.0.0)",
+ org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.jpt.jpa.core;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.jpt.jpa.ui;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.jpt.jpadiagrameditor.ui;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="[3.4.0,4.0.0)",
+ org.eclipse.wst.common.frameworks;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.wst.common.modulecore;bundle-version="[1.2.1,2.0.0)",
+ org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)",
+ org.junit4;bundle-version="[4.8.1,5.0.0)"
+Export-Package: org.eclipse.jpt.jpadiagrameditor.ui.tests.internal;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.editor;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.listener;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.ui;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.util;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.preferences;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.provider;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.relation;x-internal:=true,
+ org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util;x-internal:=true
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/about.html b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/about.html
new file mode 100644
index 0000000000..be534ba44f
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>May 02, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributor's license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/build.properties b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/build.properties
new file mode 100644
index 0000000000..276e3ca748
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/build.properties
@@ -0,0 +1,7 @@
+bin.includes = .,\
+ META-INF/,\
+ about.html,\
+ test.xml,\
+ plugin.properties
+source.. = src/
+output.. = bin/
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/plugin.properties b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/plugin.properties
new file mode 100644
index 0000000000..b5bcd87dcc
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/plugin.properties
@@ -0,0 +1,14 @@
+# ====================================================================
+# To code developer:
+# Do NOT change the properties between this line and the
+# "%%% END OF TRANSLATED PROPERTIES %%%" line.
+# Make a new property name, append to the end of the file and change
+# the code to use the new property.
+# ====================================================================
+
+# ====================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# ====================================================================
+
+pluginName=Dali Java Persistence Tools - JPA Diagram Editor JUnit Tests
+providerName = Eclipse Web Tools Platform \ No newline at end of file
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/AllJpaEditorTests.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/AllJpaEditorTests.java
new file mode 100644
index 0000000000..8d341fdc7c
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/AllJpaEditorTests.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * <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;
+
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.editor.EditorTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.AddAttributeFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.AddJPAEntityFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.AddRelationFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.ClickAddFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.CreateDeleteOnlyAttributeTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.DeleteRelationFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.DirectEditAttributeFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.LayoutEntityFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.OpenMiniatureViewFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.RefactorAttributeTypeFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.feature.SaveEntityFeatureTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.listener.JPAProjectListenerTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.ui.ModelIntegrationTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.modelintegration.util.ModelIntegrationUtilTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.preferences.JPAEditorPreferenceInitializerTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.preferences.JPAEditorPreferencesPageTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.provider.JPAEditorToolBehaviorProviderTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.relation.CreateRelationsTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.CreateDeleteEntity;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.JPAEditorUtilTest;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.JPASolverTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+// I have commented out the tests that required the persistence.jar,
+// please use a "org.eclipse.jpt.jpa.jar" env. var. to access it.
+//
+// Before un-commented out these tests, make sure that they are
+// passing locally with a "org.eclipse.jpt.jpa.jar" env. var.
+// If not it will break the build.
+// -Tran Le
+
+@RunWith(Suite.class)
+@SuiteClasses( {
+ JPAEditorPreferenceInitializerTest.class,
+ JPAEditorPreferencesPageTest.class,
+ AddJPAEntityFeatureTest.class,
+// ClickAddFeatureTest.class,
+// CreateDeleteEntity.class,
+ DirectEditAttributeFeatureTest.class,
+ EditorTest.class,
+ JPAEditorToolBehaviorProviderTest.class,
+// JPAEditorUtilTest.class,
+ JPASolverTest.class,
+// OpenMiniatureViewFeatureTest.class,
+// RefactorAttributeTypeFeatureTest.class,
+// SaveEntityFeatureTest.class,
+ AddRelationFeatureTest.class,
+ AddAttributeFeatureTest.class,
+// CreateDeleteOnlyAttributeTest.class,
+// JPAProjectListenerTest.class,
+// ModelIntegrationTest.class,
+ ModelIntegrationUtilTest.class,
+ LayoutEntityFeatureTest.class,
+ DeleteRelationFeatureTest.class,
+// CreateRelationsTest.class
+ })
+
+public class AllJpaEditorTests {
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java
new file mode 100644
index 0000000000..1292ea29c5
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPACreateFactory.java
@@ -0,0 +1,442 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+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.IResource;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+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.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.common.utility.internal.ArrayTools;
+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.JpaRootContextNode;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProperties;
+import org.eclipse.jpt.jpa.core.internal.facet.JpaFacetInstallDataModelProvider;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.URLEscaper;
+import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.project.facet.core.IFacetedProject;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+
+@SuppressWarnings("restriction")
+public class JPACreateFactory {
+
+ public static final String JPA_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.jpa.jar";
+ public static final String ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY = "org.eclipse.jpt.eclipselink.jar";
+
+ private static JPACreateFactory factory = null;
+ private IFacetedProject facetedProject;
+ private IProject project;
+ private IJavaProject javaProject;
+ //private IPackageFragmentRoot sourceFolder;
+ JpaProject jpaProject;
+
+ public static synchronized JPACreateFactory instance() {
+ if (factory == null)
+ factory = new JPACreateFactory();
+ return factory;
+ }
+
+ private IProject buildPlatformProject(String projectName) throws CoreException {
+ IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
+ description.setAutoBuilding(true);
+ ResourcesPlugin.getWorkspace().setDescription(description);
+ IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ p.create(null);
+ p.open(null);
+ return p;
+ }
+
+ protected IDataModel buildJpaConfigDataModel() {
+ IDataModel dataModel = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
+ dataModel.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, "1.0");
+ dataModel.setProperty(JpaFacetDataModelProperties.PLATFORM, null /*GenericPlatform.VERSION_1_0.getId()*/);
+ dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.TRUE);
+ return dataModel;
+ }
+
+ public JpaProject createJPAProject(String projectName) throws CoreException {
+ return createJPAProject(projectName, null);
+ }
+
+
+
+ public JpaProject createJPAProject(String projectName, IDataModel jpaConfig) throws CoreException {
+ project = buildPlatformProject(projectName);
+ javaProject = createJavaProject(project, true);
+ String jpaFacetVersion = "1.0";
+ if (jpaConfig != null) {
+ jpaFacetVersion = jpaConfig.getStringProperty(IFacetDataModelProperties.FACET_VERSION_STR);
+ }
+ installFacet(facetedProject, "jst.utility", "1.0");
+ installFacet(facetedProject, "jpt.jpa", jpaFacetVersion, jpaConfig);
+ addJar(javaProject, jpaJarName());
+ if (eclipseLinkJarName() != null) {
+ addJar(javaProject, eclipseLinkJarName());
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ int cnt = 0;
+ while ((jpaProject == null) && (cnt < 1000)){
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ jpaProject = JptJpaCorePlugin.getJpaProject(project);
+ cnt++;
+ }
+ jpaProject.setDiscoversAnnotatedClasses(true);
+// jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject));
+ return jpaProject;
+ }
+
+ public static String eclipseLinkJarName() {
+ return getSystemProperty(ECLIPSELINK_JAR_NAME_SYSTEM_PROPERTY);
+ }
+
+ public void installFacet(IFacetedProject facetedProject,
+ String facetName,
+ String versionName) throws CoreException {
+ installFacet(facetedProject, facetName, versionName, null);
+ }
+
+ public void uninstallFacet(IFacetedProject facetedProject,
+ String facetName,
+ String versionName) throws CoreException {
+ uninstallFacet(facetedProject, facetName, versionName, null);
+ }
+
+ /**
+ * if 'config' is null (and 'facetName' is "jpt.jpa"), the JPA project will be built with the defaults
+ * defined in JpaFacetInstallDataModelProvider#getDefaultProperty(String)
+ */
+ public void installFacet(IFacetedProject facetedProject,
+ String facetName,
+ String versionName,
+ IDataModel config) throws CoreException {
+ facetedProject.installProjectFacet(this.facetVersion(facetName, versionName), config, null);
+ }
+
+ public void uninstallFacet(IFacetedProject facetedProject,
+ String facetName,
+ String versionName,
+ IDataModel config) throws CoreException {
+ facetedProject.uninstallProjectFacet(this.facetVersion(facetName, versionName), config, null);
+ }
+
+ private IProjectFacetVersion facetVersion(String facetName, String versionName) {
+ return ProjectFacetsManager.getProjectFacet(facetName).getVersion(versionName);
+ }
+
+ private static String getSystemProperty(String propertyName) {
+ return System.getProperty(propertyName);
+ }
+
+ public void addJar(IJavaProject javaProject, String jarPath) throws JavaModelException {
+ this.addClasspathEntry(javaProject, JavaCore.newLibraryEntry(new Path(jarPath), null, null));
+ }
+
+ private void addClasspathEntry(IJavaProject javaProject, IClasspathEntry entry) throws JavaModelException {
+ javaProject.setRawClasspath(ArrayTools.add(javaProject.getRawClasspath(), entry), null);
+ }
+
+ private IFacetedProject createFacetedProject(IProject project) throws CoreException {
+ return ProjectFacetsManager.create(project, true, null); // true = "convert if necessary"
+ }
+
+ public IJavaProject createJavaProject(IProject project,
+ @SuppressWarnings("unused") boolean autoBuild) throws CoreException {
+ facetedProject = createFacetedProject(project);
+ installFacet(facetedProject, "jst.java", "5.0");
+ javaProject = JavaCore.create(project);
+ //sourceFolder = javaProject.getPackageFragmentRoot(project.getFolder("src"));
+ return javaProject;
+ }
+
+ public static String jpaJarName() {
+ File file = null;
+ try {
+ URL bundleRoot = JPAEditorTestsActivator.getDefault().getBundle().getEntry("/resources/javax.persistence_1.0.0.v200905011740.jar");
+ URL fileURL = FileLocator.toFileURL(bundleRoot);
+ fileURL = new URL(URLEscaper.escape(fileURL.toString()));
+ file = new File(fileURL.toURI());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return file.getAbsolutePath();
+ }
+
+ public IFile createEntity(JpaProject jpaProject, String fullyQualifiedName) throws Exception {
+ StringTokenizer tokenizer = new StringTokenizer(fullyQualifiedName, ".");
+ ArrayList<String> nameElements = new ArrayList<String>();
+ while(tokenizer.hasMoreElements()){
+ nameElements.add(tokenizer.nextToken());
+ }
+ ArrayList<String> packageFragments = new ArrayList<String>();
+ for(int i=0;i<nameElements.size()-1;i++){
+ packageFragments.add(nameElements.get(i));
+ }
+ String[] packageStrings = new String[packageFragments.size()];
+ for(int i=0;i<packageFragments.size();i++){
+ packageStrings[i] = packageFragments.get(i);
+ }
+ String name = nameElements.get(Math.max(0, nameElements.size()-1));
+// SynchronousJpaProjectUpdater updater = new SynchronousJpaProjectUpdater(jpaProject);
+// updater.start();
+ JpaRootContextNode jpaProjectContent = jpaProject.getRootContextNode();
+ PersistenceXml persXML = jpaProjectContent.getPersistenceXml();
+ int cnt = 0;
+ while ((persXML == null) && (cnt < 100)) {
+ Thread.sleep(250);
+ persXML = jpaProjectContent.getPersistenceXml();
+ cnt++;
+ }
+ if (persXML == null)
+ throw new NullPointerException("The persistence XML is not created");
+
+ IFile entity1 = createEntityInProject(jpaProject.getProject(), packageStrings, name);
+ JavaResourcePersistentType jrpt = jpaProject.getJavaResourcePersistentType(fullyQualifiedName);
+ cnt = 0;
+ while((jrpt == null) && (cnt < 100)) {
+ try {
+ Thread.sleep(250);
+ } catch (Exception e) {}
+ jrpt = jpaProject.getJavaResourcePersistentType(fullyQualifiedName);
+ cnt++;
+ }
+ if (jrpt == null)
+ throw new NullPointerException("The entity '" + fullyQualifiedName + "' could not be created");
+ return entity1;
+ }
+
+ @SuppressWarnings("deprecation")
+ public IFile createEntityInProject(IProject project,
+ String[] packageFragments,
+ String entityName) throws IOException,
+ CoreException,
+ JavaModelException {
+ IJavaProject javaProject = JavaCore.create(project);
+ IPackageFragmentRoot[] packageFragmentRoots = new IPackageFragmentRoot[0];
+ final IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
+ for (IClasspathEntry classpathEntry : classpathEntries) {
+ if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ packageFragmentRoots = javaProject.getPackageFragmentRoots(classpathEntry);
+ break;
+ }
+ }
+
+ String folderName = packageFragmentRoots[0].getResource().getName();
+ for (String fragment : packageFragments) {
+ folderName += Path.SEPARATOR + fragment;
+ }
+ String packageName = packageFragments[0];
+ for (int i = 1; i < packageFragments.length; i++) {
+ packageName += "." + packageFragments[i];
+ }
+
+ IPath path = new Path(folderName);
+ IFolder folder = project.getFolder(path);
+ return createEntity(folder, packageName , entityName);
+ }
+
+ private IFile createEntity(IFolder folder, String packageName, String entityName) throws IOException, CoreException {
+ String entityShortName = entityName.substring(entityName.lastIndexOf('.') + 1);
+ if (!folder.exists()) {
+ createDirectories(folder, true, true, new NullProgressMonitor());
+ }
+ IFile file = folder.getFile(entityShortName + ".java");
+ if (!file.exists()) {
+ String content = "package " + packageName + ";\n\n"
+ + "import javax.persistence.*;\n\n"
+ + "@Entity \n"
+ + "public class " + entityShortName + " {\n"
+ + " private int id;\n"
+ + " @Id \n"
+ + " public int getId() {\n"
+ + " return id;\n"
+ + " }\n"
+ + " public void setId(int id) {\n"
+ + " this.id = id;\n"
+ + " }\n"
+ + "}"; //$NON-NLS-1$
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ try {
+ stream.write(content.getBytes());
+ stream.flush();
+ file.create(new ByteArrayInputStream(stream.toByteArray()), true, new NullProgressMonitor());
+ } finally {
+ stream.close();
+ }
+ }
+ return file;
+ }
+
+ private void createDirectories(IContainer container, boolean force,
+ boolean local, IProgressMonitor monitor) throws CoreException {
+ if (container != null && container instanceof IFolder) {
+ IFolder folder = (IFolder) container;
+ if (!folder.exists()) {
+ // depth first
+ IContainer parent = folder.getParent();
+ createDirectories(parent, force, local, null);
+ // own second
+ folder.create(force, local, monitor);
+ }
+ }
+ }
+
+ public static ReadOnlyPersistentAttribute getPersistentAttribute(IFile entity, String attributeName){
+ Set<ReadOnlyPersistentAttribute> result = getEntityFields(entity);
+ for(ReadOnlyPersistentAttribute attribute : result){
+ if(attributeName.equals(attribute.getName())){
+ return attribute;
+ }
+ }
+ return null;
+ }
+
+ public static PersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ PersistentType entity = (PersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public static Set<ReadOnlyPersistentAttribute> getEntityFields(IFile file){
+ Set<ReadOnlyPersistentAttribute> result = new HashSet<ReadOnlyPersistentAttribute>();
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ if(jpaFile == null){
+ return result;
+ }
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ PersistentType entity = (PersistentType) node;
+ for (Iterator<ReadOnlyPersistentAttribute> k = entity.allAttributes(); k.hasNext(); ) {
+ ReadOnlyPersistentAttribute attribute = k.next();
+ result.add(attribute);
+ }
+ }
+ return result;
+ }
+
+ public void addAttributes(IFile entity, String attName, String attType, String annotation, String attActName, boolean isCollection){
+ JavaPersistentType javaPersistentType = (JavaPersistentType)getPersistentType(entity);
+ int cnt = 0;
+ while ((javaPersistentType == null) && (cnt < 100)) {
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {}
+ javaPersistentType = (JavaPersistentType)getPersistentType(entity);
+ cnt++;
+ }
+ if (javaPersistentType == null)
+ throw new RuntimeException("The entity could not be created");
+ ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(entity);
+ JpaArtifactFactory.instance().addNewAttribute(javaPersistentType, compilationUnit, attName, attType, annotation, attActName, isCollection, null);
+ }
+
+ private IFile createFieldAnnotatedEntity(IFolder folder, String packageName, String entityName) throws IOException, CoreException {
+ String entityShortName = entityName.substring(entityName.lastIndexOf('.') + 1);
+ if (!folder.exists()) {
+ createDirectories(folder, true, true, new NullProgressMonitor());
+ }
+ IFile file = folder.getFile(entityShortName + ".java");
+ if (!file.exists()) {
+ String content = "package " + packageName + ";\n\n"
+ + "import javax.persistence.*;\n\n"
+ + "@Entity \n"
+ + "public class " + entityShortName + " {\n"
+ + " @Id \n"
+ + " private int id;\n"
+ + " public int getId() {\n"
+ + " return id;\n"
+ + " }\n"
+ + " public void setId(int id) {\n"
+ + " this.id = id;\n"
+ + " }\n"
+ + "}"; //$NON-NLS-1$
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ try {
+ stream.write(content.getBytes());
+ stream.flush();
+ file.create(new ByteArrayInputStream(stream.toByteArray()), true, new NullProgressMonitor());
+ } finally {
+ stream.close();
+ }
+ }
+ return file;
+ }
+
+ @SuppressWarnings("deprecation")
+ public IFile createFieldAnnotatedEntityInProject(IProject project, String[] packageFragments, String entityName) throws IOException, CoreException, JavaModelException {
+ IJavaProject javaProject = JavaCore.create(project);
+ IPackageFragmentRoot[] packageFragmentRoots = new IPackageFragmentRoot[0];
+ final IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
+ for (IClasspathEntry classpathEntry : classpathEntries) {
+ if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
+ packageFragmentRoots = javaProject.getPackageFragmentRoots(classpathEntry);
+ break;
+ }
+ }
+
+ String folderName = packageFragmentRoots[0].getResource().getName();
+ for (String fragment : packageFragments) {
+ folderName += Path.SEPARATOR + fragment;
+ }
+ String packageName = packageFragments[0];
+ for (int i = 1; i < packageFragments.length; i++) {
+ packageName += "." + packageFragments[i];
+ }
+
+ IPath path = new Path(folderName);
+ IFolder folder = project.getFolder(path);
+ return createFieldAnnotatedEntity(folder, packageName , entityName);
+ }
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java
new file mode 100644
index 0000000000..0986bff109
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/JPAEditorTestsActivator.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * <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;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+public class JPAEditorTestsActivator extends Plugin {
+
+ /**
+ *
+ */
+ public JPAEditorTestsActivator() {
+ }
+
+ // The shared instance
+ private static JPAEditorTestsActivator plugin;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static JPAEditorTestsActivator getDefault() {
+ return plugin;
+ }
+
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java
new file mode 100644
index 0000000000..d16b031506
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/editor/EditorTest.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * <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.editor;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertNotNull;
+
+import org.easymock.EasyMock;
+import org.eclipse.gef.EditPart;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jpt.jpa.core.JpaStructureNode;
+import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelection;
+import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionManager;
+import org.eclipse.jpt.jpa.ui.internal.selection.JpaSelectionParticipant;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditor;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleListener;
+
+@SuppressWarnings("restriction")
+public class EditorTest {
+
+ @Test
+ public void testJPADiagramEditorCreation() {
+ JPADiagramEditor ed = new JPADiagramEditor();
+ assertNotNull(ed);
+ }
+
+
+ @Test
+ public void testJPADiagramEditorPlugin() {
+ JPADiagramEditorPlugin plugin = new JPADiagramEditorPlugin();
+ BundleContext bc = EasyMock.createMock(BundleContext.class);
+ Bundle bundle = EasyMock.createMock(Bundle.class);
+ EasyMock.expect(bundle.getSymbolicName()).andStubReturn("");
+ EasyMock.expect(bc.getBundle()).andStubReturn(bundle);
+ bc.addBundleListener(EasyMock.isA(BundleListener.class));
+ bc.removeBundleListener(EasyMock.isA(BundleListener.class));
+ EasyMock.replay(bc, bundle);
+ try {
+ plugin.start(bc);
+ plugin.stop(bc);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ EasyMock.verify(bc);
+ }
+
+ @Test
+ public void testSelectionChanged() {
+ final IJPAEditorFeatureProvider provider = EasyMock
+ .createMock(IJPAEditorFeatureProvider.class);
+
+ IWorkbenchPart part = replayPart();
+
+ PictogramElement pe = EasyMock.createMock(PictogramElement.class);
+ replay(pe);
+ EditPart editPart = EasyMock.createMock(EditPart.class);
+ expect(editPart.getModel()).andReturn(pe);
+ replay(editPart);
+
+ JpaStructureNode jpaNodeToBeSelected = EasyMock
+ .createMock(JpaStructureNode.class);
+ expect(provider.getBusinessObjectForPictogramElement(pe)).andReturn(
+ jpaNodeToBeSelected);
+ replay(provider);
+
+ // test
+ JpaSelectionManager manager = EasyMock
+ .createMock(JpaSelectionManager.class);
+ manager.select(isA(JpaSelection.class),
+ (JpaSelectionParticipant) eq(null));
+ replay(manager);
+
+ JPADiagramEditor.ISelectionManagerFactory factory = EasyMock
+ .createMock(JPADiagramEditor.ISelectionManagerFactory.class);
+ expect(factory.getSelectionManager(isA(IWorkbenchWindow.class)))
+ .andReturn(manager);
+ replay(factory);
+ JPADiagramEditor editor = createEditor(provider, factory);
+ // test
+ editor.selectionChanged(part, new StructuredSelection(editPart));
+ verify(manager);
+ }
+
+ private JPADiagramEditor createEditor(final IJPAEditorFeatureProvider provider,
+ JPADiagramEditor.ISelectionManagerFactory factory) {
+ IWorkbenchPage page = EasyMock.createMock(IWorkbenchPage.class);
+ expect(page.isPartVisible(isA(IWorkbenchPart.class)))
+ .andReturn(false);
+ expect(page.getActiveEditor()).andStubReturn(null);
+ replay(page);
+ final IWorkbenchPartSite site = EasyMock
+ .createMock(IWorkbenchPartSite.class);
+ expect(site.getPage()).andStubReturn(page);
+ replay(site);
+
+ JPADiagramEditor editor = new JPADiagramEditor(factory) {
+ @Override
+ public IJPAEditorFeatureProvider getFeatureProvider() {
+ return provider;
+ }
+
+ public IWorkbenchPartSite getSite() {
+ return site;
+ }
+ };
+ return editor;
+ }
+
+ private IWorkbenchPart replayPart() {
+ IWorkbenchWindow window = EasyMock.createMock(IWorkbenchWindow.class);
+ replay(window);
+ IWorkbenchPage page = EasyMock.createMock(IWorkbenchPage.class);
+ IWorkbenchPartSite site = EasyMock.createMock(IWorkbenchPartSite.class);
+ expect(site.getWorkbenchWindow()).andReturn(window);
+ expect(site.getPage()).andStubReturn(page);
+ replay(site);
+ IWorkbenchPart part = EasyMock.createMock(IWorkbenchPart.class);
+ expect(part.getSite()).andStubReturn(site);
+ expect(page.isPartVisible(isA(IWorkbenchPart.class)))
+ .andReturn(false);
+ expect(page.getActiveEditor()).andReturn(null);
+ replay(page);
+ replay(part);
+ return part;
+ }
+
+ @Test
+ public void testSelectionChangedTextSelection() {
+ JPADiagramEditor editor = createEditor(null, null);
+ editor.selectionChanged(null, new ISelection() {
+ public boolean isEmpty() {
+ return false;
+ }
+ });
+ }
+
+ @Test
+ public void testSelectionChangedNotEditPart() {
+ JPADiagramEditor editor = createEditor(null, null);
+ editor.selectionChanged(null, new StructuredSelection(new Object()));
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddAttributeFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddAttributeFeatureTest.java
new file mode 100644
index 0000000000..67958b7e54
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddAttributeFeatureTest.java
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import java.util.Arrays;
+
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.IDirectEditingInfo;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.impl.AddContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AddAttributeFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+
+ private AddContext context;
+
+ private JavaPersistentAttribute jpa;
+
+ private ContainerShape entityShape;
+
+ private ICustomFeature expandFeature;
+
+ private IAddFeature graphicalAdd;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ jpa = EasyMock.createMock(JavaPersistentAttribute.class);
+ context = new AddContext();
+ context.setNewObject(jpa);
+ context.setTargetContainer(entityShape);
+ graphicalAdd = EasyMock.createMock(IAddFeature.class);
+ expandFeature = EasyMock.createMock(ICustomFeature.class);
+ }
+
+ @Test
+ public void testAddNotJPA() {
+ context.setNewObject(new Object());
+ assertNull(callAdd());
+ }
+
+
+ @SuppressWarnings("unused")
+ private void confgirueAttributeShape(ContainerShape attributeContainer) {
+ ContainerShape attributeShape = EasyMock.createMock(ContainerShape.class);
+ expect(featureProvider.getPictogramElementForBusinessObject(jpa)).andReturn(attributeShape);
+ expect(attributeShape.getContainer()).andReturn(attributeContainer);
+ replay(attributeShape);
+ }
+
+ @SuppressWarnings({ "unchecked", "unused" })
+ private ContainerShape replayTextShape(Text text) {
+ EList<GraphicsAlgorithm> children = EasyMock.createMock(EList.class);
+ children.add(text);
+ GraphicsAlgorithm ga = EasyMock.createMock(GraphicsAlgorithm.class);
+ expect(ga.getGraphicsAlgorithmChildren()).andReturn(children);
+ replay(ga);
+ ContainerShape textShape = EasyMock.createMock(ContainerShape.class);
+ expect(textShape.getGraphicsAlgorithm()).andReturn(ga);
+ replay(textShape);
+ return textShape;
+ }
+
+ @SuppressWarnings("unused")
+ private IDirectEditingInfo configureDirectEditing(Text text, ContainerShape textShape) {
+ IDirectEditingInfo info = EasyMock.createMock(IDirectEditingInfo.class);
+ info.setGraphicsAlgorithm(text);
+ info.setMainPictogramElement(textShape);
+ info.setPictogramElement(textShape);
+ expect(featureProvider.getDirectEditingInfo()).andReturn(info);
+ replay(info);
+ return info;
+ }
+
+ @SuppressWarnings("unused")
+ private ICustomContext createCustomContextMatcher(final PictogramElement[] elements) {
+ EasyMock.reportMatcher(new IArgumentMatcher() {
+ public void appendTo(StringBuffer buffer) {
+ }
+
+ public boolean matches(Object argument) {
+ if (!ICustomContext.class.isInstance(argument))
+ return false;
+ ICustomContext context = (ICustomContext) argument;
+ return Arrays.equals(context.getPictogramElements(), elements);
+ }
+ });
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ private IAddContext contextMatcher() {
+ EasyMock.reportMatcher(new IArgumentMatcher() {
+
+ public void appendTo(StringBuffer buffer) {
+ }
+
+ public boolean matches(Object argument) {
+ if (!IAddContext.class.isInstance(argument))
+ return false;
+ IAddContext context = (IAddContext) argument;
+ // compare by reference
+ if (jpa != context.getNewObject())
+ return false;
+ if (entityShape != context.getTargetContainer())
+ return false;
+ return true;
+
+ }
+
+ });
+ return null;
+ }
+
+ private PictogramElement callAdd() {
+ IAddFeature fixture = createFeature();
+ return fixture.add(context);
+ }
+
+ @Test
+ public void testGetFeatureProvider() {
+ assertSame(featureProvider, createFeature().getFeatureProvider());
+ }
+
+ @Test
+ public void testCanAddObject() {
+ context.setNewObject(new Object());
+ // test
+ assertEquals(false, callCanAdd());
+ }
+
+ @Test
+ public void testCanAddJpt() {
+ // test
+ assertEquals(true, callCanAdd());
+ }
+
+ private boolean callCanAdd() {
+ IAddFeature fixture = createFeature();
+ boolean result = fixture.canAdd(context);
+ return result;
+ }
+
+ private IAddFeature createFeature() {
+ replay(featureProvider);
+ replay(graphicalAdd);
+ replay(expandFeature);
+ return new AddAttributeFeature(featureProvider, graphicalAdd, expandFeature);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddJPAEntityFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddJPAEntityFeatureTest.java
new file mode 100644
index 0000000000..edabfaf27b
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddJPAEntityFeatureTest.java
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import org.easymock.EasyMock;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.mm.Property;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Image;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.algorithms.styles.Font;
+import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramsPackage;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AddJPAEntityFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+
+
+ @Before
+ public void setUp() throws Exception {
+ Thread.sleep(2000);
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(featureProvider.getAttribsNum((Shape) EasyMock.anyObject())).andStubReturn(0);
+ IDiagramTypeProvider idp = EasyMock.createMock(IDiagramTypeProvider.class);
+ expect(featureProvider.getDiagramTypeProvider()).andStubReturn(idp);
+ expect(featureProvider.increaseAttribsNum((Shape) EasyMock.anyObject())).andStubReturn(1);
+ Diagram d = EasyMock.createMock(Diagram.class);
+ expect(idp.getDiagram()).andStubReturn(d);
+ Color c = EasyMock.createMock(Color.class);
+ expect(c.getBlue()).andStubReturn(0);
+ expect(c.getRed()).andStubReturn(0);
+ expect(c.getGreen()).andStubReturn(0);
+ EList<Color> col = new BasicInternalEList<Color>(Color.class);
+ expect(d.getColors()).andStubReturn(col);
+ Color c1 = EasyMock.createMock(Color.class);
+ c1.setRed(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ c1.setGreen(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ c1.setBlue(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+
+ replay(d, c, c1, idp, featureProvider);
+ }
+
+
+ @Test
+ public void testAddText() {
+ Font f = EasyMock.createMock(Font.class);
+ Text t = EasyMock.createMock(Text.class);
+ t.setFont(f);
+ EasyMock.expectLastCall().asStub();
+ expect(t.getX()).andStubReturn(0);
+ expect(t.getY()).andStubReturn(0);
+
+ f.setName("Arial");
+ EasyMock.expectLastCall().asStub();
+ f.setSize(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ f.setItalic(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ f.setBold(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ t.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setValue("abc");
+ EasyMock.expectLastCall().asStub();
+
+ t.setForeground((Color) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+ t.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);
+ EasyMock.expectLastCall().asStub();
+ t.setVerticalAlignment(Orientation.ALIGNMENT_TOP);
+ EasyMock.expectLastCall().asStub();
+
+ Font f1 = EasyMock.createMock(Font.class);
+ f1.setBold(true);
+ EasyMock.expectLastCall().asStub();
+ expect(t.getFont()).andStubReturn(f1);
+
+ Rectangle textRectangle = EasyMock.createMock(Rectangle.class);
+ EList<GraphicsAlgorithm> lst = new BasicInternalEList<GraphicsAlgorithm>(GraphicsAlgorithm.class);
+ expect(textRectangle.getGraphicsAlgorithmChildren()).andStubReturn(lst);
+
+ replay(f1, f, t, textRectangle);
+ UpdateAttributeFeature.addText(featureProvider, textRectangle, "abc");
+ }
+
+ @Test
+ public void testaddRectangleForIcon() {
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ Rectangle rect = EasyMock.createMock(Rectangle.class);
+ expect(rect.getX()).andStubReturn(0);
+ expect(rect.getY()).andStubReturn(0);
+ rect.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ rect.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ cs.setGraphicsAlgorithm(rect);
+ EasyMock.expectLastCall().asStub();
+ rect.setFilled(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setLineVisible(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setX(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ rect.setY(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ rect.setWidth(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ cs.setGraphicsAlgorithm(EasyMock.isA(Rectangle.class));
+ EasyMock.expectLastCall().asStub();
+ replay(rect, cs);
+ UpdateAttributeFeature.addRectangleForIcon(cs, 0);
+ }
+
+ @Test
+ public void testAddRectangleForText() {
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ Rectangle rect = EasyMock.createMock(Rectangle.class);
+ expect(rect.getX()).andStubReturn(0);
+ expect(rect.getY()).andStubReturn(0);
+ rect.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ rect.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ cs.setGraphicsAlgorithm(rect);
+ EasyMock.expectLastCall().asStub();
+ rect.setFilled(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setLineVisible(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setX(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ rect.setY(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ rect.setWidth(EasyMock.anyInt());
+ rect.setLineVisible(EasyMock.anyBoolean());
+ cs.setGraphicsAlgorithm(EasyMock.isA(Rectangle.class));
+ EasyMock.expectLastCall().asStub();
+ replay(rect, cs);
+ UpdateAttributeFeature.addRectangleForText(cs, 0, 120);
+ }
+
+ @Test
+ public void testAddAttribute() {
+ GraphicsAlgorithm ga = EasyMock.createMock(GraphicsAlgorithm.class);
+ expect(ga.getWidth()).andStubReturn(20);
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ expect(cs.getGraphicsAlgorithm()).andStubReturn(ga);
+ Rectangle rect = EasyMock.createMock(Rectangle.class);
+ expect(rect.getX()).andStubReturn(0);
+ expect(rect.getY()).andStubReturn(0);
+ rect.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ rect.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ rect.setFilled(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setLineVisible(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ rect.setX(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ rect.setY(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+
+ EList<Property> props = new BasicInternalEList<Property>(Property.class);
+ EList<Property> props1 = new BasicInternalEList<Property>(Property.class);
+
+ expect(cs.getProperties()).andStubReturn(props);
+
+ cs.setVisible(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ cs.setActive(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ cs.setContainer((ContainerShape) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ expect(cs1.getProperties()).andStubReturn(props1);
+ cs1.setVisible(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ cs1.setActive(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ cs1.setContainer((ContainerShape) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+ PictogramsPackage p = EasyMock.createMock(PictogramsPackage.class);
+ Property pr = EasyMock.createMock(Property.class);
+ cs1.setGraphicsAlgorithm((GraphicsAlgorithm) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+ Image img = EasyMock.createMock(Image.class);
+ expect(img.getX()).andStubReturn(0);
+ expect(img.getY()).andStubReturn(0);
+ img.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ img.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ img.setX(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ img.setY(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ img.setId("org.eclisp.jpt.ui.diagrameditor.field");
+ EasyMock.expectLastCall().asStub();
+ img.setProportional(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ img.setStretchH(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ img.setStretchV(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ EList<GraphicsAlgorithm> ch = new BasicInternalEList<GraphicsAlgorithm>(GraphicsAlgorithm.class);
+ expect(rect.getGraphicsAlgorithmChildren()).andStubReturn(ch);
+ expect(pr.getKey()).andStubReturn("prop_shape_type");
+ Text t = EasyMock.createMock(Text.class);
+ expect(t.getX()).andStubReturn(0);
+ expect(t.getY()).andStubReturn(0);
+ t.setWidth(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setX(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setY(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setHeight(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ t.setValue("");
+ EasyMock.expectLastCall().asStub();
+ Font f = EasyMock.createMock(Font.class);
+ f.setName((String) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+
+ f.setSize(EasyMock.anyInt());
+ EasyMock.expectLastCall().asStub();
+ f.setItalic(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ f.setBold(EasyMock.anyBoolean());
+ EasyMock.expectLastCall().asStub();
+ expect(t.getFont()).andStubReturn(f);
+ t.setFont((Font) EasyMock.anyObject());
+ EasyMock.expectLastCall().asStub();
+ EasyMock.expectLastCall().asStub();
+ t.setForeground((Color) EasyMock.anyObject());
+ t.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);
+ t.setVerticalAlignment(Orientation.ALIGNMENT_TOP);
+ f.setBold(true);
+ replay(rect, ga, img, cs, cs1, p, pr, t, f);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java
new file mode 100644
index 0000000000..1b777dfb48
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/AddRelationFeatureTest.java
@@ -0,0 +1,329 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.aryEq;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IAddBendpointFeature;
+import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.context.IAddBendpointContext;
+import org.eclipse.graphiti.features.context.IAddConnectionContext;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.mm.algorithms.Polyline;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.services.IGaService;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.AddRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorImageCreator;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
+import org.eclipse.swt.graphics.Point;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AddRelationFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+
+ private IJPAEditorImageCreator imageCreator;
+
+ private IJPAEditorUtil jpaEditorUtil;
+
+ private IDiagramTypeProvider diagramProvider;
+
+ private Diagram diagram;
+
+ private IAddConnectionContext context;
+
+ private IPeServiceUtil peUtil;
+
+ private IGaService gaUtil;
+
+ private IAddBendpointFeature ft;
+
+ private Resource resource;
+
+ private static String OWNER_AT_NAME = "ownerAttr"; //$NON-NLS-1$
+
+ private static String INVERSE_AT_NAME = "inverseAttr"; //$NON-NLS-1$
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ imageCreator = EasyMock.createMock(IJPAEditorImageCreator.class);
+ jpaEditorUtil = EasyMock.createMock(IJPAEditorUtil.class);
+ diagramProvider = EasyMock.createMock(IDiagramTypeProvider.class);
+ diagram = EasyMock.createMock(Diagram.class);
+ context = EasyMock.createMock(IAddConnectionContext.class);
+ peUtil = EasyMock.createMock(IPeServiceUtil.class);
+ gaUtil = EasyMock.createMock(IGaService.class);
+ ft = EasyMock.createMock(IAddBendpointFeature.class);
+
+
+ TransactionalEditingDomain defaultTransEditDomain = EasyMock.createMock(TransactionalEditingDomain.class);
+ ResourceSet resourceSet = EasyMock.createMock(ResourceSet.class);
+ expect(defaultTransEditDomain.getResourceSet()).andStubReturn(resourceSet);
+ EList<Adapter> eAdapters = EasyMock.createMock(EList.class);
+ expect(resourceSet.eAdapters()).andStubReturn(eAdapters);
+ //IFile diagramFile = project.getFile(diagramFileName.removeFirstSegments(1));
+ //IPath diagramFilePath = diagramFile.getFullPath();
+
+ //String pathName = diagramFilePath.toString();
+ //URI resourceURI = URI.createPlatformResourceURI(pathName, true);
+ resource = EasyMock.createMock(Resource.class);
+ expect(resourceSet.getResource(isA(URI.class), EasyMock.anyBoolean())).andStubReturn(resource);
+
+ expect(resource.getResourceSet()).andStubReturn(resourceSet);
+ replay(defaultTransEditDomain, resourceSet, resource);
+
+ }
+
+ @Test
+ public void testCanAddNotAddConnectionContext() {
+ IAddContext context = EasyMock.createMock(IAddContext.class);
+ verifyCanAdd(context, false);
+ }
+
+ @Test
+ public void testCanAddNoRelation() throws Exception {
+ IAddConnectionContext context = EasyMock.createMock(IAddConnectionContext.class);
+ Object notARelation = new Object();
+ expect(context.getNewObject()).andReturn(notARelation);
+ verifyCanAdd(context, false);
+ }
+
+ @Test
+ public void testCanAdd() throws Exception {
+ IAddConnectionContext context = EasyMock.createMock(IAddConnectionContext.class);
+ IRelation relation = EasyMock.createMock(IRelation.class);
+ replay(relation);
+ expect(context.getNewObject()).andReturn(relation);
+ verifyCanAdd(context, true);
+ }
+
+ @Test
+ public void testGetFeatureProvider() {
+ IAddFeature fixture = createFeature();
+ assertSame(featureProvider, fixture.getFeatureProvider());
+ }
+
+ @SuppressWarnings("unused")
+ private void expectManyEndDecorator(double location) {
+ ConnectionDecorator d = EasyMock.createMock(ConnectionDecorator.class);
+ Polyline pl = EasyMock.createMock(Polyline.class);
+ expect(pl.getX()).andReturn(0);
+ expect(pl.getY()).andReturn(0);
+ expect(imageCreator.createManyEndDecorator(isA(Connection.class), eq(location))).andReturn(d);
+ expect(d.getGraphicsAlgorithm()).andReturn(pl);
+ replay(d, pl);
+ }
+
+ @SuppressWarnings("unused")
+ private void expectManyStartDecorator(double location) {
+ ConnectionDecorator d = EasyMock.createMock(ConnectionDecorator.class);
+ Polyline pl = EasyMock.createMock(Polyline.class);
+ expect(pl.getX()).andReturn(0);
+ expect(pl.getY()).andReturn(0);
+ expect(imageCreator.createManyStartDecorator(isA(Connection.class), eq(location))).andReturn(d);
+ expect(d.getGraphicsAlgorithm()).andReturn(pl);
+ replay(d, pl);
+ }
+
+ @SuppressWarnings("unused")
+ private void expectManyEndWithArrow(final double location) {
+ ConnectionDecorator d = EasyMock.createMock(ConnectionDecorator.class);
+ Polyline pl = EasyMock.createMock(Polyline.class);
+ expect(pl.getX()).andReturn(0);
+ expect(pl.getY()).andReturn(0);
+ expect(imageCreator.createManyEndWithArrowDecorator(isA(Connection.class), eq(location))).andReturn(d);
+ expect(d.getGraphicsAlgorithm()).andReturn(pl);
+ replay(d, pl);
+ }
+
+ @SuppressWarnings("unused")
+ private void expectArrow(final double location) {
+ ConnectionDecorator d = EasyMock.createMock(ConnectionDecorator.class);
+ Polyline pl = EasyMock.createMock(Polyline.class);
+ expect(pl.getX()).andReturn(0);
+ expect(pl.getY()).andReturn(0);
+ expect(imageCreator.createArrowConnectionDecorator(isA(Connection.class), eq(location))).andReturn(d);
+ expect(d.getGraphicsAlgorithm()).andReturn(pl);
+ replay(d, pl);
+ }
+
+ @SuppressWarnings("unused")
+ private void expectTextConnectionDecorator(String text, double location) {
+ expect(imageCreator.createCardinalityConnectionDecorator(isA(Connection.class), eq(text), eq(location))).andReturn(
+ null);
+ }
+
+ @SuppressWarnings("unused")
+ private void configureRelation(IRelation relation, final RelDir direction, final RelType type) {
+ expect(relation.getOwnerAttributeName()).andStubReturn(OWNER_AT_NAME);
+ expect(relation.getInverseAttributeName()).andStubReturn(INVERSE_AT_NAME);
+ expect(relation.getRelDir()).andStubReturn(direction);
+ expect(relation.getRelType()).andStubReturn(type);
+ }
+
+ private void configureProvidersForAdd(IRelation relation) {
+ expect(diagramProvider.getDiagram()).andReturn(diagram);
+ expect(featureProvider.getDiagramTypeProvider()).andReturn(diagramProvider);
+ expect(featureProvider.getPeUtil()).andReturn(peUtil);
+ expect(featureProvider.getAddBendpointFeature(isA(IAddBendpointContext.class))).andStubReturn(ft);
+ expect(context.getNewObject()).andReturn(relation);
+
+ }
+
+ @SuppressWarnings("unused")
+ private void verifyAdd(IRelation relation, boolean expectId) {
+ FreeFormConnection connection = configureConnection(relation, expectId);
+ replay(connection);
+ PictogramElement result = callAdd();
+ assertSame(connection, result);
+ verify(context);
+ verify(featureProvider);
+ verify(imageCreator);
+ verify(jpaEditorUtil);
+ verify(diagram);
+ verify(diagramProvider);
+ verify(relation);
+ }
+
+ private PictogramElement callAdd() {
+ IAddFeature fixture = createFeature();
+ PictogramElement result = fixture.add(context);
+ return result;
+ }
+
+ private FreeFormConnection configureConnection(IRelation relation, boolean expectId) {
+ final String relationId = "someId"; //$NON-NLS-1$
+ if (expectId)
+ expect(relation.getId()).andStubReturn(relationId);
+ replay(relation);
+ configureProvidersForAdd(relation);
+ Anchor startAnchor = replayAnchor();
+ Anchor endAnchor = replayAnchor();
+ expect(context.getSourceAnchor()).andReturn(startAnchor);
+ expect(context.getTargetAnchor()).andReturn(endAnchor);
+
+ gaUtil.setLocation(isA(Polyline.class), EasyMock.anyInt() , EasyMock.anyInt());
+ gaUtil.setLocation(isA(Polyline.class), EasyMock.anyInt() , EasyMock.anyInt());
+
+ FreeFormConnection connection = createConnection(startAnchor, endAnchor);
+ expect(peUtil.createFreeFormConnection(diagram)).andReturn(connection);
+ expect(imageCreator.createConnectionLine(diagram, connection)).andReturn(null);
+ ft.addBendpoint(isA(IAddBendpointContext.class));
+
+ List<Point> pts = new LinkedList<Point>();
+ Point pt1 = new Point(100, 100);
+ //Point pt2 = new Point(200, 200);
+ pts.add(pt1);
+ //pts.add(pt2);
+ expect(jpaEditorUtil.createBendPointList(connection, false)).andReturn(pts);
+ featureProvider.putKeyToBusinessObject(relationId, relation);
+ featureProvider.link(eq(connection), aryEq(new IRelation[] { relation }));
+ expect(featureProvider.layoutIfPossible(isA(ILayoutContext.class))).andReturn(null);
+ return connection;
+ }
+
+ private Anchor replayAnchor() {
+ Anchor startAnchor = EasyMock.createMock(Anchor.class);
+ replay(startAnchor);
+ return startAnchor;
+ }
+
+ private FreeFormConnection createConnection(Anchor startAnchor, Anchor endAnchor) {
+ FreeFormConnection connection = EasyMock.createMock(FreeFormConnection.class);
+ connection.setStart(startAnchor);
+ connection.setEnd(endAnchor);
+ connection.setVisible(true);
+ connection.setActive(true);
+
+ org.eclipse.graphiti.mm.algorithms.styles.Point pt = EasyMock.createMock(org.eclipse.graphiti.mm.algorithms.styles.Point.class);
+ expect(pt.getX()).andStubReturn(100);
+ expect(pt.getY()).andStubReturn(100);
+
+ org.eclipse.graphiti.mm.algorithms.styles.Point pt1 = EasyMock.createMock(org.eclipse.graphiti.mm.algorithms.styles.Point.class);
+ expect(pt1.getX()).andStubReturn(200);
+ expect(pt1.getY()).andStubReturn(200);
+
+
+ EList<org.eclipse.graphiti.mm.algorithms.styles.Point> pts1 = new BasicInternalEList<org.eclipse.graphiti.mm.algorithms.styles.Point>(org.eclipse.graphiti.mm.algorithms.styles.Point.class);
+ pts1.add(pt);
+ pts1.add(pt1);
+ expect(connection.getBendpoints()).andStubReturn(pts1);
+ replay(pt, pt1);
+ return connection;
+ }
+
+ private void verifyCanAdd(IAddContext context, final boolean expected) {
+ replay(context);
+ boolean result = callCanAdd(context);
+ assertEquals(expected, result);
+ verify(context);
+ }
+
+ private boolean callCanAdd(IAddContext context) {
+ IAddFeature fixture = createFeature();
+ return fixture.canAdd(context);
+ }
+
+ private IAddFeature createFeature() {
+ replay(featureProvider);
+ replay(imageCreator);
+ replay(jpaEditorUtil);
+ replay(diagramProvider);
+ replay(diagram);
+ replay(context);
+ replay(peUtil);
+ replay(gaUtil);
+ replay(ft);
+ return new AddRelationFeature(featureProvider, imageCreator, jpaEditorUtil);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java
new file mode 100644
index 0000000000..a700ef5c66
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/ClickAddFeatureTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNotNull;
+
+import org.easymock.EasyMock;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IDirectEditingInfo;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateContext;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.ClickAddAttributeButtonFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.IEditor;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ClickAddFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+ private ICreateContext context;
+ final String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = null;
+ JavaPersistentType jpt = null;
+ ICompilationUnit cu = null;
+
+ @Before
+ public void setUp() throws Exception {
+ System.setProperty(JPACreateFactory.JPA_JAR_NAME_SYSTEM_PROPERTY, "C:\\lib\\persistence-api-1.0.jar");
+ JptJpaCorePlugin.getJpaProjectManager();
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
+ assertNotNull(jpaProject);
+ IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ context = EasyMock.createMock(ICreateContext.class);
+ expect(context.getTargetContainer()).andStubReturn(cs);
+ expect(context.getX()).andStubReturn(0);
+ expect(context.getY()).andStubReturn(0);
+ expect(context.getWidth()).andStubReturn(100);
+ expect(context.getHeight()).andStubReturn(100);
+ expect(context.getTargetConnection()).andStubReturn(null);
+ IDirectEditingInfo dei = EasyMock.createMock(IDirectEditingInfo.class);
+ dei.setActive(true);
+ Thread.sleep(2000);
+ jpt = (JavaPersistentType)JPACreateFactory.getPersistentType(entity);
+ int cnt = 0;
+ while ((cnt < 50) && (jpt == null)) {
+ Thread.sleep(200);
+ jpt = (JavaPersistentType)JPACreateFactory.getPersistentType(entity);
+ cnt++;
+ }
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs)).andStubReturn(jpt);
+ expect(featureProvider.getPictogramElementForBusinessObject(jpt)).andStubReturn(null);
+ cu = JavaCore.createCompilationUnitFrom(entity);
+ cnt = 0;
+ while ((cnt < 50) && (cu == null)) {
+ Thread.sleep(200);
+ cu = JavaCore.createCompilationUnitFrom(entity);
+ cnt++;
+ }
+ expect(featureProvider.getCompilationUnit((JavaPersistentType) EasyMock.anyObject())).andReturn(cu).anyTimes();
+ expect(featureProvider.addIfPossible(isA(IAddContext.class))).andStubReturn(null);
+ expect(featureProvider.getDirectEditingInfo()).andStubReturn(dei);
+
+ IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class);
+ expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut);
+
+ IDiagramTypeProvider diagramTypeProvider = EasyMock.createMock(IDiagramTypeProvider.class);
+ expect(featureProvider.getDiagramTypeProvider()).andStubReturn(diagramTypeProvider);
+ IEditor ed = EasyMock.createMock(IEditor.class);
+ expect(diagramTypeProvider.getDiagramEditor()).andStubReturn(ed);
+ IWorkbenchPartSite ws = EasyMock.createMock(IWorkbenchPartSite.class);
+ expect(ed.getSite()).andStubReturn(ws);
+ ut.formatCode((ICompilationUnit)EasyMock.anyObject(), (IWorkbenchPartSite)EasyMock.anyObject());
+
+ featureProvider.addAddIgnore(jpt, "attribute1");
+
+ replay(featureProvider, cs, context, dei, diagramTypeProvider, ed, ws, ut);
+ }
+
+ @Test
+ public void testClickAddAttributeButtonFeature(){
+ if ((jpt == null) || (cu == null))
+ return; // The test wasn't setup properly
+ ClickAddAttributeButtonFeature feature = new ClickAddAttributeButtonFeature(featureProvider);
+ Object[] created = feature.create(context);
+ assertNotNull(created[0]);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java
new file mode 100644
index 0000000000..3ac34cc448
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateDeleteOnlyAttributeTest.java
@@ -0,0 +1,229 @@
+/*******************************************************************************
+ * <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.feature;
+
+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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+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.features.context.IAddContext;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
+import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
+import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CreateDeleteOnlyAttributeTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+ final String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = null;
+ JavaPersistentType jpt = null;
+
+ @Before
+ public void setUp() throws Exception{
+ JptJpaCorePlugin.getJpaProjectManager();
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
+ assertNotNull(jpaProject);
+ IFile entity = factory.createEntity(jpaProject, "org.eclipse.Entity1");
+ jpt = (JavaPersistentType)JPACreateFactory.getPersistentType(entity);
+ int c = 0;
+ while ((jpt == null) && (c < 100)) {
+ try {
+ Thread.sleep(250);
+ } catch (Exception e) {}
+ jpt = (JavaPersistentType)JPACreateFactory.getPersistentType(entity);
+ c++;
+ }
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(featureProvider.getBusinessObjectForPictogramElement(isA(ContainerShape.class))).andStubReturn(jpt);
+ expect(featureProvider.getBusinessObjectForPictogramElement(null)).andReturn(JPACreateFactory.getPersistentType(entity));
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
+ expect(featureProvider.addIfPossible(isA(IAddContext.class))).andStubReturn(null);
+ expect(featureProvider.getPictogramElementForBusinessObject(jpt)).andStubReturn(isA(ContainerShape.class));
+ ICompilationUnit cu = JavaCore.createCompilationUnitFrom(entity);
+ expect(featureProvider.getCompilationUnit(jpt)).andStubReturn(cu);
+ replay(featureProvider);
+ }
+
+
+ @Test
+ public void testCreatePropertyAnnotatedAttribute() throws Exception {
+ EntityAttributesChangeTestListener lsnr = new EntityAttributesChangeTestListener(0, 1);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ deleteAttribute("id");
+ assertTrue(lsnr.waitForEvents());
+ jpt.removeListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ lsnr = new EntityAttributesChangeTestListener(2, 0);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ JpaArtifactFactory.instance().makeNewAttribute(featureProvider, jpt, featureProvider.getCompilationUnit(jpt), "aaa", "java.lang.String", null, "aaa", null, false, true);
+ assertFalse(lsnr.waitForEvents());
+ assertEquals(1, lsnr.incrementCounter);
+ assertEquals(0, lsnr.decrementCounter);
+ }
+
+
+
+ @Test
+ public void testCreateFieldAnnotatedAttribute() throws Exception {
+ EntityAttributesChangeTestListener lsnr = new EntityAttributesChangeTestListener(0, 1);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ deleteAttribute("id");
+ assertTrue(lsnr.waitForEvents());
+ jpt.removeListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ lsnr = new EntityAttributesChangeTestListener(2, 0);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ JpaArtifactFactory.instance().makeNewAttribute(featureProvider, jpt, featureProvider.getCompilationUnit(jpt), "aaa", "java.lang.String", null, "aaa", null, false, false);
+ assertFalse(lsnr.waitForEvents());
+ assertEquals(1, lsnr.incrementCounter);
+ assertEquals(0, lsnr.decrementCounter);
+ }
+
+
+ @Test
+ public void testDeletePropertyAnnotatedAttribute() throws Exception {
+ EntityAttributesChangeTestListener lsnr = new EntityAttributesChangeTestListener(0, 2);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ deleteAttribute("id");
+ assertFalse(lsnr.waitForEvents());
+ assertEquals(0, lsnr.incrementCounter);
+ assertEquals(1, lsnr.decrementCounter);
+ }
+
+
+ @Test
+ public void testDeleteFieldAnnotatedAttribute() throws Exception {
+ EntityAttributesChangeTestListener lsnr = new EntityAttributesChangeTestListener(1, 1);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ deleteAttribute("id");
+ JpaArtifactFactory.instance().makeNewAttribute(featureProvider, jpt, featureProvider.getCompilationUnit(jpt), "aaa", "java.lang.String", null, "aaa", null, false, false);
+ assertTrue(lsnr.waitForEvents());
+ jpt.removeListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ lsnr = new EntityAttributesChangeTestListener(0, 2);
+ jpt.addListChangeListener(JavaPersistentType.ATTRIBUTES_LIST, lsnr);
+ deleteAttribute("aaa");
+ assertFalse(lsnr.waitForEvents());
+ assertEquals(0, lsnr.incrementCounter);
+ assertEquals(1, lsnr.decrementCounter);
+ }
+
+
+
+ private void deleteAttribute(String attrName) {
+ JpaArtifactFactory.instance().deleteAttribute(jpt, attrName, featureProvider);
+ }
+
+
+ public static class EntityAttributesChangeTestListener implements ListChangeListener {
+
+ private Semaphore sem = new Semaphore(1);
+
+ private int toBeAdded;
+ private int toBeRemove;
+
+ public EntityAttributesChangeTestListener(int add, int remove) {
+ this.toBeAdded = add;
+ this.toBeRemove = remove;
+ try {
+ sem.acquire(1);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public boolean waitForEvents() throws InterruptedException {
+ return sem.tryAcquire(5, TimeUnit.SECONDS);
+ }
+
+ public int incrementCounter = 0;
+ public int decrementCounter = 0;
+
+ public void listChanged(ListChangeEvent event) {
+ }
+
+ public void itemsAdded(ListAddEvent arg0) {
+ incrementCounter++;
+ if(this.incrementCounter >= toBeAdded && this.decrementCounter>= toBeRemove ) {
+ sem.release();
+ }
+ }
+
+ public void itemsMoved(ListMoveEvent arg0) {
+ }
+
+ public void itemsRemoved(ListRemoveEvent arg0) {
+ decrementCounter++;
+ if(this.incrementCounter >= toBeAdded && this.decrementCounter>= toBeRemove ) {
+ sem.release();
+ }
+ }
+
+ public void itemsReplaced(ListReplaceEvent arg0) {
+ }
+
+ public void listCleared(ListClearEvent arg0) {
+ }
+ };
+
+ @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/feature/CreateRelationFeaturesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java
new file mode 100644
index 0000000000..441d184d57
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/CreateRelationFeaturesTest.java
@@ -0,0 +1,573 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+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.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.ICreateConnectionContext;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+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.JavaPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyBiDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToManyUniDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneBiDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateManyToOneUniDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToManyUniDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneBiDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.CreateOneToOneUniDirRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelDir;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation.RelType;
+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;
+
+@SuppressWarnings("restriction")
+public class CreateRelationFeaturesTest {
+ 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);
+ Thread.sleep(2000);
+ }
+
+ @Test
+ public void testCreateOneToOneUniDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateOneToOneUniDirRelationFeature ft = new CreateOneToOneUniDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ cu1.becomeWorkingCopy(new NullProgressMonitor());
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+ cu2.becomeWorkingCopy(new NullProgressMonitor());
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ OneToOneUniDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.ONE_TO_ONE, rel.getRelType());
+ assertEquals(RelDir.UNI, rel.getRelDir());
+ assertSame(rel.getOwner(), t1);
+ assertSame(rel.getInverse(), t2);
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ assertTrue(JpaArtifactFactory.instance().isMethodAnnotated(t1));
+ JavaPersistentAttribute jpa = t1.getAttributeNamed("id");
+ assertFalse(JpaArtifactFactory.instance().isRelationAnnotated(jpa));
+ jpa = t1.getAttributeNamed(rel.getOwnerAttributeName());
+ assertTrue(JpaArtifactFactory.instance().isRelationAnnotated(jpa));
+ }
+
+ @Test
+ public void testCreateOneToOneBiDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateOneToOneBiDirRelationFeature ft = new CreateOneToOneBiDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ OneToOneBiDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.ONE_TO_ONE, rel.getRelType());
+ assertEquals(RelDir.BI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ assertNotNull(t2.getAttributeNamed(rel.getInverseAttributeName()));
+ }
+
+
+ @Test
+ public void testCreateManyToOneUniDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateManyToOneUniDirRelationFeature ft = new CreateManyToOneUniDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ ManyToOneUniDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.MANY_TO_ONE, rel.getRelType());
+ assertEquals(RelDir.UNI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ }
+
+
+ @Test
+ public void testCreateManyToOneBiDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateManyToOneBiDirRelationFeature ft = new CreateManyToOneBiDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ ManyToOneBiDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.MANY_TO_ONE, rel.getRelType());
+ assertEquals(RelDir.BI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ assertNotNull(t2.getAttributeNamed(rel.getInverseAttributeName()));
+ }
+
+ @Test
+ public void testCreateOneToManyUniDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateOneToManyUniDirRelationFeature ft = new CreateOneToManyUniDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ OneToManyUniDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.ONE_TO_MANY, rel.getRelType());
+ assertEquals(RelDir.UNI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ }
+
+ @Test
+ public void testCreateManyToManyUniDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateManyToManyUniDirRelationFeature ft = new CreateManyToManyUniDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ ManyToManyUniDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.MANY_TO_MANY, rel.getRelType());
+ assertEquals(RelDir.UNI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ }
+
+ @Test
+ public void testCreateManyToManyBiDirRelationFeature() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateManyToManyBiDirRelationFeature ft = new CreateManyToManyBiDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ ManyToManyBiDirRelation rel = ft.createRelation(featureProvider, cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.MANY_TO_MANY, rel.getRelType());
+ assertEquals(RelDir.BI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ assertNotNull(t2.getAttributeNamed(rel.getInverseAttributeName()));
+ }
+
+
+ public static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DeleteRelationFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DeleteRelationFeatureTest.java
new file mode 100644
index 0000000000..b5548c9fd0
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DeleteRelationFeatureTest.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+
+import org.easymock.EasyMock;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteRelationFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.BidirectionalRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util.IEditor;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.junit.Test;
+
+public class DeleteRelationFeatureTest {
+
+ @Test
+ public void testPostDelete(){
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(featureProvider.getRemoveFeature(isA(IRemoveContext.class))).andReturn(null);
+ IJPAEditorUtil ut = EasyMock.createMock(IJPAEditorUtil.class);
+ expect(featureProvider.getJPAEditorUtil()).andStubReturn(ut);
+ IDeleteContext ctx = EasyMock.createMock(IDeleteContext.class);
+ PictogramElement pe = EasyMock.createMock(PictogramElement.class);
+ expect(ctx.getPictogramElement()).andStubReturn(pe);
+ BidirectionalRelation rel = EasyMock.createMock(BidirectionalRelation.class);
+ ICompilationUnit cu1 = EasyMock.createMock(ICompilationUnit.class);
+ ICompilationUnit cu2 = EasyMock.createMock(ICompilationUnit.class);
+ JavaPersistentType jpt1 = EasyMock.createMock(JavaPersistentType.class);
+ JavaPersistentType jpt2 = EasyMock.createMock(JavaPersistentType.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(rel);
+ expect(rel.getOwner()).andStubReturn(jpt1);
+ expect(rel.getInverse()).andStubReturn(jpt2);
+ expect(featureProvider.getCompilationUnit(jpt1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(jpt2)).andStubReturn(cu2);
+
+ IWorkbenchPartSite ws = EasyMock.createMock(IWorkbenchPartSite.class);
+
+ IDiagramTypeProvider p = EasyMock.createMock(IDiagramTypeProvider.class);
+ IEditor e = EasyMock.createMock(IEditor.class);
+ expect(featureProvider.getDiagramTypeProvider()).andStubReturn(p);
+ expect(p.getDiagramEditor()).andStubReturn(e);
+ expect(e.getSite()).andStubReturn(ws);
+ ut.organizeImports(cu1, ws);
+ ut.organizeImports(cu2, ws);
+
+ replay(featureProvider, ctx, ut, rel, jpt1, jpt2, cu1, cu2, pe, p, e, ws);
+
+ DeleteRelationFeature feature = new DeleteRelationFeature(featureProvider);
+ feature.postDelete(ctx);
+ }
+}
+
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DirectEditAttributeFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DirectEditAttributeFeatureTest.java
new file mode 100644
index 0000000000..a48ee0dd5c
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/DirectEditAttributeFeatureTest.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * <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.feature;
+
+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 java.text.MessageFormat;
+
+import org.easymock.EasyMock;
+import org.eclipse.graphiti.features.IDirectEditingFeature;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IDirectEditingContext;
+import org.eclipse.jdt.core.JavaConventions;
+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.feature.DirectEditAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DirectEditAttributeFeatureTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testCheckValueValidStringByJavaConventions() {
+ JavaPersistentType jpt = EasyMock.createNiceMock(JavaPersistentType.class);
+ JavaPersistentAttribute jpa = configureJpaForJpt(jpt);
+ expect(jpt.getAttributeNamed(isA(String.class))).andStubReturn(jpa);
+ replay(jpa, jpt);
+
+ IFeatureProvider provider = replayJpaForNullPe(jpa);
+ IDirectEditingContext context = replayNullPeContext();
+
+ IDirectEditingFeature feature = new DirectEditAttributeFeature(provider);
+ assertNotValidJavaConventionField(feature, context, "");
+ assertNotValidJavaConventionField(feature, context, "1a");
+ assertNotValidJavaConventionField(feature, context, "d d");
+ assertValidField(feature, context, "$d");
+ assertNotValidJavaConventionField(feature, context, "enum");
+ }
+
+ @Test
+ public void testCheckValueValidStringDuplicateAttribute() {
+ JavaPersistentAttribute otherJpa = EasyMock.createMock(JavaPersistentAttribute.class);
+ JavaPersistentType jpt = EasyMock.createMock(JavaPersistentType.class);
+ expect(jpt.getAttributeNamed("attrName")).andStubReturn(otherJpa);
+
+ JavaPersistentAttribute jpa = configureJpaForJpt(jpt);
+ replay(jpa, jpt, otherJpa);
+
+ IFeatureProvider provider = replayJpaForNullPe(jpa);
+ IDirectEditingContext context = replayNullPeContext();
+
+ IDirectEditingFeature feature = new DirectEditAttributeFeature(provider);
+
+ assertEquals(MessageFormat.format(JPAEditorMessages.DirectEditAttributeFeature_attributeExists, "attrName"), feature.checkValueValid("attrName", context));
+ }
+
+ private IFeatureProvider replayJpaForNullPe(JavaPersistentAttribute jpa) {
+ IFeatureProvider provider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(provider.getBusinessObjectForPictogramElement(null)).andStubReturn(jpa);
+ replay(provider);
+ return provider;
+ }
+
+ private JavaPersistentAttribute configureJpaForJpt(JavaPersistentType jpt) {
+ JavaPersistentAttribute jpa = EasyMock.createMock(JavaPersistentAttribute.class);
+ expect(jpa.getParent()).andStubReturn(jpt);
+ return jpa;
+ }
+
+ private IDirectEditingContext replayNullPeContext() {
+ IDirectEditingContext context = EasyMock.createMock(IDirectEditingContext.class);
+ expect(context.getPictogramElement()).andStubReturn(null);
+ replay(context);
+ return context;
+ }
+
+ private void assertValidField(IDirectEditingFeature feature, IDirectEditingContext context, String field) {
+ assertEquals(null, feature.checkValueValid(field, context));
+ }
+
+ private void assertNotValidJavaConventionField(IDirectEditingFeature feature, IDirectEditingContext context,
+ String field) {
+ final String sourceLevel = "1.5";
+ final String complianceLevel = "1.5";
+ assertEquals(JavaConventions.validateFieldName(field, sourceLevel, complianceLevel).getMessage(), feature
+ .checkValueValid(field, context));
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/LayoutEntityFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/LayoutEntityFeatureTest.java
new file mode 100644
index 0000000000..e9fbe8566b
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/LayoutEntityFeatureTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * <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.feature;
+
+import org.easymock.EasyMock;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.LayoutJPAEntityFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IGraphicsUpdater;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.junit.Test;
+
+public class LayoutEntityFeatureTest {
+
+ @Test
+ public void testIfNewlyAddedEntityShapeIsExpanded() {
+ IJPAEditorFeatureProvider fp = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ ILayoutContext ctx = EasyMock.createMock(ILayoutContext.class);
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ GraphicsAlgorithm ga = EasyMock.createMock(GraphicsAlgorithm.class);
+ EasyMock.expect(cs.getGraphicsAlgorithm()).andStubReturn(ga);
+ EasyMock.expect(ctx.getPictogramElement()).andStubReturn(cs);
+ EasyMock.expect(ga.getHeight()).andStubReturn(80);
+ EasyMock.expect(ga.getWidth()).andStubReturn(100);
+ //EasyMock.expect(cs.is___Alive()).andStubReturn(true);
+ EList<Shape> shList = new BasicInternalEList<Shape>(Shape.class);
+ EasyMock.expect(cs.getChildren()).andStubReturn(shList);
+ IPeServiceUtil peUtil = EasyMock.createMock(IPeServiceUtil.class);
+ EasyMock.expect(fp.getPeUtil()).andStubReturn(peUtil);
+ EasyMock.expect(peUtil.getProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(null);
+ EasyMock.expect(peUtil.removeProperty(cs, JPAEditorConstants.COLLAPSE_FEATURES)).andStubReturn(false);
+ IGraphicsUpdater gu = EasyMock.createMock(IGraphicsUpdater.class);
+ EasyMock.expect(fp.getGraphicsUpdater()).andStubReturn(gu);
+ gu.updateEntityHeigth(cs);
+
+ EasyMock.replay(fp, ctx, cs, ga, peUtil, gu);
+ LayoutJPAEntityFeature ft = new LayoutJPAEntityFeature(fp);
+ ft.layout(ctx);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/OpenMiniatureViewFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/OpenMiniatureViewFeatureTest.java
new file mode 100644
index 0000000000..80b95a5c7d
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/OpenMiniatureViewFeatureTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNotNull;
+
+import org.easymock.EasyMock;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.OpenMiniatureViewFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OpenMiniatureViewFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+ final String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = 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);
+ }
+
+ @Test
+ public void testExecute() {
+ OpenMiniatureViewFeature ft = new OpenMiniatureViewFeature(featureProvider);
+ IAddContext ctx = EasyMock.createMock(IAddContext.class);
+ ft.execute(ctx);
+ }
+
+
+}
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
new file mode 100644
index 0000000000..358f92e92d
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RefactorAttributeTypeFeatureTest.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * <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.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.core.resources.IProject;
+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.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.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;
+
+@SuppressWarnings("unused")
+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.getResourcePersistentAttribute());
+ assertEquals("int", typeName2);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RemoveAttributeFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RemoveAttributeFeatureTest.java
new file mode 100644
index 0000000000..31b46a400a
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/RemoveAttributeFeatureTest.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Date;
+
+import org.easymock.EasyMock;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.features.custom.ICustomFeature;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.RemoveAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RemoveAttributeFeatureTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+ private IRemoveContext 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);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testRemoveAttributeFeature() {
+ GraphicsAlgorithm algorithm = EasyMock.createNiceMock(GraphicsAlgorithm.class);
+ replay(algorithm);
+
+ EList<Anchor> list = EasyMock.createMock(EList.class);
+ Shape shape = EasyMock.createNiceMock(Shape.class);
+
+ expect(shape.getGraphicsAlgorithm()).andReturn(algorithm);
+ expect(shape.getAnchors()).andReturn(list);
+ replay(shape);
+
+ //EList<Shape> listShape = new BasicInternalEList<Shape>(Shape.class);
+
+ ContainerShape pictogramElement = EasyMock.createMock(ContainerShape.class);
+ Resource res = EasyMock.createMock(Resource.class);
+ expect(pictogramElement.eResource()).andStubReturn(res);
+
+ ResourceSet rs = EasyMock.createMock(ResourceSet.class);
+ expect(res.getResourceSet()).andStubReturn(rs);
+ EList<Adapter> ead = new BasicInternalEList<Adapter>(Adapter.class);
+ expect(rs.eAdapters()).andStubReturn(ead);
+
+ replay(pictogramElement, res, rs);
+
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(featureProvider.getBusinessObjectForPictogramElement(pictogramElement)).andReturn(JPACreateFactory.getPersistentAttribute(entity, "att"));
+ expect(featureProvider.decreaseAttribsNum(pictogramElement)).andReturn(0);
+ expect(featureProvider.getKeyForBusinessObject(isA(Object.class))).andReturn("");
+ expect(featureProvider.remove("")).andReturn(null);
+ expect(featureProvider.getRelationRelatedToAttribute(isA(JavaPersistentAttribute.class))).andReturn(null);
+ replay(featureProvider);
+
+ context = EasyMock.createMock(IRemoveContext.class);
+ expect(context.getPictogramElement()).andReturn(pictogramElement);
+ replay(context);
+
+ ICustomFeature graphicalRemove = EasyMock.createMock(ICustomFeature.class);
+ graphicalRemove.execute(isA(ICustomContext.class));
+ replay(graphicalRemove);
+
+ RemoveAttributeFeature feature = new RemoveAttributeFeature(featureProvider, graphicalRemove);
+ feature.preRemove(context);
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java
new file mode 100644
index 0000000000..ab352d93e2
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/SaveEntityFeatureTest.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+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.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+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.jpa.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.SaveEntityFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+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;
+
+@SuppressWarnings("restriction")
+public class SaveEntityFeatureTest {
+ final String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = null;
+
+ @Before
+ public void setUp() throws Exception{
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+ }
+
+ @Test
+ public void testExecute() throws Exception {
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ PictogramElement pe = EasyMock.createMock(PictogramElement.class);
+
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ int cnt = 0;
+ while ((cnt < 25) && (t1 == null)) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ cnt++;
+ }
+ if (t1 == null)
+ return;
+ expect(featureProvider.getBusinessObjectForPictogramElement(pe)).andStubReturn(t1);
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(createCompilationUnitFrom(customerFile)).anyTimes();
+
+
+ SaveEntityFeature ft = new SaveEntityFeature(featureProvider);
+ ICustomContext ctx = EasyMock.createMock(ICustomContext.class);
+
+ PictogramElement[] pes = new PictogramElement[1];
+ pes[0] = pe;
+ expect(ctx.getPictogramElements()).andStubReturn(pes);
+
+ replay(featureProvider, ctx, pe);
+ ft.execute(ctx);
+ }
+
+ public static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/UpdateAttributeFeatureTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/UpdateAttributeFeatureTest.java
new file mode 100644
index 0000000000..792c7c31d3
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/feature/UpdateAttributeFeatureTest.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * <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.feature;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Date;
+import java.util.Iterator;
+
+import org.easymock.EasyMock;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.UpdateAttributeFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+public class UpdateAttributeFeatureTest {
+
+ 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);
+ }
+
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ @Test
+ public void testUpdateAttributeFeature(){
+ Text text = EasyMock.createMock(Text.class);
+ text.setValue(EasyMock.isA(java.lang.String.class));
+ EasyMock.replay(text);
+
+ EList<GraphicsAlgorithm> listChildren = new BasicInternalEList<GraphicsAlgorithm>(GraphicsAlgorithm.class);
+
+
+ EasyMock.expect(listChildren.get(0)).andReturn(text);
+ EasyMock.replay(listChildren);
+
+
+ Rectangle rectangle = EasyMock.createMock(Rectangle.class);
+ EasyMock.expect(rectangle.getGraphicsAlgorithmChildren()).andReturn(listChildren);
+ EasyMock.expect(rectangle.getY()).andReturn(0).times(2);
+ EasyMock.replay(rectangle);
+
+ Iterator<Shape> iteratorShape = EasyMock.createNiceMock(Iterator.class);
+ EasyMock.expect(iteratorShape.hasNext()).andReturn(false);
+ EasyMock.replay(iteratorShape);
+
+ EList<Shape> listShape = new BasicInternalEList<Shape>(Shape.class);
+
+ ContainerShape containerShape = EasyMock.createMock(ContainerShape.class);
+ EasyMock.expect(containerShape.getChildren()).andReturn(listShape);
+ EasyMock.replay(containerShape);
+
+ Shape shape = EasyMock.createMock(Shape.class);
+ Resource res = EasyMock.createMock(Resource.class);
+ ResourceSet rs = EasyMock.createMock(ResourceSet.class);
+ EasyMock.expect(res.getResourceSet()).andStubReturn(rs);
+ EList<Adapter> ads = new BasicInternalEList<Adapter>(Adapter.class);
+ EasyMock.expect(rs.eAdapters()).andStubReturn(ads);
+ EasyMock.expect(shape.eResource()).andStubReturn(res);
+
+
+
+ EasyMock.expect(shape.getGraphicsAlgorithm()).andReturn(rectangle).times(3);
+ EasyMock.expect(shape.getContainer()).andReturn(containerShape);
+
+
+ EasyMock.replay(shape, res, rs);
+
+ context = EasyMock.createMock(ICustomContext.class);
+ EasyMock.expect(context.getInnerPictogramElement()).andReturn(shape);
+ EasyMock.replay(context);
+
+ featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ EasyMock.expect(featureProvider.getBusinessObjectForPictogramElement(shape)).andReturn(null);
+ EasyMock.replay(featureProvider);
+
+ UpdateAttributeFeature feature = new UpdateAttributeFeature(featureProvider);
+ feature.execute(context);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java
new file mode 100644
index 0000000000..6584dab502
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/listener/JPAProjectListenerTest.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * <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.listener;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNotNull;
+
+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.features.IRemoveFeature;
+import org.eclipse.graphiti.features.context.IRemoveContext;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+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.jpa.core.context.persistence.PersistenceUnit;
+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.JPASolver;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+@SuppressWarnings("restriction")
+public class JPAProjectListenerTest {
+ 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(getPersistentType(entity));
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
+ }
+
+ public static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+ @Test
+ public void testJPAProjectListener() {
+ JPASolver slv = new JPASolver();
+ slv.setFeatureProvider(featureProvider);
+ jpaProject.addCollectionChangeListener("mark", slv.new JPAProjectListener());
+ PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpaProject);
+ JavaPersistentType jpt = JpaArtifactFactory.instance().getJPT("org.eclipse.Entity1", pu);
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ expect(featureProvider.getPictogramElementForBusinessObject(jpt)).andStubReturn(cs);
+ IRemoveFeature ft = EasyMock.createMock(IRemoveFeature.class);
+ expect(featureProvider.getRemoveFeature(isA(IRemoveContext.class))).andReturn(ft);
+ // The remove method should be invoked exactly once
+ ft.remove(isA(IRemoveContext.class));
+ replay(ft, cs, featureProvider);
+ JpaArtifactFactory.instance().deleteEntityClass(jpt, featureProvider);
+ }
+
+ @Test
+ public void testJPAProjectListenerNoRemove() {
+ JPASolver slv = new JPASolver();
+ slv.setFeatureProvider(featureProvider);
+ jpaProject.addCollectionChangeListener("mark", slv.new JPAProjectListener());
+ PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpaProject);
+ JavaPersistentType jpt = JpaArtifactFactory.instance().getJPT("org.eclipse.Entity1", pu);
+ expect(featureProvider.getPictogramElementForBusinessObject(jpt)).andStubReturn(null);
+ IRemoveFeature ft = EasyMock.createMock(IRemoveFeature.class);
+ expect(featureProvider.getRemoveFeature(isA(IRemoveContext.class))).andReturn(ft);
+ replay(ft, featureProvider);
+ // if the container shape is null the remove method of the feature should not be invoked
+ JpaArtifactFactory.instance().deleteEntityClass(jpt, featureProvider);
+ }
+
+
+ @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 {
+ try {
+ IProject project = jpaProject.getProject();
+ project.close(monitor);
+ project.close(monitor);
+ project.delete(true, true, monitor);
+ } catch (Exception e) {
+ //ignore
+ }
+ }
+ } , monitor);
+ }
+
+
+}
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
new file mode 100644
index 0000000000..322b59b254
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/ui/ModelIntegrationTest.java
@@ -0,0 +1,238 @@
+/*******************************************************************************
+ * <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;
+
+@SuppressWarnings("restriction")
+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(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 = 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 = 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 static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ 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
new file mode 100644
index 0000000000..692bbd5519
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/modelintegration/util/ModelIntegrationUtilTest.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * <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.jpt.jpadiagrameditor.ui.internal.modelintegration.util.ModelIntegrationUtil;
+import org.junit.Test;
+
+
+@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");
+ }
+}
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
new file mode 100644
index 0000000000..f34965d054
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferenceInitializerTest.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * <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
new file mode 100644
index 0000000000..718896e8c3
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/preferences/JPAEditorPreferencesPageTest.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * <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/JPAEditorFeatureProviderTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorFeatureProviderTest.java
new file mode 100644
index 0000000000..eb46f6523d
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorFeatureProviderTest.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * <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.provider;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.easymock.EasyMock;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IDeleteFeature;
+import org.eclipse.graphiti.features.context.IDeleteContext;
+import org.eclipse.graphiti.mm.Property;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+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.feature.ClickRemoveAttributeButtonFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteJPAEntityFeature;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.feature.DeleteRelationFeature;
+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.ManyToManyUniDirRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IJpaSolver;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class JPAEditorFeatureProviderTest {
+
+
+ private IJpaSolver solver;
+ private String businessObjectKey;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ solver = EasyMock.createMock(IJpaSolver.class);
+ businessObjectKey = "someValue";
+ }
+
+ @Test
+ public void testAttributesGroupDeleteFeature(){
+ PictogramElement pe = replayPictogramElement();
+
+ expect(solver.getBusinessObjectForKey(businessObjectKey)).andReturn(new Object());
+ IJPAEditorFeatureProvider provider = createFeatureProvider();
+
+ //test
+ IDeleteContext context = replayDeleteContext(pe);
+ assertNull(provider.getDeleteFeature(context));
+ }
+
+ @Test
+ public void testAttributeDeleteFeature(){
+ PictogramElement pe = replayPictogramElement();
+ JavaPersistentAttribute jpa = replayAttribute();
+ expect(solver.getBusinessObjectForKey(businessObjectKey)).andStubReturn(jpa);
+ IJPAEditorFeatureProvider provider = createFeatureProvider();
+
+ //test
+ IDeleteContext context = replayDeleteContext(pe);
+ assertNotNull(provider.getDeleteFeature(context));
+ IDeleteFeature feature = provider.getDeleteFeature(context);
+ assertTrue(feature instanceof ClickRemoveAttributeButtonFeature);
+ }
+
+ @Test
+ public void testEntityDeleteFeature(){
+ PictogramElement pe = replayPictogramElement();
+ JavaPersistentType jpt = replayJPT("TestEntity");
+
+ expect(solver.getBusinessObjectForKey(businessObjectKey)).andStubReturn(jpt);
+ IJPAEditorFeatureProvider provider = createFeatureProvider();
+
+ //test
+ IDeleteContext context = replayDeleteContext(pe);
+ assertNotNull(provider.getDeleteFeature(context));
+ IDeleteFeature deleteFeature = provider.getDeleteFeature(context);
+ assertTrue(deleteFeature instanceof DeleteJPAEntityFeature);
+ }
+
+ @Test
+ public void testRelationDeleteFeature(){
+ PictogramElement pe = replayPictogramElement();
+ JavaPersistentType jpt1 = replayJPT("TestEntity1");
+ JavaPersistentType jpt2 = replayJPT("TestEntity2");
+ IJPAEditorFeatureProvider provider = createFeatureProvider();
+
+ AbstractRelation relation = new ManyToManyUniDirRelation(provider, jpt1, jpt2, "attribute1", false, null, null);
+ expect(solver.getBusinessObjectForKey(businessObjectKey)).andStubReturn(relation);
+
+ //test
+ IDeleteContext context = replayDeleteContext(pe);
+ assertNotNull(provider.getDeleteFeature(context));
+ IDeleteFeature deleteFeature = provider.getDeleteFeature(context);
+ assertTrue(deleteFeature instanceof DeleteRelationFeature);
+ }
+
+ private JavaPersistentType replayJPT(String name){
+ JavaPersistentType jpt = EasyMock.createMock(JavaPersistentType.class);
+ expect(jpt.getName()).andReturn(name);
+ replay(jpt);
+ return jpt;
+ }
+
+ private JavaPersistentAttribute replayAttribute(){
+ JavaPersistentAttribute attribute = EasyMock.createMock(JavaPersistentAttribute.class);
+ expect(attribute.getName()).andReturn("attribute");
+ replay(attribute);
+ return attribute;
+ }
+
+ @SuppressWarnings("unchecked")
+ private PictogramElement replayPictogramElement(){
+ PictogramElement pe = EasyMock.createMock(PictogramElement.class);
+ Resource r = EasyMock.createMock(Resource.class);
+ expect(pe.eResource()).andStubReturn(r);
+ //expect(pe.is___Alive()).andStubReturn(true);
+ EList<Property> properties = EasyMock.createMock(EList.class);
+ Property prop = EasyMock.createMock(Property.class);
+ expect(prop.getKey()).andStubReturn("independentObject");
+ expect(prop.getValue()).andStubReturn(businessObjectKey);
+ replay(prop, r);
+ properties.add(prop);
+ expect(pe.getProperties()).andStubReturn(properties);
+ replay(pe);
+ return pe;
+ }
+
+ private IJPAEditorFeatureProvider createFeatureProvider() {
+ IDiagramTypeProvider dtp = EasyMock.createMock(IDiagramTypeProvider.class);
+ replay(dtp);
+ solver.setFeatureProvider(isA(IJPAEditorFeatureProvider.class));
+ replay(solver);
+ IJPAEditorFeatureProvider provider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(provider.getDiagramTypeProvider()).andStubReturn(dtp);
+ //provider.get
+ replay(provider);
+ return provider;
+ }
+
+ private IDeleteContext replayDeleteContext(PictogramElement pe){
+ IDeleteContext context = EasyMock.createMock(IDeleteContext.class);
+ expect(context.getPictogramElement()).andStubReturn(pe);
+ replay(context);
+ return context;
+ }
+
+}
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
new file mode 100644
index 0000000000..a987680cdb
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/provider/JPAEditorToolBehaviorProviderTest.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * <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/CreateRelationAttributesTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java
new file mode 100644
index 0000000000..bb913fc62e
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationAttributesTest.java
@@ -0,0 +1,621 @@
+/*******************************************************************************
+ * <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.relation;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+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.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+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.AttributeMapping;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaManyToManyMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaManyToOneMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaOneToManyMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaOneToOneMapping;
+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.jpa.core.resource.java.JavaResourcePersistentType;
+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.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("restriction")
+public class CreateRelationAttributesTest {
+
+ 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(getPersistentType(entity));
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
+ replay(featureProvider);
+ }
+
+ public static PersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node : getRootNodes(jpaFile)) {
+ PersistentType entity = (PersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
+ if (!cu.isWorkingCopy())
+ try {
+ cu.becomeWorkingCopy(new NullProgressMonitor());
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return cu;
+ }
+
+ @Test
+ public void testAddAnnotation() throws Exception {
+ assertNotNull(jpaProject);
+ //jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject));
+ IFile customerFile = JPACreateFactory.instance().createEntityInProject(jpaProject.getProject(), new String[]{"abc"}, "Customer");
+ IFile addressFile = JPACreateFactory.instance().createEntityInProject(jpaProject.getProject(), new String[]{"abc"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("abc.Customer");
+ assertNotNull(customerType);
+
+
+ PersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("abc.Address");
+ assertNotNull(customerType);
+
+
+ PersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute attr = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)t1, (JavaPersistentType)t2, "add", "add", false,
+ createCompilationUnitFrom(customerFile),
+ createCompilationUnitFrom(addressFile));
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+ PersistenceUnit pu = jpaProject.getRootContextNode().getPersistenceXml().getPersistence().persistenceUnits().next();
+ t1 = pu.getPersistentType("abc.Customer");
+ assertNotNull(attr);
+
+ }
+
+
+ @Test
+ public void testAddOneToOneUnidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+
+ PersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.Address");
+ assertNotNull(customerType);
+
+
+ PersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute attr = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)t1, (JavaPersistentType)t2, "address", "address", false,
+ createCompilationUnitFrom((IFile)t1.getResource()),
+ createCompilationUnitFrom((IFile)t2.getResource()));
+ assertNotNull(attr);
+
+ JpaArtifactFactory.instance().addOneToOneUnidirectionalRelation(featureProvider, (JavaPersistentType)t1, attr);
+
+ PersistentType pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (pt == null) {
+ Thread.sleep(200);
+ pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute cPersistentAttribute = pt.resolveAttribute("address");
+ assertNotNull(cPersistentAttribute);
+
+ }
+
+
+ @Test
+ public void testAddOneToOneBidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Customer");
+
+ IFile creditCardFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "CreditCard");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.Customer");
+ assertNotNull(customerType);
+
+
+ PersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ assertTrue(creditCardFile.exists());
+ JavaResourcePersistentType creditCardType = jpaProject.getJavaResourcePersistentType("com.CreditCard");
+ assertNotNull(creditCardFile);
+
+
+ PersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, creditCardType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, creditCardType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute attr = JpaArtifactFactory.instance().
+ addAttribute( featureProvider, (JavaPersistentType)t1, (JavaPersistentType)t2, "creditCard", "creditCard", false,
+ createCompilationUnitFrom((IFile)t1.getResource()),
+ createCompilationUnitFrom((IFile)t2.getResource()));
+ assertNotNull(attr);
+
+ JavaPersistentAttribute attr2 = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)t2, (JavaPersistentType)t1, "customer", "customer", false,
+ createCompilationUnitFrom((IFile)t2.getResource()),
+ createCompilationUnitFrom((IFile)t1.getResource()));
+ assertNotNull(attr2);
+
+ JpaArtifactFactory.instance().addOneToOneBidirectionalRelation(featureProvider, (JavaPersistentType)t1, attr, (JavaPersistentType)t2, attr2);
+
+ PersistentType ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (ownerPersistentType == null) {
+ Thread.sleep(200);
+ ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute ownerPersistentAttribute = ownerPersistentType.resolveAttribute("creditCard");
+ assertNotNull(ownerPersistentAttribute);
+ assertTrue(ownerPersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping ownerSideMapping = ownerPersistentAttribute.getMapping();
+ assertTrue(ownerSideMapping instanceof JavaOneToOneMapping);
+
+ assertTrue(((JavaOneToOneMapping)ownerSideMapping).isRelationshipOwner());
+
+ PersistentType inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, creditCardType.getQualifiedName());
+ while (inversePersistentType == null) {
+ Thread.sleep(200);
+ inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, creditCardType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute inversePersistentAttribute = inversePersistentType.resolveAttribute("customer");
+ assertNotNull(inversePersistentAttribute);
+ assertTrue(inversePersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping inverseSideMapping = inversePersistentAttribute.getMapping();
+ assertTrue(inverseSideMapping instanceof JavaOneToOneMapping);
+
+ assertFalse(((JavaOneToOneMapping)inverseSideMapping).isRelationshipOwner());
+ }
+
+
+ @Test
+ public void testAddOneToManyUnidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Customer");
+
+ IFile phoneFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Phone");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.Customer");
+ assertNotNull(customerType);
+
+
+ PersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ assertTrue(phoneFile.exists());
+ JavaResourcePersistentType phoneType = jpaProject.getJavaResourcePersistentType("com.Phone");
+ assertNotNull(customerType);
+
+
+ PersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, phoneType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, phoneType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute attr = JpaArtifactFactory.instance().addAttribute(featureProvider, (JavaPersistentType)t1, (JavaPersistentType)t2, "phones", "phones", true,
+ createCompilationUnitFrom((IFile)t1.getResource()),
+ createCompilationUnitFrom((IFile)t2.getResource()));
+ assertNotNull(attr);
+
+ JpaArtifactFactory.instance().addOneToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)t1, attr);
+
+ PersistentType pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (pt == null) {
+ Thread.sleep(200);
+ pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, phoneType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute cPersistentAttribute = pt.resolveAttribute("phones");
+ assertNotNull(cPersistentAttribute);
+
+ AttributeMapping mapping = cPersistentAttribute.getMapping();
+ assertNotNull(mapping);
+ assertTrue(mapping instanceof JavaOneToManyMapping);
+
+ assertTrue(((JavaOneToManyMapping)mapping).isRelationshipOwner());
+ }
+
+
+ @Test
+ public void testAddOneToManyBidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile cruiseFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Cruise");
+ IFile reservationFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Reservation");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(cruiseFile.exists());
+ JavaResourcePersistentType cruiseType = jpaProject.getJavaResourcePersistentType("com.Cruise");
+ assertNotNull(cruiseType);
+
+
+ PersistentType singleSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ while (singleSidePersistentType == null) {
+ Thread.sleep(200);
+ singleSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ }
+
+ assertTrue(reservationFile.exists());
+ JavaResourcePersistentType reservationType= jpaProject.getJavaResourcePersistentType("com.Reservation");
+ assertNotNull(reservationFile);
+
+
+ PersistentType manySidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ while (manySidePersistentType == null) {
+ Thread.sleep(200);
+ manySidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute singleSideAttribute = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)singleSidePersistentType, (JavaPersistentType)manySidePersistentType, "reservations", "reservations", true,
+ createCompilationUnitFrom((IFile)singleSidePersistentType.getResource()),
+ createCompilationUnitFrom((IFile)manySidePersistentType.getResource()));
+ assertNotNull(singleSideAttribute);
+
+ JavaPersistentAttribute manySideAttribute = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)manySidePersistentType, (JavaPersistentType)singleSidePersistentType, "cruise", "cruise", false,
+ createCompilationUnitFrom((IFile)manySidePersistentType.getResource()),
+ createCompilationUnitFrom((IFile)singleSidePersistentType.getResource()));
+ assertNotNull(manySideAttribute);
+
+ JpaArtifactFactory.instance().addOneToManyBidirectionalRelation(featureProvider, (JavaPersistentType)singleSidePersistentType, singleSideAttribute, (JavaPersistentType)manySidePersistentType, manySideAttribute);
+
+ // In one-to-many bidirectional relation many side is ALWAYS owner
+ PersistentType inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ while (inversePersistentType == null) {
+ Thread.sleep(200);
+ inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute inversePersistentAttribute = inversePersistentType.resolveAttribute("reservations");
+ assertNotNull(inversePersistentAttribute);
+ assertTrue(inversePersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping inverseSideMapping = inversePersistentAttribute.getMapping();
+ assertTrue(inverseSideMapping instanceof JavaOneToManyMapping);
+
+ assertFalse(((JavaOneToManyMapping)inverseSideMapping).isRelationshipOwner());
+
+ // In one-to-many bidirectional relation many side is ALWAYS owner
+ PersistentType ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ int c = 0;
+ while ((ownerPersistentType == null) && (c < 50)) {
+ Thread.sleep(200);
+ ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ c++;
+ }
+ assertNotNull(ownerPersistentType);
+
+ ReadOnlyPersistentAttribute ownerPersistentAttribute = ownerPersistentType.resolveAttribute("cruise");
+ c = 0;
+ while ((ownerPersistentAttribute == null) && (c < 50)) {
+ Thread.sleep(200);
+ ownerPersistentAttribute = ownerPersistentType.resolveAttribute("cruise");
+ c++;
+ }
+
+ assertNotNull(ownerPersistentAttribute);
+ assertTrue(ownerPersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping ownerSideMapping = ownerPersistentAttribute.getMapping();
+ c = 0;
+ while ((ownerSideMapping == null) && (c < 50)) {
+ Thread.sleep(200);
+ ownerSideMapping = ownerPersistentAttribute.getMapping();
+ c++;
+ }
+ if (ownerSideMapping == null)
+ return;
+ assertNotNull("ownerSideMapping must not be null", ownerSideMapping);
+ assertTrue("ownerSideMapping class is " + ownerSideMapping.getClass().getName(), JavaManyToOneMapping.class.isInstance(ownerSideMapping));
+
+ assertTrue(((JavaManyToOneMapping)ownerSideMapping).isRelationshipOwner());
+ }
+
+
+ @Test
+ public void testAddManyToOneUnidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile cruiseFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Cruise");
+ IFile shipFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Ship");
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(cruiseFile.exists());
+ JavaResourcePersistentType cruiseType = jpaProject.getJavaResourcePersistentType("com.Cruise");
+ assertNotNull(cruiseType);
+
+ PersistentType manySidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ while (manySidePersistentType == null) {
+ Thread.sleep(200);
+ manySidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ }
+
+ assertTrue(shipFile.exists());
+ JavaResourcePersistentType shipType = jpaProject.getJavaResourcePersistentType("com.Ship");
+ assertNotNull(cruiseType);
+
+
+ PersistentType singleSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, shipType.getQualifiedName());
+ while (singleSidePersistentType == null) {
+ Thread.sleep(200);
+ singleSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, shipType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute mappedAttribute = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)manySidePersistentType, (JavaPersistentType)singleSidePersistentType, "ship", "ship", true,
+ createCompilationUnitFrom((IFile)manySidePersistentType.getResource()),
+ createCompilationUnitFrom((IFile)singleSidePersistentType.getResource()));
+ assertNotNull(mappedAttribute);
+
+ JpaArtifactFactory.instance().addManyToOneUnidirectionalRelation(featureProvider, (JavaPersistentType)manySidePersistentType, mappedAttribute);
+
+ PersistentType pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cruiseType.getQualifiedName());
+ while (pt == null) {
+ Thread.sleep(200);
+ pt = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, shipType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute cPersistentAttribute = pt.resolveAttribute("ship");
+ int cnt = 0;
+ while ((cPersistentAttribute == null) && (cnt < 100)) {
+ Thread.sleep(250);
+ cPersistentAttribute = pt.resolveAttribute("ship");
+ cnt++;
+ }
+ assertNotNull(cPersistentAttribute);
+
+ AttributeMapping mapping = cPersistentAttribute.getMapping();
+ cnt = 0;
+ while ((mapping == null) && (cnt < 100)) {
+ Thread.sleep(250);
+ mapping = cPersistentAttribute.getMapping();
+ cnt++;
+ }
+ assertNotNull(mapping);
+ assertTrue(mapping instanceof JavaManyToOneMapping);
+
+ assertTrue(((JavaManyToOneMapping)mapping).isRelationshipOwner());
+ }
+
+
+ @Test
+ public void testAddManyToManyBidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile reservationFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Reservation");
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Customer");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(reservationFile.exists());
+ JavaResourcePersistentType reservationType = jpaProject.getJavaResourcePersistentType("com.Reservation");
+ assertNotNull(reservationType);
+
+ PersistentType ownerSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ while (ownerSidePersistentType == null) {
+ Thread.sleep(200);
+ ownerSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ }
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.Customer");
+ assertNotNull(customerFile);
+
+
+ PersistentType inverseSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (inverseSidePersistentType == null) {
+ Thread.sleep(200);
+ inverseSidePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute ownerSideAttribute = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)ownerSidePersistentType, (JavaPersistentType)inverseSidePersistentType, "customers", "customers", true,
+ createCompilationUnitFrom((IFile)ownerSidePersistentType.getResource()),
+ createCompilationUnitFrom((IFile)inverseSidePersistentType.getResource()));
+ assertNotNull(ownerSideAttribute);
+
+ JavaPersistentAttribute inverseSideAttributes = JpaArtifactFactory.instance().addAttribute(featureProvider, (JavaPersistentType)inverseSidePersistentType, (JavaPersistentType)ownerSidePersistentType, "reservations", "reservations", true,
+ createCompilationUnitFrom((IFile)inverseSidePersistentType.getResource()),
+ createCompilationUnitFrom((IFile)ownerSidePersistentType.getResource()));
+ assertNotNull(inverseSideAttributes);
+
+ JpaArtifactFactory.instance().addManyToManyBidirectionalRelation(featureProvider, (JavaPersistentType)ownerSidePersistentType, ownerSideAttribute, (JavaPersistentType)inverseSidePersistentType, inverseSideAttributes);
+
+ PersistentType ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ while (ownerPersistentType == null) {
+ Thread.sleep(200);
+ ownerPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute ownerPersistentAttribute = ownerPersistentType.resolveAttribute("customers");
+ assertNotNull(ownerPersistentAttribute);
+ assertTrue(ownerPersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping ownerSideMapping = ownerPersistentAttribute.getMapping();
+ assertTrue(ownerSideMapping instanceof JavaManyToManyMapping);
+
+ assertTrue(((JavaManyToManyMapping)ownerSideMapping).isRelationshipOwner());
+
+ PersistentType inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (inversePersistentType == null) {
+ Thread.sleep(200);
+ inversePersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute inversePersistentAttribute = inversePersistentType.resolveAttribute("reservations");
+ assertNotNull(inversePersistentAttribute);
+ assertTrue(inversePersistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping inverseSideMapping = inversePersistentAttribute.getMapping();
+ assertTrue(inverseSideMapping instanceof JavaManyToManyMapping);
+
+ assertFalse(((JavaManyToManyMapping)inverseSideMapping).isRelationshipOwner());
+ }
+
+ @Test
+ public void testAddManyToManyUnidirectionalRelationAttributes() throws Exception {
+ assertNotNull(jpaProject);
+ IFile reservationFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Reservation");
+ IFile cabinFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Cabin");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(reservationFile.exists());
+ JavaResourcePersistentType reservationType = jpaProject.getJavaResourcePersistentType("com.Reservation");
+ assertNotNull(reservationType);
+
+ PersistentType annotatedPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ while (annotatedPersistentType == null) {
+ Thread.sleep(200);
+ annotatedPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ }
+
+ assertTrue(cabinFile.exists());
+ JavaResourcePersistentType cabinType = jpaProject.getJavaResourcePersistentType("com.Cabin");
+ assertNotNull(cabinFile);
+
+
+ PersistentType referencedPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cabinType.getQualifiedName());
+ while (referencedPersistentType == null) {
+ Thread.sleep(200);
+ referencedPersistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, cabinType.getQualifiedName());
+ }
+
+ JavaPersistentAttribute annotatedSideAttribute = JpaArtifactFactory.instance().
+ addAttribute(featureProvider, (JavaPersistentType)annotatedPersistentType, (JavaPersistentType)referencedPersistentType, "cabins", "cabins", true,
+ createCompilationUnitFrom((IFile)annotatedPersistentType.getResource()),
+ createCompilationUnitFrom((IFile)referencedPersistentType.getResource()));
+ assertNotNull(annotatedSideAttribute);
+
+ JpaArtifactFactory.instance().addManyToManyUnidirectionalRelation(featureProvider, (JavaPersistentType)annotatedPersistentType, annotatedSideAttribute);
+
+ PersistentType persistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ while (persistentType == null) {
+ Thread.sleep(200);
+ persistentType = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, reservationType.getQualifiedName());
+ }
+
+ ReadOnlyPersistentAttribute persistentAttribute = persistentType.resolveAttribute("cabins");
+ assertNotNull(persistentAttribute);
+ assertTrue(persistentAttribute instanceof JavaPersistentAttribute);
+
+ AttributeMapping mapping = persistentAttribute.getMapping();
+ assertTrue(mapping instanceof JavaManyToManyMapping);
+
+ assertTrue(((JavaManyToManyMapping)mapping).isRelationshipOwner());
+ }
+
+
+
+
+}
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
new file mode 100644
index 0000000000..7b333d77ca
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsInFieldAnnotatedEntitiesTest.java
@@ -0,0 +1,509 @@
+/*******************************************************************************
+ * <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.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.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.JavaResourcePersistentType;
+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;
+
+@SuppressWarnings("restriction")
+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(getPersistentType(entity));
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
+ replay(featureProvider);
+ }
+
+ public static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node: getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ 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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("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/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java
new file mode 100644
index 0000000000..6a3bba47a6
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/relation/CreateRelationsTest.java
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * <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.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.ArrayList;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.easymock.EasyMock;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.common.utility.Command;
+import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
+import org.eclipse.jpt.common.utility.internal.synchronizers.CallbackAsynchronousSynchronizer;
+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.JavaResourcePersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.ManyToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToManyAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OneToOneAnnotation;
+import org.eclipse.jpt.jpa.core.resource.java.OwnableRelationshipMappingAnnotation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.propertypage.JPADiagramPropertyPage;
+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;
+
+
+@SuppressWarnings({ "unused", "restriction" })
+public class CreateRelationsTest {
+
+ private IJPAEditorFeatureProvider featureProvider;
+ final String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = null;
+ IEclipseFacade eclipseFacade = null;
+ private static final int MAX_NUM_OF_ITERATIONS = 250;
+ JavaPersistentType t1 = null;
+ ICompilationUnit cu1 = null;
+ JavaPersistentType t2 = null;
+ ICompilationUnit cu2 = null;
+
+
+ @Before
+ public void setUp() throws Exception {
+
+ JptJpaCorePlugin.getJpaProjectManager();
+ 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(getPersistentType(entity));
+ expect(featureProvider.getCompilationUnit(isA(JavaPersistentType.class))).andReturn(JavaCore.createCompilationUnitFrom(entity)).anyTimes();
+
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ int c = 0;
+ while ((t1 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
+ jpaProject.update(null);
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ c++;
+ }
+
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(isA(Shape.class));
+ cu1 = JavaCore.createCompilationUnitFrom(customerFile);
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.Address");
+ assertNotNull(customerType);
+
+
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ c = 0;
+ while ((t2 == null) && (c < MAX_NUM_OF_ITERATIONS)) {
+ jpaProject.update(null);
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ c++;
+ }
+
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(isA(Shape.class));
+ cu2 = JavaCore.createCompilationUnitFrom(addressFile);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Properties props = new Properties();
+ props.setProperty(JPADiagramPropertyPage.PROP_COLLECTION_TYPE.getLocalName(), "collection");
+ expect(featureProvider.loadProperties(jpaProject.getProject())).andStubReturn(props);
+
+ replay(featureProvider);
+
+ }
+
+ public static JavaPersistentType getPersistentType(IFile file){
+ JpaFile jpaFile = JptJpaCorePlugin.getJpaFile(file);
+ for (JpaStructureNode node: getRootNodes(jpaFile)) {
+ JavaPersistentType entity = (JavaPersistentType) node;
+ return entity;
+ }
+ return null;
+ }
+
+ private static Iterable<JpaStructureNode> getRootNodes(JpaFile jpaFile) {
+ if(jpaFile == null){
+ return EmptyIterable.instance();
+ }
+ return jpaFile.getRootStructureNodes();
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+ @Test
+ public void testCreateOneToOneUnidirRelation() throws Exception {
+
+ AbstractRelation rel = new OneToOneUniDirRelation(featureProvider, t1, t2, "address",
+ true,
+ cu1,
+ cu2);
+ assertNotNull(rel);
+ assertSame(t1, rel.getOwner());
+ assertSame(t2, rel.getInverse());
+ assertEquals("address", rel.getOwnerAttributeName());
+ JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address");
+ assertNotNull(ownerAt);
+ OneToOneAnnotation an = (OneToOneAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertNull(an.getMappedBy());
+ }
+
+
+ @Test
+ public void testCreateOneToOneBidirRelation() throws Exception {
+
+ 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);
+ OneToOneAnnotation an = (OneToOneAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertNull(an.getMappedBy());
+
+ JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer");
+ assertNotNull(inverseAt);
+ an = (OneToOneAnnotation)inverseAt.getResourcePersistentAttribute().getAnnotation(OneToOneAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertEquals("address", an.getMappedBy());
+
+ }
+
+
+ @Test
+ public void testCreateOneToManyUnidirRelation() throws Exception {
+ AbstractRelation rel = new OneToManyUniDirRelation(featureProvider, t1, t2, "address",
+ true,
+ cu1,
+ cu2);
+ assertNotNull(rel);
+ assertSame(t1, rel.getOwner());
+ assertSame(t2, rel.getInverse());
+ assertEquals("address", rel.getOwnerAttributeName());
+ JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address");
+ assertNotNull(ownerAt);
+
+ OneToManyAnnotation an = (OneToManyAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(OneToManyAnnotation.ANNOTATION_NAME);
+ assertNull(an.getMappedBy());
+ }
+
+
+
+ @Test
+ public void testCreateManyToOneUnidirRelation() throws Exception {
+ AbstractRelation rel = new ManyToOneUniDirRelation(featureProvider, t1, t2, "address",
+ true,
+ cu1,
+ cu2);
+ assertNotNull(rel);
+ assertSame(t1, rel.getOwner());
+ assertSame(t2, rel.getInverse());
+ assertEquals("address", rel.getOwnerAttributeName());
+ JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address");
+ assertNotNull(ownerAt);
+ ManyToOneAnnotation an = (ManyToOneAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ }
+
+ @Test
+ public void testCreateManyToOneBidirRelation() throws Exception {
+ 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);
+ ManyToOneAnnotation an = (ManyToOneAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(ManyToOneAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+
+ assertEquals("customer", rel.getInverseAttributeName());
+ JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer");
+ assertNotNull(inverseAt);
+ OneToManyAnnotation an1 = (OneToManyAnnotation)inverseAt.getResourcePersistentAttribute().getAnnotation(OneToManyAnnotation.ANNOTATION_NAME);
+ assertNotNull(an1);
+ assertEquals("address", an1.getMappedBy());
+ }
+
+ @Test
+ public void testCreateManyToManyUnidirRelation() throws Exception {
+ AbstractRelation rel = new ManyToManyUniDirRelation(featureProvider, t1, t2, "address",
+ true,
+ cu1,
+ cu2);
+ assertNotNull(rel);
+ assertSame(t1, rel.getOwner());
+ assertSame(t2, rel.getInverse());
+ assertEquals("address", rel.getOwnerAttributeName());
+ JavaPersistentAttribute ownerAt = t1.getAttributeNamed("address");
+ assertNotNull(ownerAt);
+ ManyToManyAnnotation an = (ManyToManyAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertNull(an.getMappedBy());
+ }
+
+ @Test
+ public void testCreateManyToManyBidirRelation() throws Exception {
+ AbstractRelation rel = new ManyToManyBiDirRelation(featureProvider, t1, t2, "address", "customer",
+ true,
+ createCompilationUnitFrom((IFile)t1.getResource()),
+ 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);
+ ManyToManyAnnotation an = (ManyToManyAnnotation)ownerAt.getResourcePersistentAttribute().getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertNull(an.getMappedBy());
+
+ JavaPersistentAttribute inverseAt = t2.getAttributeNamed("customer");
+ assertNotNull(inverseAt);
+ an = (ManyToManyAnnotation)inverseAt.getResourcePersistentAttribute().getAnnotation(ManyToManyAnnotation.ANNOTATION_NAME);
+ assertNotNull(an);
+ assertEquals("address", an.getMappedBy());
+
+ }
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java
new file mode 100644
index 0000000000..693793b3b3
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/CreateDeleteEntity.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * <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.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
+import org.eclipse.jpt.jpa.core.context.PersistentType;
+import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+//import org.eclipse.jpt.jpa.core.internal.SynchronousJpaProjectUpdater;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+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 CreateDeleteEntity {
+
+ private static final String TEST_PROJECT = "Test";
+ private JPACreateFactory factory = JPACreateFactory.instance();
+ private JpaProject jpaProject = null;
+
+ @Before
+ public void setUp() throws Exception {
+ JptJpaCorePlugin.getJpaProjectManager();
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+ }
+
+ @Test
+ public void testCreateAndDeleteEntity() throws Exception {
+ assertNotNull(jpaProject);
+// SynchronousJpaProjectUpdater updater = new SynchronousJpaProjectUpdater(jpaProject);
+// updater.start();
+ JpaRootContextNode jpaProjectContent = jpaProject.getRootContextNode();
+ assertNotNull(jpaProjectContent);
+// if(jpaProjectContent.getPersistenceXml() == null) {
+// updater = new SynchronousJpaProjectUpdater(jpaProject);
+// updater.start();
+// }
+ Thread.sleep(2000);
+ PersistenceXml persistenceXml = jpaProjectContent.getPersistenceXml();
+ assertNotNull(persistenceXml);
+ Persistence p = persistenceXml.getPersistence();
+ int cnt = 0;
+ while ((p == null) && (cnt < 25)) {
+ Thread.sleep(250);
+ p = persistenceXml.getPersistence();
+ cnt++;
+ }
+ assertTrue("Can't obtain persistence object", p != null);
+ assertTrue(persistenceXml.getPersistence().persistenceUnitsSize() == 1);
+ //java.lang.UnsupportedOperationException: No PersistenceUnit in this context
+ //PersistenceUnit persistenceUnit = persistenceXml.getPersistence().getPersistenceUnit();
+ PersistenceUnit persistenceUnit = persistenceXml.getPersistence().persistenceUnits().next();
+ assertNotNull(persistenceUnit);
+ assertTrue(persistenceUnit.classRefsSize() == 0);
+ IFile entity1 = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com"}, "Entity1");
+ assertTrue(entity1.exists());
+// if(jpaProject.getJavaResourcePersistentType("com.Entity1") == null) {
+// updater = new SynchronousJpaProjectUpdater(jpaProject);
+// updater.start();
+// }
+ JavaResourcePersistentType persistenceType = jpaProject.getJavaResourcePersistentType("com.Entity1");
+ int c = 0;
+ while ((persistenceType == null) && (c < 100)) {
+ Thread.sleep(500);
+ jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+ persistenceType = jpaProject.getJavaResourcePersistentType("com.Entity1");
+ c++;
+ }
+ assertNotNull(persistenceType);
+ PersistentType t = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, persistenceType.getQualifiedName());
+ c = 0;
+ while ((t == null) && (c < 100)) {
+ Thread.sleep(500);
+ t = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, persistenceType.getQualifiedName());
+ c++;
+ }
+ JpaArtifactFactory.instance().deletePersistenceTypeResource(t);
+ assertFalse(entity1.exists());
+// updater = new SynchronousJpaProjectUpdater(jpaProject);
+// updater.start();
+ jpaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ JptJpaCorePlugin.rebuildJpaProject(jpaProject.getProject());
+ persistenceType = ((JpaProject)jpaProject).getJavaResourcePersistentType("com.Entity1");
+ c = 0;
+ while ((persistenceType != null) && (c < 250)) {
+ Thread.sleep(500);
+ jpaProject = JptJpaCorePlugin.getJpaProject(jpaProject.getProject());
+ persistenceType = ((JpaProject)jpaProject).getJavaResourcePersistentType("com.Entity1");
+ c++;
+ }
+ assertNull(persistenceType);
+ assertNotNull(jpaProject);
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/IEditor.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/IEditor.java
new file mode 100644
index 0000000000..4e5c9a7706
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/IEditor.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * <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.util;
+
+import org.eclipse.graphiti.platform.IDiagramEditor;
+import org.eclipse.ui.IEditorPart;
+
+public interface IEditor extends IEditorPart, IDiagramEditor {
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPAEditorUtilTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPAEditorUtilTest.java
new file mode 100644
index 0000000000..e1a5e4c53f
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPAEditorUtilTest.java
@@ -0,0 +1,402 @@
+/*******************************************************************************
+ * <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.util;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+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.emf.common.util.EList;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.pictograms.Anchor;
+import org.eclipse.graphiti.mm.pictograms.AnchorContainer;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+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.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.IPeServiceUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.SizePosition;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants.ShapeType;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.eclipse.swt.graphics.Point;
+import org.junit.Test;
+
+public class JPAEditorUtilTest {
+ @Test
+ public void testCapitalizeFirstLetter() {
+ String s = "abcdef";
+ String res = JPAEditorUtil.capitalizeFirstLetter(s);
+ assertEquals(res.substring(0, 1), "A");
+ assertEquals(s.substring(1), res.substring(1));
+ }
+
+ @Test
+ public void testDecapitalizeFirstLetter() {
+ String s = "ABCDEFGHIJK";
+ String res = JPAEditorUtil.decapitalizeFirstLetter(s);
+ assertEquals(res.substring(0, 1), "a");
+ assertEquals(s.substring(1), res.substring(1));
+ }
+
+ @Test
+ public void testRevertFirstLetterCase() {
+ String s = "ABCDEFGHIJK";
+ String res = JPAEditorUtil.revertFirstLetterCase(s);
+ assertEquals(res.substring(0, 1), "a");
+ assertEquals(s.substring(1), res.substring(1));
+ String res1 = JPAEditorUtil.revertFirstLetterCase(res);
+ assertEquals(res1.substring(0, 1), "A");
+ assertEquals(res1.substring(1), res.substring(1));
+ }
+
+ @Test
+ public void testEqualsIgnoreFirstLetterCase() {
+ String s1 = "abcdefg";
+ String s2 = "Abcdefg";
+ assertTrue(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+
+ s1 = "";
+ s2 = "";
+ assertTrue(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+
+ s1 = "gjgIyguiyGUYuGUYGuyg";
+ s2 = "gjgIyguiyGUYuGUYGuyg";
+ assertTrue(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+
+ s1 = "LjgIyguiyGUYuGUYGuyg";
+ s2 = "LjgIyguiyGUYuGUYGuyg";
+ assertTrue(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+
+ s1 = "gjgIyguiyGUYuGUYGuygs";
+ s2 = "gjgIyguiyGUYuGUYGuyg";
+ assertFalse(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+
+ s1 = "LjgIyguiyGUyuGUYGuyg";
+ s2 = "LjgIyguiyGUYuGUYGuyg";
+ assertFalse(JPAEditorUtil.equalsIgnoreFirstLetterCase(s1, s2));
+ }
+
+ @Test
+ public void testCutFromLastDot() {
+ String s = "";
+ String res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals(s, res);
+ s = "jdhksajhdk";
+ res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals(s, res);
+ s = "jdhksajhdk.";
+ res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals("", res);
+ s = ".jdhksajhdk";
+ res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals("jdhksajhdk", res);
+ s = "jdhks.ajhdk";
+ res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals("ajhdk", res);
+ s = "dss.dsdsd.jd.hks.ajhdk";
+ res = JPAEditorUtil.cutFromLastDot(s);
+ assertEquals("ajhdk", res);
+ }
+
+
+ @Test
+ public void testStripQuotes() {
+ String s = "";
+ String res = JPAEditorUtil.stripQuotes(s);
+ assertEquals("", res);
+
+ s = "\"\"";
+ res = JPAEditorUtil.stripQuotes(s);
+ assertEquals("", res);
+
+ s = "\"fdsjfjslkdjflks\"";
+ res = JPAEditorUtil.stripQuotes(s);
+ assertEquals("fdsjfjslkdjflks", res);
+
+ s = "\"fdsjfjslkdjflks";
+ res = JPAEditorUtil.stripQuotes(s);
+ assertEquals("\"fdsjfjslkdjflks", res);
+
+ s = "fdsjfjslkdjflks\"";
+ res = JPAEditorUtil.stripQuotes(s);
+ assertEquals("fdsjfjslkdjflks\"", res);
+ }
+
+ @Test
+ public void testGetJPType() throws Exception {
+
+ String TEST_PROJECT = "Test";
+ JpaProject jpaProject = null;
+ JPACreateFactory factory = null;
+ String testProjectName = TEST_PROJECT + "_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(testProjectName);
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ ICompilationUnit cu = createCompilationUnitFrom(customerFile);
+ Thread.sleep(2000);
+ JavaPersistentType jpt = JPAEditorUtil.getJPType(cu);
+ assertEquals(customerType.getQualifiedName(), jpt.getName());
+ }
+
+ @Test
+ public void testProduceValidAttributeName() {
+ String s = "a";
+ String res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals(s, res);
+
+ s = "A";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("a", res);
+
+ s = "aT";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("AT", res);
+
+ s = "At";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("at", res);
+
+ s = "AT";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("AT", res);
+
+ s = "a1";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("a1", res);
+
+ s = "A1";
+ res = JPAEditorUtil.produceValidAttributeName(s);
+ assertEquals("a1", res);
+
+ }
+
+ @Test
+ public void testCreateImports() throws Exception {
+ String TEST_PROJECT = "Test";
+ JpaProject jpaProject = null;
+ JPACreateFactory factory = null;
+ String testProjectName = TEST_PROJECT + "_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(testProjectName);
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ ICompilationUnit cu = createCompilationUnitFrom(customerFile);
+
+ JPAEditorUtil.createImports(cu, "java.util.Hashtable<java.lang.StringBuffer,java.lang.Set<java.lang.String>>");
+ }
+
+ @Test
+ public void testSizePosition() {
+ SizePosition sp = new SizePosition(1,2,3,4);
+ assertTrue(sp.getWidth() == 1);
+ assertTrue(sp.getHeight() == 2);
+ assertTrue(sp.getX() == 3);
+ assertTrue(sp.getY() == 4);
+ }
+
+ @Test
+ public void testGetText() throws Exception {
+ String TEST_PROJECT = "Test";
+ JpaProject jpaProject = null;
+ JPACreateFactory factory = null;
+ String testProjectName = TEST_PROJECT + "_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(testProjectName);
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ int cnt = 0;
+ while ((cnt < 25) && (t1 == null)) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ cnt++;
+ }
+ if (t1 == null)
+ return;
+ assertNotNull(JPAEditorUtil.getText(t1));
+ assertNotNull(JPAEditorUtil.getTooltipText(t1));
+ JavaPersistentAttribute jpa = t1.getAttributeNamed("id");
+ assertNotNull(jpa);
+ assertNotNull(JPAEditorUtil.getText(jpa));
+ assertNotNull(JPAEditorUtil.getTooltipText(jpa));
+
+ }
+
+ @Test
+ public void testSetJPTNameInShape() {
+ final String NEW_NAME = "NewJPTName";
+ ContainerShape cs = EasyMock.createMock(ContainerShape.class);
+ Shape sh = EasyMock.createMock(Shape.class);
+ GraphicsAlgorithm ga = EasyMock.createMock(GraphicsAlgorithm.class);
+ IPeServiceUtil peUtil = EasyMock.createMock(IPeServiceUtil.class);
+ EasyMock.expect(peUtil.getPropertyValue(sh, JPAEditorConstants.PROP_SHAPE_TYPE)).andStubReturn(ShapeType.HEADER.toString());
+ EList<Shape> shapes = new BasicInternalEList<Shape>(Shape.class);
+ shapes.add(sh);
+ EasyMock.expect(cs.getChildren()).andStubReturn(shapes);
+ Text txt = EasyMock.createMock(Text.class);
+ EList<GraphicsAlgorithm> gaCh = new BasicInternalEList<GraphicsAlgorithm>(GraphicsAlgorithm.class);
+ gaCh.add(txt);
+ EasyMock.expect(sh.getGraphicsAlgorithm()).andStubReturn(ga);
+ EasyMock.expect(ga.getGraphicsAlgorithmChildren()).andStubReturn(gaCh);
+ txt.setValue(NEW_NAME);
+ EasyMock.replay(cs, sh, ga, peUtil, txt);
+ JPAEditorUtil.setJPTNameInShape(cs, NEW_NAME, peUtil);
+ }
+
+ @Test
+ public void testCreateBendPointList1() {
+ FreeFormConnection c = EasyMock.createMock(FreeFormConnection.class);
+ Anchor startAnchor = EasyMock.createMock(Anchor.class);
+ Anchor endAnchor = EasyMock.createMock(Anchor.class);
+ AnchorContainer startAnchorContainer = EasyMock.createMock(AnchorContainer.class);
+ AnchorContainer endAnchorContainer = EasyMock.createMock(AnchorContainer.class);
+ expect(c.getStart()).andStubReturn(startAnchor);
+ expect(c.getEnd()).andStubReturn(endAnchor);
+ expect(startAnchor.getParent()).andStubReturn(startAnchorContainer);
+ expect(endAnchor.getParent()).andStubReturn(endAnchorContainer);
+ RoundedRectangle rectStart = createMock(RoundedRectangle.class);
+ RoundedRectangle rectEnd = createMock(RoundedRectangle.class);
+ expect(startAnchorContainer.getGraphicsAlgorithm()).andStubReturn(rectStart);
+ expect(endAnchorContainer.getGraphicsAlgorithm()).andStubReturn(rectEnd);
+ expect(rectStart.getX()).andStubReturn(100);
+ expect(rectStart.getY()).andStubReturn(100);
+ expect(rectStart.getWidth()).andStubReturn(200);
+ expect(rectStart.getHeight()).andStubReturn(120);
+ expect(rectEnd.getX()).andStubReturn(100);
+ expect(rectEnd.getY()).andStubReturn(800);
+ expect(rectEnd.getWidth()).andStubReturn(200);
+ expect(rectEnd.getHeight()).andStubReturn(120);
+
+ EList<Connection> ccc = new BasicInternalEList<Connection>(Connection.class);
+ expect(startAnchor.getOutgoingConnections()).andStubReturn(ccc);
+ expect(endAnchor.getOutgoingConnections()).andStubReturn(ccc);
+
+ EasyMock.replay(c, startAnchor, endAnchor, startAnchorContainer, endAnchorContainer, rectStart, rectEnd);
+
+
+
+ List<Point> lst = JPAEditorUtil.createBendPointList(c, false);
+ assertTrue(lst.size() == 2);
+ for (Point p : lst) {
+ assertTrue(p.x >= 0);
+ assertTrue(p.y >= 0);
+
+ assertTrue(p.x <= 1000000);
+ assertTrue(p.y <= 1000000);
+ }
+
+ }
+
+ @Test
+ public void testCreateBendPointList2() {
+ FreeFormConnection c = EasyMock.createMock(FreeFormConnection.class);
+ Anchor startAnchor = EasyMock.createMock(Anchor.class);
+ Anchor endAnchor = EasyMock.createMock(Anchor.class);
+ AnchorContainer startAnchorContainer = EasyMock.createMock(AnchorContainer.class);
+ AnchorContainer endAnchorContainer = EasyMock.createMock(AnchorContainer.class);
+ expect(c.getStart()).andStubReturn(startAnchor);
+ expect(c.getEnd()).andStubReturn(endAnchor);
+ expect(startAnchor.getParent()).andStubReturn(startAnchorContainer);
+ expect(endAnchor.getParent()).andStubReturn(endAnchorContainer);
+ RoundedRectangle rectStart = createMock(RoundedRectangle.class);
+ RoundedRectangle rectEnd = createMock(RoundedRectangle.class);
+ expect(startAnchorContainer.getGraphicsAlgorithm()).andStubReturn(rectStart);
+ expect(endAnchorContainer.getGraphicsAlgorithm()).andStubReturn(rectEnd);
+ expect(rectStart.getX()).andStubReturn(100);
+ expect(rectStart.getY()).andStubReturn(100);
+ expect(rectStart.getWidth()).andStubReturn(200);
+ expect(rectStart.getHeight()).andStubReturn(120);
+ expect(rectEnd.getX()).andStubReturn(800);
+ expect(rectEnd.getY()).andStubReturn(100);
+ expect(rectEnd.getWidth()).andStubReturn(200);
+ expect(rectEnd.getHeight()).andStubReturn(120);
+
+ EList<Connection> ccc = new BasicInternalEList<Connection>(Connection.class);
+ expect(startAnchor.getOutgoingConnections()).andStubReturn(ccc);
+ expect(endAnchor.getOutgoingConnections()).andStubReturn(ccc);
+
+ EasyMock.replay(c, startAnchor, endAnchor, startAnchorContainer, endAnchorContainer, rectStart, rectEnd);
+
+ List<Point> lst = JPAEditorUtil.createBendPointList(c, false);
+ assertTrue(lst.size() == 2);
+ for (Point p : lst) {
+ assertTrue(p.x >= 0);
+ assertTrue(p.y >= 0);
+
+ assertTrue(p.x <= 1000000);
+ assertTrue(p.y <= 1000000);
+ }
+
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPASolverTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPASolverTest.java
new file mode 100644
index 0000000000..e0c83b4f46
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JPASolverTest.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * <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.util;
+
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.net.URI;
+
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.BasicInternalEList;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.mm.Property;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.PictogramsPackage;
+import org.eclipse.graphiti.platform.IDiagramEditor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.context.java.JavaTypeMapping;
+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.IJPAEditorUtil;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPASolver;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("unused")
+public class JPASolverTest {
+
+ private IEclipseFacade eclipseFacade;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ eclipseFacade = createEclipseFacade();
+ }
+
+ @Test
+ public void testResourceListenerRegistered() {
+ IWorkspace workspace = EasyMock.createMock(IWorkspace.class);
+ workspace.addResourceChangeListener(isA(IResourceChangeListener.class), eq(IResourceChangeEvent.POST_BUILD));
+ replay(workspace);
+ IEclipseFacade facade = EasyMock.createMock(IEclipseFacade.class);
+ expect(facade.getWorkspace()).andStubReturn(workspace);
+ replay(facade);
+ new JPASolver(facade, null);
+ verify(workspace, facade);
+ }
+
+ private IFile replayFile() {
+ IFile file = EasyMock.createMock(IFile.class);
+ URI uri = URI.create("file://project//aaa");
+ expect(file.getLocationURI()).andStubReturn(uri);
+ expect(file.exists()).andStubReturn(true);
+ IProject proj = EasyMock.createMock(IProject.class);
+ expect(proj.getType()).andStubReturn(IResource.PROJECT);
+ expect(file.getType()).andStubReturn(IResource.FILE);
+ expect(file.getFullPath()).andStubReturn(new Path("C:\\project\\aaa"));
+ IFile clsPath = EasyMock.createMock(IFile.class);
+ expect(proj.getFile(".classpath")).andStubReturn(clsPath);
+ try {
+ expect(proj.hasNature("org.eclipse.jdt.core.javanature")).andStubReturn(true);
+ } catch (CoreException e) {}
+ expect(file.getProject()).andStubReturn(proj);
+ replay(file, proj);
+ return file;
+ }
+
+ private JavaPersistentType createJptForResource(IFile file, String name) {
+ JavaPersistentType jpt = EasyMock.createNiceMock(JavaPersistentType.class);
+ JpaProject jpaProject = EasyMock.createNiceMock(JpaProject.class);
+ JavaTypeMapping m = EasyMock.createNiceMock(JavaTypeMapping.class);
+ expect(jpt.getResource()).andStubReturn(file);
+ expect(jpt.getJpaProject()).andStubReturn(jpaProject);
+ expect(jpt.getMapping()).andStubReturn(m);
+ if (name != null)
+ expect(jpt.getName()).andStubReturn(name);
+ replay(jpt, jpaProject);
+ return jpt;
+ }
+
+ private IEclipseFacade createEclipseFacade() {
+ IEclipseFacade facade = EasyMock.createMock(IEclipseFacade.class);
+ return facade;
+ }
+
+ private void configureForWorkspace(IEclipseFacade facade) {
+ IWorkspace workspace = EasyMock.createMock(IWorkspace.class);
+ workspace.addResourceChangeListener(isA(IResourceChangeListener.class), eq(IResourceChangeEvent.POST_BUILD));
+ replay(workspace);
+ expect(facade.getWorkspace()).andStubReturn(workspace);
+ }
+
+ private IJPAEditorFeatureProvider configureRefreshEditorProvider() {
+ IDiagramEditor editor = EasyMock.createMock(IDiagramEditor.class);
+ editor.refresh();
+ replay(editor);
+ IDiagramTypeProvider diagramProvider = EasyMock.createMock(IDiagramTypeProvider.class);
+ expect(diagramProvider.getDiagramEditor()).andStubReturn(editor);
+ replay(diagramProvider);
+ IJPAEditorFeatureProvider provider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ expect(provider.getDiagramTypeProvider()).andStubReturn(diagramProvider);
+ return provider;
+ }
+
+ private IMarkerDelta replayDelta(IResource resource) {
+ IMarkerDelta delta = EasyMock.createMock(IMarkerDelta.class);
+ expect(delta.getResource()).andStubReturn(resource);
+ replay(delta);
+ return delta;
+ }
+
+ private JPASolver createSolver(IEclipseFacade facade, IJPAEditorUtil util) {
+ return new JPASolver(facade, util);
+ }
+
+ public static IResourceChangeListener eqResourceListener(IArgumentMatcher matcher) {
+ EasyMock.reportMatcher(matcher);
+ return null;
+ }
+
+ private IResourceChangeEvent replayEvent(IResource resource) {
+ IResourceChangeEvent event = EasyMock.createMock(IResourceChangeEvent.class);
+ expect(event.findMarkerDeltas(null, true)).andStubReturn(new IMarkerDelta[] { replayDelta(resource) });
+ replay(event);
+ return event;
+ }
+
+ private IResourceChangeEvent replayEmptyEvent() {
+ IResourceChangeEvent event = EasyMock.createMock(IResourceChangeEvent.class);
+ expect(event.findMarkerDeltas(null, true)).andStubReturn(new IMarkerDelta[] {});
+ replay(event);
+ return event;
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JpaArtifactFactoryTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JpaArtifactFactoryTest.java
new file mode 100644
index 0000000000..6deaa6883f
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/JpaArtifactFactoryTest.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * <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.util;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+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.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType;
+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.JpaArtifactFactory;
+import org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.JPACreateFactory;
+import org.eclipse.jpt.common.utility.model.event.ListAddEvent;
+import org.eclipse.jpt.common.utility.model.event.ListChangeEvent;
+import org.eclipse.jpt.common.utility.model.event.ListClearEvent;
+import org.eclipse.jpt.common.utility.model.event.ListMoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListRemoveEvent;
+import org.eclipse.jpt.common.utility.model.event.ListReplaceEvent;
+import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JpaArtifactFactoryTest {
+
+ String TEST_PROJECT = "Test";
+ private JpaProject jpaProject = null;
+ private JPACreateFactory factory = null;
+ IEclipseFacade eclipseFacade = null;
+ public static int cnt = 0;
+
+ @Before
+ public void setUp() throws Exception {
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPAProject(TEST_PROJECT + "_" + System.currentTimeMillis());
+ assertNotNull(jpaProject);
+ Thread.sleep(2000);
+ }
+
+ /*
+ @Test
+ public void testJpaArtifactoryAttributeRelatedMethods() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+ IFile addressFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Address");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("com.test.Customer");
+ assertNotNull(customerType);
+
+ assertTrue(addressFile.exists());
+ JavaResourcePersistentType addressType = jpaProject.getJavaResourcePersistentType("com.test.Address");
+ assertNotNull(addressType);
+
+ JavaPersistentType t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ while (t1 == null) {
+ Thread.sleep(200);
+ t1 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, customerType.getQualifiedName());
+ }
+ JavaPersistentType t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ while (t2 == null) {
+ Thread.sleep(200);
+ t2 = JpaArtifactFactory.instance().getContextPersistentType(jpaProject, addressType.getQualifiedName());
+ }
+
+
+ CreateOneToOneBiDirRelationFeature ft = new CreateOneToOneBiDirRelationFeature(featureProvider);
+ ICreateConnectionContext ctx = EasyMock.createMock(ICreateConnectionContext.class);
+
+ ContainerShape cs1 = EasyMock.createMock(ContainerShape.class);
+ ContainerShape cs2 = EasyMock.createMock(ContainerShape.class);
+
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs1)).andStubReturn(t1);
+ expect(featureProvider.getBusinessObjectForPictogramElement(cs2)).andStubReturn(t2);
+ expect(featureProvider.getPictogramElementForBusinessObject(t1)).andStubReturn(cs1);
+ expect(featureProvider.getPictogramElementForBusinessObject(t2)).andStubReturn(cs2);
+
+ Anchor a1 = EasyMock.createMock(Anchor.class);
+ Anchor a2 = EasyMock.createMock(Anchor.class);
+ expect(a1.getParent()).andStubReturn(cs1);
+ expect(a2.getParent()).andStubReturn(cs2);
+ expect(ctx.getSourceAnchor()).andStubReturn(a1);
+ expect(ctx.getTargetAnchor()).andStubReturn(a2);
+
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ ICompilationUnit cu2 = createCompilationUnitFrom(addressFile);
+
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ expect(featureProvider.getCompilationUnit(t2)).andStubReturn(cu2);
+
+ Connection conn = EasyMock.createMock(Connection.class);
+ expect(featureProvider.addIfPossible((IAddContext)EasyMock.anyObject())).andStubReturn(conn);
+ replay(featureProvider, a1, a2, cs1, cs2, ctx);
+ ft.create(ctx);
+ OneToOneBiDirRelation rel = ft.createRelation(cs1, cs2);
+ assertNotNull(rel);
+ assertNotNull(rel.getId());
+ assertEquals(RelType.ONE_TO_ONE, rel.getRelType());
+ assertEquals(RelDir.BI, rel.getRelDir());
+ assertNotNull(t1.getAttributeNamed(rel.getOwnerAttributeName()));
+ assertNotNull(t2.getAttributeNamed(rel.getInverseAttributeName()));
+
+ JavaPersistentAttribute jpa = t1.getAttributeNamed(rel.getOwnerAttributeName());
+ assertTrue(JpaArtifactFactory.instance().hasEntityAnnotation(t1));
+
+ //JavaPersistentAttribute jpa1 = JpaArtifactFactory.instance().getRelatedAttribute(t1, t2);
+ //assertNotNull(jpa1);
+ //assertSame(jpa1, t2.getAttributeNamed(rel.getInverseAttributeName()));
+
+ List<String> ans = JpaArtifactFactory.instance().getAnnotationStrings(jpa);
+ assertNotNull(ans);
+ assertTrue(ans.size() > 0);
+ assertTrue(ans.contains("@OneToOne"));
+ JpaArtifactFactory.instance().deleteAttribute(t1, rel.getOwnerAttributeName(), featureProvider);
+ jpa = t1.getAttributeNamed(rel.getOwnerAttributeName());
+ assertNull(jpa);
+ }
+ */
+
+ @Test
+ public void testEntityListener() throws Exception {
+ IJPAEditorFeatureProvider featureProvider = EasyMock.createMock(IJPAEditorFeatureProvider.class);
+ assertNotNull(jpaProject);
+ IFile customerFile = factory.createEntityInProject(jpaProject.getProject(), new String[]{"com","test"}, "Customer");
+
+ jpaProject.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, new NullProgressMonitor());
+
+ assertTrue(customerFile.exists());
+ JavaResourcePersistentType customerType = jpaProject.getJavaResourcePersistentType("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());
+ }
+ ICompilationUnit cu1 = createCompilationUnitFrom(customerFile);
+ expect(featureProvider.getCompilationUnit(t1)).andStubReturn(cu1);
+ replay(featureProvider);
+
+// Catches problem with multiple events - Eclipse bugzilla bug #259103
+
+// cnt = 0;
+// t1.addListChangeListener(new EntityAttributesChangeListener());
+// JpaArtifactFactory.instance().deleteAttribute(t1, "id", featureProvider);
+// Thread.sleep(10000);
+// assertTrue("The listener is being triggered " + cnt + " times", cnt == 1);
+
+ }
+
+ public ICompilationUnit createCompilationUnitFrom(IFile file) {
+ return JavaCore.createCompilationUnitFrom(file);
+ }
+
+
+
+ public class EntityAttributesChangeListener implements ListChangeListener {
+
+ public void listChanged(ListChangeEvent event) {
+ }
+
+ public void itemsAdded(ListAddEvent arg0) {
+ }
+
+ public void itemsMoved(ListMoveEvent arg0) {
+ }
+
+ public void itemsRemoved(ListRemoveEvent arg0) {
+ cnt++;
+ }
+
+ public void itemsReplaced(ListReplaceEvent arg0) {
+ }
+
+ public void listCleared(ListClearEvent arg0) {
+ }
+ };
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/URLEscaper.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/URLEscaper.java
new file mode 100644
index 0000000000..1a66ba2c0c
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/src/org/eclipse/jpt/jpadiagrameditor/ui/tests/internal/util/URLEscaper.java
@@ -0,0 +1,18 @@
+package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util;
+
+public class URLEscaper {
+ private static final String specialChars = " <>#%{}|^~[]`;?@=&$";
+ private static final String escapeCodes = "%20%3C%3E%23%25%7B%7D%7C%5E%7E%5B%5D%60%3B%3F%40%3D%26%24";
+
+ public static String escape(String s) {
+ if (s == null)
+ return null;
+ StringBuffer res = new StringBuffer("");
+ for (int i = 0; i < s.length(); i++) {
+ char ch = s.charAt(i);
+ int ind = specialChars.indexOf(ch);
+ res.append(((ind >= 0) ? escapeCodes.substring(ind * 3, ind * 3 + 3) : ch));
+ }
+ return res.toString();
+ }
+}
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
new file mode 100644
index 0000000000..236affcaf2
--- /dev/null
+++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/test.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+
+<project name="testsuite" default="run" basedir=".">
+ <!-- The property ${eclipse-home} should be passed into this script -->
+ <!-- Set a meaningful default value for when it is not. -->
+ <echo message="basedir ${basedir}" />
+ <echo message="eclipse place ${eclipse-home}" />
+ <!-- sets the properties plugin-name -->
+ <property name="plugin-name" value="org.eclipse.jpt.jpadiagrameditor.ui.tests"/>
+ <echo level="debug" message="testRoot: ${testRoot}" />
+ <fail message="testRoot must be set" unless="testRoot" />
+
+ <!-- This target holds all initialization code that needs to be done for -->
+ <!-- all tests that are to be run. Initialization for individual tests -->
+ <!-- should be done within the body of the suite target. -->
+ <target name="init">
+ <tstamp/>
+ <delete>
+ <fileset dir="${eclipse-home}" includes="org*.xml"/>
+ </delete>
+ </target>
+
+ <!-- This target defines the tests that need to be run. -->
+ <target name="suite1">
+ <property file="${testRoot}/testServer.properties"/>
+ <property name="jpae-folder" value="${eclipse-home}/jpae_folder"/>
+ <delete dir="${jpae-folder}" quiet="true"/>
+
+ <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="data-dir" value="${jpae-folder}"/>
+ <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}"/>
+ </ant>
+</target>
+
+ <!-- This target holds code to cleanup the testing environment after -->
+ <!-- after all of the tests have been run. You can use this target to -->
+ <!-- delete temporary files that have been created. -->
+ <target name="cleanup">
+ </target>
+
+ <!-- This target runs the test suite. Any actions that need to happen -->
+ <!-- after all the tests have been run should go here. -->
+ <target name="run" depends="init, suite1, cleanup">
+ </target>
+</project>

Back to the top