Search in sources :

Example 6 with BehaviorDescr

use of org.drools.compiler.lang.descr.BehaviorDescr in project drools by kiegroup.

the class RuleParserTest method testWindowDeclaration.

@Test
public void testWindowDeclaration() throws Exception {
    final String text = "package org.drools\n" + "declare window Ticks\n" + "    @doc(\"last 10 stock ticks\")\n" + "    $s : StockTick( source == \"NYSE\" )\n" + "        over window:length( 10, $s.symbol )\n" + "        from entry-point stStream\n" + "end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
    assertEquals("org.drools", pkg.getName());
    assertEquals(1, pkg.getWindowDeclarations().size());
    WindowDeclarationDescr wdd = pkg.getWindowDeclarations().iterator().next();
    assertEquals("Ticks", wdd.getName());
    assertEquals(1, wdd.getAnnotations().size());
    assertEquals("\"last 10 stock ticks\"", wdd.getAnnotation("doc").getValue());
    PatternDescr pd = wdd.getPattern();
    assertNotNull(pd);
    assertEquals("$s", pd.getIdentifier());
    assertEquals("StockTick", pd.getObjectType());
    assertEquals("stStream", pd.getSource().getText());
    assertEquals(1, pd.getBehaviors().size());
    BehaviorDescr bd = pd.getBehaviors().get(0);
    assertEquals("window", bd.getType());
    assertEquals("length", bd.getSubType());
    assertEquals(2, bd.getParameters().size());
    assertEquals("10", bd.getParameters().get(0));
    assertEquals("$s.symbol", bd.getParameters().get(1));
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) BehaviorDescr(org.drools.compiler.lang.descr.BehaviorDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) WindowDeclarationDescr(org.drools.compiler.lang.descr.WindowDeclarationDescr) Test(org.junit.Test)

Aggregations

BehaviorDescr (org.drools.compiler.lang.descr.BehaviorDescr)6 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)3 Test (org.junit.Test)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)2 Behavior (org.drools.core.rule.Behavior)2 StockTick (org.drools.compiler.StockTick)1 AndDescr (org.drools.compiler.lang.descr.AndDescr)1 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)1 TypeDeclarationDescr (org.drools.compiler.lang.descr.TypeDeclarationDescr)1 WindowDeclarationDescr (org.drools.compiler.lang.descr.WindowDeclarationDescr)1 ClassObjectType (org.drools.core.base.ClassObjectType)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)1 Pattern (org.drools.core.rule.Pattern)1 AssignExpr (org.drools.javaparser.ast.expr.AssignExpr)1 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)1 MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)1 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)1