fail( kBuilder.getErrors().toString() );
}
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );
KnowledgePackage pack = kBase.getKnowledgePackage( "org.drools.compiler.test.definitions" );
assertNotNull( pack );
assertEquals( 2, pack.getFunctionNames().size() );
assertTrue( pack.getFunctionNames().contains( "fun1" ) );
assertTrue( pack.getFunctionNames().contains( "fun2" ) );
assertEquals( 2, pack.getGlobalVariables().size() );
GlobalImpl g1 = new GlobalImpl( "N", "java.lang.Integer" );
GlobalImpl g2 = new GlobalImpl( "list", "java.util.List" );
assertTrue( pack.getGlobalVariables().contains( g1 ) );
assertTrue( pack.getGlobalVariables().contains( g2 ) );
assertEquals( 2, pack.getFactTypes().size() );
FactType type;
for ( int j = 0; j < 2; j++ ) {
type = pack.getFactTypes().iterator().next();
if ( type.getName().equals( "org.drools.compiler.test.definitions.Person" ) ) {
assertEquals( 2, type.getFields().size() );
} else if (type.getName().equals( "org.drools.compiler.test.definitions.Foo" ) ) {
assertEquals( "org.drools.compiler.test.definitions.Person", type.getSuperClass() );
FactField fld = type.getField( "bar" );
assertEquals( 3, fld.getIndex() );
assertEquals( String.class, fld.getType() );
} else {
fail("Unexpected fact type " + type);
}
}
assertEquals( 2, pack.getQueries().size() );
for ( Query q : pack.getQueries() ) {
assertTrue( q.getName().equals( "qry1" ) || q.getName().equals( "qry2" ) );
}
assertEquals( 4, pack.getRules().size() );
assertTrue( pack.getRules().containsAll( pack.getQueries() ) );
}