Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel StrĂ¼ber2020-06-27 06:30:19 +0000
committerDaniel StrĂ¼ber2020-06-27 06:30:19 +0000
commitca98f98fbb78d63ed91d562365607202be12b721 (patch)
treecd9c849799f7ab5ee3bee43d300c5ab51967053c /plugins
parent5ced9d34e4081dd8fc2d417319bf72d3247eda9b (diff)
downloadorg.eclipse.emft.henshin-ca98f98fbb78d63ed91d562365607202be12b721.tar.gz
org.eclipse.emft.henshin-ca98f98fbb78d63ed91d562365607202be12b721.tar.xz
org.eclipse.emft.henshin-ca98f98fbb78d63ed91d562365607202be12b721.zip
Deal with problematic new test cases for CompactAPI (2)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/matching/constraints/DomainSlot.java42
-rw-r--r--plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CModuleTests.java261
-rw-r--r--plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CNodeTests.java240
-rw-r--r--plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CRuleTests.java189
-rw-r--r--plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CUnitTests.java143
5 files changed, 836 insertions, 39 deletions
diff --git a/plugins/org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/matching/constraints/DomainSlot.java b/plugins/org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/matching/constraints/DomainSlot.java
index 3746d3436..c59b3af0a 100644
--- a/plugins/org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/matching/constraints/DomainSlot.java
+++ b/plugins/org.eclipse.emf.henshin.interpreter/src/org/eclipse/emf/henshin/interpreter/matching/constraints/DomainSlot.java
@@ -15,7 +15,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
@@ -148,9 +147,9 @@ public class DomainSlot {
return false;
}
- //if (!setValueAndLock()) {
- // return false;
- //}
+ if (!setValueAndLock()) {
+ return false;
+ }
// Check the variable?
if (!checkedVariables.contains(variable)) {
@@ -159,13 +158,6 @@ public class DomainSlot {
return false;
}
- //Check injective
- if(injective)
- {
- if(!checkInjective(variable, domainMap))
- return false;
- }
-
// Check the dangling constraints:
if (dangling) {
for (DanglingConstraint danglingConstraint : variable.danglingConstraints) {
@@ -221,34 +213,6 @@ public class DomainSlot {
return true;
}
-
- /**Check if matching of variables violates injective
- * @param variable
- * @param domainMap
- */
- private Boolean checkInjective(Variable variable, Map<Variable, DomainSlot> domainMap) {
-
- if(variable.name.isEmpty())
- return true;
-
- for (Entry<Variable, DomainSlot> entry : domainMap.entrySet()) {
- Variable checkDoaminVariable = entry.getKey();
- DomainSlot checkDomainSlot = entry.getValue();
- // If different variables have the same name
- if (checkDoaminVariable.name.equals(variable.name) && variable != checkDoaminVariable)
- // And the variables correspond to the same type
- if (checkDoaminVariable.typeConstraint.type == variable.typeConstraint.type) {
- // Compare whether their corresponding maps are consistent
- if (checkDomainSlot.initialized) {
- if (checkDomainSlot.value != domainMap.get(variable).value) {
- return false;
- }
- }
- }
- }
-
- return true;
- }
/**
* Removes the lock on this domain slot. If the domain contains additional
diff --git a/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CModuleTests.java b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CModuleTests.java
new file mode 100644
index 000000000..3a171ff4d
--- /dev/null
+++ b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CModuleTests.java
@@ -0,0 +1,261 @@
+package org.eclipse.emf.henshin.tests.compact;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.henshin.model.ConditionalUnit;
+import org.eclipse.emf.henshin.model.HenshinFactory;
+import org.eclipse.emf.henshin.model.IndependentUnit;
+import org.eclipse.emf.henshin.model.IteratedUnit;
+import org.eclipse.emf.henshin.model.Module;
+import org.eclipse.emf.henshin.model.PriorityUnit;
+import org.eclipse.emf.henshin.model.Rule;
+import org.eclipse.emf.henshin.model.SequentialUnit;
+import org.eclipse.emf.henshin.model.Unit;
+import org.eclipse.emf.henshin.model.compact.CModule;
+import org.eclipse.emf.henshin.model.compact.CRule;
+import org.eclipse.emf.henshin.model.compact.CUnit;
+import org.eclipse.emf.henshin.model.resource.HenshinResourceSet;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CModuleTests {
+
+ static String path;
+
+ static EPackage pack;
+ static HenshinResourceSet res;
+ static File moduleFile, moduleFile2;
+ static Rule r;
+ static Unit u;
+ static Module m;
+
+ CModule mod;
+
+ @Before
+ public void globalSetup() {
+ path = "src/org/eclipse/emf/henshin/tests/compact/";
+ res = new HenshinResourceSet(path);
+ pack = res.registerDynamicEPackages("bank.ecore").get(0);
+
+ moduleFile = new File("module.henshin");
+ if(moduleFile.exists()) {
+ moduleFile.delete();
+ }
+
+ moduleFile2 = new File(path+"test.henshin");
+ if(moduleFile2.exists()) {
+ moduleFile2.delete();
+ }
+
+ r = HenshinFactory.eINSTANCE.createRule("rule");
+
+ m = res.getModule("bank.henshin");
+
+ u = HenshinFactory.eINSTANCE.createLoopUnit();
+ u.setName("unit");
+ }
+
+ @Before
+ public void localSetup() {
+ mod = new CModule("module");
+ }
+
+
+ @Test
+ public void createModuleTest() {
+ mod = new CModule("module");
+ assertNotNull(mod);
+ assertEquals(mod.getModule().getName(),"module");
+ }
+
+ @Test
+ public void addImportTest() {
+ assertTrue(mod.getModule().getImports().isEmpty());
+ mod.addImport(pack);
+ assertEquals(mod.getModule().getImports().get(0),pack);
+ }
+
+ @Test
+ public void addImportFromFile() {
+ assertTrue(mod.getModule().getImports().isEmpty());
+ mod.addImportsFromFile(path+"bank.ecore");
+ assertTrue(!mod.getModule().getImports().isEmpty());
+ }
+
+ @Test
+ public void reuseModuleTest() {
+ mod = new CModule(m);
+ assertEquals(mod.getModule(),m);
+ }
+
+ @Test
+ public void loadModuleTest() {
+ mod = CModule.loadFromFile(path+"bank.henshin");
+ //.equals is not implemented for Module-Class. .toString is. Therefore the Strings are compared rather than the Modules themselves.
+ assertEquals(mod.getModule().toString(),m.toString());
+ }
+
+ @Test
+ public void saveTestWithName() {
+ mod = new CModule(m);
+ assertTrue(!moduleFile2.exists());
+ mod.save(path+"test");
+ assertTrue(moduleFile2.exists());
+ }
+
+ @Test
+ public void saveTestWithoutName() {
+ mod = new CModule(m);
+ mod.getModule().setName("module");
+ assertTrue(!moduleFile.exists());
+ mod.save();
+ assertTrue(moduleFile.exists());
+ }
+
+ @Test
+ public void addRuleTest() {
+ CRule c = mod.addRule(r);
+ assertTrue(!mod.getModule().getUnits().isEmpty());
+ assertNotNull(c);
+ assertNotNull(mod.getModule().getUnit("rule"));
+ assertNotNull(c.getUnit());
+ }
+
+ @Test
+ public void addUnitTest() {
+ CUnit cu = mod.addUnit(u);
+ assertTrue(mod.getModule().getUnits().contains(u));
+ assertNotNull(cu);
+ assertNotNull(cu.getUnit());
+ assertNotNull(mod.getModule().getUnit("unit"));
+ }
+
+ @Test
+ public void ruleCreationTest() {
+ CRule cr = mod.createRule("rule");
+ assertNotNull(cr);
+ assertNotNull(cr.getUnit());
+ assertTrue(mod.getModule().getUnits().contains(cr.getUnit()));
+ }
+
+ @Test
+ public void loopUnitCreationTest() {
+ CRule cr = mod.addRule(r);
+ mod.createLoop(cr);
+ assertTrue(mod.getModule().getUnits().size()==2);
+ assertNotNull(mod.getModule().getUnit("rule-Loop"));
+
+ }
+
+ @Test
+ public void iteratedUnitCreationTest() {
+ CRule cr = mod.addRule(r);
+ mod.createIteration(cr,"2");
+ assertTrue(mod.getModule().getUnits().size()==2);
+ assertNotNull(mod.getModule().getUnit("rule-Iteration"));
+ assertEquals(((IteratedUnit)mod.getModule().getUnit("rule-Iteration")).getIterations(),"2");
+ }
+
+ @Test
+ public void conditionalUnitCreationTestWithElse() {
+ CRule cr = mod.addRule(r);
+ mod.createConditional(cr,cr,cr,"conditional");
+ assertTrue(mod.getModule().getUnits().size()==2);
+ ConditionalUnit cu = (ConditionalUnit) mod.getModule().getUnit("conditional");
+ assertNotNull(cu);
+ assertEquals(cu.getIf(),r);
+ assertEquals(cu.getThen(),r);
+ assertEquals(cu.getElse(),r);
+ }
+
+ @Test
+ public void conditionalUnitCreationTestWithoutElse() {
+ CRule cr = mod.addRule(r);
+ mod.createConditional(cr,cr,null,"conditional");
+ assertTrue(mod.getModule().getUnits().size()==2);
+ ConditionalUnit cu = (ConditionalUnit) mod.getModule().getUnit("conditional");
+ assertNotNull(cu);
+ assertEquals(cu.getIf(),r);
+ assertEquals(cu.getThen(),r);
+ assertNull(cu.getElse());
+ }
+
+ @Test
+ public void priorityUnitCreationTest() {
+ CRule cr = mod.addRule(r);
+ assertNull(mod.getModule().getUnit("priority"));
+ mod.addToPriority(cr, "priority");
+ PriorityUnit pu = (PriorityUnit) mod.getModule().getUnit("priority");
+ assertNotNull(pu);
+ assertTrue(pu.getSubUnits().contains(cr.getUnit()));
+ }
+
+ @Test
+ public void priorityUnitAddTest() {
+ CRule cr = mod.addRule(r);
+ mod.addToPriority(cr, "priority");
+ assertNotNull(mod.getModule().getUnit("priority"));
+ assertEquals(mod.getModule().getUnit("priority").getSubUnits(false).size(),1);
+ mod.addToPriority(cr, "priority");
+ assertEquals(mod.getModule().getUnit("priority").getSubUnits(false).size(),2);
+ }
+
+ @Test
+ public void sequentialUnitCreationTest() {
+ CRule cr = mod.addRule(r);
+ assertNull(mod.getModule().getUnit("sequence"));
+ mod.addToSequence(cr, "sequence");
+ SequentialUnit su = (SequentialUnit) mod.getModule().getUnit("sequence");
+ assertNotNull(su);
+ assertTrue(su.getSubUnits().contains(cr.getUnit()));
+ }
+
+ @Test
+ public void sequentialUnitAddTest() {
+ CRule cr = mod.addRule(r);
+ mod.addToSequence(cr, "sequence");
+ assertNotNull(mod.getModule().getUnit("sequence"));
+ assertEquals(mod.getModule().getUnit("sequence").getSubUnits(false).size(),1);
+ mod.addToSequence(cr, "sequence");
+ assertEquals(mod.getModule().getUnit("sequence").getSubUnits(false).size(),2);
+ }
+
+ @Test
+ public void independentUnitCreationTest() {
+ CRule cr = mod.addRule(r);
+ assertNull(mod.getModule().getUnit("independent"));
+ mod.addToIndependent(cr, "independent");
+ IndependentUnit iu = (IndependentUnit) mod.getModule().getUnit("independent");
+ assertNotNull(iu);
+ assertTrue(iu.getSubUnits().contains(cr.getUnit()));
+ }
+
+ @Test
+ public void independentUnitAddTest() {
+ CRule cr = mod.addRule(r);
+ mod.addToIndependent(cr, "independent");
+ assertNotNull(mod.getModule().getUnit("independent"));
+ assertEquals(mod.getModule().getUnit("independent").getSubUnits(false).size(),1);
+ mod.addToIndependent(cr, "independent");
+ assertEquals(mod.getModule().getUnit("independent").getSubUnits(false).size(),2);
+ }
+
+
+ @Test
+ public void getAllCUnitsTest() {
+ mod = new CModule(m);
+ List<CUnit> list = mod.getAllCUnits();
+ assertEquals(list.size(),m.getUnits().size());
+ for(CUnit cu: list)
+ {
+ assertTrue(m.getUnits().contains(cu.getUnit()));
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CNodeTests.java b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CNodeTests.java
new file mode 100644
index 000000000..d302fcc4a
--- /dev/null
+++ b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CNodeTests.java
@@ -0,0 +1,240 @@
+package org.eclipse.emf.henshin.tests.compact;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.henshin.model.Action;
+import org.eclipse.emf.henshin.model.Attribute;
+import org.eclipse.emf.henshin.model.Edge;
+import org.eclipse.emf.henshin.model.Node;
+import org.eclipse.emf.henshin.model.compact.CModule;
+import org.eclipse.emf.henshin.model.compact.CNode;
+import org.eclipse.emf.henshin.model.compact.CRule;
+import org.eclipse.emf.henshin.model.resource.HenshinResourceSet;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CNodeTests {
+
+ static EClass account, bank;
+ static EReference ref;
+ static EAttribute att;
+ static String path;
+ static EPackage pack;
+
+ CRule rule;
+ CModule mod;
+ CNode node1, node2;
+
+ @BeforeClass
+ public static void globalSetUp() {
+ path = "src/org/eclipse/emf/henshin/tests/compact/";
+ HenshinResourceSet hrs = new HenshinResourceSet(path);
+ pack = hrs.registerDynamicEPackages("bank.ecore").get(0);
+ account = (EClass) pack.getEClassifier("Account");
+ bank = (EClass) pack.getEClassifier("Bank");
+ ref = bank.getEReferences().get(1);// accounts
+ att = account.getEAllAttributes().get(1);// credit
+ }
+
+ @Before
+ public void localSetUp() {
+ mod = new CModule("module");
+ mod.addImport(pack);
+ rule = mod.createRule("rule");
+ node1 = rule.createNode(bank);
+ node2 = rule.createNode(account);
+ }
+
+ @Test
+ public void canCreateEdgeTest() {
+ assertEquals(node1.canCreateEdge(node2, ref),
+ rule.getUnit().canCreateEdge(node1.getNode(), node2.getNode(), ref));
+ }
+
+ @Test
+ public void canCreateEdgeRefStringTest() {
+ assertEquals(node1.canCreateEdge(node2, "accounts"),
+ rule.getUnit().canCreateEdge(node1.getNode(), node2.getNode(), ref));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void canCreateEdgeWrongRefTest() {
+ node1.canCreateEdge(node2, "cheesecake");
+ }
+
+ @Test
+ public void createEdgeTest() {
+ node1.createEdge(node2, ref, new Action(Action.Type.PRESERVE));
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test
+ public void createEdgeDefaultActionTest() {
+ node1.createEdge(node2, ref);
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test
+ public void createEdgeDefaultActionStringRefTest() {
+ node1.createEdge(node2, "accounts");
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test
+ public void createEdgeStringRefTest() {
+ node1.createEdge(node2, "accounts", new Action(Action.Type.PRESERVE));
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test
+ public void createEdgeStringActionTest() {
+ node1.createEdge(node2, ref, "preserve");
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test
+ public void createEdgeAllStringsTest() {
+ node1.createEdge(node2, "accounts", "preserve");
+ Edge edge = rule.getUnit().getLhs().getEdges().get(0);
+ assertEquals(edge.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(edge.getSource(), node1.getNode());
+ assertEquals(edge.getTarget(), node2.getNode());
+ assertEquals(edge.getType(), ref);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createEdgeWrongActionTest1() {
+ node1.createEdge(node2, "accounts", "cheesecake");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createEdgeWrongActionTest2() {
+ node1.createEdge(node2, ref, "cheesecake");
+
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createEdgeFailTest() {
+ node1.createEdge(node2, "clients");
+ }
+
+ @Test
+ public void createAttributeTest() {
+ node2.createAttribute(att, "1000", new Action(Action.Type.PRESERVE));
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test
+ public void createAttributeDefaultActionTest() {
+ node2.createAttribute(att, "1000");
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), node2.getNode().getAction().getType());
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test
+ public void createAttributeStringAttTest() {
+ node2.createAttribute("credit", "1000", new Action(Action.Type.PRESERVE));
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test
+ public void createAttributeStringActionTest() {
+ node2.createAttribute(att, "1000", "preserve");
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test
+ public void createAttributeDefaultActionStringRefTest() {
+ node2.createAttribute("credit", "1000");
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), node2.getNode().getAction().getType());
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test
+ public void createAttributeAllStrings() {
+ node2.createAttribute("credit", "1000", "preserve");
+ Attribute attribute = node2.getNode().getAttributes().get(0);
+ assertEquals(attribute.getAction().getType(), Action.Type.PRESERVE);
+ assertEquals(attribute.getNode(), node2.getNode());
+ assertEquals(attribute.getType(), att);
+ assertEquals(attribute.getValue(), "1000");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createAttributeWrongActionTest1() {
+ node2.createAttribute("credit", "1000", "cheesecake");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createAttributeWrongActionTest2() {
+ node2.createAttribute(att, "1000", "cheesecake");
+ }
+
+ @Test
+ public void setAttributeResultTest() {
+ node2.createAttribute(att, "1000->2000", new Action(Action.Type.PRESERVE));
+ Node node = rule.getUnit().getMappings().getImage(node2.getNode(), rule.getUnit().getRhs());
+ assertEquals(node2.getNode().getAttribute(att).getValue(), "1000");
+ assertEquals(node.getAttribute(att).getValue(), "2000");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createAttributeWrongAttributeTest() {
+ node2.createAttribute("cheesecake", "1000", new Action(Action.Type.PRESERVE));
+ }
+
+ @Test
+ public void setNodeTest() {
+ node2.setNode(node1.getNode());
+ assertEquals(node1.getNode(), node2.getNode());
+ }
+
+ @Test
+ public void setNameTest() {
+ node1.setName("name");
+ assertEquals(node1.getNode().getName(), "name");
+ }
+}
diff --git a/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CRuleTests.java b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CRuleTests.java
new file mode 100644
index 000000000..75e6fe582
--- /dev/null
+++ b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CRuleTests.java
@@ -0,0 +1,189 @@
+package org.eclipse.emf.henshin.tests.compact;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.henshin.model.Action;
+import org.eclipse.emf.henshin.model.AttributeCondition;
+import org.eclipse.emf.henshin.model.HenshinFactory;
+import org.eclipse.emf.henshin.model.NestedCondition;
+import org.eclipse.emf.henshin.model.Not;
+import org.eclipse.emf.henshin.model.Or;
+import org.eclipse.emf.henshin.model.Rule;
+import org.eclipse.emf.henshin.model.compact.CModule;
+import org.eclipse.emf.henshin.model.compact.CNode;
+import org.eclipse.emf.henshin.model.compact.CRule;
+import org.eclipse.emf.henshin.model.compact.CUnit;
+import org.eclipse.emf.henshin.model.resource.HenshinResourceSet;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CRuleTests {
+
+ static EClass account;
+ static String path;
+ static EPackage pack;
+ CModule mod;
+ CRule rule;
+
+ @BeforeClass
+ public static void globalSetUp() {
+ path = "src/org/eclipse/emf/henshin/tests/compact/";
+ HenshinResourceSet hrs = new HenshinResourceSet(path);
+ pack = hrs.registerDynamicEPackages("bank.ecore").get(0);
+ account = (EClass) pack.getEClassifier("Account");
+ }
+
+ @Before
+ public void localSetUp() {
+ mod = new CModule("module");
+ mod.addImport(pack);
+ rule = mod.createRule("rule");
+ }
+
+ @Test
+ public void createNodeTest() {
+ CNode node = rule.createNode(account, new Action(Action.Type.PRESERVE));
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test
+ public void createNodeTestClassStringTest() {
+ CNode node = rule.createNode("Account", new Action(Action.Type.PRESERVE));
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test
+ public void createNodeTestActionStringTest() {
+ CNode node = rule.createNode(account, "preserve");
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test
+ public void createNodeAllStrings() {
+ CNode node = rule.createNode("Account", "preserve");
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test
+ public void createNodeDefaultActionTest() {
+ CNode node = rule.createNode(account);
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test
+ public void createNodeDefaultActionClassStringTest() {
+ CNode node = rule.createNode("Account");
+ assertTrue(!rule.getUnit().getLhs().getNodes().isEmpty());
+ assertEquals(node.getNode().getType(),account);
+ assertEquals(node.getNode().getAction().getType(),Action.Type.PRESERVE);
+ assertEquals(node.getNode().getGraph(), rule.getUnit().getLhs());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createNodeWrongActionStringTest1() {
+ rule.createNode(account, "cheesecake");
+ }
+
+
+ @Test(expected = RuntimeException.class)
+ public void createNodeWrongActionStringTest2() {
+ rule.createNode("Account", "cheesecake");
+ }
+
+
+ @Test
+ public void createNodeInMultiRuleTest() {
+ rule.createParameter("in", "param", EcorePackage.Literals.EINT);
+
+ CNode node = rule.createNode(account, "delete*/myMultiRule");
+ assertEquals(node.getNode().getAction().getPath()[0], "myMultiRule");
+ //Assert that ParameterKinds get fixed when MultiRule is used!
+ Rule multi = rule.getUnit().getMultiRule("myMultiRule");
+ assertEquals(rule.getUnit().getParameter("param").getKind(), multi.getParameter("param").getKind());
+ }
+
+ @Test
+ public void createNodeInNAC() {
+ CNode node = rule.createNode(account, "forbid#myNAC");
+ assertTrue(rule.getUnit().getLhs().getNAC("myNAC").getConclusion().getNodes().contains(node.getNode()));
+ }
+
+ @Test
+ public void createNodeInPAC() {
+ CNode node = rule.createNode(account, "require#myPAC");
+ assertTrue(rule.getUnit().getLhs().getPAC("myPAC").getConclusion().getNodes().contains(node.getNode()));
+ }
+
+ @Test
+ public void extractNACTest() {
+ rule.createNode(account, "forbid#myNAC");
+ Not n = rule.getNAC("myNAC");
+ assertEquals(n, ((Not)rule.getUnit().getLhs().getFormula()));
+ }
+
+ @Test
+ public void extractPACTest() {
+ rule.createNode(account, "require#myPAC");
+ NestedCondition n = rule.getPAC("myPAC");
+ assertEquals(n, rule.getUnit().getLhs().getFormula());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void extractNACNonExistentTest() {
+ rule.getNAC("myNAC");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void extractPACNonExistentTest() {
+ rule.getPAC("myPAC");
+ }
+
+ @Test
+ public void setFormulaTest() {
+ Or or = HenshinFactory.eINSTANCE.createOr();
+ rule.setPreConditionFormula(or);
+ assertEquals(rule.getUnit().getLhs().getFormula(), or);
+ }
+
+ @Test
+ public void createAttributeConditionTest() {
+ rule.createParameter("in", "param", EcorePackage.Literals.EINT);
+ rule.createAttributeCondition("cond", "param=100");
+ AttributeCondition cond = rule.getUnit().getAttributeConditions().get(0);
+ assertEquals(cond.getConditionText(), "param=100");
+ assertEquals(cond.getName(), "cond");
+ }
+
+ @Test
+ public void setUnitTest() {
+ CRule newRule = mod.createRule("newRule");
+ newRule.setUnit(rule.getUnit());
+ assertEquals(newRule.getUnit(), rule.getUnit());
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void setUnitTestNotARule() {
+ CUnit unit = mod.createLoop(rule);
+ rule.setUnit(unit.getUnit());
+ }
+}
diff --git a/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CUnitTests.java b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CUnitTests.java
new file mode 100644
index 000000000..7cbbf373d
--- /dev/null
+++ b/plugins/org.eclipse.emf.henshin.tests/src/org/eclipse/emf/henshin/tests/compact/CUnitTests.java
@@ -0,0 +1,143 @@
+package org.eclipse.emf.henshin.tests.compact;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.henshin.model.Parameter;
+import org.eclipse.emf.henshin.model.ParameterKind;
+import org.eclipse.emf.henshin.model.ParameterMapping;
+import org.eclipse.emf.henshin.model.compact.CModule;
+import org.eclipse.emf.henshin.model.compact.CRule;
+import org.eclipse.emf.henshin.model.compact.CUnit;
+import org.eclipse.emf.henshin.model.resource.HenshinResourceSet;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class CUnitTests {
+
+ static EClassifier account;
+ static String path;
+ static EPackage pack;
+ CModule mod, bank;
+ CUnit unit;
+ CRule rule;
+
+ @BeforeClass
+ public static void globalSetup() {
+ path = "src/org/eclipse/emf/henshin/tests/compact/";
+ HenshinResourceSet hrs = new HenshinResourceSet(path);
+ pack = hrs.registerDynamicEPackages("bank.ecore").get(0);
+ account = pack.getEClassifier("Account");
+
+ }
+
+ @Before
+ public void localSetup() {
+ mod = new CModule("module");
+ rule = mod.createRule("rule");
+ unit = mod.createLoop(rule);
+ }
+
+ @Test
+ public void createParameterTest() {
+ unit.createParameter(ParameterKind.IN, "param", EcorePackage.Literals.EINT);
+ Parameter par = unit.getUnit().getParameter("param");
+ assertNotNull(par);
+ assertEquals(par.getKind(), ParameterKind.IN);
+ assertEquals(par.getName(), "param");
+ assertEquals(par.getType(), EcorePackage.Literals.EINT);
+ }
+
+ @Test
+ public void createParameterWithStringKind() {
+ unit.createParameter("in", "param", EcorePackage.Literals.EINT);
+ Parameter par = unit.getUnit().getParameter("param");
+ assertNotNull(par);
+ assertEquals(par.getKind(), ParameterKind.IN);
+ assertEquals(par.getName(), "param");
+ assertEquals(par.getType(), EcorePackage.Literals.EINT);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createParameterWithWrongStringKind() {
+ unit.createParameter("cheesecake", "param", EcorePackage.Literals.EINT);
+ }
+
+ @Test
+ public void createParameterWithClassifierString() {
+ mod.addImport(pack);
+ rule.createParameter(ParameterKind.IN, "param", "Account");
+ Parameter par = rule.getUnit().getParameter("param");
+ assertEquals(par.getType(), account);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void createParameterWithWrongClassifierString() {
+ unit.createParameter(ParameterKind.IN, "param", "cheesecake");
+ }
+
+ @Test
+ public void createParameterAllStrings() {
+ mod.addImport(pack);
+ rule.createParameter("inout", "param", "Account");
+ Parameter par = rule.getUnit().getParameter("param");
+ assertNotNull(par);
+ assertEquals(par.getKind(), ParameterKind.INOUT);
+ assertEquals(par.getType(), account);
+ assertEquals(par.getName(), "param");
+ }
+
+ @Test
+ public void mapParameterTest() {
+ unit.createParameter("out", "param1", EcorePackage.Literals.EINT);
+ rule.createParameter("in", "param2", EcorePackage.Literals.EINT);
+ assertTrue(unit.getUnit().getParameterMappings().isEmpty());
+ unit.mapParameterToSubunit("param1", "rule", "param2");
+ assertTrue(!unit.getUnit().getParameterMappings().isEmpty());
+ EList<ParameterMapping> list = unit.getUnit().getParameterMappings();
+ ParameterMapping map = list.get(0);
+ assertEquals(map.getSource(), unit.getUnit().getParameter("param1"));
+ assertEquals(map.getTarget(), rule.getUnit().getParameter("param2"));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void mapParameterWrongUnitTest() {
+ unit.createParameter("out", "param1", EcorePackage.Literals.EINT);
+ rule.createParameter("in", "param2", EcorePackage.Literals.EINT);
+ unit.mapParameterToSubunit("param1", "cheesecake", "param2");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void mapParameterWrongParamTest1() {
+ unit.createParameter("out", "param1", EcorePackage.Literals.EINT);
+ rule.createParameter("in", "param2", EcorePackage.Literals.EINT);
+ unit.mapParameterToSubunit("cheesecake", "rule", "param2");
+ ;
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void mapParameterWrongParamTest2() {
+ unit.createParameter("out", "param1", EcorePackage.Literals.EINT);
+ rule.createParameter("in", "param2", EcorePackage.Literals.EINT);
+ unit.mapParameterToSubunit("param1", "rule", "cheesecake");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void mapParameterTypesNotEqualTest() {
+ unit.createParameter("out", "param1", EcorePackage.Literals.EINT);
+ rule.createParameter("in", "param2", EcorePackage.Literals.ESTRING);
+ unit.mapParameterToSubunit("param1", "rule", "param2");
+ }
+
+ @Test
+ public void setUnitTest() {
+ unit.setUnit(rule.getUnit());
+ assertEquals(unit.getUnit(), rule.getUnit());
+ }
+}

Back to the top