use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class LinkFilterTest method testImpactAnalysisHelper.
@Test
public void testImpactAnalysisHelper() {
// ImpactAnalysisHelper simply returns a sub map which contains only a changed node and impacted nodes
// So we can assertNull for non-impacted nodes. (Links are not modified)
AnalysisModel analysisModel = new ModelBuilder().build(SIMPLE_RULE);
// default ALL
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper(LinkFilter.POSITIVE);
Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R3"));
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R4"));
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.NEGATIVE);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R2"));
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R4"));
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.UNKNOWN);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R2"));
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R3"));
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.POSITIVE_NEGATIVE);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R4"));
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.POSITIVE_UNKNOWN);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R3"));
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.NEGATIVE_UNKNOWN);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertNull(impactedSubGraph.getNodeMap().get("mypkg.R2"));
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
graph = converter.toGraph(analysisModel);
impactFilter = new ImpactAnalysisHelper(LinkFilter.ALL);
impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R1");
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
assertLink(impactedSubGraph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
}
use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class SpecialUsageTest method testExistsNot.
@Test
public void testExistsNot() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + " $c : ControlFact(keyword == \"ABC\", $orderId : orderId)\n" + "then\n" + " ControlFact $newFact = new ControlFact();" + " $newFact.keyword = \"DEF\";" + " $newFact.orderId = $orderId;" + " insert($newFact);" + "end\n" + "rule R2 when\n" + " $c : ControlFact(keyword == \"ABC\")\n" + " exists(not ControlFact(keyword == \"DEF\", $orderId : orderId))\n" + "then\n" + "end\n";
// runRule(str, new ControlFact("123", "ABC"));
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
// we may not need to have UNKNOWN
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.NEGATIVE, ReactivityType.UNKNOWN);
}
use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.
the class SpecialUsageTest method testBindVariableLiteralModifyMap.
@Test
public void testBindVariableLiteralModifyMap() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1\n" + "when\n" + " $c : ControlFact( $value : \"Value1\" )\n" + "then\n" + " $c.mapData[\"Key1\"] = $value;\n" + " modify ($c) {mapData = $c.mapData};\n" + "end\n" + "rule R2 when\n" + " $c : ControlFact(mapData[\"Key1\"] == \"Value1\")\n" + "then\n" + "end";
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 SpecialUsageTest method testMapWithFunction.
@Test
public void testMapWithFunction() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "import " + ProductItem.class.getCanonicalName() + ";" + "import static " + FunctionUtils.class.getCanonicalName() + ".convertMapToBigDecimal;" + "dialect \"mvel\"" + "rule R1 when\n" + " $c : ControlFact()\n" + "then\n" + " $c.mapData[\"Price\"] = \"100.0\";" + " modify ($c) {mapData = $c.mapData};" + "end\n" + "rule R2 when\n" + " ControlFact($price : convertMapToBigDecimal(mapData, \"Price\"))\n" + " ProductItem(price == $price)\n" + "then\n" + "end\n";
// runRule(str, new ControlFact(), new ProductItem("Product1", new BigDecimal("100.0")));
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.model.AnalysisModel in project drools by kiegroup.
the class SpecialUsageTest method testInsertWithValue.
@Test
public void testInsertWithValue() {
String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + " $c : ControlFact(keyword == \"ABC\", $orderId : orderId)\n" + "then\n" + " ControlFact $newFact = new ControlFact();" + " $newFact.keyword = \"DEF\";" + " $newFact.orderId = $orderId;" + " insert($newFact);" + "end\n" + "rule R2 when\n" + " $c : ControlFact(keyword == \"DEF\")\n" + "then\n" + "end\n";
// runRule(str, new ControlFact("123", "ABC"));
AnalysisModel analysisModel = new ModelBuilder().build(str);
ModelToGraphConverter converter = new ModelToGraphConverter();
Graph graph = converter.toGraph(analysisModel);
assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
}
Aggregations