Search in sources :

Example 16 with CEDescrBuilder

use of org.drools.drl.ast.dsl.CEDescrBuilder in project drools by kiegroup.

the class KiePMMLDescrLhsFactoryTest method commonDeclarePatternWithConstraint.

@Test
public void commonDeclarePatternWithConstraint() {
    String patternType = "TEMPERATURE";
    String constraintsString = "value < 35";
    final CEDescrBuilder<CEDescrBuilder<CEDescrBuilder<RuleDescrBuilder, AndDescr>, NotDescr>, ExistsDescr> existsBuilder = lhsBuilder.not().exists();
    KiePMMLDescrLhsFactory.factory(lhsBuilder).commonDeclarePatternWithConstraint(existsBuilder, patternType, constraintsString);
    assertNotNull(existsBuilder.getDescr());
    final List<BaseDescr> descrs = existsBuilder.getDescr().getDescrs();
    assertNotNull(descrs);
    assertEquals(1, descrs.size());
    assertTrue(descrs.get(0) instanceof PatternDescr);
    PatternDescr patternDescr = (PatternDescr) descrs.get(0);
    assertEquals(patternType, patternDescr.getObjectType());
    assertNull(patternDescr.getIdentifier());
    assertTrue(patternDescr.getConstraint() instanceof AndDescr);
    AndDescr andDescr = (AndDescr) patternDescr.getConstraint();
    assertEquals(1, andDescr.getDescrs().size());
    assertTrue(andDescr.getDescrs().get(0) instanceof ExprConstraintDescr);
    ExprConstraintDescr exprConstraintDescr = (ExprConstraintDescr) andDescr.getDescrs().get(0);
    assertFalse(exprConstraintDescr.isNegated());
    assertEquals(ExprConstraintDescr.Type.NAMED, exprConstraintDescr.getType());
    assertEquals(constraintsString, exprConstraintDescr.getExpression());
}
Also used : CEDescrBuilder(org.drools.drl.ast.dsl.CEDescrBuilder) RuleDescrBuilder(org.drools.drl.ast.dsl.RuleDescrBuilder) ExistsDescr(org.drools.drl.ast.descr.ExistsDescr) PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) BaseDescr(org.drools.drl.ast.descr.BaseDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

CEDescrBuilder (org.drools.drl.ast.dsl.CEDescrBuilder)16 RuleDescrBuilder (org.drools.drl.ast.dsl.RuleDescrBuilder)14 AccumulateDescrBuilder (org.drools.drl.ast.dsl.AccumulateDescrBuilder)13 AttributeDescrBuilder (org.drools.drl.ast.dsl.AttributeDescrBuilder)13 DeclareDescrBuilder (org.drools.drl.ast.dsl.DeclareDescrBuilder)13 EntryPointDeclarationDescrBuilder (org.drools.drl.ast.dsl.EntryPointDeclarationDescrBuilder)13 EnumDeclarationDescrBuilder (org.drools.drl.ast.dsl.EnumDeclarationDescrBuilder)13 EnumLiteralDescrBuilder (org.drools.drl.ast.dsl.EnumLiteralDescrBuilder)13 FieldDescrBuilder (org.drools.drl.ast.dsl.FieldDescrBuilder)13 ForallDescrBuilder (org.drools.drl.ast.dsl.ForallDescrBuilder)13 FunctionDescrBuilder (org.drools.drl.ast.dsl.FunctionDescrBuilder)13 GlobalDescrBuilder (org.drools.drl.ast.dsl.GlobalDescrBuilder)13 ImportDescrBuilder (org.drools.drl.ast.dsl.ImportDescrBuilder)13 NamedConsequenceDescrBuilder (org.drools.drl.ast.dsl.NamedConsequenceDescrBuilder)13 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)13 PatternDescrBuilder (org.drools.drl.ast.dsl.PatternDescrBuilder)13 QueryDescrBuilder (org.drools.drl.ast.dsl.QueryDescrBuilder)13 TypeDeclarationDescrBuilder (org.drools.drl.ast.dsl.TypeDeclarationDescrBuilder)13 WindowDeclarationDescrBuilder (org.drools.drl.ast.dsl.WindowDeclarationDescrBuilder)13 AnnotatedDescrBuilder (org.drools.drl.ast.dsl.AnnotatedDescrBuilder)12