use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class TypeDeclarationMergingTest method testOverrideFromDeeperHierarchyParentInterface.
@Test
public void testOverrideFromDeeperHierarchyParentInterface() {
// inherits role from and typesafe from the other
String str = "" + "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + IB.class.getCanonicalName() + "\n" + " @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
KnowledgeBuilderImpl builder = getPackageBuilder(str);
TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
assertEquals(true, tdecl.isTypesafe());
assertEquals(Role.Type.FACT, tdecl.getRole());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class TypeDeclarationMergingTest method testOverrideFromMixedHierarchyParentInterface.
@Test
public void testOverrideFromMixedHierarchyParentInterface() {
// inherits role from and typesafe from the other
String str = "" + "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
KnowledgeBuilderImpl builder = getPackageBuilder(str);
TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
assertEquals(true, tdecl.isTypesafe());
assertEquals(Role.Type.FACT, tdecl.getRole());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class ConsequenceOffsetTest method testConsequenceOffset.
@Test
public void testConsequenceOffset() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(ConsequenceOffsetTest.class.getResourceAsStream("test_consequenceOffset.drl")), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
int offset = -1;
assertEquals(false, kbuilder.hasErrors());
for (RuleDescr rule : ((KnowledgeBuilderImpl) kbuilder).getPackageDescrs("com.sample").get(0).getRules()) {
if (rule.getName().equals("test")) {
offset = rule.getConsequenceOffset();
}
}
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newInputStreamResource(ConsequenceOffsetTest.class.getResourceAsStream("test_consequenceOffset2.drl")), ResourceType.DRL);
kbuilder.add(ResourceFactory.newInputStreamResource(ConsequenceOffsetTest.class.getResourceAsStream("test_consequenceOffset.drl")), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
for (RuleDescr rule : ((KnowledgeBuilderImpl) kbuilder).getPackageDescrs("com.sample").get(0).getRules()) {
if (rule.getName().equals("test")) {
assertEquals(offset, rule.getConsequenceOffset());
return;
}
}
fail();
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class AnnotationsTest method testCollectAnnotationsParsingAndBuilding.
@Test
public void testCollectAnnotationsParsingAndBuilding() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl();
kBuilder.addPackage(new PackageDescr("org.drools"));
String ruleDrl = "package org.drools.compiler; " + " " + "dialect 'mvel' " + " " + "import java.util.Collection; " + "import " + Annot.class.getCanonicalName() + "; " + " " + "rule \"test collect with annotation\" " + " when " + " Collection() from collect ( " + " String() @Annot " + " ) " + " then " + "end " + "";
final PackageDescr pkgDescr = parser.parse(new StringReader(ruleDrl));
// just checking there is no parsing errors
assertFalse(parser.getErrors().toString(), parser.hasErrors());
kBuilder.addPackage(pkgDescr);
assertTrue(kBuilder.getErrors().toString(), kBuilder.getErrors().isEmpty());
final RuleImpl rule = kBuilder.getPackage(pkgDescr.getName()).getRule("test collect with annotation");
List<? extends RuleConditionElement> nested = ((Pattern) rule.getLhs().getChildren().get(0)).getSource().getNestedElements();
assertEquals(1, nested.size());
Map<String, AnnotationDefinition> annotations = ((Pattern) nested.get(0)).getAnnotations();
assertEquals(1, annotations.size());
assertNotNull(annotations.keySet().iterator().next());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class AnnotationsTest method testAnnotationOnLHSAndMerging.
@Test
public void testAnnotationOnLHSAndMerging() throws Exception {
final DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
final KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl();
String ruleDrl = "package org.drools.compiler; " + " " + "import " + Annot.class.getCanonicalName() + "; " + " " + "rule \"test collect with annotation\" " + " when " + " ( and @Annot " + " String() " + " Integer() ) " + " then " + "end " + "";
final PackageDescr pkgDescr = parser.parse(new StringReader(ruleDrl));
kBuilder.addPackage(pkgDescr);
assertTrue(kBuilder.getErrors().toString(), kBuilder.getErrors().isEmpty());
}
Aggregations