Search in sources :

Example 36 with AnalysisModel

use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.

the class RhsTest method testForEachDelete.

@Test
public void testForEachDelete() {
    String str = "package mypkg;\n" + "import " + List.class.getCanonicalName() + ";" + "rule R1\n" + "  when\n" + "    $objectList : List() from collect(Object())\n" + "  then\n" + "    for(Object $object : $objectList){\n" + "      delete($object);\n" + "    }\n" + "end";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    // at the moment, R1's patternClass is parsed as `List`. It will be addressed in DROOLS-6616
    assertLink(graph, "mypkg.R1", "mypkg.R1");
}
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 37 with AnalysisModel

use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.

the class RhsTest method testForEachInsert.

@Test
public void testForEachInsert() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1\n" + "  when\n" + "    $person : Person()\n" + "  then\n" + "    for(Address $address : $person.getAddresses()){\n" + "      insert($address);\n" + "    }\n" + "end\n" + "rule R2\n" + "  when\n" + "    Address()\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);
}
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 38 with AnalysisModel

use of org.drools.impact.analysis.model.AnalysisModel 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 39 with AnalysisModel

use of org.drools.impact.analysis.model.AnalysisModel 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)

Example 40 with AnalysisModel

use of org.drools.impact.analysis.model.AnalysisModel in project drools by kiegroup.

the class SpecialUsageTest method testBindVariableLiteralInsert.

@Test
public void testBindVariableLiteralInsert() {
    String str = "package mypkg;\n" + "import " + Address.class.getCanonicalName() + ";" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  Address(city == \"Tokyo\", $data : \"ABC\")\n" + "then\n" + "  Person person = new Person(\"John\");\n" + "  person.setLikes($data);\n" + "  insert(person);\n" + "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);
}
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)

Aggregations

AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)40 Graph (org.drools.impact.analysis.graph.Graph)38 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)38 Test (org.junit.Test)38 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)36 Person (org.drools.impact.analysis.integrationtests.domain.Person)9 ImpactAnalysisHelper (org.drools.impact.analysis.graph.ImpactAnalysisHelper)6 Address (org.drools.impact.analysis.integrationtests.domain.Address)5 GraphCollapsionHelper (org.drools.impact.analysis.graph.GraphCollapsionHelper)4 ControlFact (org.drools.impact.analysis.integrationtests.domain.ControlFact)3 ArrayList (java.util.ArrayList)2 Node (org.drools.impact.analysis.graph.Node)2 PropHolder (org.drools.impact.analysis.integrationtests.domain.PropHolder)2 ImpactAnalysisKieModule (org.drools.impact.analysis.parser.internal.ImpactAnalysisKieModule)2 KieServices (org.kie.api.KieServices)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ReleaseId (org.kie.api.builder.ReleaseId)2 BigDecimal (java.math.BigDecimal)1 Order (org.drools.impact.analysis.example.domain.Order)1