Search in sources :

Example 1 with ControlFact

use of org.drools.impact.analysis.integrationtests.domain.ControlFact 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)

Example 2 with ControlFact

use of org.drools.impact.analysis.integrationtests.domain.ControlFact in project drools by kiegroup.

the class SpecialUsageTest method testModifyMapInt.

@Test
public void testModifyMapInt() {
    String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + "  $c : ControlFact()\n" + "then\n" + "  $c.mapDataInt[\"Key1\"] = 100;" + "  modify ($c) {mapDataInt = $c.mapDataInt};" + "end\n" + "rule R2 when\n" + "  $c : ControlFact(mapDataInt[\"Key1\"] == 100)\n" + "then\n" + "end\n" + "rule R3 when\n" + "  $c : ControlFact(mapDataInt[\"Key1\"] != 100)\n" + "then\n" + "end\n" + "rule R4 when\n" + "  $c : ControlFact(mapDataInt[\"Key2\"] == 100)\n" + "then\n" + "end\n" + "rule R5 when\n" + "  $c : ControlFact(mapDataInt[\"Key1\"] == 200)\n" + "then\n" + "end\n";
    // runRule(str, new ControlFact());
    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.R1", "mypkg.R4", ReactivityType.UNKNOWN);
    assertLink(graph, "mypkg.R1", "mypkg.R5", 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) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) ControlFact(org.drools.impact.analysis.integrationtests.domain.ControlFact) Test(org.junit.Test)

Example 3 with ControlFact

use of org.drools.impact.analysis.integrationtests.domain.ControlFact in project drools by kiegroup.

the class SpecialUsageTest method testModifyMap.

@Test
public void testModifyMap() {
    String str = "package mypkg;\n" + "import " + ControlFact.class.getCanonicalName() + ";" + "dialect \"mvel\"" + "rule R1 when\n" + "  $c : ControlFact()\n" + "then\n" + "  $c.mapData[\"Key1\"] = \"Value1\";" + "  modify ($c) {mapData = $c.mapData};" + "end\n" + "rule R2 when\n" + "  $c : ControlFact(mapData[\"Key1\"] == \"Value1\")\n" + "then\n" + "end\n" + "rule R3 when\n" + "  $c : ControlFact(mapData[\"Key1\"] != \"Value1\")\n" + "then\n" + "end\n" + "rule R4 when\n" + "  $c : ControlFact(mapData[\"Key2\"] == \"Value1\")\n" + "then\n" + "end\n" + "rule R5 when\n" + "  $c : ControlFact(mapData[\"Key1\"] == \"Value2\")\n" + "then\n" + "end\n";
    // runRule(str, new ControlFact());
    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.R1", "mypkg.R4", ReactivityType.UNKNOWN);
    assertLink(graph, "mypkg.R1", "mypkg.R5", 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) 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)3 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)3 ControlFact (org.drools.impact.analysis.integrationtests.domain.ControlFact)3 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)3 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)3 Test (org.junit.Test)3