use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class BasicGraphTest method testLoop.
@Test
public void testLoop() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + " $p : Person(name == \"Mario\")\n" + "then\n" + " modify($p) { setAge( 18 ) };" + "end\n" + "rule R2 when\n" + " $p : Person(age > 10)\n" + "then\n" + " modify($p) { setName( \"Toshiya\" ) };" + "end\n";
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(graph, "mypkg.R2", "mypkg.R1", ReactivityType.NEGATIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class RhsTest method testForEachDelete.
@Test
public void testForEachDelete() {
String str = "package mypkg;\n" + "import " + List.class.getCanonicalName() + ";" + "rule R1\n" + " when\n" + " $objectList : List() from collect(Object())\n" + " then\n" + " for(Object $object : $objectList){\n" + " delete($object);\n" + " }\n" + "end";
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
// at the moment, R1's patternClass is parsed as `List`. It will be addressed in DROOLS-6616
assertLink(graph, "mypkg.R1", "mypkg.R1");
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class RhsTest method testForEachInsert.
@Test
public void testForEachInsert() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1\n" + " when\n" + " $person : Person()\n" + " then\n" + " for(Address $address : $person.getAddresses()){\n" + " insert($address);\n" + " }\n" + "end\n" + "rule R2\n" + " when\n" + " Address()\n" + " then\n" + "end\n";
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class SpecialUsageTest method testModifyMapInt.
@Test
public void testModifyMapInt() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + " $c : ControlFact()\n" + "then\n" + " $c.mapDataInt[\"Key1\"] = 100;" + " modify ($c) {mapDataInt = $c.mapDataInt};" + "end\n" + "rule R2 when\n" + " $c : ControlFact(mapDataInt[\"Key1\"] == 100)\n" + "then\n" + "end\n" + "rule R3 when\n" + " $c : ControlFact(mapDataInt[\"Key1\"] != 100)\n" + "then\n" + "end\n" + "rule R4 when\n" + " $c : ControlFact(mapDataInt[\"Key2\"] == 100)\n" + "then\n" + "end\n" + "rule R5 when\n" + " $c : ControlFact(mapDataInt[\"Key1\"] == 200)\n" + "then\n" + "end\n";
// runRule(str, new ControlFact());
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
assertLink(graph, "mypkg.R1", "mypkg.R5", ReactivityType.NEGATIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class SpecialUsageTest method testModifyMap.
@Test
public void testModifyMap() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + " $c : ControlFact()\n" + "then\n" + " $c.mapData[\"Key1\"] = \"Value1\";" + " modify ($c) {mapData = $c.mapData};" + "end\n" + "rule R2 when\n" + " $c : ControlFact(mapData[\"Key1\"] == \"Value1\")\n" + "then\n" + "end\n" + "rule R3 when\n" + " $c : ControlFact(mapData[\"Key1\"] != \"Value1\")\n" + "then\n" + "end\n" + "rule R4 when\n" + " $c : ControlFact(mapData[\"Key2\"] == \"Value1\")\n" + "then\n" + "end\n" + "rule R5 when\n" + " $c : ControlFact(mapData[\"Key1\"] == \"Value2\")\n" + "then\n" + "end\n";
// runRule(str, new ControlFact());
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
assertLink(graph, "mypkg.R1", "mypkg.R5", ReactivityType.NEGATIVE);
}
Aggregations