Search in sources :

Example 16 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder 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);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 17 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder 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);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 18 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder 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);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 19 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder 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);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) ProductItem(org.drools.impact.analysis.integrationtests.domain.ProductItem) Test(org.junit.Test)

Example 20 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder 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);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) ControlFact(org.drools.impact.analysis.integrationtests.domain.ControlFact) Test(org.junit.Test)

Aggregations

Graph (org.drools.impact.analysis.graph.Graph)36 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)36 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)36 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)36 Test (org.junit.Test)34 Person (org.drools.impact.analysis.integrationtests.domain.Person)9 Address (org.drools.impact.analysis.integrationtests.domain.Address)5 ImpactAnalysisHelper (org.drools.impact.analysis.graph.ImpactAnalysisHelper)4 ControlFact (org.drools.impact.analysis.integrationtests.domain.ControlFact)3 GraphCollapsionHelper (org.drools.impact.analysis.graph.GraphCollapsionHelper)2 PropHolder (org.drools.impact.analysis.integrationtests.domain.PropHolder)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Node (org.drools.impact.analysis.graph.Node)1 AbstractGraphTest (org.drools.impact.analysis.integrationtests.AbstractGraphTest)1 ProductItem (org.drools.impact.analysis.integrationtests.domain.ProductItem)1 LoanApplication (org.drools.impact.analysis.integrationtests.kogito.domain.LoanApplication)1