pkg );
AssetItem rule2 = pkg.addAsset( "rule2",
"" );
rule2.updateFormat( AssetFormats.BUSINESS_RULE );
RuleModel model = new RuleModel();
model.name = "rule2";
FactPattern pattern = new FactPattern( "Person" );
SingleFieldConstraint con = new SingleFieldConstraint();
con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );
con.setValue( "name soundslike 'foobar'" );
pattern.addConstraint( con );
pattern.setBoundName( "p" );
ActionSetField action = new ActionSetField( "p" );
ActionFieldValue value = new ActionFieldValue( "age",
"42",
SuggestionCompletionEngine.TYPE_NUMERIC );
action.addFieldValue( value );
model.addLhsItem( pattern );
model.addRhsItem( action );
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() );
}
}
assertNull( result );
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[] binPkgs = (Package[]) DroolsStreamUtils.streamIn( binPackage );
assertNotNull( binPkgs );
assertEquals( 1,
binPkgs.length );
Package binPkg = binPkgs[0];
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 );
assertNull( result );
// check that the rule name in the model is being set
AssetItem asset2 = pkg.addAsset( "testSetRuleName",
"" );
asset2.updateFormat( AssetFormats.BUSINESS_RULE );
asset2.checkin( "" );
RuleModel model2 = new RuleModel();
assertNull( model2.name );
RepositoryAssetService repositoryAssetService = getRepositoryAssetService();
RuleAsset asset = repositoryAssetService.loadRuleAsset( asset2.getUUID() );
asset.content = (PortableObject) model2;