KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeAgentConfiguration conf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
// needs to be newInstance=true, bugzilla 733008 works fine with newInstance=false
conf.setProperty("drools.agent.newInstance", "true");
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent(
"agent", kbase, conf);
try {
ResourceFactory.getResourceChangeNotifierService().start();
ResourceFactory.getResourceChangeScannerService().start();
ResourceChangeScannerConfiguration sconf = ResourceFactory
.getResourceChangeScannerService()
.newResourceChangeScannerConfiguration();
sconf.setProperty("drools.resource.scanner.interval", "5");
ResourceFactory.getResourceChangeScannerService().configure(sconf);
kagent.applyChangeSet(res);
kbase = kagent.getKnowledgeBase();
Thread.sleep(1000);
assertEquals(2, kbase.getKnowledgePackages().iterator().next().getRules().size());
System.out.println("BUGZILLA 733008 total rules: " + kbase.getKnowledgePackages().iterator().next().getRules().size());
for (Rule r : kbase.getKnowledgePackages().iterator().next().getRules()) {
System.out.println(r.getName());
}
// Change Guvnor's repo with REST api by deleting asset rule2
Abdera abdera = new Abdera();
AbderaClient client = new AbderaClient(abdera);
client.addCredentials(baseURL.toExternalForm(),
null,
null,
new org.apache.commons.httpclient.UsernamePasswordCredentials("admin",
"admin"));
ClientResponse deleteResponse = client.delete(
new URL(baseURL, "rest/packages/scanForChangeInRepository/assets/ruleB2").toExternalForm());
assertEquals(204, deleteResponse.getStatus());
ClientResponse binaryResponse = client.get(
new URL(baseURL, "rest/packages/scanForChangeInRepository/binary").toExternalForm());
assertEquals(200, binaryResponse.getStatus());
// detect the change
Thread.sleep(6000);
kbase = kagent.getKnowledgeBase();
assertEquals(1, kbase.getKnowledgePackages().iterator().next().getRules().size());
} finally {
kagent.dispose();
ResourceFactory.getResourceChangeNotifierService().stop();
ResourceFactory.getResourceChangeScannerService().stop();
}
}