use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class DrlSyntaxTest method testNot1.
@Test
public void testNot1() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "then\n" + " insert(new Person());" + "end\n" + "rule R2 when\n" + " not (Person())\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.NEGATIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class DrlSyntaxTest method testGlobal.
@Test
public void testGlobal() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "global java.util.List resultList;" + "rule R1 when\n" + " $p : Person(name == \"Mario\")\n" + "then\n" + " modify($p) { setAge( 18 ) };" + " insert(\"Done\");\n" + "end\n" + "rule R2 when\n" + " $p : Person(age > 15)\n" + "then\n" + "end\n" + "rule R3 when\n" + " $p : String(this == \"Done\")\n" + "then\n" + " resultList.add($p);" + "end\n";
List<Person> resultList = new ArrayList<>();
runRuleWithGlobal(str, "resultList", resultList, new Person("Mario", 10));
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.POSITIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class DrlSyntaxTest method testNot2.
@Test
public void testNot2() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1 when\n" + " $p : Person()\n" + "then\n" + " delete($p);" + "end\n" + "rule R2 when\n" + " not (Person())\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.R1", ReactivityType.NEGATIVE);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class DrlSyntaxTest method testExists2.
@Test
public void testExists2() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1 when\n" + " $p : Person()\n" + "then\n" + " delete($p);" + "end\n" + "rule R2 when\n" + " exists (Person())\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.R1", ReactivityType.NEGATIVE);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.NEGATIVE);
}
use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.
the class ImpactAnalysisTest method testOrderRulesBackward.
@Test
public void testOrderRulesBackward() {
AnalysisModel analysisModel = new ModelBuilder().build(ORDER_RULES);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
// View rules which impact R5
ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
Graph impactingSubGraph = impactFilter.filterImpactingNodes(graph, "mypkg.R5");
assertEquals(Status.IMPACTING, impactingSubGraph.getNodeMap().get("mypkg.R1").getStatus());
assertEquals(Status.IMPACTING, impactingSubGraph.getNodeMap().get("mypkg.R2").getStatus());
assertEquals(Status.IMPACTING, impactingSubGraph.getNodeMap().get("mypkg.R3").getStatus());
assertEquals(Status.IMPACTING, impactingSubGraph.getNodeMap().get("mypkg.R4").getStatus());
assertEquals(Status.TARGET, impactingSubGraph.getNodeMap().get("mypkg.R5").getStatus());
assertNull(impactingSubGraph.getNodeMap().get("mypkg.R6"));
// TextReporter test
String hierarchyText = TextReporter.toHierarchyText(impactingSubGraph);
List<String> lines = Arrays.asList(hierarchyText.split(System.lineSeparator()));
Assertions.assertThat(lines).containsExactlyInAnyOrder("R1[!]", INDENT + "R3[!]", INDENT + INDENT + "R5[@]", INDENT + INDENT + INDENT + "(R3)", "R2[!]", INDENT + "(R3)", "R4[!]", INDENT + "(R5)");
String flatText = TextReporter.toFlatText(impactingSubGraph);
List<String> lines2 = Arrays.asList(flatText.split(System.lineSeparator()));
Assertions.assertThat(lines2).containsExactlyInAnyOrder("R1[!]", "R2[!]", "R3[!]", "R4[!]", "R5[@]");
}
Aggregations