use of org.drools.impact.analysis.graph.Graph 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[@]");
}
use of org.drools.impact.analysis.graph.Graph in project drools by kiegroup.
the class KogitoDrlSyntaxTest method testModify.
@Test
public void testModify() {
String str = "package org.drools.impact.analysis.integrationtests.kogito;\n" + "unit LoanUnit;\n" + "import " + LoanApplication.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $l: /loanApplications[ applicant.age >= 20, deposit < 1000, amount <= 2000 ]\n" + "then\n" + " modify($l) { setApproved(true) };\n" + "end\n" + "\n" + "rule R2 when\n" + " $l: /loanApplications[ approved ]\n" + "then\n" + " System.out.println(\"APPROVED! $l : \" + $l);\n" + "end";
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "org.drools.impact.analysis.integrationtests.kogito.R1", "org.drools.impact.analysis.integrationtests.kogito.R2", ReactivityType.POSITIVE);
}
use of org.drools.impact.analysis.graph.Graph in project drools by kiegroup.
the class BasicGraphTest method test5Rules.
@Test
public void test5Rules() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.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 > 15)\n" + "then\n" + " insert(new Address(\"Milan\"));" + "end\n" + "rule R3 when\n" + " $p : Person(age < 15)\n" + "then\n" + " insert(new Address(\"Milan\"));" + "end\n" + "rule R4 when\n" + " $a : Address()\n" + "then\n" + "end\n" + "rule R5 when\n" + " $i : Integer()\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);
assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertLink(graph, "mypkg.R2", "mypkg.R4", ReactivityType.POSITIVE);
assertLink(graph, "mypkg.R3", "mypkg.R4", ReactivityType.POSITIVE);
ModelToGraphConverter converterPositiveOnly = new ModelToGraphConverter(true);
Graph graph2 = converterPositiveOnly.toGraph(analysisModel);
assertLink(graph2, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(graph2, "mypkg.R1", "mypkg.R3");
assertLink(graph2, "mypkg.R2", "mypkg.R4", ReactivityType.POSITIVE);
assertLink(graph2, "mypkg.R3", "mypkg.R4", ReactivityType.POSITIVE);
}
use of org.drools.impact.analysis.graph.Graph in project drools by kiegroup.
the class BasicGraphTest method testBeta.
@Test
public void testBeta() {
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" + " $a : Integer()\n" + " $p2 : Person(age > $a)\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.UNKNOWN);
}
use of org.drools.impact.analysis.graph.Graph in project drools by kiegroup.
the class BasicGraphTest method testInsertRelation.
@Test
public void testInsertRelation() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + " String(this == \"Start\")\n" + "then\n" + " Person p = new Person();\n" + " p.setName(\"John\");\n" + " insert(p);\n" + "end\n" + "rule R2 when\n" + " $p : Person(name == \"John\")\n" + "then\n" + "end\n" + "rule R3 when\n" + " $p : Person(name == \"Paul\")\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);
assertLink(graph, "mypkg.R1", "mypkg.R3");
}
Aggregations