Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoratikhomirov2006-02-09 16:58:39 +0000
committeratikhomirov2006-02-09 16:58:39 +0000
commita94cb9fda2a519d63511538e6c456c6a343d13fe (patch)
treebdfaa31acc3e0587dc5ec256bc403a280f2dcefd /tests
parente4577c36068a09d20043194a8d5fcc102237bfc7 (diff)
downloadorg.eclipse.gmf-tooling-a94cb9fda2a519d63511538e6c456c6a343d13fe.tar.gz
org.eclipse.gmf-tooling-a94cb9fda2a519d63511538e6c456c6a343d13fe.tar.xz
org.eclipse.gmf-tooling-a94cb9fda2a519d63511538e6c456c6a343d13fe.zip
#116432 support domain models comprising of several packages
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/CompilationTest.java22
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/DiaGenSetup.java13
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiPackageGenSetup.java40
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiplePackagesDomainModelSetup.java147
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/TestSetupTest.java34
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSetup.java15
-rw-r--r--tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSource.java2
7 files changed, 259 insertions, 14 deletions
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/CompilationTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/CompilationTest.java
index 0c878d60c..5048f3be4 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/CompilationTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/gen/CompilationTest.java
@@ -12,15 +12,23 @@
package org.eclipse.gmf.tests.gen;
import java.io.IOException;
+import java.util.HashSet;
import junit.framework.TestCase;
import org.eclipse.emf.common.util.URI;
import org.eclipse.gmf.tests.Plugin;
+import org.eclipse.gmf.tests.setup.DiaDefSetup;
import org.eclipse.gmf.tests.setup.DiaGenFileSetup;
import org.eclipse.gmf.tests.setup.DiaGenSource;
+import org.eclipse.gmf.tests.setup.DomainModelSource;
import org.eclipse.gmf.tests.setup.GenProjectBaseSetup;
+import org.eclipse.gmf.tests.setup.MapDefSource;
+import org.eclipse.gmf.tests.setup.MapSetup;
+import org.eclipse.gmf.tests.setup.MultiPackageGenSetup;
+import org.eclipse.gmf.tests.setup.MultiplePackagesDomainModelSetup;
import org.eclipse.gmf.tests.setup.SessionSetup;
+import org.eclipse.gmf.tests.setup.ToolDefSetup;
public class CompilationTest extends TestCase {
@@ -50,6 +58,20 @@ public class CompilationTest extends TestCase {
}
}
+ public void testCompileMultiPackageDomain() throws Exception {
+ DomainModelSource ds = new MultiplePackagesDomainModelSetup().init();
+ MapDefSource ms = new MapSetup().init(new DiaDefSetup(null).init(), ds, new ToolDefSetup());
+
+ final HashSet additionalPacks = new HashSet(8);
+ additionalPacks.add(ds.getNodeA().getEClass().getEPackage());
+ additionalPacks.add(ds.getNodeB().getEClass().getEPackage());
+ additionalPacks.add(ds.getLinkAsClass().getEClass().getEPackage());
+
+ DiaGenSource gmfGenSource = new MultiPackageGenSetup(additionalPacks).init(ms);
+
+ new GenProjectBaseSetup().generateAndCompile(SessionSetup.getRuntimeWorkspaceSetup(), gmfGenSource);
+ }
+
protected void tearDown() throws Exception {
super.tearDown();
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/DiaGenSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/DiaGenSetup.java
index c600e8c02..9ca1ef68e 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/DiaGenSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/DiaGenSetup.java
@@ -19,6 +19,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.gmf.bridge.genmodel.BasicDiagramRunTimeModelHelper;
import org.eclipse.gmf.bridge.genmodel.BasicGenModelAccess;
@@ -150,10 +151,7 @@ public class DiaGenSetup implements DiaGenSource {
final CollectingDispenser uniquenessDispenser = new CollectingDispenser();
final GenModelNamingMediatorImpl namingMediator = new GenModelNamingMediatorImpl(uniquenessDispenser);
DiagramGenModelTransformer t = new DiagramGenModelTransformer(drth, namingMediator);
- BasicGenModelAccess gma = new BasicGenModelAccess(mapSource.getCanvas().getDomainModel());
- IStatus gmaStatus = gma.createDummy();
- Assert.assertTrue("Need (fake) genModel for transformation to work", gmaStatus.isOK());
- t.setEMFGenModel(gma.model());
+ t.setEMFGenModel(initGenModel(mapSource.getCanvas().getDomainModel()));
t.transform(mapSource.getMapping());
myGenDiagram = t.getResult().getDiagram();
uniquenessDispenser.forget();
@@ -187,6 +185,13 @@ public class DiaGenSetup implements DiaGenSource {
return this;
}
+ protected GenModel initGenModel(EPackage domainModel) {
+ BasicGenModelAccess gma = new BasicGenModelAccess(domainModel);
+ IStatus gmaStatus = gma.createDummy();
+ Assert.assertTrue("Need (fake) genModel for transformation to work", gmaStatus.isOK());
+ return gma.model();
+ }
+
private void confineInResource() {
new ResourceImpl(URI.createURI("uri://org.eclipse.gmf/tests/DiaGenSetup")).getContents().add(myGenDiagram.getEditorGen());
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiPackageGenSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiPackageGenSetup.java
new file mode 100644
index 000000000..e301a7a58
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiPackageGenSetup.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.setup;
+
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.gmf.bridge.genmodel.BasicGenModelAccess;
+
+/**
+ * @author artem
+ */
+public class MultiPackageGenSetup extends DiaGenSetup {
+
+ private final Collection myDomainPackages;
+
+ public MultiPackageGenSetup(Collection domainPackages) {
+ myDomainPackages = domainPackages;
+ }
+
+ protected GenModel initGenModel(EPackage domainModel) {
+ BasicGenModelAccess gma = new BasicGenModelAccess(domainModel);
+ IStatus gmaStatus = gma.createDummy(true, myDomainPackages);
+ Assert.assertTrue("Need (fake) genModel for transformation to work", gmaStatus.isOK());
+ return gma.model();
+ }
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiplePackagesDomainModelSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiplePackagesDomainModelSetup.java
new file mode 100644
index 000000000..64fb25838
--- /dev/null
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/MultiplePackagesDomainModelSetup.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * 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:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.tests.setup;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
+
+/**
+ * TODO separate setup for case with subpackages
+ * @author artem
+ */
+public class MultiplePackagesDomainModelSetup implements DomainModelSource {
+ private EPackage myPrimaryPackage;
+ private NodeData myNodeFirstPackage;
+ private NodeData myNodeSecondPackage;
+ private EClass myDiagramElement;
+ private LinkData myLinkThirdPackage;
+ private EReference myLinkFromFirstToSecond;
+
+ public MultiplePackagesDomainModelSetup() {
+ }
+
+ public MultiplePackagesDomainModelSetup init() {
+ myPrimaryPackage = createPackage("prim");
+ final EClass iElement = createEClass("IElement", null, false, true);
+ myPrimaryPackage.getEClassifiers().add(iElement);
+ final EClass iDiagramContainer = createEClass("IDiagramContainer", null, true, false);
+ final EReference cr = createERef("all", true, iElement);
+ iDiagramContainer.getEStructuralFeatures().add(cr);
+ myPrimaryPackage.getEClassifiers().add(iDiagramContainer);
+
+ final EPackage p2 = createPackage("first");
+ final EClass node1 = createEClass("Node1", iElement);
+ p2.getEClassifiers().add(node1);
+
+ final EPackage p3 = createPackage("second");
+ final EClass node2 = createEClass("Node2", iElement);
+ p3.getEClassifiers().add(node2);
+
+ final EPackage p4 = createPackage("third");
+ final EClass link = createEClass("Link", null);
+ final EReference target = createERef("targetToN1", false, node1);
+ link.getEStructuralFeatures().add(target);
+ final EClass someShitToContain = createEClass("SomeShitToContain", null, false, true);
+ final EClass diagramContainerImpl = createEClass("DiagramContainerImpl", iDiagramContainer, false, false);
+ p4.getEClassifiers().add(link);
+ p4.getEClassifiers().add(someShitToContain);
+ p4.getEClassifiers().add(diagramContainerImpl);
+
+ final EReference linkCont = createERef("links", true, link);
+ node2.getEStructuralFeatures().add(linkCont);
+ node1.getEStructuralFeatures().add(createERef("someShit", true, someShitToContain));
+ final EReference lnkNode2 = createERef("lnkNode2", false, node2);
+ node1.getEStructuralFeatures().add(lnkNode2);
+
+ // make sure p1 references p4 - just for fun
+ iDiagramContainer.getEStructuralFeatures().add(createERef("anotherShit", true, someShitToContain));
+
+ // init fields
+ myNodeFirstPackage = new NodeData(node1, null, cr);
+ myNodeSecondPackage = new NodeData(node2, null, cr);
+ myLinkFromFirstToSecond = lnkNode2;
+ myLinkThirdPackage = new LinkData(link, target, linkCont);
+ myDiagramElement = iDiagramContainer;
+
+ confineInResource("r1", Collections.singletonList(myPrimaryPackage));
+ confineInResource("r2", Arrays.asList(new Object[] {p2, p3, p4}));
+
+ return this;
+ }
+
+ private static EClass createEClass(String name, EClass superClass) {
+ return createEClass(name, superClass, false, false);
+ }
+
+ private static EClass createEClass(String name, EClass superClass, boolean isA, boolean isI) {
+ EClass rv = EcoreFactory.eINSTANCE.createEClass();
+ rv.setInterface(isI);
+ rv.setAbstract(isA);
+ rv.setName(name);
+ if (superClass != null) {
+ rv.getESuperTypes().add(superClass);
+ }
+ return rv;
+ }
+
+ private static EPackage createPackage(String name) {
+ EPackage p = EcoreFactory.eINSTANCE.createEPackage();
+ p.setName(name);
+ p.setNsPrefix("ns" + name);
+ p.setNsURI("uri:/gmf/tests/multi/" + name);
+ return p;
+ }
+
+ private static EReference createERef(String name, boolean isCont, EClass toContain) {
+ EReference cr = EcoreFactory.eINSTANCE.createEReference();
+ cr.setContainment(isCont);
+ cr.setName(name);
+ cr.setEType(toContain);
+ return cr;
+ }
+
+ private void confineInResource(String name, List toConfine) {
+ new ResourceImpl(URI.createURI("uri://org.eclipse.gmf/tests/MultiPackSetup/" + name)).getContents().addAll(toConfine);
+ }
+
+ public EPackage getModel() {
+ return myPrimaryPackage;
+ }
+
+ public NodeData getNodeA() {
+ return myNodeSecondPackage;
+ }
+
+ public NodeData getNodeB() {
+ return myNodeFirstPackage;
+ }
+
+ public LinkData getLinkAsClass() {
+ return myLinkThirdPackage;
+ }
+
+ public EReference getLinkAsRef() {
+ return myLinkFromFirstToSecond;
+ }
+
+ public EClass getDiagramElement() {
+ return myDiagramElement;
+ }
+}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/TestSetupTest.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/TestSetupTest.java
index 085517593..be90e2a8d 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/TestSetupTest.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/TestSetupTest.java
@@ -12,11 +12,13 @@
package org.eclipse.gmf.tests.setup;
import java.io.IOException;
+import java.util.HashSet;
import java.util.Iterator;
import junit.framework.TestCase;
import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.gmf.gmfgraph.Canvas;
import org.eclipse.gmf.gmfgraph.Connection;
@@ -89,11 +91,25 @@ public class TestSetupTest extends TestCase {
public void testDomainModelSetup() {
DomainModelSetup s = new DomainModelSetup().init();
- doAssert(Diagnostician.INSTANCE.validate(s.getDiagramElement()));
- doAssert(Diagnostician.INSTANCE.validate(s.getNodeA().getEClass()));
- doAssert(Diagnostician.INSTANCE.validate(s.getLinkAsRef()));
- doAssert(Diagnostician.INSTANCE.validate(s.getLinkAsClass().getEClass()));
- doAssert(Diagnostician.INSTANCE.validate(s.getModel()));
+ doDomainSourceTests(s);
+ }
+
+ public void testMultiPackageSetup() throws Exception {
+ DomainModelSource s = new MultiplePackagesDomainModelSetup().init();
+ doDomainSourceTests(s);
+ final HashSet additionalPacks = new HashSet(8);
+ additionalPacks.add(s.getNodeA().getEClass().getEPackage());
+ additionalPacks.add(s.getNodeB().getEClass().getEPackage());
+ additionalPacks.add(s.getLinkAsClass().getEClass().getEPackage());
+
+ DiaDefSource gmfGraph = new DiaDefFileSetup().init(Assistant.getBasicGraphDef());
+ ToolDefSource toolDef = new ToolDefSetup();
+ MapDefSource mapSource = new MapSetup().init(gmfGraph, s, toolDef);
+ final Resource resource = s.getModel().eResource();
+ resource.getContents().add(mapSource.getMapping());
+ resource.getContents().add(toolDef.getRegistry());
+ doAssert("Map", Diagnostician.INSTANCE.validate(mapSource.getCanvas()));
+ doDiaGenTests(new MultiPackageGenSetup(additionalPacks).init(mapSource));
}
public void testDiaGenSetupDM() {
@@ -119,6 +135,14 @@ public class TestSetupTest extends TestCase {
doAssert("GenDiagram", d);
}
+ private static void doDomainSourceTests(DomainModelSource s) {
+ doAssert(Diagnostician.INSTANCE.validate(s.getDiagramElement()));
+ doAssert(Diagnostician.INSTANCE.validate(s.getNodeA().getEClass()));
+ doAssert(Diagnostician.INSTANCE.validate(s.getLinkAsRef()));
+ doAssert(Diagnostician.INSTANCE.validate(s.getLinkAsClass().getEClass()));
+ doAssert(Diagnostician.INSTANCE.validate(s.getModel()));
+ }
+
private static void doAssert(Diagnostic d) {
doAssert("", d);
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSetup.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSetup.java
index 2bffdd7ce..46381af0c 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSetup.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSetup.java
@@ -32,6 +32,7 @@ public class ToolDefSetup implements ToolDefSource {
private final ContextMenu myNodeMenu;
private final AbstractTool myNodeTool;
private final AbstractTool myLinkTool;
+ private ToolRegistry myRegistry;
public ToolDefSetup() {
myMainMenu = GMFToolFactory.eINSTANCE.createMainMenu();
@@ -59,11 +60,11 @@ public class ToolDefSetup implements ToolDefSource {
p.getTools().add(myNodeTool);
p.getTools().add(myLinkTool);
- ToolRegistry registry = GMFToolFactory.eINSTANCE.createToolRegistry();
- registry.getSharedActions().add(shared);
- registry.getAllMenus().add(myMainMenu);
- registry.getAllMenus().add(myNodeMenu);
- registry.setPalette(p);
+ myRegistry = GMFToolFactory.eINSTANCE.createToolRegistry();
+ myRegistry.getSharedActions().add(shared);
+ myRegistry.getAllMenus().add(myMainMenu);
+ myRegistry.getAllMenus().add(myNodeMenu);
+ myRegistry.setPalette(p);
}
private CreationTool createTool(String title) {
@@ -83,6 +84,10 @@ public class ToolDefSetup implements ToolDefSource {
return a;
}
+ public ToolRegistry getRegistry() {
+ return myRegistry;
+ }
+
public MainMenu getMainMenu() {
return myMainMenu;
}
diff --git a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSource.java b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSource.java
index 389baedfc..f8d6e16b4 100644
--- a/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSource.java
+++ b/tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/setup/ToolDefSource.java
@@ -15,6 +15,7 @@ import org.eclipse.gmf.tooldef.AbstractTool;
import org.eclipse.gmf.tooldef.ContextMenu;
import org.eclipse.gmf.tooldef.MainMenu;
import org.eclipse.gmf.tooldef.Palette;
+import org.eclipse.gmf.tooldef.ToolRegistry;
/**
* @author artem
@@ -22,6 +23,7 @@ import org.eclipse.gmf.tooldef.Palette;
*/
public interface ToolDefSource {
+ ToolRegistry getRegistry();
MainMenu getMainMenu();
ContextMenu getNodeContextMenu();
AbstractTool getNodeCreationTool();

Back to the top