Search in sources :

Example 66 with PackageDescr

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

the class RuleParserTest method testEvalMultiple.

@Test
public void testEvalMultiple() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "eval_multiple.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(4, rule.getLhs().getDescrs().size());
    final EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(0);
    assertEqualsIgnoreWhitespace("abc(\"foo\") + 5", (String) eval.getContent());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
    assertEquals("Foo", pattern.getObjectType());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) EvalDescr(org.drools.compiler.lang.descr.EvalDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 67 with PackageDescr

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

the class RuleParserTest method testEntryPointDeclaration.

@Test
public void testEntryPointDeclaration() throws Exception {
    final String text = "package org.drools\n" + "declare entry-point eventStream\n" + "    @source(\"jndi://queues/events\")\n" + "    @foo( true )\n" + "end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
    assertEquals("org.drools", pkg.getName());
    assertEquals(1, pkg.getEntryPointDeclarations().size());
    EntryPointDeclarationDescr epd = pkg.getEntryPointDeclarations().iterator().next();
    assertEquals("eventStream", epd.getEntryPointId());
    assertEquals(2, epd.getAnnotations().size());
    assertEquals("\"jndi://queues/events\"", epd.getAnnotation("source").getValue());
    assertEquals("true", epd.getAnnotation("foo").getValue());
}
Also used : EntryPointDeclarationDescr(org.drools.compiler.lang.descr.EntryPointDeclarationDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 68 with PackageDescr

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

the class RuleParserTest method testEval.

@Test
public void testEval() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "eval_parsing.drl");
    assertEquals("org.drools.compiler", pkg.getName());
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule1 = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule1.getLhs().getDescrs().size());
}
Also used : RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 69 with PackageDescr

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

the class RuleParserTest method testDialect.

@Test
public void testDialect() throws Exception {
    final String source = "dialect 'mvel'";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    AttributeDescr attr = (AttributeDescr) pkg.getAttributes().get(0);
    assertEquals("dialect", attr.getName());
    assertEquals("mvel", attr.getValue());
}
Also used : PackageDescr(org.drools.compiler.lang.descr.PackageDescr) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr) Test(org.junit.Test)

Example 70 with PackageDescr

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

the class RuleParserTest method testAccumulate.

@Test
public void testAccumulate() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
    assertEqualsIgnoreWhitespace("int x = 0 ;", accum.getInitCode());
    assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
    assertNull(accum.getReverseCode());
    assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
    assertFalse(accum.isExternalFunction());
    final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
    assertEquals("Person", pattern.getObjectType());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) Test(org.junit.Test)

Aggregations

PackageDescr (org.drools.compiler.lang.descr.PackageDescr)239 Test (org.junit.Test)192 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)103 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)85 DrlParser (org.drools.compiler.compiler.DrlParser)44 AndDescr (org.drools.compiler.lang.descr.AndDescr)39 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)27 InputStreamReader (java.io.InputStreamReader)25 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)23 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)22 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)19 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)19 KiePackage (org.kie.api.definition.KiePackage)18 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)17 Cheese (org.drools.compiler.Cheese)16 KieSession (org.kie.api.runtime.KieSession)16 List (java.util.List)15 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)15 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)15 DrlDumper (org.drools.compiler.lang.DrlDumper)14