Search in sources :

Example 26 with AnalysisModel

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

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

Example 28 with AnalysisModel

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

the class PropertyTest method testPropertyInFunction.

@Test
public void testPropertyInFunction() {
    String str = "package mypkg;\n" + "import " + Person.class.getCanonicalName() + ";" + "rule R1 when\n" + "  $p : Person()\n" + "then\n" + "  modify ($p) {setAge(42)};" + "end\n" + "rule R2 when\n" + "  $p : Person(calculateToMonth(age) > 480)\n" + "then\n" + "end\n";
    // runRule(str, new Person("John"));
    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) Person(org.drools.impact.analysis.integrationtests.domain.Person) Test(org.junit.Test)

Example 29 with AnalysisModel

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

the class TypeTest method testLiteralsInequality.

private void testLiteralsInequality(String propName, String value1, String value2, String thresholdValue, String dialect) {
    String setter = "set" + StringUtils.ucFirst(propName);
    String str = "package mypkg;\n" + "import " + PropHolder.class.getCanonicalName() + ";\n" + "dialect \"" + dialect + "\"\n" + "rule R1 when\n" + "  $p : PropHolder(id == 0)\n" + "then\n" + "  modify ($p) {" + setter + "(" + value1 + ")};\n" + "end\n" + "rule R2 when\n" + "  $p : PropHolder(id == 1)\n" + "then\n" + "  modify ($p) {" + setter + "(" + value2 + ")};\n" + "end\n" + "rule R3 when\n" + "  $p : PropHolder(" + propName + " < " + thresholdValue + ")\n" + "then\n" + "end\n" + "rule R4 when\n" + "  $p : PropHolder(" + propName + " > " + thresholdValue + ")\n" + "then\n" + "end\n";
    // PropHolder holder = new PropHolder();
    // holder.setId(0);
    // runRule(str, holder);
    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) PropHolder(org.drools.impact.analysis.integrationtests.domain.PropHolder) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter)

Example 30 with AnalysisModel

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

the class TypeTest method testLiteralsEquality.

private void testLiteralsEquality(String propName, String value1, String value2, String dialect) {
    String setter = "set" + StringUtils.ucFirst(propName);
    String str = "package mypkg;\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "import " + BigInteger.class.getCanonicalName() + ";\n" + "import " + PropHolder.class.getCanonicalName() + ";\n" + "dialect \"" + dialect + "\"\n" + "rule R1 when\n" + "  $p : PropHolder(id == 0)\n" + "then\n" + "  modify ($p) {" + setter + "(" + value1 + ")};\n" + "end\n" + "rule R2 when\n" + "  $p : PropHolder(id == 1)\n" + "then\n" + "  modify ($p) {" + setter + "(" + value2 + ")};\n" + "end\n" + "rule R3 when\n" + "  $p : PropHolder(" + propName + " == " + value1 + ")\n" + "then\n" + "end\n" + "rule R4 when\n" + "  $p : PropHolder(" + propName + " == " + value2 + ")\n" + "then\n" + "end\n";
    // PropHolder holder = new PropHolder();
    // holder.setId(0);
    // runRule(str, holder);
    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) PropHolder(org.drools.impact.analysis.integrationtests.domain.PropHolder) ModelToGraphConverter(org.drools.impact.analysis.graph.ModelToGraphConverter) BigDecimal(java.math.BigDecimal)

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