Search in sources :

Example 1 with PropHolder

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

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

Graph (org.drools.impact.analysis.graph.Graph)2 ModelToGraphConverter (org.drools.impact.analysis.graph.ModelToGraphConverter)2 PropHolder (org.drools.impact.analysis.integrationtests.domain.PropHolder)2 AnalysisModel (org.drools.impact.analysis.model.AnalysisModel)2 ModelBuilder (org.drools.impact.analysis.parser.ModelBuilder)2 BigDecimal (java.math.BigDecimal)1