Search in sources :

Example 11 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.

the class BasicGraphTest method testInsertDelete.

@Test
public void testInsertDelete() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person()\n" + "then\n" + "  insert(new Address());" + "end\n" + "rule R2 when\n" + "  $p : Person()\n" + "  $a : Address()\n" + "then\n" + "  delete($p);" + "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.R2", "mypkg.R1", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R2", "mypkg.R2", ReactivityType.NEGATIVE);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) Address(org.drools.impact.analysis.integrationtests.domain.Address) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 12 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.

the class BasicGraphTest method testInsertRelationNot.

@Test
public void testInsertRelationNot() {
    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" + "  not( Person(name == \"John\") )\n" + "then\n" + "end\n" + "rule R3 when\n" + "  not( 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.NEGATIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R3");
}
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) Person(org.drools.impact.analysis.integrationtests.domain.Person) Test(org.junit.Test)

Example 13 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.

the class GraphCollapsionTest method testDrlRuleNamePrefix.

@Test
public void testDrlRuleNamePrefix() {
    String str = "package mypkg;\n" + "import " + Order.class.getCanonicalName() + ";" + "\n" + "rule CustomerCheck_1\n" + "  when\n" + "    $o : Order(customerMembershipRank > 5)\n" + "  then\n" + "    modify($o) {\n" + "      setDiscount(1000);\n" + "    }\n" + "end\n" + "\n" + "rule CustomerCheck_2\n" + "  when\n" + "    $o : Order(customerAge > 60)\n" + "  then\n" + "    modify($o) {\n" + "      setDiscount(2000);\n" + "    }\n" + "end\n" + "\n" + "rule PriceCheck_1\n" + "  when\n" + "    $o : Order(itemPrice < 2000, discount >= 2000)\n" + "  then\n" + "    modify($o) {\n" + "      setStatus(\"Too much discount\");\n" + "    }\n" + "end\n" + "\n" + "rule PriceCheck_2\n" + "  when\n" + "    $o : Order(itemPrice > 5000)\n" + "  then\n" + "    modify($o) {\n" + "      setStatus(\"Exclusive order\");\n" + "    }\n" + "end\n" + "\n" + "rule StatusCheck_1\n" + "  when\n" + "    $o : Order(status == \"Too much discount\")\n" + "  then\n" + "    modify($o) {\n" + "      setDiscount(500);\n" + "    }\n" + "end\n" + "\n" + "rule StatusCheck_2\n" + "  when\n" + "    Order(status == \"Exclusive order\")\n" + "  then\n" + "    // Do some work...\n" + "end";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    Graph collapsedGraph = new GraphCollapsionHelper().collapseWithRuleNamePrefix(graph);
    assertEquals(3, collapsedGraph.getNodeMap().size());
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    // --- impact analysis
    // Assuming that "modify" action in PriceCheck_X is changed
    // modify action in PriceCheck_X
    Node changedNode = collapsedGraph.getNodeMap().get("mypkg.PriceCheck");
    ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
    Graph impactedSubGraph = impactFilter.filterImpactedNodes(collapsedGraph, changedNode);
    assertNull(impactedSubGraph.getNodeMap().get("mypkg.CustomerCheck"));
    assertEquals(Status.CHANGED, impactedSubGraph.getNodeMap().get("mypkg.PriceCheck").getStatus());
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.StatusCheck").getStatus());
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) Node(org.drools.impact.analysis.graph.Node) GraphCollapsionHelper(org.drools.impact.analysis.graph.GraphCollapsionHelper) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 14 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.

the class LinkFilterTest method testModelToGraphConverter.

@Test
public void testModelToGraphConverter() {
    AnalysisModel analysisModel = new ModelBuilder().build(SIMPLE_RULE);
    ModelToGraphConverter converter = new ModelToGraphConverter(LinkFilter.POSITIVE);
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R3");
    assertLink(graph, "mypkg.R1", "mypkg.R4");
    converter = new ModelToGraphConverter(LinkFilter.NEGATIVE);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2");
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R4");
    converter = new ModelToGraphConverter(LinkFilter.UNKNOWN);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2");
    assertLink(graph, "mypkg.R1", "mypkg.R3");
    assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
    converter = new ModelToGraphConverter(LinkFilter.POSITIVE_NEGATIVE);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R4");
    converter = new ModelToGraphConverter(LinkFilter.POSITIVE_UNKNOWN);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R3");
    assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
    converter = new ModelToGraphConverter(LinkFilter.NEGATIVE_UNKNOWN);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2");
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.UNKNOWN);
    converter = new ModelToGraphConverter(LinkFilter.ALL);
    graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "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) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 15 with ModelBuilder

use of org.drools.impact.analysis.parser.ModelBuilder in project drools by kiegroup.

the class LinkFilterTest method testGraphCollapsionHelper.

@Test
public void testGraphCollapsionHelper() {
    // GraphCollapsionHelper creates a map with new nodes and links
    // default ALL
    AnalysisModel analysisModel = new ModelBuilder().build(RULE_WITH_PREFIX);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    GraphCollapsionHelper collapsionHelper = new GraphCollapsionHelper(LinkFilter.POSITIVE);
    Graph collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.POSITIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.POSITIVE);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck");
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.NEGATIVE);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.UNKNOWN);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck");
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.UNKNOWN);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck");
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.POSITIVE_NEGATIVE);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.POSITIVE_UNKNOWN);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.POSITIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.POSITIVE, ReactivityType.UNKNOWN);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck");
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.NEGATIVE_UNKNOWN);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.NEGATIVE, ReactivityType.UNKNOWN);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
    collapsionHelper = new GraphCollapsionHelper(LinkFilter.ALL);
    collapsedGraph = collapsionHelper.collapseWithRuleNamePrefix(graph);
    assertLink(collapsedGraph, "mypkg.CustomerCheck", "mypkg.PriceCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE);
    assertLink(collapsedGraph, "mypkg.PriceCheck", "mypkg.StatusCheck", ReactivityType.POSITIVE, ReactivityType.NEGATIVE, ReactivityType.UNKNOWN);
    assertLink(collapsedGraph, "mypkg.StatusCheck", "mypkg.PriceCheck", ReactivityType.NEGATIVE);
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) GraphCollapsionHelper(org.drools.impact.analysis.graph.GraphCollapsionHelper) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) 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