Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-01-31 07:30:46 -0500
committerHenrik Rentz-Reichert2011-01-31 07:30:46 -0500
commit50fa074d9582238432b06143eb2783ff7e2cc119 (patch)
treee9fb3394db1066ac236c49b5b16f5ffb54dc2b13 /tests
parentbb22ea7289144d47eb128e3335e8d0d6e1a00c4f (diff)
downloadorg.eclipse.etrice-50fa074d9582238432b06143eb2783ff7e2cc119.tar.gz
org.eclipse.etrice-50fa074d9582238432b06143eb2783ff7e2cc119.tar.xz
org.eclipse.etrice-50fa074d9582238432b06143eb2783ff7e2cc119.zip
ui.structure.tests: test with inheritance
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/.project62
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/models/ActorClass.room2
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithBindings.room2
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithInheritance.room57
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithReferences.room2
-rw-r--r--tests/org.eclipse.etrice.ui.structure.tests/src/org/eclipse/etrice/ui/structure/commands/TestActorClassWithInheritance.java167
6 files changed, 261 insertions, 31 deletions
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/.project b/tests/org.eclipse.etrice.ui.structure.tests/.project
index aa27fa17a..91db75bd0 100644
--- a/tests/org.eclipse.etrice.ui.structure.tests/.project
+++ b/tests/org.eclipse.etrice.ui.structure.tests/.project
@@ -1,28 +1,34 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.etrice.ui.structure.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>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.etrice.ui.structure.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>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClass.room b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClass.room
index 6a22f2385..7817b1301 100644
--- a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClass.room
+++ b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClass.room
@@ -1,4 +1,4 @@
-RoomModel ActorClass {
+RoomModel ^ActorClass {
ActorClass MyActorClass {
}
}
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithBindings.room b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithBindings.room
index 9eae5ec6c..7ce1473c7 100644
--- a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithBindings.room
+++ b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithBindings.room
@@ -1,4 +1,4 @@
-RoomModel ActorClassWithPorts {
+RoomModel ActorClassWithBindings {
ProtocolClass MyProtocol {
incoming {
Message in1 ()
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithInheritance.room b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithInheritance.room
new file mode 100644
index 000000000..60d214912
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithInheritance.room
@@ -0,0 +1,57 @@
+RoomModel ActorClassWithInheritance {
+ ProtocolClass MyProtocol {
+ incoming {
+ Message in1 ()
+ Message in2 ()
+ }
+ outgoing {
+ Message out1 ()
+ }
+ }
+
+ ProtocolClass MyControl {
+ incoming {
+ Message in1 ()
+ }
+ outgoing {
+ Message out1 ()
+ }
+ }
+
+ ActorClass SubActor {
+ Interface {
+ Port fct: MyProtocol
+ Port ctl: MyControl
+ }
+ }
+
+ ActorClass MyBaseClass {
+ Interface {
+ Port ip : MyProtocol
+ }
+ Structure {
+ ActorRef sub_a : SubActor
+
+ Binding ip and sub_a.fct
+ }
+ }
+
+ ActorClass MyActorClass extends MyBaseClass {
+ Interface {
+ Port p : MyProtocol
+ }
+ Structure {
+ conjugated Port ctl : MyControl
+ conjugated Port sp1 : MyProtocol
+ conjugated Port sp2 : MyProtocol
+ external Port p
+
+ ActorRef sub_b : SubActor
+ ActorRef sub_c : SubActor
+
+ Binding ctl and sub_a.ctl
+ Binding sp1 and sub_b.fct
+ Binding sp2 and sub_c.fct
+ }
+ }
+}
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithReferences.room b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithReferences.room
index 5640ecb27..e94bda656 100644
--- a/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithReferences.room
+++ b/tests/org.eclipse.etrice.ui.structure.tests/models/ActorClassWithReferences.room
@@ -1,4 +1,4 @@
-RoomModel ActorClassWithPorts {
+RoomModel ActorClassWithReferences {
ProtocolClass MyProtocol {
incoming {
Message in1 ()
diff --git a/tests/org.eclipse.etrice.ui.structure.tests/src/org/eclipse/etrice/ui/structure/commands/TestActorClassWithInheritance.java b/tests/org.eclipse.etrice.ui.structure.tests/src/org/eclipse/etrice/ui/structure/commands/TestActorClassWithInheritance.java
new file mode 100644
index 000000000..876a41498
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.structure.tests/src/org/eclipse/etrice/ui/structure/commands/TestActorClassWithInheritance.java
@@ -0,0 +1,167 @@
+package org.eclipse.etrice.ui.structure.commands;
+
+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 java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.Binding;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
+import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
+import org.eclipse.etrice.ui.structure.support.BindingSupport;
+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
+import org.eclipse.graphiti.mm.algorithms.Rectangle;
+import org.eclipse.graphiti.mm.algorithms.Text;
+import org.eclipse.graphiti.mm.algorithms.styles.Color;
+import org.eclipse.graphiti.mm.pictograms.Connection;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.PictogramElement;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.eclipse.graphiti.util.IColorConstant;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestActorClassWithInheritance extends TestBase {
+
+ private ActorClass ac = null;
+
+ @Before
+ public void setUp() {
+ loadModelFile();
+
+ assertEquals("models read", 1, getModels().size());
+ assertEquals("actor classes in our model", 3, getModels().get(0).getActorClasses().size());
+
+ for (ActorClass a : getModels().get(0).getActorClasses()) {
+ if (a.getName().equals("MyActorClass")) {
+ ac = a;
+ break;
+ }
+ }
+ assertNotNull("ActorClass expected", ac);
+ }
+
+ @After
+ public void tearDown() {
+ removeDiagramsDirectory();
+ }
+
+ @Override
+ protected String getModelFileName() {
+ return "ActorClassWithInheritance.room";
+ }
+
+ private boolean isEqual(Color c, IColorConstant cc) {
+ if (c.getRed()!=cc.getRed())
+ return false;
+ if (c.getGreen()!=cc.getGreen())
+ return false;
+ if (c.getBlue()!=cc.getBlue())
+ return false;
+ return true;
+ }
+
+ @Test
+ public void checkReferences() {
+ Diagram diagram = DiagramAccess.getDiagram(ac);
+ ContainerShape shape = (ContainerShape) diagram.getChildren().get(0);
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
+ assertTrue("bo is ActorClass", bo instanceof ActorClass);
+
+ // re-assign this because the old Java object is another instance since it comes from another resource
+ ac = (ActorClass) bo;
+
+ assertEquals("actor class child shapes", 8, shape.getChildren().size());
+
+ int nRefs = 0;
+ for (Shape childShape : shape.getChildren()) {
+ EObject[] bos = Graphiti.getLinkService()
+ .getAllBusinessObjectsForLinkedPictogramElement(childShape);
+ assertEquals("business objects", 1, bos.length);
+ if (!(bos[0] instanceof Port)) {
+ assertTrue("bo is actor ref", bos[0] instanceof ActorRef);
+ nRefs++;
+
+ ActorRef ar = (ActorRef) bos[0];
+ boolean inherited = (ar.eContainer()!=ac);
+
+ assertNotNull("ga is there (invisible rectangle)", childShape.getGraphicsAlgorithm());
+ assertTrue("ga is invisible rectangle", childShape.getGraphicsAlgorithm() instanceof Rectangle);
+ assertFalse("ga is invisible", childShape.getGraphicsAlgorithm().getFilled());
+ assertFalse("ga is invisible", childShape.getGraphicsAlgorithm().getLineVisible());
+ assertEquals("border rect", 1, childShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().size());
+ GraphicsAlgorithm borderRect = childShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
+ if (inherited)
+ assertTrue("border rect background", isEqual(borderRect.getForeground(), ActorContainerRefSupport.INHERITED_COLOR));
+ else
+ assertTrue("border rect background", isEqual(borderRect.getForeground(), ActorContainerRefSupport.LINE_COLOR));
+
+ // ports of actor refs
+ assertEquals("grand child shapes", 3, ((ContainerShape)childShape).getChildren().size());
+ for (Shape grandChildShape : ((ContainerShape)childShape).getChildren()) {
+ // skip the actor ref label
+ if (grandChildShape.getGraphicsAlgorithm() instanceof Text)
+ continue;
+
+ bos = Graphiti.getLinkService()
+ .getAllBusinessObjectsForLinkedPictogramElement(grandChildShape);
+ assertEquals("business objects", 1, bos.length);
+ assertTrue("bo is port", bos[0] instanceof Port);
+ }
+ }
+ }
+ assertEquals("number of actor references", 3, nRefs);
+ }
+
+ @Test
+ public void checkBindings() {
+ Diagram diagram = DiagramAccess.getDiagram(ac);
+ ContainerShape shape = (ContainerShape) diagram.getChildren().get(0);
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
+ assertTrue("bo is ActorClass", bo instanceof ActorClass);
+
+ // re-assign this because the old Java object is another instance since it comes from another resource
+ ac = (ActorClass) bo;
+
+ assertEquals("bindings", 4, diagram.getConnections().size());
+
+ for (Connection conn : diagram.getConnections()) {
+ EObject[] bos = Graphiti.getLinkService().getAllBusinessObjectsForLinkedPictogramElement(conn);
+ assertEquals("business objects", 1, bos.length);
+ assertTrue("binding", bos[0] instanceof Binding);
+
+ Binding b = (Binding) bos[0];
+ boolean inherited = (b.eContainer()!=ac);
+
+ if (inherited)
+ assertTrue("border rect background", isEqual(conn.getGraphicsAlgorithm().getForeground(), BindingSupport.INHERITED_COLOR));
+ else
+ assertTrue("border rect background", isEqual(conn.getGraphicsAlgorithm().getForeground(), BindingSupport.LINE_COLOR));
+
+ // the first port is part of the only MyActor instance
+ List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, b.getEndpoint1().getPort());
+ assertEquals("instances of first port", 1, pes.size());
+
+ // the second port is part of SubActor which has three instances
+ pes = Graphiti.getLinkService().getPictogramElements(diagram, b.getEndpoint2().getPort());
+ assertEquals("instances of second port", 3, pes.size());
+ assertNull("first ref", b.getEndpoint1().getActorRef());
+
+ // the second ref is represented once in the diagram
+ assertNotNull("second ref", b.getEndpoint2().getActorRef());
+ pes = Graphiti.getLinkService().getPictogramElements(diagram, ((ActorRef)b.getEndpoint2().getActorRef()));
+ assertEquals("instances of second ref", 1, pes.size());
+ }
+ }
+
+}

Back to the top