Search in sources :

Example 6 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class KogitoDrlSyntaxTest method testModify.

@Test
public void testModify() {
    String str = "package org.drools.impact.analysis.integrationtests.kogito;\n" + "unit LoanUnit;\n" + "import " + LoanApplication.class.getCanonicalName() + ";\n" + "rule R1 when\n" + "    $l: /loanApplications[ applicant.age >= 20, deposit < 1000, amount <= 2000 ]\n" + "then\n" + "    modify($l) { setApproved(true) };\n" + "end\n" + "\n" + "rule R2 when\n" + "    $l: /loanApplications[ approved ]\n" + "then\n" + "    System.out.println(\"APPROVED! $l : \" + $l);\n" + "end";
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "org.drools.impact.analysis.integrationtests.kogito.R1", "org.drools.impact.analysis.integrationtests.kogito.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) LoanApplication(org.drools.impact.analysis.integrationtests.kogito.domain.LoanApplication) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test) AbstractGraphTest(org.drools.impact.analysis.integrationtests.AbstractGraphTest)

Example 7 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter 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 8 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class BasicGraphTest method testBeta.

@Test
public void testBeta() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setAge( 18 ) };" + "end\n" + "rule R2 when\n" + "  $a : Integer()\n" + "  $p2 : Person(age > $a)\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.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 9 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class BasicGraphTest method testInsertRelation.

@Test
public void testInsertRelation() {
    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" + "  $p : Person(name == \"John\")\n" + "then\n" + "end\n" + "rule R3 when\n" + "  $p : 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.POSITIVE);
    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 10 with ModelToGraphConverter

use of org.drools.impact.analysis.graph.ModelToGraphConverter in project drools by kiegroup.

the class BasicGraphTest method test3Rules.

@Test
public void test3Rules() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person(name == \"Mario\")\n" + "then\n" + "  modify($p) { setAge( 18 ) };" + "  insert(\"Done\");\n" + "end\n" + "rule R2 when\n" + "  $p : Person(age > 15)\n" + "then\n" + "end\n" + "rule R3 when\n" + "  $p : String(this == \"Done\")\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.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)

Aggregations

Graph (org.drools.impact.analysis.graph.Graph)38 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)38 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)38 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)36 Test (org.junit.Test)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