rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
rule2.checkin( "" );
repo.save();
BuilderResult result = repositoryPackageService.buildPackage( pkg.getUUID(),
true );
if ( result != null ) {
for ( int i = 0; i < result.getLines().size(); i++ ) {
System.err.println( result.getLines().get( i ).getMessage() );
}
}
assertFalse( result.hasLines() );
pkg = repo.loadPackage( "testBinaryPackageCompileBRL" );
byte[] binPackage = pkg.getCompiledPackageBytes();
// Here is where we write it out is needed... set to true if needed for
// the binary test below "testLoadAndExecBinary"
boolean saveBinPackage = false;
if ( saveBinPackage ) {
FileOutputStream out = new FileOutputStream( "RepoBinPackage.pkg" );
out.write( binPackage );
out.flush();
out.close();
}
assertNotNull( binPackage );
Package binPkg = (Package) DroolsStreamUtils.streamIn( binPackage );
assertNotNull( binPkg );
assertTrue( binPkg.isValid() );
// and this shows off the "soundex" thing...
Person p = new Person( "fubar" );
BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
loader.addPackage( new ByteArrayInputStream( binPackage ) );
RuleBase rb = loader.getRuleBase();
StatelessSession sess = rb.newStatelessSession();
sess.execute( p );
assertEquals( 42,
p.getAge() );
repositoryPackageService.createPackageSnapshot( "testBinaryPackageCompileBRL",
"SNAP1",
false,
"" );
pattern.setFactType( "PersonX" );
rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
rule2.checkin( "" );
result = repositoryPackageService.buildPackage( pkg.getUUID(),
true );
assertNotNull( result );
assertTrue( result.getLines().size() > 0 );
// assertEquals(2, results.length);
assertEquals( rule2.getName(),
result.getLines().get( 0 ).getAssetName() );
assertEquals( AssetFormats.BUSINESS_RULE,
result.getLines().get( 0 ).getAssetFormat() );
assertNotNull( result.getLines().get( 0 ).getMessage() );
assertEquals( rule2.getUUID(),
result.getLines().get( 0 ).getUuid() );
pkg = repo.loadPackageSnapshot( "testBinaryPackageCompileBRL",
"SNAP1" );
result = repositoryPackageService.buildPackage( pkg.getUUID(),
true );
assertFalse( result.hasLines() );
// check that the rule name in the model is being set
AssetItem asset2 = pkg.addAsset( "testSetRuleName",
"" );
asset2.updateFormat( AssetFormats.BUSINESS_RULE );