/** * This this case we will test errors that occur in rule assets, not in functions or package * header. */ public void testErrorsInRuleAsset() throws Exception { RulesRepository repo = getRepo(); // first, setup the package correctly: PackageItem pkg = repo.createPackage("testErrorsInRuleAsset", ""); AssetItem model = pkg.addAsset("model", "qed"); model.updateFormat(AssetFormats.MODEL); model.updateBinaryContentAttachment(this.getClass().getResourceAsStream("/billasurf.jar")); model.checkin(""); ServiceImplementation.updateDroolsHeader( "import com.billasurf.Board\n global com.billasurf.Person customer", pkg); repo.save(); AssetItem goodRule = pkg.addAsset("goodRule", ""); goodRule.updateFormat(AssetFormats.DRL); goodRule.updateContent("rule 'yeah' \n when \n Board() \n then \n System.out.println(42); end"); goodRule.checkin(""); AssetItem badRule = pkg.addAsset("badRule", "xxx"); badRule.updateFormat(AssetFormats.DRL); badRule.updateContent("if something then another"); badRule.checkin(""); ContentPackageAssembler asm = new ContentPackageAssembler(pkg); assertTrue(asm.hasErrors()); assertFalse(asm.isPackageConfigurationInError()); for (ContentAssemblyError err : asm.getErrors()) { assertTrue(err.itemInError.getName().equals(badRule.getName())); assertNotEmpty(err.errorReport); } }
/** Test package configuration errors, including header, functions, DSL files. */ public void testPackageConfigWithErrors() throws Exception { // test the config, no rule assets yet RulesRepository repo = getRepo(); PackageItem pkg = repo.createPackage("testBuilderPackageConfig", "x"); ServiceImplementation.updateDroolsHeader("import java.util.List", pkg); AssetItem func = pkg.addAsset("func1", "a function"); func.updateFormat(AssetFormats.FUNCTION); func.updateContent( "function void doSomething() { \n System.err.println(List.class.toString()); }"); func.checkin("yeah"); func = pkg.addAsset("func2", "q"); func.updateFormat(AssetFormats.FUNCTION); func.updateContent("function void foo() { \nSystem.err.println(42); \n}"); func.checkin(""); AssetItem ass = pkg.addAsset("dsl", "m"); ass.updateFormat(AssetFormats.DSL); ass.updateContent("[when]Foo bar=String()"); ass.checkin(""); repo.save(); // now lets light it up ContentPackageAssembler assembler = new ContentPackageAssembler(pkg); assertFalse(assembler.hasErrors()); Package bin = assembler.getBinaryPackage(); assertNotNull(bin); assertEquals("testBuilderPackageConfig", bin.getName()); assertEquals(2, bin.getFunctions().size()); assertTrue(bin.isValid()); assertEquals(1, assembler.builder.getDSLMappingFiles().size()); ServiceImplementation.updateDroolsHeader("koo koo ca choo", pkg); assembler = new ContentPackageAssembler(pkg); assertTrue(assembler.hasErrors()); assertTrue(assembler.isPackageConfigurationInError()); ServiceImplementation.updateDroolsHeader("import java.util.Date", pkg); assembler = new ContentPackageAssembler(pkg); assertTrue(assembler.hasErrors()); assertTrue(assembler.getErrors().get(0).itemInError instanceof AssetItem); assertEquals("func1", assembler.getErrors().get(0).itemInError.getName()); try { assembler.getBinaryPackage(); fail("should not work as is in error."); } catch (IllegalStateException e) { assertNotNull(e.getMessage()); } // fix it up ServiceImplementation.updateDroolsHeader("import java.util.List", pkg); assembler = new ContentPackageAssembler(pkg); assertFalse(assembler.hasErrors()); // now break a DSL and check the error ass.updateContent("rubbish"); ass.checkin(""); assembler = new ContentPackageAssembler(pkg); assertTrue(assembler.hasErrors()); assertTrue(assembler.getErrors().get(0).itemInError.getName().equals(ass.getName())); assertNotEmpty(assembler.getErrors().get(0).errorReport); assertFalse(assembler.isPackageConfigurationInError()); // now fix it up ass.updateContent("[when]foo=String()"); ass.checkin(""); assembler = new ContentPackageAssembler(pkg); assertFalse(assembler.hasErrors()); // break a func, and check for error func.updateContent("goo"); func.checkin(""); assembler = new ContentPackageAssembler(pkg); assertTrue(assembler.hasErrors()); assertFalse(assembler.isPackageConfigurationInError()); assertTrue(assembler.getErrors().get(0).itemInError.getName().equals(func.getName())); assertNotEmpty(assembler.getErrors().get(0).errorReport); }