pkg = repo.loadModule( "testLoadAndExecBinary" );
byte[] binPackage = pkg.getCompiledBinaryBytes();
File file = new File( System.getProperty( "java.io.tmpdir" ) + File.separator + "RepoBinPackage.pkg" );
FileManager fm = new FileManager();
try {
//Attempt to delete existing temporary file that may be lingering around
fm.deleteFile( file );
// Save file for actual test
FileOutputStream out = new FileOutputStream( file );
out.write( binPackage );
out.flush();
out.close();
//Test
Person p = new Person( "fubar" );
KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
kb.add( new InputStreamResource( new ByteArrayInputStream( binPackage ) ),
ResourceType.PKG );
KnowledgeBase kbase = kb.newKnowledgeBase();
StatelessKnowledgeSession sess = kbase.newStatelessKnowledgeSession();
sess.execute( p );
assertEquals( 42,
p.getAge() );
} finally {
//Tidy up
fm.deleteFile( file );
}
}