Search in sources :

Example 1 with Address

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

the class BasicGraphTest method test5Rules.

@Test
public void test5Rules() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "import " + Address.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setAge( 18 ) };" + "end\n" + "rule R2 when\n" + "  $p : Person(age > 15)\n" + "then\n" + "  insert(new Address(\"Milan\"));" + "end\n" + "rule R3 when\n" + "  $p : Person(age < 15)\n" + "then\n" + "  insert(new Address(\"Milan\"));" + "end\n" + "rule R4 when\n" + "  $a : Address()\n" + "then\n" + "end\n" + "rule R5 when\n" + "  $i : Integer()\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);
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R2", "mypkg.R4", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R3", "mypkg.R4", ReactivityType.POSITIVE);
    ModelToGraphConverter converterPositiveOnly = new ModelToGraphConverter(true);
    Graph graph2 = converterPositiveOnly.toGraph(analysisModel);
    assertLink(graph2, "mypkg.R1", "mypkg.R2", ReactivityType.POSITIVE);
    assertLink(graph2, "mypkg.R1", "mypkg.R3");
    assertLink(graph2, "mypkg.R2", "mypkg.R4", ReactivityType.POSITIVE);
    assertLink(graph2, "mypkg.R3", "mypkg.R4", 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 2 with Address

use of org.drools.impact.analysis.integrationtests.domain.Address 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 3 with Address

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

Aggregations

Graph (org.drools.impact.analysis.graph.Graph)3 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)3 Address (org.drools.impact.analysis.integrationtests.domain.Address)3 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)3 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)3 Test (org.junit.Test)3