private void setupTest(String consequence, Map<String, Object> namedConsequences) {
InternalKnowledgePackage pkg = new KnowledgePackageImpl( "org.drools" );
pkg.addImport( new ImportDeclaration( "org.drools.compiler.Cheese" ) );
KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
KnowledgeBuilderImpl kBuilder = new KnowledgeBuilderImpl( pkg, conf );
ruleDescr = new RuleDescr( "test consequence builder" );
ruleDescr.setConsequence( consequence );
for ( Entry<String, Object> entry : namedConsequences.entrySet() ) {
ruleDescr.addNamedConsequences( entry.getKey(), entry.getValue() );
}
RuleImpl rule = new RuleImpl( ruleDescr.getName() );
PackageRegistry pkgRegistry = kBuilder.getPackageRegistry( pkg.getName() );
DialectCompiletimeRegistry reg = kBuilder.getPackageRegistry( pkg.getName() ).getDialectCompiletimeRegistry();
context = new RuleBuildContext( kBuilder,
ruleDescr,
reg,
pkg,
reg.getDialect( pkgRegistry.getDialect() ) );
rule.addPattern( new Pattern( 0,
new ClassObjectType( Cheese.class ),
"$cheese" ) );
Pattern p = new Pattern( 1,
new ClassObjectType( Person.class ),
"$persone" );
Declaration declr = p.addDeclaration( "age" );
final InternalReadAccessor extractor = PatternBuilder.getFieldReadAccessor(context,
new BindingDescr("age", "age"),
p.getObjectType(),
"age",
declr,
true);
rule.addPattern( p );
context.getBuildStack().push(rule.getLhs());
context.getDialect().getConsequenceBuilder().build(context, RuleImpl.DEFAULT_CONSEQUENCE_NAME);
for ( String name : namedConsequences.keySet() ) {
context.getDialect().getConsequenceBuilder().build( context, name );
}
context.getDialect().addRule( context );
pkgRegistry.getPackage().addRule(context.getRule());
kBuilder.compileAll();
kBuilder.reloadAll();
}