}
@Test
public void testSimplePackageBuildNoErrors() throws Exception {
ServiceImplementation serviceImplementation = getServiceImplementation();
RulesRepository repo = serviceImplementation.getRulesRepository();
PackageItem pkg = repo.createPackage("testSimplePackageBuildNoErrors",
"");
AssetItem model = pkg.addAsset("model",
"qed");
model.updateFormat(AssetFormats.MODEL);
model.updateBinaryContentAttachment(this.getClass().getResourceAsStream("/billasurf.jar"));
model.checkin("");
DroolsHeader.updateDroolsHeader("import com.billasurf.Board\n global com.billasurf.Person customer",
pkg);
AssetItem rule1 = pkg.addAsset("rule_1",
"");
rule1.updateFormat(AssetFormats.DRL);
rule1.updateContent("rule 'rule1' \n when Board() \n then customer.setAge(42); \n end");
rule1.checkin("");
AssetItem rule2 = pkg.addAsset("rule2",
"");
rule2.updateFormat(AssetFormats.DRL);
rule2.updateContent("agenda-group 'q' \n when \n Board() \n then \n System.err.println(42);");
rule2.checkin("");
AssetItem rule3 = pkg.addAsset("A file",
"");
rule3.updateFormat(AssetFormats.DRL);
rule3.updateContent("package testSimplePackageBuildNoErrors\n rule 'rule3' \n when \n then \n customer.setAge(43); \n end \n" + "rule 'rule4' \n when \n then \n System.err.println(44); \n end");
rule3.checkin("");
repo.save();
PackageAssembler asm = new PackageAssembler(pkg);
asm.compile();
assertFalse(asm.hasErrors());
assertNotNull(asm.getBinaryPackage());
Package[] binPkgs = asm.getBinaryPackage();
assertNotNull( binPkgs );
assertEquals( 1,
binPkgs.length );
Package bin = binPkgs[0];
assertEquals(pkg.getName(),
bin.getName());
assertTrue(bin.isValid());
assertEquals(4,
bin.getRules().length);
//now create a snapshot
repo.createPackageSnapshot(pkg.getName(),
"SNAP_1");
//and screw up the the non snapshot one
DroolsHeader.updateDroolsHeader("koo koo ca choo",
pkg);
asm = new PackageAssembler(pkg);
asm.compile();
assertTrue(asm.hasErrors());
//check the snapshot is kosher
pkg = repo.loadPackageSnapshot(pkg.getName(),
"SNAP_1");
asm = new PackageAssembler(pkg);
asm.compile();
assertFalse(asm.hasErrors());