diff options
author | Petya Sabeva | 2012-09-17 14:17:12 +0000 |
---|---|---|
committer | Petya Sabeva | 2012-09-17 14:31:36 +0000 |
commit | 49321fa53f2717f31f6747de662243e240c2f943 (patch) | |
tree | 2ff8fa756fa7b2dd3b295b6e306b59299d248b39 | |
parent | 90fcfa8db95bb0646125f8c482ce627a90a8b74e (diff) | |
download | webtools.dali-49321fa53f2717f31f6747de662243e240c2f943.tar.gz webtools.dali-49321fa53f2717f31f6747de662243e240c2f943.tar.xz webtools.dali-49321fa53f2717f31f6747de662243e240c2f943.zip |
[383656] - Extend JPA Diagram editor's tests using SWTBot for GEF
Change-Id: I2da31334b720b8849968bc43457dec58d84015ca
31 files changed, 4797 insertions, 91 deletions
diff --git a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml index fea3540353..587e752f65 100644 --- a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml +++ b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml @@ -8,12 +8,15 @@ <packaging>pom</packaging> <properties> - <tycho-version>0.9.0</tycho-version> + <tycho-version>0.15.0</tycho-version> </properties> <modules> <module>../../plugins/org.eclipse.jpt.jpadiagrameditor.ui</module> - <!-- module>../../tests/org.eclipse.jpt.jpadiagrameditor.tests</module --> + <module>../../plugins/org.eclipse.jpt.jpadiagrameditor.doc.user</module> + <module>../../plugins/org.eclipse.jpt.jpadiagrameditor.branding</module> + <!-- module>../../tests/org.eclipse.jpt.jpadiagrameditor.ui.tests</module> + <module>../../tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests</module--> <module>../../features/org.eclipse.jpt.jpadiagrameditor.feature</module> <module>../org.eclipse.jpt.jpadiagrameditor.repository</module> </modules> @@ -21,17 +24,24 @@ <build> <plugins> <plugin> - <groupId>org.sonatype.tycho</groupId> + <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-maven-plugin</artifactId> <version>${tycho-version}</version> <extensions>true</extensions> </plugin> <plugin> - <groupId>org.sonatype.tycho</groupId> + <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho-version}</version> <configuration> <resolver>p2</resolver> + <!-- dependencies> + <dependency> + <type>eclipse-feature</type> + <artifactId>org.eclipse.jpt.jpa.feature</artifactId> + <version>0.0.0</version> + </dependency> + </dependencies--> </configuration> </plugin> </plugins> @@ -39,13 +49,14 @@ <repositories> <repository> - <id>indigo</id> - <url>http://download.eclipse.org/releases/staging/</url> + <id>Juno</id> + <url>http://download.eclipse.org/releases/juno/</url> <layout>p2</layout> </repository> <repository> - <id>Juno</id> - <url>http://build.eclipse.org/webtools/committers/wtp-R3.4.0-I/20110805150738/I-3.4.0-20110805150738/repository/</url> + <id>Kepler</id> + <!-- url>http://download.eclipse.org/releases/juno/</url--> + <url>http://build.eclipse.org/webtools/committers/wtp4x-R3.5.0-I/20120913044711/I-3.5.0-20120913044711/repository/</url> <layout>p2</layout> </repository> <repository> @@ -53,7 +64,26 @@ <url>http://download.eclipse.org/graphiti/updates/milestones/</url> <layout>p2</layout> </repository> - + <repository> + <id>swtbot</id> + <layout>p2</layout> + <url>http://download.eclipse.org/technology/swtbot/helios/dev-build/update-site</url> + </repository> </repositories> + <profiles> + <profile> + <id>swttests</id> + <modules> + <module>../../tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests</module> + </modules> + </profile> + <profile> + <id>jtests</id> + <modules> + <module>../../tests/org.eclipse.jpt.jpadiagrameditor.ui.tests</module> + </modules> + </profile> + </profiles> + </project>
\ No newline at end of file diff --git a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/site.xml b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/category.xml index a13eae758c..33d1411f07 100644 --- a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/site.xml +++ b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/category.xml @@ -1,7 +1,7 @@ -<?xml version="1.0" encoding="UTF-8"?> -<site> - <feature url="features/org.eclipse.jpt.jpadiagrameditor.feature_1.1.0.qualifier.jar" id="org.eclipse.jpt.jpadiagrameditor.feature" version="1.1.0.qualifier"> - <category name="jpa_diagram_editor"/> - </feature> - <category-def name="jpa_diagram_editor" label="JPA Diagram Editor"/> -</site> +<?xml version="1.0" encoding="UTF-8"?>
+<site>
+ <feature url="features/org.eclipse.jpt.jpadiagrameditor.feature_1.1.0.qualifier.jar" id="org.eclipse.jpt.jpadiagrameditor.feature" version="1.1.0.qualifier">
+ <category name="jpa_diagram_editor"/>
+ </feature>
+ <category-def name="jpa_diagram_editor" label="JPA Diagram Editor"/>
+</site>
diff --git a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml index 338dcc4f6c..00ac863ab6 100644 --- a/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml +++ b/jpa_diagram_editor/development/org.eclipse.jpt.jpadiagrameditor.repository/pom.xml @@ -10,19 +10,7 @@ </parent> <artifactId>org.eclipse.jpt.jpadiagrameditor.repository</artifactId> - <packaging>eclipse-update-site</packaging> + <packaging>eclipse-repository</packaging> <name>JPA Editor Update Site</name> - <build> - <plugins> - <plugin> - <groupId>org.sonatype.tycho</groupId> - <artifactId>maven-osgi-packaging-plugin</artifactId> - <configuration> - <archiveSite>true</archiveSite> - </configuration> - </plugin> - </plugins> - </build> - </project>
\ No newline at end of file diff --git a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/build.properties b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/build.properties index 9c242a160d..8136c53d62 100644 --- a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/build.properties +++ b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/build.properties @@ -10,4 +10,5 @@ ############################################################################### bin.includes = feature.xml,\ eclipse_update_120.jpg,\ - feature.properties
\ No newline at end of file + feature.properties + diff --git a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/feature.xml b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/feature.xml index 14e1c1e775..e2d4038d85 100644 --- a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/feature.xml +++ b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.feature/feature.xml @@ -44,4 +44,4 @@ version="0.0.0"
unpack="false"/>
-</feature>
\ No newline at end of file +</feature> diff --git a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.tests.feature/feature.xml b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.tests.feature/feature.xml index 20cf80e968..80118ee72f 100644 --- a/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.tests.feature/feature.xml +++ b/jpa_diagram_editor/features/org.eclipse.jpt.jpadiagrameditor.tests.feature/feature.xml @@ -22,7 +22,7 @@ <requires> <import plugin="org.easymock" version="2.4.0" match="compatible"/> <import feature="org.eclipse.graphiti.feature" version="0.10.0" match="greaterOrEqual"/> - <import feature="org.eclipse.jpt.jpa.feature" version="3.0.0" match="greaterOrEqual"/> + <import feature="org.eclipse.jpt.jpa.feature" version="3.1.0" match="greaterOrEqual"/> </requires> <plugin @@ -30,5 +30,11 @@ download-size="0" install-size="0" version="0.0.0"/> + + <plugin + id="org.eclipse.jpt.jpadiagrameditor.swtbot.tests" + download-size="0" + install-size="0" + version="0.0.0"/> </feature> diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml new file mode 100644 index 0000000000..8d023a94a0 --- /dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.branding/pom.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId> + <groupId>org.eclipse.jpt.jpadiagrameditor</groupId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath> + </parent> + + <artifactId>org.eclipse.jpt.jpadiagrameditor.branding</artifactId> + <packaging>eclipse-plugin</packaging> + <name>JPA Diagram Editor Branding Plug-in</name> + +</project> + diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/META-INF/MANIFEST.MF index 66fc9f83ed..6f35b22053 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/META-INF/MANIFEST.MF +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/META-INF/MANIFEST.MF @@ -3,6 +3,6 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.jpt.jpadiagrameditor.doc.user; singleton:=true -Bundle-Version: 1.0.100.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Localization: plugin Require-Bundle: org.eclipse.help;bundle-version="[3.3.100,4.0.0)" diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml new file mode 100644 index 0000000000..520c50da4d --- /dev/null +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.doc.user/pom.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId> + <groupId>org.eclipse.jpt.jpadiagrameditor</groupId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath> + </parent> + + <artifactId>org.eclipse.jpt.jpadiagrameditor.doc.user</artifactId> + <packaging>eclipse-plugin</packaging> + <name>JPA Diagram Editor Branding Plug-in</name> + +</project> + diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF index b0989d7733..4103eba4ce 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.jpt.jpadiagrameditor.ui;singleton:=true -Bundle-Version: 1.0.200.qualifier +Bundle-Version: 1.1.0.qualifier Bundle-Activator: org.eclipse.jpt.jpadiagrameditor.ui.internal.JPADiagramEditorPlugin Bundle-ActivationPolicy: lazy Bundle-ClassPath: . diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml index b0b1cff07c..27ced134e5 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/pom.xml @@ -1,16 +1,16 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <version>1.0.100-SNAPSHOT</version> - - <parent> - <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId> - <groupId>org.eclipse.jpt.jpadiagrameditor</groupId> - <version>1.1.0-SNAPSHOT</version> - <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath> - </parent> - - <artifactId>org.eclipse.jpt.jpadiagrameditor.ui</artifactId> - <packaging>eclipse-plugin</packaging> - <name>JPA Diagram Editor Plug-in</name> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <version>1.1.0-SNAPSHOT</version>
+
+ <parent>
+ <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
+ <groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.jpt.jpadiagrameditor.ui</artifactId>
+ <packaging>eclipse-plugin</packaging>
+ <name>JPA Diagram Editor Plug-in</name>
</project>
\ No newline at end of file diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java index 064c5e4104..dcd307be63 100644 --- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java +++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java @@ -1817,4 +1817,4 @@ public class JpaArtifactFactory { } -}
\ No newline at end of file +} diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.classpath b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.classpath new file mode 100644 index 0000000000..8a8f1668cd --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.project b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.project new file mode 100644 index 0000000000..f253c37427 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jpt.jpadiagrameditor.swtbot.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.swtbot.tests/.settings/org.eclipse.jdt.core.prefs b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..f287d53cf4 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/META-INF/MANIFEST.MF b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..dd4411ade4 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/META-INF/MANIFEST.MF @@ -0,0 +1,37 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-Vendor: %providerName +Bundle-SymbolicName: org.eclipse.jpt.jpadiagrameditor.swtbot.tests;singleton:=true +Bundle-Version: 1.1.0.qualifier +Bundle-Activator: org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPAEditorTestsActivator +Bundle-ActivationPolicy: lazy +Bundle-ClassPath: . +Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +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.9.0,1.0.0)", + org.eclipse.graphiti.ui;bundle-version="[0.9.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.eclipse.core.filesystem;bundle-version="[1.3.1,2.0.0)", + org.junit4;bundle-version="[4.0.0,5.0.0)", + org.eclipse.swtbot.eclipse.core;bundle-version="2.0.5", + org.eclipse.swtbot.eclipse.gef.finder;bundle-version="2.0.5", + org.eclipse.swtbot.eclipse.finder;bundle-version="2.0.5", + org.eclipse.swtbot.junit4_x;bundle-version="2.0.5", + org.hamcrest;bundle-version="1.1.0", + org.apache.log4j, + org.eclipse.swtbot.forms.finder;bundle-version="2.0.5" diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/about.html b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/about.html new file mode 100644 index 0000000000..be534ba44f --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.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.swtbot.tests/build.properties b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/build.properties new file mode 100644 index 0000000000..41eb6ade2b --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/plugin.properties b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/plugin.properties new file mode 100644 index 0000000000..b5bcd87dcc --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.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.swtbot.tests/pom.xml b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml new file mode 100644 index 0000000000..0dd1c08f81 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/pom.xml @@ -0,0 +1,45 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId> + <groupId>org.eclipse.jpt.jpadiagrameditor</groupId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath> + </parent> + + <artifactId>org.eclipse.jpt.jpadiagrameditor.swtbot.tests</artifactId> + <packaging>eclipse-test-plugin</packaging> + <name>JPA Diagram Editor SWTBot Test Plug-in</name> + + <build> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-surefire-plugin</artifactId> + <version>${tycho-version}</version> + <configuration> + <!-- testSuite>org.eclipse.jpt.jpadiagrameditor.ui.tests</testSuite> + <testClass>org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.AllJpaEditorTests</testClass--> + <useUIHarness>true</useUIHarness> + <useUIThread>false</useUIThread> + <systemProperties combine.children="append"> + <org.eclipse.jpt.jpa.jar>${org.eclipse.jpt.jpa.jar}</org.eclipse.jpt.jpa.jar> + </systemProperties> + <argLine>-Xms128m -Xmx512m -XX:MaxPermSize=256m</argLine> + <product>org.eclipse.sdk.ide</product> + <application>org.eclipse.ui.ide.workbench</application> + <dependencies> + <dependency> + <type>p2-installable-unit</type> + <artifactId>org.eclipse.sdk.ide</artifactId> + <version>0.0.0</version> + </dependency> + </dependencies> + </configuration> + </plugin> + </plugins> + </build> + +</project>
\ No newline at end of file diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java new file mode 100644 index 0000000000..d47bed7e39 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPACreateFactory.java @@ -0,0 +1,643 @@ +/******************************************************************************* + * <copyright> + * + * Copyright (c) 2005, 2011 SAP AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stefan Dimov - initial API, implementation and documentation + * + * </copyright> + * + *******************************************************************************/ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +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.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.core.resource.java.JavaResourceAbstractType; +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.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.jpadiagrameditor.ui.internal.util.JpaArtifactFactory; +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, "1.0"); + } + + public JpaProject createJPA20Project(String projectName) throws CoreException { + return createJPAProject(projectName, null, "2.0"); + } + + + public JpaProject createJPAProject(String projectName, IDataModel jpaConfig, String jpaFacetVersion) throws CoreException { + project = buildPlatformProject(projectName); + javaProject = createJavaProject(project, true); + 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 = this.getJpaProject(project); + int cnt = 0; + while ((jpaProject == null) && (cnt < 1000)){ + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + jpaProject = this.getJpaProject(project); + cnt++; + } + jpaProject.setDiscoversAnnotatedClasses(true); +// jpaProject.setUpdater(new SynchronousJpaProjectUpdater(jpaProject)); + return jpaProject; + } + + private JpaProject getJpaProject(IProject p) { + return (JpaProject) p.getAdapter(JpaProject.class); + } + + 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); + } + + protected 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, + 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() { + return getSystemProperty(JPA_JAR_NAME_SYSTEM_PROPERTY); + } + + 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); + JavaResourceAbstractType jrpt = jpaProject.getJavaResourceType(fullyQualifiedName); + cnt = 0; + while((jrpt == null) && (cnt < 100)) { + try { + Thread.sleep(250); + } catch (Exception e) {} + jrpt = jpaProject.getJavaResourceType(fullyQualifiedName); + cnt++; + } + if (jrpt == null) + throw new NullPointerException("The entity '" + fullyQualifiedName + "' could not be created"); + return entity1; + } + + public IFile createEntityInProject(IProject project, + String[] packageFragments, + String entityName) throws IOException, + CoreException, + JavaModelException { + String folderName = getFolderName(project, packageFragments); + 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); + } + + @SuppressWarnings("deprecation") + private String getFolderName(IProject project, String[] packageFragments) + throws 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; + } + return folderName; + } + + 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; + } + + public IFile createEntityWithCompositePKInProject(IProject project, + String[] packageFragments, String entityName) throws IOException, + CoreException, JavaModelException { + String folderName = getFolderName(project, packageFragments); + + 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 createEntityWithCompositePK(folder, packageName, entityName); + } + + public IFile createIdClassInProject(IProject project, + String[] packageFragments, String entityName) throws IOException, + CoreException, JavaModelException { + String folderName = getFolderName(project, packageFragments); + + 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 createIdClass(folder, packageName, entityName); + } + + public IFile createEmbeddedClassInProject(IProject project, + String[] packageFragments, String entityName) throws IOException, + CoreException, JavaModelException { + String folderName = getFolderName(project, packageFragments); + + 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 createEmbeddedClass(folder, packageName, entityName); + } + + public IFile createEntityWithEmbeddedPKInProject(IProject project, + String[] packageFragments, String entityName) throws IOException, + CoreException, JavaModelException { + String folderName = getFolderName(project, packageFragments); + + 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 createEntityWithEmbeddedPK(folder, packageName, entityName); + } + + + + private IFile createEntityWithCompositePK(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" + + "@IdClass("+entityShortName+"Id.class)" + + "public class " + entityShortName + " {\n" + + " @Id \n" + + " private String firstName;\n" + + " @Id \n" + + " private String lastName;\n" + + " public "+entityShortName+"Id() {}\n" + + " public "+entityShortName+"Id(String firstName, String lastName)\n{" + + " this.firstName = firstName;\n" + + " this.lastName = lastName;\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 IFile createIdClass(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 + "Id.java"); + if (!file.exists()) { + String content = "package " + packageName + ";\n\n" + + "import javax.persistence.*;\n\n" + +"import java.io.Serializable;" + + "public class " + entityShortName + "Id {\n" + + " private String firstName;\n" + + " private String lastName;\n" + + " public String getFirstName() {\n" + + " return firstName;\n" + + " }\n" + + " public void setFirstName(String firstName) {\n" + + " this.firstName = firstName;\n" + + " }\n" + + " public String getLastName() {\n" + + " return lastName;\n" + + " }\n" + + " public void setLastName(String lastName) {\n" + + " this.lastName = lastName;\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 IFile createEntityWithEmbeddedPK(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" + + "@EmbeddedId\n" + + " private "+ entityShortName +"Id id;\n" + + "public void setId(" + entityShortName+ "Id param) {\n" + + " this.id = param;\n" + + "}\n" + + "public "+entityShortName+"Id getId() {\n" + + "return 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 IFile createEmbeddedClass(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" + + "@Embeddable\n" + + "public class " + entityShortName + " {\n" + +"private String firstName;\n" + +"public String getFirstName() {\n" + + " return firstName;\n" + + "}\n" + + "public void setFirstName(String firstName) {\n" + + "this.firstName = firstName;\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 = 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 = getJpaFile(file); + if(jpaFile == null){ + return result; + } + for (JpaStructureNode node : getRootNodes(jpaFile)) { + PersistentType entity = (PersistentType) node; + Iterator<ReadOnlyPersistentAttribute> attributes = entity.getAllAttributes().iterator(); + while (attributes.hasNext()){ + ReadOnlyPersistentAttribute attribute = attributes.next(); + result.add(attribute); + } + } + return result; + } + + private static JpaFile getJpaFile(IFile file) { + return (JpaFile) file.getAdapter(JpaFile.class); + } + + 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; + } + + public IFile createFieldAnnotatedEntityInProject(IProject project, String[] packageFragments, String entityName) throws IOException, CoreException, JavaModelException { + String folderName = getFolderName(project, packageFragments); + 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.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPAEditorTestsActivator.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPAEditorTestsActivator.java new file mode 100644 index 0000000000..61b3856e6c --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/JPAEditorTestsActivator.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * <copyright> + * + * Copyright (c) 2005, 2012 SAP AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms 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.swtbot.tests.internal; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.jpt.common.utility.internal.ReflectionTools; +import org.eclipse.jpt.jpa.core.JpaProjectManager; +import org.osgi.framework.BundleContext; + +public class JPAEditorTestsActivator extends Plugin { + + /** + * + */ + public JPAEditorTestsActivator() { + } + + // The shared instance + private static JPAEditorTestsActivator plugin; + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + JpaProjectManager jpaProjectManager = this.getJpaProjectManager(); +// ReflectionTools.executeMethod(jpaProjectManager, "executeCommandsSynchronously"); //$NON-NLS-1$ + } + + protected JpaProjectManager getJpaProjectManager() { + return (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class); + } + + @Override + 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.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/Utils.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/Utils.java new file mode 100644 index 0000000000..0f3783e39a --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/internal/Utils.java @@ -0,0 +1,156 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.Semaphore;
+
+
+/**
+ * Utility for testing purposes
+ * @author i057508
+ *
+ */
+@SuppressWarnings({"restriction", "PMD"})
+public class Utils {
+
+ /**
+ * User space system variable key.
+ */
+ private static Semaphore writeToConsolePermission = new Semaphore(1);
+ static SimpleDateFormat sdf = new SimpleDateFormat(">> [HH:mm:ss.S] ");
+
+ public final static String NEW_LINE = (System.getProperty("line.separator") != null ? System.getProperty("line.separator") : "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+
+
+
+ /** A constant for java validation error markers*/
+
+ /**
+ * the plug-in ID of this plug-in
+ */
+ public static final String COMMON_TEST_PLUGIN_ID = "com.sap.core.tools.eclipse.server.test.common";
+
+ /**
+ * Issues a message into the system console into a friendly format. The format includes current time.
+ * The order is preserved, so if another request is issued in meantime, it will be processed consequently.
+ * At the end of the message no new line will be added.
+ * @param message the message to be issued
+ */
+ public static void printFormatted(String message) {
+ try {
+ writeToConsolePermission.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.print(sdf.format(new Date()) + message);
+ writeToConsolePermission.release();
+ }
+
+ /**
+ * Issues a message into the system console. The format includes current time.
+ * The order is preserved, so if another request is issued in meantime, it will be processed consequently.
+ * At the end of the message no new line will be added.
+ * @param message the message to be issued
+ */
+ public static void print(String message) {
+ try {
+ writeToConsolePermission.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.print(message);
+ writeToConsolePermission.release();
+ }
+
+ /**
+ * Issues a message into the system console into a friendly format. The format includes current time.
+ * The order is preserved, so if another request is issued in meantime, it will be processed consequently.
+ * At the end of the message a new line will be added.
+ * @param message the message to be issued
+ */
+ public static void printlnFormatted(String message) {
+ try {
+ writeToConsolePermission.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println(sdf.format(new Date()) + message);
+ writeToConsolePermission.release();
+ }
+
+ /**
+ * Utility for printing into the system console
+ * @param message a message to be printed
+ * @param t an exception to be printed
+ */
+ public static void printlnFormatted(String message, Throwable t) {
+ StringBuilder buf = new StringBuilder();
+ buf.append(message);
+
+ if (t != null && t.getStackTrace() != null) {
+ buf.append(NEW_LINE);
+ buf.append("Exception:").append(t.getMessage());
+ buf.append(NEW_LINE);
+ buf.append("Stacktrace:");
+ buf.append(NEW_LINE);
+ buf.append(traceToString(t.getStackTrace()));
+ }
+
+ printlnFormatted(buf.toString());
+ }
+
+ /**
+ * Issues a message into the system console. The format includes current time.
+ * The order is preserved, so if another request is issued in meantime, it will be processed consequently.
+ * At the end of the message a new line will be added.
+ * @param message the message to be issued
+ */
+ public static void println(String message) {
+ try {
+ writeToConsolePermission.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println(message);
+ writeToConsolePermission.release();
+ }
+
+ /**
+ * Indicates a start of a test into the system console into a use friendly format.
+ * @param testName the name of the test.
+ */
+ public static void sayTestStarted(String testName) {
+
+ Utils.println("\n----------------------------------------------------------------------------");
+ Utils.printlnFormatted("Test [" + testName + "] started.");
+ Utils.println("----------------------------------------------------------------------------");
+ }
+
+ /**
+ * Indicates an end of a test into the system console into a use friendly format.
+ * @param testName the name of the test.
+ */
+ public static void sayTestFinished(String testName) {
+
+ Utils.println("\n----------------------------------------------------------------------------");
+ Utils.printlnFormatted("Test [" + testName + "] finished.");
+ Utils.println("----------------------------------------------------------------------------");
+ }
+
+ /**
+ * Converts stacktrace into a string
+ * @param trace the stacktrace
+ * @return the converted stacktrace
+ */
+ public static String traceToString(StackTraceElement[] trace) {
+ StringBuilder builder = new StringBuilder();
+
+ for (int i = 0; i < trace.length; i++) {
+ builder.append(trace[i]).append("\n");
+ }
+ return builder.toString();
+ }
+}
+
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java new file mode 100644 index 0000000000..8acdbae7e2 --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ConnectionIsShown.java @@ -0,0 +1,24 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+
+public class ConnectionIsShown extends DefaultCondition{
+
+ private SWTBotGefEditPart entity;
+
+ public ConnectionIsShown(SWTBotGefEditPart entity){
+ super();
+ this.entity = entity;
+ }
+
+ public boolean test() throws Exception {
+ return (!entity.sourceConnections().isEmpty() || !entity.targetConnections().isEmpty());
+ }
+
+ public String getFailureMessage() {
+ return "Relationship did not show.";
+ }
+
+}
+
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java new file mode 100644 index 0000000000..38c3a66fee --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ContextMenuHelper.java @@ -0,0 +1,130 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withRegex;
+import static org.hamcrest.core.AllOf.allOf;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+
+import java.util.Arrays;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.results.WidgetResult;
+import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
+import org.hamcrest.Matcher;
+
+public class ContextMenuHelper
+{
+
+ /**
+ * Clicks the context menu matching the text.
+ *
+ * @param text
+ * the text on the context menu.
+ * @throws WidgetNotFoundException
+ * if the widget is not found.
+ */
+ public static void clickContextMenu( final AbstractSWTBot<?> bot, final String... texts )
+ {
+ final Matcher<?>[] matchers = new Matcher<?>[texts.length];
+ for ( int i = 0; i < texts.length; i++ )
+ {
+ // matchers[i] = allOf( instanceOf( MenuItem.class ), withMnemonic( texts[i] ) );
+ matchers[i] = allOf( instanceOf( MenuItem.class ), withRegex( texts[i] ) );
+ }
+
+ // show
+ final MenuItem menuItem = UIThreadRunnable.syncExec( new WidgetResult<MenuItem>()
+ {
+ public MenuItem run()
+ {
+ MenuItem menuItem = null;
+ Control control = ( Control ) bot.widget;
+ Menu menu = control.getMenu();
+ for ( int i = 0; i < matchers.length; i++ )
+ {
+ menuItem = show( menu, matchers[i] );
+ if ( menuItem != null )
+ {
+ menu = menuItem.getMenu();
+ }
+ else
+ {
+ hide( menu );
+ break;
+ }
+ }
+
+ return menuItem;
+ }
+ } );
+ if ( menuItem == null )
+ {
+ throw new WidgetNotFoundException( "Could not find menu: " + Arrays.asList( texts ) );
+ }
+
+ // click
+ click( menuItem );
+
+ // hide
+ UIThreadRunnable.syncExec( new VoidResult()
+ {
+ public void run()
+ {
+ hide( menuItem.getParent() );
+ }
+ } );
+ }
+
+
+ private static MenuItem show( final Menu menu, final Matcher<?> matcher )
+ {
+ if ( menu != null )
+ {
+ menu.notifyListeners( SWT.Show, new Event() );
+ MenuItem[] items = menu.getItems();
+ for ( final MenuItem menuItem : items )
+ {
+ if ( matcher.matches( menuItem ) )
+ {
+ return menuItem;
+ }
+ }
+ menu.notifyListeners( SWT.Hide, new Event() );
+ }
+ return null;
+ }
+
+
+ private static void click( final MenuItem menuItem )
+ {
+ final Event event = new Event();
+ event.time = ( int ) System.currentTimeMillis();
+ event.widget = menuItem;
+ event.display = menuItem.getDisplay();
+ event.type = SWT.Selection;
+
+ UIThreadRunnable.asyncExec( menuItem.getDisplay(), new VoidResult()
+ {
+ public void run()
+ {
+ menuItem.notifyListeners( SWT.Selection, event );
+ }
+ } );
+ }
+
+
+ private static void hide( final Menu menu )
+ {
+ menu.notifyListeners( SWT.Hide, new Event() );
+ if ( menu.getParentMenu() != null )
+ {
+ hide( menu.getParentMenu() );
+ }
+ }
+}
\ No newline at end of file diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/DiagramIsEmpty.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/DiagramIsEmpty.java new file mode 100644 index 0000000000..0a3f5a9d6c --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/DiagramIsEmpty.java @@ -0,0 +1,24 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+
+public class DiagramIsEmpty extends DefaultCondition{
+
+ private SWTBotGefEditor gefEditor;
+
+ public DiagramIsEmpty(SWTBotGefEditor gefEditor){
+ super();
+ this.gefEditor = gefEditor;
+ }
+
+ public boolean test() throws Exception {
+ return gefEditor.mainEditPart().children().isEmpty();
+ }
+
+ public String getFailureMessage() {
+ return "Diagram is not empty";
+ }
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java new file mode 100644 index 0000000000..8fe4ceb87b --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/EditorProxy.java @@ -0,0 +1,966 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.asyncExec;
+import static org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable.syncExec;
+import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellIsActive;
+import static org.junit.Assert.assertEquals;
+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 static org.junit.Assert.fail;
+
+import java.awt.AWTException;
+import java.awt.Robot;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButton;
+import org.eclipse.graphiti.ui.internal.contextbuttons.ContextButtonPad;
+import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.dialogs.IDialogConstants;
+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.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.provider.IJPAEditorFeatureProvider;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefConnectionEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.utils.Position;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+
+public class EditorProxy {
+
+ private final SWTWorkbenchBot workbenchBot;
+ protected SWTGefBot bot;
+
+
+ /**
+ * Create proxy object.
+ *
+ * @param bot
+ */
+ public EditorProxy(SWTWorkbenchBot workbenchBot, SWTGefBot bot) {
+ this.workbenchBot = workbenchBot;
+ this.bot = bot;
+ }
+
+ public SWTBotGefEditor openDiagramOnJPAContentNode(String name) {
+ SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
+ projectTree.expandNode(name).expandNode("JPA Content").select();
+ ContextMenuHelper.clickContextMenu(projectTree, "Open Diagram");
+
+ workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
+ SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
+ getOkButton(jpaSupportWarningDialog).click();
+
+ SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
+ assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
+ assertTrue("Editor must not contains any entities!", entities.isEmpty());
+
+ return jpaDiagramEditor;
+ }
+
+ public SWTBotGefEditor openDiagramOnJPAProjectNode(String name) {
+ SWTBotTree projectTree = workbenchBot.viewByTitle("Project Explorer").bot().tree();
+ projectTree.expandNode(name).select();
+ ContextMenuHelper.clickContextMenu(projectTree, "JPA Tools", "Open Diagram");
+
+ workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle), 5000);
+ SWTBotShell jpaSupportWarningDialog = workbenchBot.shell(JPAEditorMessages.OpenJpaDiagramActionDelegate_jpaSupportWarningTitle);
+ getOkButton(jpaSupportWarningDialog).click();
+
+ SWTBotGefEditor jpaDiagramEditor = bot.gefEditor(name);
+ assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
+ return jpaDiagramEditor;
+ }
+
+ /**
+ * Gets the "Select Type" dialog that appears when the attribute's context menu
+ * "Refactor Attribute Type..." is selected
+ * @param jpaDiagramEditor
+ * @param attribute
+ * @return the "Select Type" dialog
+ */
+ public SWTBotShell getSelectNewAttributeTypeDialog(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart attribute) {
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_refactorAttributeType);
+
+ workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle), 5000);
+ SWTBotShell changeTypeDialog = workbenchBot.shell(JPAEditorMessages.SelectTypeDialog_chooseAttributeTypeDialogWindowTitle);
+ getNewTypeInputField(changeTypeDialog);
+ return changeTypeDialog;
+ }
+
+ /**
+ * Gets the text input field of the "Select Type" dialog, which appears when
+ * the attribute's context menu "Refcator Attribute Type..." is selected
+ * @param changeTypeDialog - the "Select Type" dialog
+ * @return the text input field
+ */
+ public SWTBotText getNewTypeInputField(SWTBotShell changeTypeDialog) {
+ SWTBotText attributeType = changeTypeDialog.bot().textWithLabel(JPAEditorMessages.SelectTypeDialog_typeLabel);
+ assertEquals("java.lang.String", attributeType.getText());
+ assertTrue(getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(getCancelButton(changeTypeDialog).isEnabled());
+ return attributeType;
+ }
+
+ /**
+ * Gets the current attribute type value
+ * @param jpaDiagramEditor
+ * @param attributeName
+ * @param fp
+ * @return the value of the attribute's type
+ */
+ public String getAttributeType(SWTBotGefEditor jpaDiagramEditor, String attributeName, final IFeatureProvider fp) {
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
+ PictogramElement el = (PictogramElement) attribute.part().getModel();
+ Object bo = fp.getBusinessObjectForPictogramElement(el);
+ assertTrue("The selected element is not an attribute!", (bo instanceof JavaPersistentAttribute));
+ String currentAttributeType = JPAEditorUtil.getAttributeTypeName((JavaPersistentAttribute)bo);
+ return currentAttributeType;
+ }
+
+ /**
+ * Adds a new attribute to the entity and checks that:
+ * 1. The newly created attribute is selected
+ * 2. The "Other Attributes" section is visible
+ * @param jpaDiagramEditor
+ * @param attributeName - the name of the attribute
+ * @return the newly added attribute
+ */
+ public SWTBotGefEditPart addAttributeToEntity(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity, String attributeName) {
+ pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_createAttributeButtonlabel);
+
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, attributeName), 10000);
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart(attributeName);
+ assertNotNull("Atrribute is not added.", attribute);
+
+ assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().size() == 1);
+ assertTrue("The newly added attribute must be selected.", jpaDiagramEditor.selectedEditParts().contains(attribute));
+
+ assertTrue("\"Other Attributes\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ return attribute;
+ }
+
+ /**
+ * Checks whether a section with the specified name is visible
+ * @param diagramEditor
+ * @param sectionTitle - the name of the section
+ * @return true, if the section with the specified name is visible,
+ * false otherwise
+ */
+ public boolean isSectionVisible(SWTBotGefEditor diagramEditor, String sectionTitle){
+ SWTBotGefEditPart section = diagramEditor.getEditPart(sectionTitle);
+ ((PictogramElement)section.part().getModel()).isVisible();
+ IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
+ return figure.isVisible();
+ }
+
+ /**
+ * Adds an entity to the diagram
+ * @param jpaDiagramEditor
+ * @param entityName - the name of the entity to be added
+ * @return the added entity
+ */
+ public SWTBotGefEditPart addEntityToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateJPAEntityFeature_jpaEntityFeatureName);
+ jpaDiagramEditor.doubleClick(x, y);
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 10000);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
+ assertFalse("Editor must contains at least one entity!", entities.isEmpty());
+
+ SWTBotGefEditPart entity = jpaDiagramEditor.getEditPart(entityName);
+ assertNotNull("Entity is not added!", entity);
+
+ SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
+ assertNotNull("Entity must have a primary key attribute!", idAttribute);
+
+ assertTrue("\"Primary Key\" section must be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ return entity;
+ }
+
+ /**
+ * Adds mapped superclass to the diagram
+ * @param jpaDiagramEditor
+ * @param entityName - the name of the mapped superclass to be added
+ * @return the added mapped superclass
+ */
+ public SWTBotGefEditPart addMappedSuperclassToDiagram(final SWTBotGefEditor jpaDiagramEditor, int x, int y, String entityName) {
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateMappedSuperclassFeature_createMappedSuperclassFeatureName);
+ jpaDiagramEditor.doubleClick(x, y);
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, entityName), 10000);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
+ assertFalse("Editor must contains at least one mapped superclass!", entities.isEmpty());
+
+ SWTBotGefEditPart mappedSuperclass = jpaDiagramEditor.getEditPart(entityName);
+ assertNotNull("Mapped superclass is not added!", mappedSuperclass);
+
+ SWTBotGefEditPart idAttribute = jpaDiagramEditor.getEditPart("id");
+ assertNull("Mapped superclass must not have a primary key attribute!", idAttribute);
+
+ assertFalse("\"Primary Key\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse("\"Relation Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("\"Other Attributes\" section must not be visible!", isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ return mappedSuperclass;
+ }
+
+
+
+ /**
+ * Pressing the "Yes" button of the "Confirm Delete" question dialog.
+ */
+ public void confirmDelete() {
+ SWTBotShell shell = getDeleteEntityDialog();
+ shell.bot().button("Yes").click();
+ }
+
+ /**
+ * Pressing the "No" button of the "Confirm Delete" question dialog.
+ */
+ public void denyDelete() {
+ SWTBotShell shell = getDeleteEntityDialog();
+ shell.bot().button("No").click();
+ }
+
+ /**
+ * Gets the dialog that appears after the "Delete" context button/menu
+ * is pressed.
+ * @return the question dialog, asking whether to the delete the selected entity
+ */
+ public SWTBotShell getDeleteEntityDialog() {
+ workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.DeleteFeature_deleteConfirm), 5000);
+ SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.DeleteFeature_deleteConfirm);
+ return shell;
+ }
+
+ /**
+ * Gets the dialog that appears after the "Refactor Entity Class -> Rename..." context menu
+ * is pressed.
+ * @return the "Rename Compilation Unit" dialog
+ */
+ public SWTBotShell getRenameEntityDialog() {
+ workbenchBot.waitUntil(shellIsActive("Rename Compilation Unit"), 5000);
+ SWTBotShell shell = workbenchBot.shell("Rename Compilation Unit");
+ assertFalse(getFinishButton(shell).isEnabled());
+ assertTrue(getCancelButton(shell).isEnabled());
+ return shell;
+ }
+
+ /**
+ * Gets the dialog that appears after the "Refactor Entity Class -> Move..." context menu
+ * is pressed.
+ * @return the "Move" dialog
+ */
+ public SWTBotShell getMoveEntityDialog() {
+ workbenchBot.waitUntil(shellIsActive("Move"), 5000);
+ SWTBotShell shell = workbenchBot.shell("Move");
+ assertFalse(getOkButton(shell).isEnabled());
+ assertTrue(getCancelButton(shell).isEnabled());
+ return shell;
+ }
+
+ /**
+ * Gets the dialog that appears after the "Remove All Entities from Diagram -> ...and Save/Discard Changes" context menu
+ * is pressed. Press the OK button.
+ */
+ public void confirmRemoveEntitiesFromDiagramDialog() {
+ workbenchBot.waitUntil(shellIsActive(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu), 5000);
+ SWTBotShell shell = workbenchBot.shell(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAllEntitiesMenu);
+ assertTrue("Ok button is disabled", getOkButton(shell).isEnabled());
+ assertTrue(getCancelButton(shell).isEnabled());
+ getOkButton(shell).click();
+ }
+
+
+ /**
+ * Deletes an entity with the specified name using the context button.
+ * @param jpaDiagramEditor
+ * @param entityName - the name of the entity to be deleted
+ */
+ public void deleteDiagramElements(SWTBotGefEditor jpaDiagramEditor){
+
+ jpaDiagramEditor.save();
+
+ List<SWTBotGefEditPart> entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
+ assertFalse("Diagram must contain at least one entity!", entitiesInDiagram.isEmpty());
+
+ Iterator<SWTBotGefEditPart> iterator = entitiesInDiagram.iterator();
+ while (iterator.hasNext()) {
+ SWTBotGefEditPart editPart = iterator.next();
+ assertNotNull(editPart);
+ editPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ }
+
+ entitiesInDiagram = jpaDiagramEditor.mainEditPart().children();
+ assertTrue("Diagram must be empty!", entitiesInDiagram.isEmpty());
+ assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
+ }
+
+ /**
+ * Press some of the entity's context buttons
+ * @param jpaDiagramEditor
+ * @param contextButtonName - the name of the button to be pressed
+ */
+ public void pressEntityContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName){
+ pressContextButton(jpaDiagramEditor, part, contextButtonName);
+ }
+
+ /**
+ * Press the "Delete Attribute" attribute's context button
+ * @param jpaDiagramEditor
+ */
+ public void pressAttributeDeleteContextButton(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part){
+ pressContextButton(jpaDiagramEditor, part, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteAttributeButtonlabel);
+ }
+
+ /**
+ * Assert that the context button pad is shown, when the mouse is placed over the
+ * entity and press the the desired button
+ * @param jpaDiagramEditor
+ * @param contextButtonName - the name of the button to be pressed.
+ */
+ @SuppressWarnings("restriction")
+ private void pressContextButton(final SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart part, String contextButtonName) {
+ jpaDiagramEditor.click(0, 0);
+ jpaDiagramEditor.click(part);
+
+ ContextButtonPad pad = findContextButtonPad(jpaDiagramEditor);
+ assertNotNull(pad);
+ for(final Object button : pad.getChildren()){
+ if(((ContextButton)button).getEntry().getText().equals(contextButtonName)){
+ asyncExec(new VoidResult() {
+ public void run() {
+ ((ContextButton)button).doClick();
+
+ }
+ });
+ }
+ }
+ }
+
+ /**
+ * Place the mouse over the entity to show the context button pad.
+ * @param jpaDiagramEditor
+ */
+ public void moveMouse(final SWTBotGefEditor jpaDiagramEditor, final int x, final int y) {
+ syncExec(new VoidResult() {
+ public void run() {
+ Robot r;
+ try {
+ r = new Robot();
+ Point p = getOrigin(jpaDiagramEditor);
+ r.mouseMove(p.x + x, p.y + y);
+ } catch (AWTException e) {
+ fail(e.getMessage());
+ }
+ }
+ });
+ }
+
+ /**
+ * Gets the context button pad, after placing the mouse over the entity
+ * @param editor
+ * @return the entity's context button pad
+ */
+ @SuppressWarnings("restriction")
+ private ContextButtonPad findContextButtonPad(SWTBotGefEditor editor) {
+ SWTBotGefEditPart rootEditPart = editor.rootEditPart();
+ IFigure feedbackLayer = ((ScalableFreeformRootEditPart) rootEditPart.part())
+ .getLayer(LayerConstants.HANDLE_LAYER);
+ ContextButtonPad cbp = null;
+ for (Object obj : feedbackLayer.getChildren()) {
+ if (obj instanceof ContextButtonPad) {
+ cbp = (ContextButtonPad) obj;
+ break;
+ }
+ }
+ return cbp;
+ }
+
+
+ private FigureCanvas getCanvas(SWTBotGefEditor editorGef) {
+ IEditorReference reference = editorGef.getReference();
+ final IEditorPart editor = reference.getEditor(true);
+ GraphicalViewer graphicalViewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class);
+ final Control control = graphicalViewer.getControl();
+ if (control instanceof FigureCanvas) {
+ FigureCanvas c = (FigureCanvas) control;
+ return c;
+ }
+ return null;
+ }
+
+ private Point getOrigin(SWTBotGefEditor editorGef) {
+ Canvas c = getCanvas(editorGef);
+ Point p = c.toDisplay(0, 0);
+ return p;
+ }
+
+ /**
+ * Get the error message that appears in the "Select Type" dialog
+ * @param dialog
+ * @return the error message
+ */
+ public SWTBotText getDialogErroMessage(SWTBotShell dialog){
+ return dialog.bot().text(1);
+ }
+
+ /**
+ * Gets the "OK" button of a dialog
+ * @param dialog
+ * @return the "OK" button
+ */
+ public SWTBotButton getOkButton(SWTBotShell dialog){
+ return dialog.bot().button(IDialogConstants.OK_LABEL);
+ }
+
+ /**
+ * Gets the "Cancel" button of a dialog
+ * @param dialog
+ * @return the "Cancel" button
+ */
+ public SWTBotButton getCancelButton(SWTBotShell dialog){
+ return dialog.bot().button(IDialogConstants.CANCEL_LABEL);
+ }
+
+ /**
+ * Gets the "Finish" button of a dialog
+ * @param dialog
+ * @return the "Finish" button
+ */
+ public SWTBotButton getFinishButton(SWTBotShell dialog) {
+ return dialog.bot().button("Finish");
+ }
+
+ /**
+ * Find the IRelation object for the given GEF Connection
+ * @param jpaDiagramEditor
+ * @param gefConn
+ * @return the IRelation object for the given GEF Connection
+ */
+ @SuppressWarnings("restriction")
+ public IRelation getConnection(SWTBotGefEditor jpaDiagramEditor, SWTBotGefConnectionEditPart gefConn){
+ IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ FreeFormConnection conn = (FreeFormConnection) gefConn.part().getModel();
+ Object ob = fp.getBusinessObjectForPictogramElement(conn);
+ if(ob instanceof IRelation){
+ return (IRelation)ob;
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets the business object (JavaPersistentType) for the given GEF element
+ * @param jpaDiagramEditor
+ * @param element
+ * @return the java persistent type for the given element, null if the selected element is not an entity
+ */
+ @SuppressWarnings("restriction")
+ public JavaPersistentType getEntityForElement(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
+ final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ PictogramElement el = (PictogramElement) element.part().getModel();
+ Object bo = fp.getBusinessObjectForPictogramElement(el);
+ if (bo instanceof JavaPersistentType){
+ return (JavaPersistentType)bo;
+ }
+ return null;
+ }
+
+ /**
+ * Gets the existing isARelation
+ * @param jpaDiagramEditor
+ * @return the existing isArelation if exists, null otherwise
+ */
+ @SuppressWarnings("restriction")
+ public IsARelation getIsARelationship(SWTBotGefEditor jpaDiagramEditor){
+ IJPAEditorFeatureProvider fp = (IJPAEditorFeatureProvider) ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ Set<IsARelation> isARelationships = fp.getAllExistingIsARelations();
+ assertFalse(isARelationships.isEmpty());
+ assertEquals(1, isARelationships.size());
+ IsARelation relation = isARelationships.iterator().next();
+ return relation;
+ }
+
+ /**
+ * CHecks whether the Entity contains unsaved changes.
+ * @param jpaDiagramEditor
+ * @param element
+ * @return true if the entity contains unsaved changes, false otherwise
+ */
+ @SuppressWarnings("restriction")
+ public boolean isEntityDirty(SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart element){
+ final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+ PictogramElement el = (PictogramElement) element.part().getModel();
+ Object bo = fp.getBusinessObjectForPictogramElement(el);
+ IResource res = null;
+ if(bo instanceof JavaPersistentAttribute){
+ res = ((JavaPersistentAttribute)bo).getResource();
+ } else if (bo instanceof JavaPersistentType){
+ res = ((JavaPersistentType)bo).getResource();
+ }
+
+ if(res != null){
+ ICompilationUnit unit = JPAEditorUtil.getCompilationUnit((IFile)res);
+ try {
+ return unit.hasUnsavedChanges();
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Select the bidirectional relation and call its "Delete" context menu.
+ * On the confirmation dialog press "No" and assert that
+ * the connection and the relative relation attributes still exist
+ * and the "Relation Attributes" sections of the entities' are visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param entity2
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertBiDirRelationIsNotDeleted(
+ SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
+ SWTBotGefEditPart entity2,
+ SWTBotGefConnectionEditPart connection,
+ String ownerAttributeName, String inverseAttributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ denyDelete();
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertFalse(entity2.targetConnections().isEmpty());
+ connection = entity1.sourceConnections().get(0);
+ assertNotNull("Attribute must not be deleted!", connection);
+ assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the bidirectional self relation and call its "Delete" context menu.
+ * On the confirmation dialog press "No" and assert that
+ * the connection and the relative relation attributes still exist
+ * and the "Relation Attributes" sections of the entities' are visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertSelfBiDirRelationIsNotDeleted(
+ SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection,
+ String ownerAttributeName, String inverseAttributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ denyDelete();
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertFalse(entity1.targetConnections().isEmpty());
+ connection = entity1.sourceConnections().get(0);
+ assertNotNull("Attribute must not be deleted!", connection);
+ assertNotNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the unidirectional relation and call its "Delete" context menu.
+ * On the confirmation dialog press "No" and assert that
+ * the connection and the relative relation attributes still exist
+ * and the "Relation Attributes" sections of the entities' are visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param entity2
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertUniDirRelationIsNotDeleted(
+ SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
+ SWTBotGefEditPart entity2,
+ SWTBotGefConnectionEditPart connection, String attributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ denyDelete();
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertFalse(entity2.targetConnections().isEmpty());
+ connection = entity1.sourceConnections().get(0);
+ assertNotNull("Attribute must not be deleted!", connection);
+ assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertTrue("\"Relation Attributes\" section of the owner entity must be visible!",isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the unidirectional self relation and call its "Delete" context menu.
+ * On the confirmation dialog press "No" and assert that
+ * the connection and the relative relation attributes still exist
+ * and the "Relation Attributes" sections of the entities' are visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertSelfUniDirRelationIsNotDeleted(
+ SWTBotGefEditor jpaDiagramEditor, SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection, String attributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ denyDelete();
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertFalse(entity1.targetConnections().isEmpty());
+ connection = entity1.sourceConnections().get(0);
+ assertNotNull("Attribute must not be deleted!", connection);
+ assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the bidirectional relation and call its "Delete" context menu.
+ * On the confirmation dialog press "Yes" and assert that
+ * the connection and the relative relation attributes do not exist anymore
+ * and the "Relation Attributes" sections of the entities' are not visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param entity2
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
+ SWTBotGefConnectionEditPart connection,
+ String ownerAttributeName, String inverseAttributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the bidirectional self relation and call its "Delete" context menu.
+ * On the confirmation dialog press "Yes" and assert that
+ * the connection and the relative relation attributes do not exist anymore
+ * and the "Relation Attributes" sections of the entities' are not visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertSelfBiDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection,
+ String ownerAttributeName, String inverseAttributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, ownerAttributeName));
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity1.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the unidirectional relation and call its "Delete" context menu.
+ * On the confirmation dialog press "Yes" and assert that
+ * the connection and the relative relation attributes do not exist anymore
+ * and the "Relation Attributes" sections of the entities' are not visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param entity2
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1, SWTBotGefEditPart entity2,
+ SWTBotGefConnectionEditPart connection, String attributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Select the unidirectional self relation and call its "Delete" context menu.
+ * On the confirmation dialog press "Yes" and assert that
+ * the connection and the relative relation attributes do not exist anymore
+ * and the "Relation Attributes" sections of the entities' are not visible.
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param connection
+ * @param ownerAttributeName
+ * @param inverseAttributeName
+ */
+ public void assertSelfUniDirRelationIsDeleted(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1,
+ SWTBotGefConnectionEditPart connection, String attributeName) {
+ connection.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ confirmDelete();
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, attributeName));
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity1.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse("\"Relation Attributes\" section of the owner entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Assert that there is exactly one GEF element representing the relationship
+ * @param jpaDiagramEditor
+ * @param entity1
+ * @param entity2
+ */
+ public void assertConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1, SWTBotGefEditPart entity2, boolean isBiDIr) {
+ //assert that there is exactly one relationship, which start from entity1
+ //and that there is no relationship which starts from entity2
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertEquals(1, entity1.sourceConnections().size());
+ assertTrue(entity2.sourceConnections().isEmpty());
+
+ //assert that there is exactly one relationship which ends in entity2
+ //and that there is no relationship which end in entity1.
+ assertFalse(entity2.targetConnections().isEmpty());
+ assertEquals(1, entity2.targetConnections().size());
+ assertTrue(entity1.targetConnections().isEmpty());
+
+ assertTrue("\"Relation Attributes\" section of the owner entity must be visible!", isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ if(isBiDIr){
+ assertTrue("\"Relation Attributes\" section of the inverse entity must be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ } else {
+ assertFalse("\"Relation Attributes\" section of the inverse entity must not be visible!", isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+ }
+
+ public void assertIsARelationExists(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1, SWTBotGefEditPart entity2) {
+ // assert that there is exactly one relationship, which start from
+ // entity2 and that there is no relationship which starts from entity2
+ assertFalse(entity2.sourceConnections().isEmpty());
+ assertEquals(1, entity2.sourceConnections().size());
+ assertTrue(entity1.sourceConnections().isEmpty());
+
+ // assert that there is exactly one relationship which ends in entity1
+ // and that there is no relationship which end in entity2.
+ assertFalse(entity1.targetConnections().isEmpty());
+ assertEquals(1, entity1.targetConnections().size());
+ assertTrue(entity2.targetConnections().isEmpty());
+ }
+
+ /**
+ * Assert that there is exactly one GEF element representing the self relationship
+ * @param jpaDiagramEditor
+ * @param entity1
+ */
+ public void assertSelfConnectionIsCreated(SWTBotGefEditor jpaDiagramEditor,
+ SWTBotGefEditPart entity1) {
+ //assert that there is exactly one relationship, which start from entity1
+ //and ends in entity2
+ assertFalse(entity1.sourceConnections().isEmpty());
+ assertEquals(1, entity1.sourceConnections().size());
+
+ assertFalse(entity1.targetConnections().isEmpty());
+ assertEquals(1, entity1.targetConnections().size());
+
+ assertTrue(isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ }
+
+ /**
+ * Assert that the owner relationship attribute exists
+ * @param jpaDiagramEditor
+ * @param rel
+ * @return the name of the owner relationship attribute
+ */
+ public String testOwnerRelationAttributeProperties(
+ SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
+ JavaPersistentAttribute ownerAttr = rel.getOwnerAnnotatedAttribute();
+ String attributeName = rel.getOwnerAttributeName();
+ assertNotNull(ownerAttr);
+ assertNotNull(jpaDiagramEditor.getEditPart(attributeName));
+
+ return attributeName;
+ }
+
+ /**
+ * Assert that the inverse relationship attribute exists.
+ * @param jpaDiagramEditor
+ * @param rel
+ * @return the name of the inverse relationship attribute
+ */
+ public String testInverseRelationAttributeProperties(
+ SWTBotGefEditor jpaDiagramEditor, IRelation rel) {
+ JavaPersistentAttribute inverseAttr = rel.getInverseAnnotatedAttribute();
+ String inverseAttributeName = rel.getInverseAttributeName();
+ assertNotNull(inverseAttr);
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ return inverseAttributeName;
+ }
+
+
+ /**
+ * Checks whether a section of a particular entity is visible
+ * @param diagramEditor
+ * @param editPart - the particular entity
+ * @param sectionTitle - the title of the section to be checked
+ * @return true, if the sections is visible, false otherwise
+ */
+ @SuppressWarnings("deprecation")
+ public boolean isSectionVisible(SWTBotGefEditor diagramEditor, SWTBotGefEditPart editPart, String sectionTitle){
+ List<SWTBotGefEditPart> children = editPart.children();
+ SWTBotGefEditPart section = diagramEditor.getEditpart(sectionTitle, children);
+ ((PictogramElement)section.part().getModel()).isVisible();
+ IFigure figure = ((GraphicalEditPart) section.part()).getFigure();
+ return figure.isVisible();
+ }
+
+ /**
+ * Change the mapping of the type or attribute.
+ * @param newMappingType
+ */
+ public void changeMappingtype(String newMappingType) {
+ workbenchBot.waitUntil(shellIsActive("Mapping Type Selection"), 5000);
+ SWTBotShell mappingTypeShell = workbenchBot.shell("Mapping Type Selection");
+ mappingTypeShell.bot().table().getTableItem(newMappingType).select();
+ getOkButton(mappingTypeShell).click();
+ }
+
+ /**
+ * Click on the mapping type link in the JPA Details view
+ * @param styledText
+ * @param position
+ */
+ public void clickOnStyledText(final SWTBotStyledText styledText, int position) {
+ styledText.navigateTo(new Position(0, position));
+ asyncExec(new VoidResult() {
+ public void run() {
+ styledText.widget.notifyListeners(SWT.MouseDown, new Event());
+ styledText.widget.notifyListeners(SWT.MouseUp, new Event());
+ }
+ });
+ }
+
+ public void waitASecond() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Assert that the relation attribute is correctly mapped in the JPA Details view
+ * @param jpaDiagramEditor
+ * @param attributeName
+ * @param relationAttributeMapping - the expected attribute mapping
+ */
+ public void assertAttributeIsCorretlyMapped(
+ SWTBotGefEditor jpaDiagramEditor, String attributeName, String relationAttributeMapping) {
+
+ //assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ jpaDetailsView.setFocus();
+ assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
+
+ SWTBotGefEditPart oneToManyAttr = jpaDiagramEditor.getEditPart(attributeName);
+ oneToManyAttr.click();
+
+ //assert that the default entity's attribute is mapped as primary key
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute '" +attributeName+ "' is mapped as " +relationAttributeMapping+ ".", styledText.getText());
+ }
+
+ /**
+ * Assert that the type is correctly mapped in the JPA Details view
+ * @param jpaDiagramEditor
+ * @param typeName
+ * @param typeMapping - the expected type mapping
+ */
+ public void assertTypeIsCorretlyMapped(
+ SWTBotGefEditor jpaDiagramEditor, String typeName, String typeMapping) {
+ workbenchBot.viewByTitle("JPA Details").close();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+ //assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
+
+ SWTBotGefEditPart type = jpaDiagramEditor.getEditPart(typeName);
+ type.click();
+
+ //assert that the default entity's attribute is mapped as the given mapping key
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Type '" +typeName+ "' is mapped as " +typeMapping+ ".", styledText.getText());
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java new file mode 100644 index 0000000000..2e33cb8cbd --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementDisappears.java @@ -0,0 +1,26 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+
+public class ElementDisappears extends DefaultCondition{
+
+ private String entityName;
+ private SWTBotGefEditor gefEditor;
+
+ public ElementDisappears(SWTBotGefEditor gefEditor, String entityName){
+ super();
+ this.gefEditor = gefEditor;
+ this.entityName = entityName;
+ }
+
+ public boolean test() throws Exception {
+ return gefEditor.getEditPart(entityName) == null;
+ }
+
+ public String getFailureMessage() {
+ return "Entity with name ''" + entityName + "'' did not show.";
+ }
+
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java new file mode 100644 index 0000000000..6eb5c5f05e --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/ElementIsShown.java @@ -0,0 +1,25 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+
+public class ElementIsShown extends DefaultCondition{
+
+ private String entityName;
+ private SWTBotGefEditor gefEditor;
+
+ public ElementIsShown(SWTBotGefEditor gefEditor, String entityName){
+ super();
+ this.gefEditor = gefEditor;
+ this.entityName = entityName;
+ }
+
+ public boolean test() throws Exception {
+ return gefEditor.getEditPart(entityName) != null;
+ }
+
+ public String getFailureMessage() {
+ return "Entity with name ''" + entityName + "'' did not show.";
+ }
+
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java new file mode 100644 index 0000000000..cbdd961d6b --- /dev/null +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.swtbot.tests/src/org/eclipse/jpt/jpadiagrameditor/swtbot/tests/ui/editor/JPADiagramEditorSWTBotTest.java @@ -0,0 +1,2410 @@ +package org.eclipse.jpt.jpadiagrameditor.swtbot.tests.ui.editor;
+
+
+import java.util.List;
+
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.ui.internal.parts.DiagramEditPart;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.JPACreateFactory;
+import org.eclipse.jpt.jpadiagrameditor.swtbot.tests.internal.Utils;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.i18n.JPAEditorMessages;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IRelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.relations.IsARelation;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JPAEditorConstants;
+import org.eclipse.jpt.jpadiagrameditor.ui.internal.util.JpaArtifactFactory;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
+import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefConnectionEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
+import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class JPADiagramEditorSWTBotTest extends SWTBotGefTestCase {
+
+ protected static String TEST_PROJECT;
+ protected static JPACreateFactory factory = JPACreateFactory.instance();
+ protected static JpaProject jpaProject;
+
+ protected static SWTGefBot bot = new SWTGefBot();
+ protected static SWTWorkbenchBot workbenchBot = new SWTWorkbenchBot();
+ protected static EditorProxy editorProxy = new EditorProxy(workbenchBot, bot);
+
+ protected static SWTBotGefEditor jpaDiagramEditor;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+
+ SWTBotPreferences.TIMEOUT = 1000;
+ try {
+ bot.viewByTitle("Welcome").close();
+ } catch (Exception e) {
+ // ignore
+ } finally {
+ SWTBotPreferences.TIMEOUT = 5000;
+ }
+ workbenchBot.perspectiveByLabel("JPA").activate();
+
+ TEST_PROJECT = "Test_" + System.currentTimeMillis();
+
+ factory = JPACreateFactory.instance();
+ jpaProject = factory.createJPA20Project(TEST_PROJECT);
+ assertNotNull(jpaProject);
+
+ jpaDiagramEditor = editorProxy.openDiagramOnJPAContentNode(TEST_PROJECT);
+
+ Thread.sleep(2000);
+ }
+
+ /**
+ * Add entity to diagram and check that it contains a "Primary Key" section
+ * with one attribute "id" and no "Relation Attributes" and "Other Attributes"
+ * sections.
+ */
+ @Test
+ public void testAddEntity() {
+ Utils.sayTestStarted("testAddEntity");
+
+ editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ jpaDiagramEditor.save();
+ assertFalse("Editor must not be dirty!", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testAddEntity");
+ }
+
+ /**
+ * Remove an entity from the diagram using the entity's context button "Delete"
+ */
+ @Test
+ public void testRemoveEntityViaButton(){
+ Utils.sayTestStarted("testRemoveEntityViaButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ editorProxy.denyDelete();
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ assertNotNull("Entity is deleted!", entity);
+
+ editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ editorProxy.confirmDelete();
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ assertNull("Entity is not deleted!", entity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaButton");
+ }
+
+ /**
+ * Remove an entity from the diagram using the entity's context menu "Delete"
+ */
+ @Test
+ public void testRemoveEntityViaContextMenu(){
+ Utils.sayTestStarted("testRemoveEntityViaContextMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ editorProxy.denyDelete();
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ assertNotNull("Entity is deleted!", entity);
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_deleteEntityFromModelButtonLabel);
+ editorProxy.confirmDelete();
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ assertNull("Entity is not deleted!", entity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaContextMenu");
+ }
+
+ /**
+ * Adds a new attribute to the entity using the entity's context button "Create Attribute"
+ */
+ @Test
+ public void testAddAttribute(){
+ Utils.sayTestStarted("testRemoveEntityViaContextMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveEntityViaContextMenu");
+ }
+
+ /**
+ * Removes the attribute using the "Delete Attribute" context button.
+ */
+ @Test
+ public void testRemoveAttributeViaContextButton(){
+ Utils.sayTestStarted("testRemoveAttributeViaContextButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ editorProxy.pressAttributeDeleteContextButton(jpaDiagramEditor, attribute);
+ editorProxy.denyDelete();
+ attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNotNull("Attribute must not be deleted!", attribute);
+
+ editorProxy.pressAttributeDeleteContextButton(jpaDiagramEditor, attribute);
+ editorProxy.confirmDelete();
+ attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNull("Attribute must be deleted!", attribute);
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeViaContextButton");
+ }
+
+ /**
+ * Removes the attribute using the "Delete" context menu.
+ */
+ @Test
+ public void testRemoveAttributeViaMenu(){
+ Utils.sayTestStarted("testRemoveAttributeViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ jpaDiagramEditor.save();
+
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.denyDelete();
+ attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNotNull("Attribute must not be deleted!", attribute);
+
+ attribute.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNull("Attribute must be deleted!", attribute);
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAttributeViaMenu");
+ }
+
+ /**
+ * Adds a new attribute and rename it
+ */
+ @Test
+ public void testDirectEditingAttribute(){
+ Utils.sayTestStarted("testDirectEditingAttribute");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertNotNull("The attribute must not be renamed!", attribute);
+
+ jpaDiagramEditor.directEditType("newAttrName");
+ SWTBotGefEditPart oldAttribute = jpaDiagramEditor.getEditPart("attribute1");
+ SWTBotGefEditPart newAttribute = jpaDiagramEditor.getEditPart("newAttrName");
+ assertNotNull("The attribute must be renamed!", newAttribute);
+ assertNull("The attribute must be renamed!", oldAttribute);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingAttribute");
+ }
+
+ /**
+ * Adds a new entity and rename it
+ */
+ @Ignore
+ @Test
+ public void testDirectEditingEntity(){
+ Utils.sayTestStarted("testDirectEditingEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.moveMouse(jpaDiagramEditor, 100, 70);
+ entity.click();
+ entity.activateDirectEdit();
+ jpaDiagramEditor.directEditType("NewEntityName");
+ editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
+
+ SWTBotGefEditPart oldEntity = jpaDiagramEditor.getEditPart("Entity1");
+ SWTBotGefEditPart newEntity = jpaDiagramEditor.getEditPart("NewEntityName");
+ assertNotNull("The entity must be renamed!", newEntity);
+ assertNull("The attribute must be renamed!", oldEntity);
+
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDirectEditingEntity");
+ }
+
+ /**
+ * Test that the source of the entity is opened, when is double clicked on it
+ */
+ @Ignore
+ @Test
+ public void testDoubleClickOnEntity(){
+ Utils.sayTestStarted("testDoubleClickOnEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ editorProxy.moveMouse(jpaDiagramEditor, 100, 70);
+ jpaDiagramEditor.doubleClick(entity);
+ editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
+
+ SWTBotEditor activeEditor = workbenchBot.activeEditor();
+ assertEquals("The Java editor of the enity did not open!", "Entity1.java", activeEditor.getTitle());
+ activeEditor.close();
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDoubleClickOnEntity");
+ }
+
+ /**
+ * Change the attribute type.
+ */
+ @Test
+ @SuppressWarnings("restriction")
+ public void testChangeAttributeType(){
+ Utils.sayTestStarted("testChangeAttributeType");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ SWTBotGefEditPart attribute = editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertNotNull("The attribute must not be renamed!", attribute);
+ final IFeatureProvider fp = ((DiagramEditPart)jpaDiagramEditor.mainEditPart().part()).getFeatureProvider();
+
+ String currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
+ assertEquals("java.lang.String", currentAttributeType);
+
+ SWTBotShell changeTypeDialog = editorProxy.getSelectNewAttributeTypeDialog(jpaDiagramEditor, attribute);
+ SWTBotText attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
+
+ //test invalid attribute type
+ attributeType.setText("");
+ assertFalse(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ SWTBotText dialogError = editorProxy.getDialogErroMessage(changeTypeDialog);
+ assertEquals(" The new type name must not be empty", dialogError.getText());
+ //cancel the dialog
+ editorProxy.getCancelButton(changeTypeDialog).click();
+
+ //assert that the attribute type is not changed
+ currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
+ assertEquals("The attribute type must not be changed!", "java.lang.String", currentAttributeType);
+
+ changeTypeDialog = editorProxy.getSelectNewAttributeTypeDialog(jpaDiagramEditor, attribute);
+ attributeType = editorProxy.getNewTypeInputField(changeTypeDialog);
+
+ //change the attribute type to int
+ attributeType.setText("int");
+ assertTrue(editorProxy.getOkButton(changeTypeDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(changeTypeDialog).isEnabled());
+ //confirm the dialog
+ editorProxy.getOkButton(changeTypeDialog).click();
+ //assert that the attribute's type is changed
+ String newAttributeType = currentAttributeType = editorProxy.getAttributeType(jpaDiagramEditor, "attribute1", fp);
+ assertFalse("The attribute type must be changed!", ("java.lang.String").equals(newAttributeType));
+ assertEquals("The attribute type must be changed!", "int", newAttributeType);
+
+ assertTrue("Editor must be dirty!", jpaDiagramEditor.isDirty());
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeAttributeType");
+ }
+
+ /**
+ * Rename the entity using its context menu "Refactor Entity Class -> Rename..."
+ */
+ @Ignore
+ @Test
+ public void testRenameEntityViaMenu(){
+ Utils.sayTestStarted("testRenameEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_renameEntityClass);
+
+ SWTBotShell renameEntityDialog = editorProxy.getRenameEntityDialog();
+ SWTBotText entityName = renameEntityDialog.bot().textWithLabel("New name:");
+
+ //test invalid entity name
+ entityName.setText("");
+ assertFalse(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ entityName.setText("NewEntityName");
+ assertTrue(editorProxy.getFinishButton(renameEntityDialog).isEnabled());
+ assertTrue(editorProxy.getCancelButton(renameEntityDialog).isEnabled());
+
+ editorProxy.getFinishButton(renameEntityDialog).click();
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "NewEntityName"), 10000);
+
+ entity = jpaDiagramEditor.getEditPart("NewEntityName");
+ assertNotNull("Entity name must be changed!", entity);
+ assertNull("Entity naem must be changed!", jpaDiagramEditor.getEditPart("Entity1"));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRenameEntityViaMenu");
+ }
+
+ /**
+ * Move the entity class using the entity's context menu "Refactor Entity Class -> Move..."
+ */
+ @Ignore
+ @Test
+ public void testMoveEntityViaMenu() throws JavaModelException{
+ Utils.sayTestStarted("testMoveEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ JpaArtifactFactory factory = JpaArtifactFactory.instance();
+
+ String packageName = factory.getMappedSuperclassPackageDeclaration(editorProxy.getEntityForElement(jpaDiagramEditor, entity));
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_moveEntityClass);
+
+ SWTBotShell moveEntityDialog = editorProxy.getMoveEntityDialog();
+ moveEntityDialog.bot().tree().getTreeItem(TEST_PROJECT).select().expandNode("src").expandNode("org").select().click();
+ assertTrue(editorProxy.getOkButton(moveEntityDialog).isEnabled());
+ editorProxy.getOkButton(moveEntityDialog).click();
+ editorProxy.waitASecond();
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ String newEntityPackage= factory.getMappedSuperclassPackageDeclaration(editorProxy.getEntityForElement(jpaDiagramEditor, entity));
+ assertFalse("Entity must be moved!", packageName.equals(newEntityPackage));
+ assertTrue("Entity must be changed!", newEntityPackage.equals("org"));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testMoveEntityViaMenu");
+ }
+
+ /**
+ * Collapse/expand entity using its context buttons
+ */
+ @Test
+ public void testCollapseExapandEntityViaContextButton(){
+ Utils.sayTestStarted("testCollapseExapandEntityViaContextButton");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ int heigth = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, "Collapse");
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ int newHeight = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be collapsed!", JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < heigth);
+
+ editorProxy.pressEntityContextButton(jpaDiagramEditor, entity, "Expand");
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ newHeight = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth, newHeight);
+ assertTrue(newHeight > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEntityViaContextButton");
+ }
+
+ /**
+ * Collapse/expand entity using its context menus
+ */
+ @Test
+ public void testCollapseExapandEntityViaMenu(){
+ Utils.sayTestStarted("testCollapseExapandEntityViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ int heigth = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseEntityMenuItem);
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ int newHeight = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be collapsed!", JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < heigth);
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandEntityMenuItem);
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ newHeight = ((PictogramElement)entity.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth, newHeight);
+ assertTrue(newHeight > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandEntityViaMenu");
+ }
+
+ /**
+ * Collapse/expand all entities using the context menus
+ */
+ @Test
+ public void testCollapseExapandAllEntitiesViaMenu(){
+ Utils.sayTestStarted("testCollapseExapandAllEntitiesViaMenu");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ int heigth1 = ((PictogramElement)entity1.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 300, 50, "Entity2");
+
+ int heigth2 = ((PictogramElement)entity2.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseAllEntitiesMenuItem);
+
+ //check that entity1 is collapsed
+ entity1 = jpaDiagramEditor.getEditPart("Entity1");
+ int newHeight1 = ((PictogramElement)entity1.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity1 must be collapsed!", JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight1);
+ assertTrue(newHeight1 < heigth1);
+
+ //check that entity2 is collapsed
+ entity2 = jpaDiagramEditor.getEditPart("Entity2");
+ int newHeight2 = ((PictogramElement)entity2.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity2 must be collapsed!", JPAEditorConstants.ENTITY_MIN_HEIGHT, newHeight2);
+ assertTrue(newHeight2 < heigth2);
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandAllEntitiesMenuItem);
+
+ //check that entity1 is expanded
+ entity1 = jpaDiagramEditor.getEditPart("Entity1");
+ newHeight1 = ((PictogramElement)entity1.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth1, newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+
+ //check that entity2 is expanded
+ entity2 = jpaDiagramEditor.getEditPart("Entity2");
+ newHeight2 = ((PictogramElement)entity2.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Entity must be expanded!", heigth2, newHeight2);
+ assertTrue(newHeight2 > JPAEditorConstants.ENTITY_MIN_HEIGHT);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExapandAllEntitiesViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the "Discard Changes" context menu.
+ * Assert that the newly added attribute is removed and the entity does not contain unsaved
+ * changes.
+ */
+ @Test
+ public void testDiscardChanges(){
+ Utils.sayTestStarted("testDiscardChanges");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_discardChangesMenuItem);
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNull("Changes must be discard!", attribute);
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testDiscardChanges");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the entity's context menu "Remove All Entities from Diagram ->
+ * ... and Discard Changes" context menu. Assert that the diagram is empty. Call "Show All Entities" context menu and
+ * assert that the newly added attribute is removed and the entity does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndDiscardChangesViaMenu(){
+ Utils.sayTestStarted("testRemoveAndDiscardChangesViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("Diagram must contain at least one entity!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndDiscardAllEntitiesAction);
+ editorProxy.confirmRemoveEntitiesFromDiagramDialog();
+ assertTrue("Diagram must be empty!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+ assertFalse("Diagram must contain at least one entity!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNull("Changes must be discard!", attribute);
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndDiscardChangesViaMenu");
+ }
+
+ /**
+ * Add a new attribute without saving the entity and call the entity's context menu "Remove All Entities from Diagram ->
+ * ... and Save Changes" context menu. Assert that the diagram is empty. Call "Show All Entities" context menu and
+ * assert that the newly added attribute is added and the entity does not contain unsaved changes.
+ */
+ @Test
+ public void testRemoveAndSaveChangesViaMenu(){
+ Utils.sayTestStarted("testRemoveAndSaveChangesViaMenu");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ assertFalse("Diagram must contain at least one entity!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_removeAndSaveAllEntitiesAction);
+ editorProxy.confirmRemoveEntitiesFromDiagramDialog();
+ assertTrue("Diagram must be empty!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+ assertFalse("Diagram must contain at least one entity!", jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ entity = jpaDiagramEditor.getEditPart("Entity1");
+ SWTBotGefEditPart attribute = jpaDiagramEditor.getEditPart("attribute1");
+ assertNotNull("Changes must be discard!", attribute);
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testRemoveAndSaveChangesViaMenu");
+ }
+
+ /**
+ * Add a new attribute to the entity. From the entity's context menu
+ * select "Save". Assert that the entity does not contain any unsaved changes,
+ * but the diagram editor is still dirty.
+ */
+ @Test
+ public void testSaveOnlyEntity(){
+ Utils.sayTestStarted("testSaveOnlyEntity");
+
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ assertFalse("\"Other Attributes\" section must not be visible!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.addAttributeToEntity(jpaDiagramEditor, entity, "attribute1");
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertTrue(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ entity.click();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_saveButtonText);
+ assertTrue("Editor must be dirty", jpaDiagramEditor.isDirty());
+ assertFalse(editorProxy.isEntityDirty(jpaDiagramEditor, entity));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSaveOnlyEntity");
+ }
+
+ /**
+ * Create a JPA project and one entity in it.
+ * Open the JPA diagram editor and call the
+ * "Show All Entities" context menu.
+ * Assert that the previously created entity is
+ * shown in the diagram.
+ * @throws Exception
+ */
+ @Test
+ public void testShowAllEntities() throws Exception{
+ Utils.sayTestStarted("testShowAllEntities");
+
+ factory.createEntity(jpaProject, "com.sap.test.Customer");
+ assertTrue(jpaDiagramEditor.mainEditPart().children().isEmpty());
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_showAllTheEntities);
+
+ List<SWTBotGefEditPart> entities = jpaDiagramEditor.mainEditPart().children();
+ assertFalse("Diagram editor must contain at least one entity!", entities.isEmpty());
+
+ SWTBotGefEditPart entity = jpaDiagramEditor.getEditPart("Customer");
+ assertNotNull(entity);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testShowAllEntities");
+ }
+
+ /**
+ * Collapse/expand "Primary Key" section by double click on it
+ */
+ @Ignore
+ @Test
+ public void testCollapseExpandCompartmentByDoubleClick(){
+ Utils.sayTestStarted("testCollapseExpandCompartmentByDoubleClick");
+
+ editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ editorProxy.moveMouse(jpaDiagramEditor, 100, 100);
+ SWTBotGefEditPart primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+
+ int height = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ primaryKeySection.click();
+
+ jpaDiagramEditor.doubleClick(primaryKeySection);
+ primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", JPAEditorConstants.COMPARTMENT_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < height);
+
+ jpaDiagramEditor.doubleClick(primaryKeySection);
+ primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight1 = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", height, newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.COMPARTMENT_MIN_HEIGHT);
+
+ editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExpandCompartmentByDoubleClick");
+ }
+
+ /**
+ * Collapse/expand compartment by its context menu
+ */
+ @Ignore
+ @Test
+ public void testCollapseExpandCompartmentByContextMenu(){
+ Utils.sayTestStarted("testCollapseExpandCompartmentByContextMenu");
+
+ editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ editorProxy.moveMouse(jpaDiagramEditor, 100, 100);
+ SWTBotGefEditPart primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+
+ int height = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+
+ primaryKeySection.click();
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_collapseAttrGroupMenuItem);
+ primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", JPAEditorConstants.COMPARTMENT_MIN_HEIGHT, newHeight);
+ assertTrue(newHeight < height);
+
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_expandAttrMenuItem);
+ primaryKeySection = jpaDiagramEditor.getEditPart(JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape);
+ int newHeight1 = ((PictogramElement)primaryKeySection.part().getModel()).getGraphicsAlgorithm().getHeight();
+ assertEquals("Primary Key section must be collapsed!", height, newHeight1);
+ assertTrue(newHeight1 > JPAEditorConstants.COMPARTMENT_MIN_HEIGHT);
+
+ editorProxy.moveMouse(jpaDiagramEditor, 0, 0);
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testCollapseExpandCompartmentByContextMenu");
+ }
+
+ /**
+ * Test the integration between the JPA diagram editor and the JPA Details view:
+ * 1.) Close the JPA Details view
+ * 2.) Create an entity and call the context menu "Open JPA Details View"
+ * 3.) Assert that the JPA Details view is opened and the appropriate information
+ * is shown (the type is mapped as entity and the expandable sections are available).
+ * 4.) Change the mapping type to "Mapped Superclass"
+ * 5.) Change the mapping type to "Embeddable" and assert that the type is removed from the diagram
+ * 6.) Revert the mapping type to be "Entity" and call the "Show All Entities" context menu
+ * to visualize the entity in the diagram editor.
+ */
+ @Test
+ public void testChangeEntityMappingTypeViaJPADetailsView(){
+ Utils.sayTestStarted("testChangeEntityMappingTypeViaJPADetailsView");
+
+ workbenchBot.viewByTitle("JPA Details").close();
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ jpaDiagramEditor.save();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+
+ //assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
+
+ //assert that the type is mapped as entity in the JPA Deatils view
+ entity.click();
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as entity.", styledText.getText());
+ assertNotNull("Entity must be shown in the diagram!", jpaDiagramEditor.getEditPart("Entity1"));
+ //assert that the entity's sections are enabled
+ assertTrue(jpaDetailsBot.label("Entity").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+ assertTrue(jpaDetailsBot.label("Inheritance").isEnabled());
+ assertTrue(jpaDetailsBot.label("Attribute Overrides").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+ assertTrue(jpaDetailsBot.label("Secondary Tables").isEnabled());
+
+
+ //change the mapping type to "Mapped Superclass" and assert that the type is mapped
+ //as mapped superclass in the JPA Details view
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Mapped Superclass");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as mapped superclass.", styledText.getText());
+ assertNotNull("Entity must be shown in the diagram!", jpaDiagramEditor.getEditPart("Entity1"));
+ //assert that the mapped superclass'es sections are enabled
+ assertTrue(jpaDetailsBot.label("Mapped Superclass").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+
+ //change the mapping type to "Embeddable" and assert that the element is removed from the diagram
+ //and the type is mapped as embeddable in the JPA Details view
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Embeddable");
+ bot.waitUntil(new ElementDisappears(jpaDiagramEditor, "Entity1"));
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as embeddable.", styledText.getText());
+ assertNull("Entity must disappear from the diagram!", jpaDiagramEditor.getEditPart("Entity1"));
+ //assert that the embeddable's section is enabled
+// assertTrue(jpaDetailsBot.label("Embeddable").isEnabled());
+
+ //revert the mapping type to Entity
+ editorProxy.clickOnStyledText(styledText, 30);
+ editorProxy.changeMappingtype("Entity");
+ assertNull("Entity must disappear from the diagram!", jpaDiagramEditor.getEditPart("Entity1"));
+
+ jpaDiagramEditor.click(0, 0);
+
+ //call the "Show All Entities" diagram context menu to visualize the element in the diagram and
+ //assert that the type is mapped as entity in the JPA Details view
+ jpaDiagramEditor.clickContextMenu("Show All Entities");
+ assertNotNull("Entity must be shown in the diagram!", jpaDiagramEditor.getEditPart("Entity1"));
+ jpaDiagramEditor.select("Entity1");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Type 'Entity1' is mapped as entity.", styledText.getText());
+ //assert that the entity's sections are enabled
+ assertTrue(jpaDetailsBot.label("Entity").isEnabled());
+ assertTrue(jpaDetailsBot.label("Queries").isEnabled());
+ assertTrue(jpaDetailsBot.label("Inheritance").isEnabled());
+ assertTrue(jpaDetailsBot.label("Attribute Overrides").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+ assertTrue(jpaDetailsBot.label("Secondary Tables").isEnabled());
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeEntityMappingTypeViaJPADetailsView");
+ }
+
+ /**
+ * Test the integration between the JPA diagram editor and the JPA Details view:
+ * 1.) Close the JPA Details view
+ * 2.) Create an entity and call the context menu "Open JPA Details View"
+ * 3.) Assert that the JPA Details view is opened and the appropriate information
+ * is shown (the id attribute is mapped as id and the expandable sections are available).
+ * 4.) Change the attribute mapping type to "Basic" and assert that the attribute is moved to "Other Attributes" compartment
+ * 5.) Change the attribute mapping type to "On-To-Many" and assert that the attribute is moved to "Relation Attributes" compartment
+ * 7.) Revert the attribute mapping to "ID" and assert that the attributes is moved back to the "Primary Key" compartment
+ */
+ @Test
+ public void testChangeAttributeMappingTypeViaJPADetailsView(){
+ Utils.sayTestStarted("testChangeAttributeMappingTypeViaJPADetailsView");
+
+ workbenchBot.viewByTitle("JPA Details").close();
+ SWTBotGefEditPart entity = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ jpaDiagramEditor.save();
+ jpaDiagramEditor.clickContextMenu(JPAEditorMessages.JPAEditorToolBehaviorProvider_openJPADetailsView);
+
+ //assert that the JPA Details view is opened
+ SWTBotView jpaDetailsView = workbenchBot.viewByTitle("JPA Details");
+ assertTrue("JPA Details view must be opened!", jpaDetailsView.isActive());
+
+ SWTBotGefEditPart primaryKeyAttr = jpaDiagramEditor.getEditPart("id");
+ primaryKeyAttr.click();
+
+ //assert that the default entity's attribute is mapped as primary key
+ SWTBot jpaDetailsBot = jpaDetailsView.bot();
+ SWTBotStyledText styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as ID.", styledText.getText());
+ //assert that the attribute is under "Primary Key" section
+ assertTrue("Attribute must be in the \"Primary Key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse("Attribute must be in the \"Primary Key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("Attribute must be in the \"Primary Key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ //assert that the ID's sections are available
+ assertTrue(jpaDetailsBot.label("ID").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+
+ //change the attribute type to basic
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("Basic");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as basic.", styledText.getText());
+ //assert that the attribute is moved under "Other Attributes" section
+ assertFalse("Attribute must be in the \"Primary Key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse("Attribute must be in the \"Relation Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertTrue("Attribute must be in the \"Other Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ //assert that the Basic's sections are available
+ assertTrue(jpaDetailsBot.label("Basic").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+
+ //change the attribute type to Many to Many
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("Many to Many");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as many to many.", styledText.getText());
+ //assert that the attribute is moved under the "Relation Attributes" section
+ assertFalse("Attribute must be in the \"Primary key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertTrue("Attribute must be in the \"Relation Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("Attribute must be in the \"Other Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ //assert that the Many to Many's sections are available
+ assertTrue(jpaDetailsBot.label("Many to Many").isEnabled());
+ assertTrue(jpaDetailsBot.label("Joining Strategy").isEnabled());
+ assertTrue(jpaDetailsBot.label("Ordering").isEnabled());
+
+ //revert the attribute type back to Id
+ editorProxy.clickOnStyledText(styledText, 29);
+ editorProxy.changeMappingtype("ID");
+ styledText = jpaDetailsBot.styledText();
+ assertEquals("Attribute 'id' is mapped as ID.", styledText.getText());
+ //assert that the attribute is under "Primary Key" section
+ assertTrue("Attribute must be in the \"Primary Key\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse("Attribute must be in the \"Relation Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse("Attribute must be in the \"Other Attributes\" section of the entity!", editorProxy.isSectionVisible(jpaDiagramEditor, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+ //assert that the ID's sections are available
+ assertTrue(jpaDetailsBot.label("ID").isEnabled());
+ assertTrue(jpaDetailsBot.label("Type").isEnabled());
+ assertTrue(jpaDetailsBot.label("Primary Key Generation").isEnabled());
+
+ entity.click();
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testChangeAttributeMappingTypeViaJPADetailsView");
+ }
+
+ /**
+ * Creates "One to One" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testOneToOneUniDirRelationship(){
+ Utils.sayTestStarted("testOneToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One unidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to one");
+
+ editorProxy.assertUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, attributeName);
+
+ editorProxy.assertUniDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates a "One to One" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore.
+ */
+ @Test
+ public void testOneToOneUniDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testOneToOneUniDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One unidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to one");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(attributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneUniDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates "One to One" unidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToOneUniDirRelationship(){
+ Utils.sayTestStarted("testSelfOneToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create One-to-One unidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneUniDirRelationFeature_oneToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to one");
+
+ editorProxy.assertSelfUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, attributeName);
+
+ editorProxy.assertSelfUniDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates "One to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testOneToOneBiDirRelationship(){
+ Utils.sayTestStarted("testOneToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "one to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to one");
+
+ editorProxy.assertBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertBiDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates a "One to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the inverse relationship attribute and
+ * assert that the relationship is converted from bidirectional to unidirectional "One to One"
+ * relationship. Delete also the owner attribute and assert that there is no connection anymore.
+ */
+ @Test
+ public void testOneToOneBiDirRelationshipRemoveInverseAttribute(){
+ Utils.sayTestStarted("testOneToOneBiDirRelationshipRemoveInverseAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "one to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to one");
+
+ //delete the inverse attribute
+ SWTBotGefEditPart inverseAttr = jpaDiagramEditor.getEditPart(inverseAttributeName);
+ inverseAttr.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+
+ //assert that the connection still exists, but it is unidirectional now
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+ connection = entity1.sourceConnections().get(0);
+ rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+ assertEquals(ownerAttributeName, editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel));
+ assertNull(rel.getInverseAnnotatedAttribute());
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "one to one");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttr = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttr.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationshipRemoveInverseAttribute");
+ }
+
+ /**
+ * Creates a "One to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore. Assert that the inverse attribute still exists.
+ */
+ @Test
+ public void testOneToOneBiDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testOneToOneBiDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "one to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to one");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ //assert that the inverse attribute still exists
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ //assert that the inverse attribute still exists
+ assertTrue(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToOneBiDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates "One to One" bidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToOneBiDirRelationship(){
+ Utils.sayTestStarted("testSelfOneToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create One-to-One bidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToOneBiDirRelationFeature_oneToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "one to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to one");
+
+ editorProxy.assertSelfBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertSelfBiDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates "One to Many" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testOneToManyUniDirRelationship(){
+ Utils.sayTestStarted("testOneToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-Many unidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to many");
+
+ editorProxy.assertUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, attributeName);
+
+ editorProxy.assertUniDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates a "One to Many" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore.
+ */
+ @Test
+ public void testOneToManyUniDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testOneToManyUniDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create One-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to many");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(attributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testOneToManyUniDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates "One to Many" unidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfOneToManyUniDirRelationship(){
+ Utils.sayTestStarted("testSelfOneToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create One-to-Many unidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateOneToManyUniDirRelationFeature_oneToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.ONE_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "one to many");
+
+ editorProxy.assertSelfUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, attributeName);
+
+ editorProxy.assertSelfUniDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfOneToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates "Many to One" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testManyToOneUniDirRelationship(){
+ Utils.sayTestStarted("testManyToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-One unidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to one");
+
+ editorProxy.assertUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, attributeName);
+
+ editorProxy.assertUniDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to One" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore.
+ */
+ @Test
+ public void testManyToOneUniDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testManyToOneUniDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to one");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(attributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneUniDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates "Many to One" unidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToOneUniDirRelationship(){
+ Utils.sayTestStarted("testSelfManyToOneUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create Many-to-One unidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneUniDirRelationFeature_manyToOneUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to one");
+
+ editorProxy.assertSelfUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, attributeName);
+
+ editorProxy.assertSelfUniDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToOneUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testManyToOneBiDirRelationship(){
+ Utils.sayTestStarted("testManyToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to many");
+
+ editorProxy.assertBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertBiDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the inverse relationship attribute and
+ * assert that the relationship is converted from bidirectional to unidirectional "Many to One"
+ * relationship. Delete als the owner attribute and assert that there is no connection anymore.
+ */
+ @Test
+ public void testManyToOneBiDirRelationshipRemoveInverseAttribute(){
+ Utils.sayTestStarted("testManyToOneBiDirRelationshipRemoveInverseAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to many");
+
+ //delete the inverse attribute
+ SWTBotGefEditPart inverseAttr = jpaDiagramEditor.getEditPart(inverseAttributeName);
+ inverseAttr.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+
+ //assert that the connection still exists, but it is unidirectional now
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+ connection = entity1.sourceConnections().get(0);
+ rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+ assertEquals(ownerAttributeName, editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel));
+ assertNull(rel.getInverseAnnotatedAttribute());
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to one");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttr = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttr.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationshipRemoveInverseAttribute");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore. Assert that the inverse attribute still exists.
+ */
+ @Test
+ public void testManyToOneBiDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testManyToOneBiDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-One bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to many");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ //assert that the inverse attribute still exists
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ //assert that the inverse attribute still exists
+ assertTrue(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToOneBiDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates a "Many to One" bidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToOneBiDirRelationship(){
+ Utils.sayTestStarted("testSelfManyToOneBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create Many-to-Many bidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToOneBiDirRelationFeature_manyToOneBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_ONE, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to one");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "one to many");
+
+ editorProxy.assertSelfBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertSelfBiDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToOneBiDirRelationship");
+ }
+
+ /**
+ * Creates "Many to Many" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testManyToManyUniDirRelationship() {
+ Utils.sayTestStarted("testManyToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-Many unidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to many");
+
+ editorProxy.assertUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, attributeName);
+
+ editorProxy.assertUniDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to Many" unidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore.
+ */
+ @Test
+ public void testManyToManyUniDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testManyToManyUniDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-Many bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to many");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(attributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(attributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyUniDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates "Many to Many" unidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToManyUniDirRelationship(){
+ Utils.sayTestStarted("testSelfManyToManyUniDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create Many-to-Many unidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyUniDirRelationFeature_manyToManyUniDirFeatureName, 0);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String attributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+ assertNull(rel.getInverseAnnotatedAttribute());
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, attributeName, "many to many");
+
+ editorProxy.assertSelfUniDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, attributeName);
+
+ editorProxy.assertSelfUniDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, attributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToManyUniDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testManyToManyBiDirRelationship(){
+ Utils.sayTestStarted("testManyToManyBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-Many bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to many");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "many to many");
+
+ editorProxy.assertBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, entity2, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertBiDirRelationIsDeleted(jpaDiagramEditor, entity1, entity2,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationship");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the inverse relationship attribute and
+ * assert that the relationship is converted from bidirectional to unidirectional "Many to Many"
+ * relationship. Delete also the owner attribute and assert that there is no connection anymore.
+ */
+ @Test
+ public void testManyToManyBiDirRelationshipRemoveInverseAttribute(){
+ Utils.sayTestStarted("testManyToManyBiDirRelationshipRemoveInverseAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-Many bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to many");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "many to many");
+
+ //delete the inverse attribute
+ SWTBotGefEditPart inverseAttr = jpaDiagramEditor.getEditPart(inverseAttributeName);
+ inverseAttr.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+
+ //assert that the connection still exists, but it is unidirectional now
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, false);
+ connection = entity1.sourceConnections().get(0);
+ rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.UNI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ assertEquals(ownerAttributeName, editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel));
+ assertNull(rel.getInverseAnnotatedAttribute());
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to many");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttr = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttr.click();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ assertNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationshipRemoveInverseAttribute");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional relationship (from entity1 to entity2).
+ * Assert that the relation attributes exists. Delete the owner relationship attributes and
+ * assert that the connection does not exists anymore. Assert that the inverse attribute still exists.
+ */
+ @Test
+ public void testManyToManyBiDirRelationshipRemoveOwnerAttribute(){
+ Utils.sayTestStarted("testManyToManyBiDirRelationshipRemoveOwnerAttribute");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+ SWTBotGefEditPart entity2 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 200, "Entity2");
+
+ //create Many-to-Many bidirectional relation from entity1 to entity2
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity2);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertConnectionIsCreated(jpaDiagramEditor, entity1, entity2, true);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to many");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "many to many");
+
+ //delete the owner attribute
+ SWTBotGefEditPart ownerAttrPart = jpaDiagramEditor.getEditPart(ownerAttributeName);
+ ownerAttrPart.select();
+ jpaDiagramEditor.clickContextMenu("Delete");
+ editorProxy.confirmDelete();
+ //assert that the connection does not exists anymore
+ assertTrue(entity1.sourceConnections().isEmpty());
+ assertTrue(entity2.targetConnections().isEmpty());
+ assertNull(jpaDiagramEditor.getEditPart(ownerAttributeName));
+ //assert that the inverse attribute still exists
+ assertNotNull(jpaDiagramEditor.getEditPart(inverseAttributeName));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, entity1, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ //assert that the inverse attribute still exists
+ assertTrue(editorProxy.isSectionVisible(jpaDiagramEditor, entity2, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testManyToManyBiDirRelationshipRemoveOwnerAttribute");
+ }
+
+ /**
+ * Creates a "Many to Many" bidirectional self relationship (from entity1 to entity1).
+ * Assert that the relation attributes exists. Delete the relationship and
+ * assert that the attributes do not exists anymore.
+ */
+ @Test
+ public void testSelfManyToManyBiDirRelationship(){
+ Utils.sayTestStarted("testSelfManyToManyBiDirRelationship");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ //create Many-to-Many bidirectional self relation from entity1 to entity1
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateManyToManyBiDirRelationFeature_manyToManyBiDirFeatureName, 1);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(entity1);
+ bot.waitUntil(new ConnectionIsShown(entity1));
+
+ editorProxy.waitASecond();
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertSelfConnectionIsCreated(jpaDiagramEditor, entity1);
+
+ SWTBotGefConnectionEditPart connection = entity1.sourceConnections().get(0);
+ IRelation rel = editorProxy.getConnection(jpaDiagramEditor, connection);
+ assertNotNull(rel);
+ assertEquals(IRelation.RelDir.BI, rel.getRelDir());
+ assertEquals(IRelation.RelType.MANY_TO_MANY, rel.getRelType());
+
+ String ownerAttributeName = editorProxy.testOwnerRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ String inverseAttributeName = editorProxy.testInverseRelationAttributeProperties(
+ jpaDiagramEditor, rel);
+
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, ownerAttributeName, "many to many");
+ editorProxy.assertAttributeIsCorretlyMapped(jpaDiagramEditor, inverseAttributeName, "many to many");
+
+ editorProxy.assertSelfBiDirRelationIsNotDeleted(jpaDiagramEditor,
+ entity1, connection, ownerAttributeName,
+ inverseAttributeName);
+
+ editorProxy.assertSelfBiDirRelationIsDeleted(jpaDiagramEditor, entity1,
+ connection, ownerAttributeName, inverseAttributeName);
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testSelfManyToManyBiDirRelationship");
+ }
+
+ /**
+ * Creates a new Inherited entity by entity. Assert that the inherited entity
+ * does not contain a primary key.
+ */
+ @Test
+ public void testInheritedEntityByEntity(){
+ Utils.sayTestFinished("testInheritedEntityByEntity");
+
+ SWTBotGefEditPart entity1 = editorProxy.addEntityToDiagram(jpaDiagramEditor, 50, 50, "Entity1");
+
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName);
+ jpaDiagramEditor.click(entity1);
+ jpaDiagramEditor.click(50, 200);
+
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "Entity2"));
+
+ SWTBotGefEditPart inheritedEntity = jpaDiagramEditor.getEditPart("Entity2");
+ assertNotNull(inheritedEntity);
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertIsARelationExists(jpaDiagramEditor, entity1, inheritedEntity);
+
+ SWTBotGefConnectionEditPart connection = entity1.targetConnections().get(0);
+ FreeFormConnection conn = (FreeFormConnection) connection.part().getModel();
+ assertTrue(IsARelation.isIsAConnection(conn));
+ IsARelation rel = editorProxy.getIsARelationship(jpaDiagramEditor);
+ assertNotNull(rel);
+
+ assertEquals(editorProxy.getEntityForElement(jpaDiagramEditor, inheritedEntity), rel.getSubclass());
+ assertEquals(editorProxy.getEntityForElement(jpaDiagramEditor, entity1), rel.getSuperclass());
+
+ editorProxy.assertTypeIsCorretlyMapped(jpaDiagramEditor, "Entity1", "entity");
+ editorProxy.assertTypeIsCorretlyMapped(jpaDiagramEditor, "Entity2", "entity");
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testInheritedEntityByEntity");
+ }
+
+ /**
+ * Creates a new Inherited entity by mapped superclass. Assert that the inherited entity
+ * contains a primary key.
+ */
+ @Test
+ public void testInheritedEntityByMappedSuperclass(){
+ Utils.sayTestStarted("testInheritedEntityByMappedSuperclass");
+
+ SWTBotGefEditPart mappedSuperclass = editorProxy.addMappedSuperclassToDiagram(jpaDiagramEditor, 50, 50, "MpdSuprcls1");
+
+ jpaDiagramEditor.activateTool(JPAEditorMessages.CreateJPAEntityFromMappedSuperclassFeature_createInheritedEntityFeatureName);
+ jpaDiagramEditor.click(mappedSuperclass);
+ jpaDiagramEditor.click(50, 200);
+
+ bot.waitUntil(new ElementIsShown(jpaDiagramEditor, "Entity1"));
+
+ SWTBotGefEditPart inheritedEntity = jpaDiagramEditor.getEditPart("Entity1");
+ assertNotNull(inheritedEntity);
+ assertTrue(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_primaryKeysShape));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_relationAttributesShapes));
+ assertFalse(editorProxy.isSectionVisible(jpaDiagramEditor, inheritedEntity, JPAEditorMessages.AddJPAEntityFeature_basicAttributesShapes));
+
+ jpaDiagramEditor.activateDefaultTool();
+
+ editorProxy.assertIsARelationExists(jpaDiagramEditor, mappedSuperclass, inheritedEntity);
+
+ SWTBotGefConnectionEditPart connection = mappedSuperclass.targetConnections().get(0);
+ FreeFormConnection conn = (FreeFormConnection) connection.part().getModel();
+ assertTrue(IsARelation.isIsAConnection(conn));
+ IsARelation rel = editorProxy.getIsARelationship(jpaDiagramEditor);
+ assertNotNull(rel);
+
+ assertEquals(editorProxy.getEntityForElement(jpaDiagramEditor, inheritedEntity), rel.getSubclass());
+ assertEquals(editorProxy.getEntityForElement(jpaDiagramEditor, mappedSuperclass), rel.getSuperclass());
+
+ editorProxy.assertTypeIsCorretlyMapped(jpaDiagramEditor, "MpdSuprcls1", "mapped superclass");
+ editorProxy.assertTypeIsCorretlyMapped(jpaDiagramEditor, "Entity1", "entity");
+
+ editorProxy.deleteDiagramElements(jpaDiagramEditor);
+
+ jpaDiagramEditor.save();
+
+ Utils.sayTestFinished("testInheritedEntityByMappedSuperclass");
+ }
+
+ /**
+ * Test that the JPA Diagram editor is opened when the context menu
+ * "JPA Tools -> Open Diagram" of the project is called.
+ */
+ @Test
+ public void testOpenDiagramOnProjectLevel(){
+ Utils.sayTestStarted("testOpenDiagramOnProjectLevel");
+
+ workbenchBot.closeAllEditors();
+ //open JPA diagram editor on project level: JPA Tools -> Open Diagram
+ SWTBotGefEditor diagramEditor = editorProxy.openDiagramOnJPAProjectNode(TEST_PROJECT);
+ diagramEditor.close();
+
+ Utils.sayTestFinished("testOpenDiagramOnProjectLevel");
+ }
+
+ /**
+ * Test that the JPA Diagram editor is opened when the context menu "Open Diagram"
+ * of the JPA content node is called.
+ */
+ @Test
+ public void testOpenDiagramOnJPAContentNodeLevel() {
+ Utils.sayTestStarted("testOpenDiagramOnJPAContentNodeLevel");
+
+ workbenchBot.closeAllEditors();
+ //open JPA diagram editor on JPA content level: Open Diagram
+ SWTBotGefEditor diagramEditor = editorProxy.openDiagramOnJPAContentNode(TEST_PROJECT);
+ diagramEditor.close();
+
+ Utils.sayTestFinished("testOpenDiagramOnJPAContentNodeLevel");
+ }
+}
diff --git a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/pom.xml b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/pom.xml index 3acda23ff8..821d9bf210 100644 --- a/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/pom.xml +++ b/jpa_diagram_editor/tests/org.eclipse.jpt.jpadiagrameditor.ui.tests/pom.xml @@ -1,42 +1,45 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId> - <groupId>org.eclipse.jpt.jpadiagrameditor</groupId> - <version>1.1.0-SNAPSHOT</version> - <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath> - </parent> - - <artifactId>org.eclipse.jpt.ui.diagrameditor.test</artifactId> - <packaging>eclipse-test-plugin</packaging> - <name>JPA Diagram Editor Test Plug-in</name> - - <build> - <plugins> - <plugin> - <groupId>org.sonatype.tycho</groupId> - <artifactId>maven-osgi-test-plugin</artifactId> - <version>${tycho-version}</version> - <configuration> - <testSuite>org.eclipse.jpt.jpadiagrameditor.tests</testSuite> - <testClass>org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.AllJpaEditorTests</testClass> - <useUIHarness>true</useUIHarness> - <useUIThread>true</useUIThread> - <argLine>-Xms128m -Xmx512m -XX:MaxPermSize=256m</argLine> - <product>org.eclipse.sdk.ide</product> - <application>org.eclipse.ui.ide.workbench</application> - <dependencies> - <dependency> - <type>p2-installable-unit</type> - <artifactId>org.eclipse.sdk.ide</artifactId> - <version>0.0.0</version> - </dependency> - </dependencies> - </configuration> - </plugin> - </plugins> - </build> - +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>org.eclipse.jpt.jpadiagrameditor_parent</artifactId>
+ <groupId>org.eclipse.jpt.jpadiagrameditor</groupId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../../development/org.eclipse.jpt.jpadiagrameditor.releng/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.jpt.jpadiagrameditor.ui.tests</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+ <name>JPA Diagram Editor Test Plug-in</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <!-- testSuite>org.eclipse.jpt.jpadiagrameditor.ui.tests</testSuite>
+ <testClass>org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.AllJpaEditorTests</testClass-->
+ <useUIHarness>true</useUIHarness>
+ <useUIThread>false</useUIThread>
+ <systemProperties combine.children="append">
+ <org.eclipse.jpt.jpa.jar>${org.eclipse.jpt.jpa.jar}</org.eclipse.jpt.jpa.jar>
+ </systemProperties>
+ <argLine>-Xms128m -Xmx512m -XX:MaxPermSize=256m</argLine>
+ <product>org.eclipse.sdk.ide</product>
+ <application>org.eclipse.ui.ide.workbench</application>
+ <dependencies>
+ <dependency>
+ <type>p2-installable-unit</type>
+ <artifactId>org.eclipse.sdk.ide</artifactId>
+ <version>0.0.0</version>
+ </dependency>
+ </dependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file |