use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class KnowledgeBuilderTest method testTypeDeclarationNewBean.
@Test
public void testTypeDeclarationNewBean() throws Exception {
PackageDescr pkgDescr = new PackageDescr("org.drools.compiler.test");
TypeDeclarationDescr typeDescr = new TypeDeclarationDescr("NewBean");
TypeFieldDescr f1 = new TypeFieldDescr("name", new PatternDescr("String"));
TypeFieldDescr f2 = new TypeFieldDescr("age", new PatternDescr("int"));
typeDescr.addField(f1);
typeDescr.addField(f2);
pkgDescr.addTypeDeclaration(typeDescr);
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
builder.addPackage(pkgDescr);
InternalKnowledgePackage pkg = builder.getPackage(pkgDescr.getName());
assertEquals(1, pkg.getTypeDeclarations().size());
TypeDeclaration type = pkg.getTypeDeclaration("NewBean");
assertEquals("NewBean", type.getTypeName());
assertEquals(Role.Type.FACT, type.getRole());
assertEquals("org.drools.compiler.test.NewBean", type.getTypeClass().getName());
assertFalse(builder.hasErrors());
InternalKnowledgePackage bp = builder.getPackage(pkgDescr.getName());
Class newBean = bp.getPackageClassLoader().loadClass("org.drools.compiler.test.NewBean");
assertNotNull(newBean);
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationMergingTest method testOverrideFromParentClass.
@Test
public void testOverrideFromParentClass() {
// inherits role, but not typesafe
String str = "" + "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + " @typesafe(false)\n" + "end\n";
KnowledgeBuilderImpl builder = getPackageBuilder(str);
TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
assertEquals(false, tdecl.isTypesafe());
assertEquals(Role.Type.EVENT, tdecl.getRole());
}
use of org.drools.core.rule.TypeDeclaration in project drools by kiegroup.
the class TypeDeclarationMergingTest method testInheritExitenceFromParentClass.
@Test
public void testInheritExitenceFromParentClass() {
// inherits role and typesafe
String str = "" + "package org.drools.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\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.EVENT, tdecl.getRole());
}
use of org.drools.core.rule.TypeDeclaration 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.core.rule.TypeDeclaration 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());
}
Aggregations