Search in sources :

Example 21 with ModelBuilder

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

the class SpecialUsageTest method testBindVariableLiteralModify.

@Test
public void testBindVariableLiteralModify() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person($data : \"ABC\")\n" + "then\n" + "  modify($p) { setLikes( $data ) };" + "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)

Example 22 with ModelBuilder

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

the class DrlSyntaxTest method testExists1.

@Test
public void testExists1() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "then\n" + "  insert(new Person());" + "end\n" + "rule R2 when\n" + "  exists (Person())\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) Test(org.junit.Test)

Example 23 with ModelBuilder

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

the class ImpactAnalysisTest method testOrderRules.

@Test
public void testOrderRules() {
    AnalysisModel analysisModel = new ModelBuilder().build(ORDER_RULES);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    // View rules which are impacted by R2
    ImpactAnalysisHelper impactFilter = new ImpactAnalysisHelper();
    Graph impactedSubGraph = impactFilter.filterImpactedNodes(graph, "mypkg.R2");
    assertNull(impactedSubGraph.getNodeMap().get("mypkg.R1"));
    assertEquals(Status.CHANGED, impactedSubGraph.getNodeMap().get("mypkg.R2").getStatus());
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R3").getStatus());
    assertNull(impactedSubGraph.getNodeMap().get("mypkg.R4"));
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R5").getStatus());
    assertEquals(Status.IMPACTED, impactedSubGraph.getNodeMap().get("mypkg.R6").getStatus());
    // TextReporter test
    String hierarchyText = TextReporter.toHierarchyText(impactedSubGraph);
    List<String> lines = Arrays.asList(hierarchyText.split(System.lineSeparator()));
    Assertions.assertThat(lines).containsExactlyInAnyOrder("R2[*]", INDENT + "R3[+]", INDENT + INDENT + "R6[+]", INDENT + INDENT + "R5[+]", INDENT + INDENT + INDENT + "(R3)");
    String flatText = TextReporter.toFlatText(impactedSubGraph);
    List<String> lines2 = Arrays.asList(flatText.split(System.lineSeparator()));
    Assertions.assertThat(lines2).containsExactlyInAnyOrder("R2[*]", "R3[+]", "R6[+]", "R5[+]");
}
Also used : ModelBuilder(org.drools.impact.analysis.parser.ModelBuilder) Graph(org.drools.impact.analysis.graph.Graph) AnalysisModel(org.drools.impact.analysis.model.AnalysisModel) ImpactAnalysisHelper(org.drools.impact.analysis.graph.ImpactAnalysisHelper) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) Test(org.junit.Test)

Example 24 with ModelBuilder

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

the class PropertyTest method testUnaryBoolean.

@Test
public void testUnaryBoolean() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";\n" + "rule R1 when\n" + "  $p : Person(age >= 20)\n" + "then\n" + "  modify ($p) {setEmployed(true)};\n" + "end\n" + "rule R2 when\n" + "  $p : Person(age < 20)\n" + "then\n" + "  modify ($p) {setEmployed(false)};\n" + "end\n" + "rule R3 when\n" + "  $p : Person(employed)\n" + "then\n" + "end\n" + "rule R4 when\n" + "  $p : Person(!employed)\n" + "then\n" + "end\n";
    // Person person = new Person("John", 30);
    // person.setEmployed(false);
    // runRule(str, person);
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    ModelToGraphConverter converter = new ModelToGraphConverter();
    Graph graph = converter.toGraph(analysisModel);
    assertLink(graph, "mypkg.R1", "mypkg.R3", ReactivityType.POSITIVE);
    assertLink(graph, "mypkg.R1", "mypkg.R4", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R2", "mypkg.R3", ReactivityType.NEGATIVE);
    assertLink(graph, "mypkg.R2", "mypkg.R4", 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)

Example 25 with ModelBuilder

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

the class PropertyTest method testNestedProperty.

@Test
public void testNestedProperty() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person()\n" + "then\n" + "  modify ($p) {getAddress().setNumber(10)};" + "end\n" + "rule R2 when\n" + "  $p : Person(address.number == 10)\n" + "then\n" + "end\n";
    // runRule(str, new Person("John", 20, new Address()));
    AnalysisModel analysisModel = new ModelBuilder().build(str);
    // [modify ($p) {getAddress().setNumber(10)};] is parsed to modifiedProperties=[ModifiedProperty{property='address', value=null}]
    // [address.number == 10] is parsed to Constraint{type=EQUAL, property='null', value=10}
    // Currently, it results in UNKNOWN impact. Do we want to analyze this to POSITIVE? (TODO: Confirm customer's expectation)
    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) Person(org.drools.impact.analysis.integrationtests.domain.Person) 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