Skip to content
This repository was archived by the owner on Mar 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bundles/cnf/releaserepo/index.xml.sha

This file was deleted.

22 changes: 11 additions & 11 deletions bundles/specmate-cause-effect-patterns/.classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
24 changes: 12 additions & 12 deletions bundles/specmate-integration-test/.classpath
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="bin_test" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="bin_test" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
WENN A=5 UND B=3 DANN C=7 ENDE-WENN
WENN A=5 UND X=9 DANN C=7 ENDE-WENN
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible to add multiline text to the test?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model generation does not work when special chars (e.g. [(*<)) or umlauts (ÄÖÜ etc.) are in the text
The model generation does not work when line breaks are in the text (see comment below)

Pelase fix and add tests

WENN X = Z ODER Y>4 DANN F="Test" ENDE-WENN
WENN A=1 DANN WENN B=1 DANN C=1 ENDE-WENN ENDE-WENN
WENN A=1 DANN B=1 SONST C=2 ENDE-WENN
WENN A=1 DANN B=1 SONST C=2 ENDE-WENN
WENN A=1 DANN WENN B=1 DANN C=1 SONST C=2 ENDE-WENN ENDE-WENN
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.json.JSONArray;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

import com.specmate.model.requirements.CEGModel;
import com.specmate.model.requirements.CEGNode;
import com.specmate.model.requirements.NodeType;
import com.specmate.model.requirements.RequirementsFactory;
import com.specmate.objectif.resolve.BusinessRuleUtil;
import com.specmate.objectif.resolve.rule.AndNode;
import com.specmate.objectif.resolve.rule.BusinessRuleNode;
Expand All @@ -18,95 +23,267 @@
import com.specmate.objectif.resolve.rule.OrNode;
import com.specmate.xtext.XTextException;

public class ObjectifTest {
// Two types of tests:
// 1) tests for checking the functionality of the xtext parsing
// 2) tests for checking the functionality of the pseudo code translator
public class ObjectifTest extends ModelGenerationTestBase {

public ObjectifTest() throws Exception {
super();
}

// Unit tests for the Xtext Parsing
@Test
public void testLoadRules() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
Assert.assertTrue(rules.size() == 4);
Assert.assertTrue(rules.size() == 5);
}

@Test
public void testAND() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
BusinessRuleNode rule = rules.get(0);
ObjectifNode cause = rule.getCause();
Assert.assertTrue(cause instanceof AndNode);
ObjectifNode causeA = ((AndNode)cause).getLeft();
ObjectifNode causeB = ((AndNode)cause).getRight();

ObjectifNode causeA = ((AndNode) cause).getLeft();
ObjectifNode causeB = ((AndNode) cause).getRight();
Assert.assertTrue(causeA instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)causeA).getContent().equals("A=5"));
Assert.assertTrue(((LiteralNode) causeA).getContent().equals("A=5"));
Assert.assertTrue(causeB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)causeB).getContent().equals("B=3"));
Assert.assertTrue(((LiteralNode) causeB).getContent().equals("X=9"));

ObjectifNode effect = rule.getEffect();
Assert.assertTrue(effect instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)effect).getContent().equals("C=7"));
Assert.assertTrue(((LiteralNode) effect).getContent().equals("C=7"));
}

@Test
public void testOR() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
BusinessRuleNode rule = rules.get(1);
ObjectifNode cause = rule.getCause();
Assert.assertTrue(cause instanceof OrNode);
ObjectifNode causeA = ((OrNode)cause).getLeft();
ObjectifNode causeB = ((OrNode)cause).getRight();

ObjectifNode causeA = ((OrNode) cause).getLeft();
ObjectifNode causeB = ((OrNode) cause).getRight();
Assert.assertTrue(causeA instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)causeA).getContent().equals("X = Z"));
Assert.assertTrue(((LiteralNode) causeA).getContent().equals("X = Z"));
Assert.assertTrue(causeB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)causeB).getContent().equals("Y>4"));
Assert.assertTrue(((LiteralNode) causeB).getContent().equals("Y>4"));

ObjectifNode effect = rule.getEffect();
Assert.assertTrue(effect instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)effect).getContent().equals("F=\"Test\""));
Assert.assertTrue(((LiteralNode) effect).getContent().equals("F=\"Test\""));
}

@Test
public void testNesting() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
BusinessRuleNode rule = rules.get(2);
ObjectifNode cause = rule.getCause();
Assert.assertTrue(cause instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)cause).getContent().equals("A=1"));
Assert.assertTrue(((LiteralNode) cause).getContent().equals("A=1"));

ObjectifNode effect = rule.getEffect();
Assert.assertTrue(effect instanceof BusinessRuleNode);
BusinessRuleNode ruleB = (BusinessRuleNode) effect;

BusinessRuleNode ruleB = (BusinessRuleNode) effect;

ObjectifNode causeB = ruleB.getCause();
Assert.assertTrue(causeB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)causeB).getContent().equals("B=1"));
Assert.assertTrue(((LiteralNode) causeB).getContent().equals("B=1"));

ObjectifNode effectB = ruleB.getEffect();
Assert.assertTrue(effectB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)effectB).getContent().equals("C=1"));
Assert.assertTrue(((LiteralNode) effectB).getContent().equals("C=1"));
}

@Test
public void testAlternative() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
BusinessRuleNode rule = rules.get(3);
ObjectifNode cause = rule.getCause();
Assert.assertTrue(cause instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)cause).getContent().equals("A=1"));
Assert.assertTrue(((LiteralNode) cause).getContent().equals("A=1"));
ObjectifNode effect = rule.getEffect();
Assert.assertTrue(effect instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)effect).getContent().equals("B=1"));
Assert.assertTrue(((LiteralNode) effect).getContent().equals("B=1"));

Assert.assertTrue(rule.hasAlternative());
ObjectifNode alternative = rule.getAlternative();
Assert.assertTrue(alternative instanceof LiteralNode);
Assert.assertTrue(((LiteralNode)alternative).getContent().equals("C=2"));
Assert.assertTrue(((LiteralNode) alternative).getContent().equals("C=2"));
}

@Test
public void testAlternativeCombinedWithNesting() throws URISyntaxException, XTextException {
List<BusinessRuleNode> rules = loadRules("/resources/test_rules.objectif");
BusinessRuleNode rule = rules.get(4);
ObjectifNode cause = rule.getCause();
Assert.assertTrue(cause instanceof LiteralNode);
Assert.assertTrue(((LiteralNode) cause).getContent().equals("A=1"));
ObjectifNode effect = rule.getEffect();
Assert.assertTrue(effect instanceof BusinessRuleNode);
BusinessRuleNode ruleB = (BusinessRuleNode) effect;

ObjectifNode causeB = ruleB.getCause();
Assert.assertTrue(causeB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode) causeB).getContent().equals("B=1"));

ObjectifNode effectB = ruleB.getEffect();
Assert.assertTrue(effectB instanceof LiteralNode);
Assert.assertTrue(((LiteralNode) effectB).getContent().equals("C=1"));

Assert.assertTrue(ruleB.hasAlternative());
ObjectifNode alternative = ruleB.getAlternative();
Assert.assertTrue(alternative instanceof LiteralNode);
Assert.assertTrue(((LiteralNode) alternative).getContent().equals("C=2"));

}

// Unit tests for the pseudo code translation
@Test
public void testModelGenerationSimplePseudoCode() {
String text = "WENN x DANN y ENDE-WENN";
RequirementsFactory f = RequirementsFactory.eINSTANCE;
CEGModel model = f.createCEGModel();
CEGNode node1 = createNode(model, "BR1", "is present", NodeType.OR);
CEGNode node2 = createNode(model, "x", "is present", null);
CEGNode node3 = createNode(model, "y", "is present", null);
createConnection(model, node1, node3, false);
createConnection(model, node2, node1, false);
JSONArray generated = generateCEGWithModelRequirementsText(text);
checkResultingModel(generated, model);
}

@Test
public void testModelGenerationPseudoCodeWithInterconnectedCauses() {
String text = "WENN x UND y UND z ODER w DANN effekt ENDE-WENN";
RequirementsFactory f = RequirementsFactory.eINSTANCE;
CEGModel model = f.createCEGModel();
CEGNode node1 = createNode(model, "BR1", "is present", NodeType.OR);
CEGNode node2 = createNode(model, "x", "is present", null);
CEGNode node3 = createNode(model, "y", "is present", null);
CEGNode node4 = createNode(model, "z", "is present", null);
CEGNode node5 = createNode(model, "w", "is present", null);
CEGNode node6 = createNode(model, "effekt", "is present", null);
CEGNode node7 = createNode(model, "Intermediate Node1", "is present", NodeType.AND);
createConnection(model, node2, node7, false);
createConnection(model, node3, node7, false);
createConnection(model, node4, node7, false);
createConnection(model, node5, node1, false);
createConnection(model, node7, node1, false);
createConnection(model, node1, node6, false);
JSONArray generated = generateCEGWithModelRequirementsText(text);
checkResultingModel(generated, model);
}

@Test
public void testModelGenerationPseudoCodeWithInterconnectedCausesAndSingleNesting() {
String text = "WENN x UND y UND z ODER w DANN WENN xB ODER yB DANN effekt ENDE-WENN ENDE-WENN";
RequirementsFactory f = RequirementsFactory.eINSTANCE;
CEGModel model = f.createCEGModel();
CEGNode node1 = createNode(model, "BR1", "is present", NodeType.OR);
CEGNode node2 = createNode(model, "x", "is present", null);
CEGNode node3 = createNode(model, "y", "is present", null);
CEGNode node4 = createNode(model, "z", "is present", null);
CEGNode node5 = createNode(model, "w", "is present", null);
CEGNode node7 = createNode(model, "Intermediate Node1", "is present", NodeType.AND);

CEGNode node8 = createNode(model, "BR2", "is present", NodeType.AND);
CEGNode node9 = createNode(model, "xB", "is present", null);
CEGNode node10 = createNode(model, "yB", "is present", null);
CEGNode node6 = createNode(model, "effekt", "is present", null);
CEGNode node11 = createNode(model, "Intermediate Node2", "is present", NodeType.OR);

createConnection(model, node2, node7, false);
createConnection(model, node3, node7, false);
createConnection(model, node4, node7, false);
createConnection(model, node5, node1, false);
createConnection(model, node7, node1, false);
createConnection(model, node1, node8, false);
createConnection(model, node9, node11, false);
createConnection(model, node10, node11, false);
createConnection(model, node11, node8, false);
createConnection(model, node8, node6, false);
JSONArray generated = generateCEGWithModelRequirementsText(text);
checkResultingModel(generated, model);
}

@Test
public void testModelGenerationPseudoCodeWithMultipleNesting() {
String text = "WENN x UND y DANN WENN xB ODER yB DANN WENN xC UND yC DANN effekt ENDE-WENN ENDE-WENN ENDE-WENN";
RequirementsFactory f = RequirementsFactory.eINSTANCE;
CEGModel model = f.createCEGModel();
CEGNode node1 = createNode(model, "BR1", "is present", NodeType.AND);
CEGNode node2 = createNode(model, "x", "is present", null);
CEGNode node3 = createNode(model, "y", "is present", null);

CEGNode node4 = createNode(model, "BR2", "is present", NodeType.AND);
CEGNode node5 = createNode(model, "xB", "is present", null);
CEGNode node6 = createNode(model, "yB", "is present", null);
CEGNode node7 = createNode(model, "Intermediate Node1", "is present", NodeType.OR);

CEGNode node8 = createNode(model, "BR3", "is present", NodeType.AND);
CEGNode node9 = createNode(model, "xC", "is present", null);
CEGNode node10 = createNode(model, "yC", "is present", null);
CEGNode node11 = createNode(model, "effekt", "is present", null);

createConnection(model, node2, node1, false);
createConnection(model, node3, node1, false);
createConnection(model, node1, node4, false);
createConnection(model, node5, node7, false);
createConnection(model, node6, node7, false);
createConnection(model, node7, node4, false);
createConnection(model, node4, node8, false);
createConnection(model, node9, node8, false);
createConnection(model, node10, node8, false);
createConnection(model, node8, node11, false);
JSONArray generated = generateCEGWithModelRequirementsText(text);
checkResultingModel(generated, model);
}

@Test
public void testModelGenerationPseudoCodeWithMultipleNestingAndAlternativeEffect() {
String text = "WENN x UND y DANN WENN xB ODER yB DANN WENN xC UND yC DANN effekt SONST aEffekt ENDE-WENN ENDE-WENN ENDE-WENN";
RequirementsFactory f = RequirementsFactory.eINSTANCE;
CEGModel model = f.createCEGModel();
CEGNode node1 = createNode(model, "BR1", "is present", NodeType.AND);
CEGNode node2 = createNode(model, "x", "is present", null);
CEGNode node3 = createNode(model, "y", "is present", null);

CEGNode node4 = createNode(model, "BR2", "is present", NodeType.AND);
CEGNode node5 = createNode(model, "xB", "is present", null);
CEGNode node6 = createNode(model, "yB", "is present", null);
CEGNode node7 = createNode(model, "Intermediate Node1", "is present", NodeType.OR);

CEGNode node8 = createNode(model, "BR3", "is present", NodeType.AND);
CEGNode node9 = createNode(model, "xC", "is present", null);
CEGNode node10 = createNode(model, "yC", "is present", null);
CEGNode node11 = createNode(model, "effekt", "is present", null);
CEGNode node12 = createNode(model, "aEffekt", "is present", null);

createConnection(model, node2, node1, false);
createConnection(model, node3, node1, false);
createConnection(model, node1, node4, false);
createConnection(model, node5, node7, false);
createConnection(model, node6, node7, false);
createConnection(model, node7, node4, false);
createConnection(model, node4, node8, false);
createConnection(model, node9, node8, false);
createConnection(model, node10, node8, false);
createConnection(model, node8, node11, false);
createConnection(model, node8, node12, true);
JSONArray generated = generateCEGWithModelRequirementsText(text);
checkResultingModel(generated, model);
}

private List<BusinessRuleNode> loadRules(String mainFile) throws URISyntaxException, XTextException {
URI main = getLocalFile(mainFile);
return new BusinessRuleUtil().loadXTextResources(main);
}

private URI getLocalFile(String fileName) throws URISyntaxException {
Bundle bundle = FrameworkUtil.getBundle(NLPServiceTest.class);
return URI.createURI(bundle.getResource(fileName).toURI().toString());
Expand Down
3 changes: 2 additions & 1 deletion bundles/specmate-model-generation/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
specmate-metrics;version=latest,\
specmate-cause-effect-patterns,\
specmate-config-api;version=latest,\
specmate-xtext;version=latest
specmate-xtext;version=latest,\
specmate-objectif
Private-Package: \
com.specmate.modelgeneration,\
com.specmate.modelgeneration.legacy
1 change: 1 addition & 0 deletions bundles/specmate-model-generation/generated/buildfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A:/specmate/bundles/specmate-model-generation/generated/specmate-model-generation.jar
Loading