public void testAddFromDdjUrl() throws IntegrationException,
SAXException,
IOException,
FactException
{
WorkingMemory workingMemory;
List list;
RuleBase ruleBase;
RuleBaseLoader ruleBaseLoader;
RuleSetLoader ruleSetLoader = new RuleSetLoader( );
// single URL parameter
ruleSetLoader.addFromUrl( RuleBaseLoaderTest.class.getResource( "simple.java.drl" ) );
// Try with addFromRuleSetLoader
ruleBaseLoader = new RuleBaseLoader( );
ruleBaseLoader.addFromRuleSetLoader( ruleSetLoader );
RuleSetCompiler[] compilers = (RuleSetCompiler[]) ruleSetLoader.getRuleSets( ).values( ).toArray( new RuleSetCompiler[]{} );
File root = null;
try
{
root = createTempDirectory( );
File file = new File( root,
"drools.ddj" );
FileOutputStream fos = new FileOutputStream( file );
fos.write( compilers[0].getBinaryDeploymentJar( ) );
fos.close( );
// Try with URL to Drools Distribution Jar, ddj
ruleBaseLoader = new RuleBaseLoader( );
ruleBaseLoader.addFromUrl( file.toURL( ) );
ruleBase = ruleBaseLoader.buildRuleBase( );
workingMemory = ruleBase.newWorkingMemory( );
list = new ArrayList( );
workingMemory.setApplicationData( "list",
list );
workingMemory.assertObject( "help" );
workingMemory.fireAllRules( );
assertEquals( "help",
list.get( 0 ) );
// Try with URL to Drools Distribution Jar, ddj []
ruleBaseLoader = new RuleBaseLoader( );
ruleBaseLoader.addFromUrl( new URL[]{file.toURL( )} );
ruleBase = ruleBaseLoader.buildRuleBase( );
workingMemory = ruleBase.newWorkingMemory( );
list = new ArrayList( );
workingMemory.setApplicationData( "list",
list );
workingMemory.assertObject( "help" );
workingMemory.fireAllRules( );
assertEquals( "help",
list.get( 0 ) );
}
catch ( Exception e )
{