use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class SpecialUsageTest method testBindVariableLiteralModify.
@Test
public void testBindVariableLiteralModify() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + " $p : Person($data : \"ABC\")\n" + "then\n" + " modify($p) { setLikes( $data ) };" + "end\n" + "rule R2 when\n" + " $p : Person(likes == \"ABC\")\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.model.AnalysisModel in project drools by kiegroup.
the class ParserTest method test.
@Test
public void test() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R when\n" + " $p : Person(name == \"Mario\")\n" + "then\n" + " modify($p) { setAge( 18 ) };" + " insert(\"Done\");\n" + "end";
AnalysisModel analysisModel = new ModelBuilder().build(str);
System.out.println(analysisModel);
}
use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class ParserTest method testInsert.
@Test
public void testInsert() {
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";
AnalysisModel analysisModel = new ModelBuilder().build(str);
System.out.println(analysisModel);
}
use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class DrlSyntaxTest method testExists1.
@Test
public void testExists1() {
String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "then\n" + " insert(new Person());" + "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.R2", ReactivityType.POSITIVE);
}
use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class ImpactAnalysisTest method testOrderRules.
@Test
public void testOrderRules() {
AnalysisModel analysisModel = new ModelBuilder().build(ORDER_RULES);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
// View rules which are impacted by R2
ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R2");
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R1"));
assertEquals(Status.CHANGED, impactedSubGraph.getNodeMap().get("mypkg.R2").getStatus());
assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R3").getStatus());
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R4"));
assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R5").getStatus());
assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R6").getStatus());
// TextReporter test
String hierarchyText = TextReporter.toHierarchyText(impactedSubGraph);
List<String> lines = Arrays.asList(hierarchyText.split(System.lineSeparator()));
Assertions.assertThat(lines).containsExactlyInAnyOrder("R2[*]", INDENT + "R3[+]", INDENT + INDENT + "R6[+]", INDENT + INDENT + "R5[+]", INDENT + INDENT + INDENT + "(R3)");
String flatText = TextReporter.toFlatText(impactedSubGraph);
List<String> lines2 = Arrays.asList(flatText.split(System.lineSeparator()));
Assertions.assertThat(lines2).containsExactlyInAnyOrder("R2[*]", "R3[+]", "R6[+]", "R5[+]");
}
Aggregations