c2.setName("42");
Rule rule = RuleModelFactory.eINSTANCE.createRule();
accessLayer.addElement(project, rule);
LogicCondition lc1 = RuleModelFactory.eINSTANCE.createLogicCondition();
accessLayer.addElement(project, lc1);
LogicCondition lc2 = RuleModelFactory.eINSTANCE.createLogicCondition();
accessLayer.addElement(project, lc2);
LogicCondition lc3 = RuleModelFactory.eINSTANCE.createLogicCondition();
accessLayer.addElement(project, lc3);
BaseCondition bc1 = RuleModelFactory.eINSTANCE.createBaseCondition();
accessLayer.addElement(project, bc1);
BaseCondition bc2 = RuleModelFactory.eINSTANCE.createBaseCondition();
accessLayer.addElement(project, bc2);
BaseCondition bc3 = RuleModelFactory.eINSTANCE.createBaseCondition();
accessLayer.addElement(project, bc3);
lc2.setType(LogicConditionType.NOT);
rule.setRuleID("TestRule");
rule.setConditions(lc1);
lc1.getBaseConditions().add(bc1);
lc1.getLogicConditions().add(lc2);
bc1.setSource("e1::name");
bc1.setTarget("e2::name");
bc2.setSource("e1::name");
bc2.setValue("test");
bc3.setSource("e1::name");
bc3.setValue("test2");
ElementDefinition e1 = RuleModelFactory.eINSTANCE.createElementDefinition();
ElementDefinition e2 = RuleModelFactory.eINSTANCE.createElementDefinition();
accessLayer.addElement(project, e1);
accessLayer.addElement(project, e2);
e1.setAlias("e1");
e2.setAlias("e2");
e1.setType("Concern");
e2.setType("Concern");
rule.getElements().add(e1);
rule.getElements().add(e2);
LinkType l1 = LinkModelFactory.eINSTANCE.createLinkType();
accessLayer.addElement(project, l1);
l1.setName("Test");
LinkType l2 = LinkModelFactory.eINSTANCE.createLinkType();
accessLayer.addElement(project, l2);
l2.setName("TestRelation");
ActionDefinition a1 = RuleModelFactory.eINSTANCE.createActionDefinition();
accessLayer.addElement(project, a1);
a1.setSourceElement("e1");
a1.setTargetElement("e2");
a1.setResultType("Test");
a1.setActionType(ActionType.CREATE_LINK);
rule.getActions().add(a1);
/*
* case 1:
*
* <and>
* e1.name = e2.name
* <not>
* e1.name = "test"
* </not>
* </and>
*/
lc2.getBaseConditions().add(bc2);
assertEquals(0, accessLayer.getElements(project, "TraceLink").size());
ruleEngine.applyRule(project, null, rule);
assertEquals(1, accessLayer.getElements(project, "TraceLink").size());
/*
* case 2:
*
* <and>
* e1.name = e2.name
* <not>
* <and>
* e1.name = "test"
* e1.name = "test2"
* </and>
* </not>
* </and>
*/
a1.setResultType("TestRelation");
lc2.getBaseConditions().clear();
lc2.getLogicConditions().add(lc3);
lc3.getBaseConditions().add(bc2);
lc3.getBaseConditions().add(bc3);
assertEquals(1, accessLayer.getElements(project, "TraceLink").size());
ruleEngine.applyRule(project, null, rule);
assertEquals(2, accessLayer.getElements(project, "TraceLink").size());
}