/** * Create a Provider. * * @param url * @param rulesets * @return * @throws Exception */ public RuleServiceProvider getServiceProvider(final String url, final String ruleset) throws Exception { // create the provider final Class clazz = this.getClass() .getClassLoader() .loadClass("org.drools.jsr94.rules.RuleServiceProviderImpl"); RuleServiceProviderManager.registerRuleServiceProvider(url, clazz); final RuleServiceProvider serviceProvider = RuleServiceProviderManager.getRuleServiceProvider(url); final RuleAdministrator ruleAdministrator = serviceProvider.getRuleAdministrator(); // register the ruleset final InputStream inStream = this.getClass().getResourceAsStream(ruleset); final RuleExecutionSet res1 = ruleAdministrator .getLocalRuleExecutionSetProvider(null) .createRuleExecutionSet(inStream, null); inStream.close(); final String uri = res1.getName(); System.out.println(uri); ruleAdministrator.registerRuleExecutionSet(uri, res1, null); return serviceProvider; }
/** Test getRuleRuntime. */ @Test public void testRuleRuntime() throws Exception { Class.forName("org.drools.jsr94.rules.RuleServiceProviderImpl"); RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager.getRuleServiceProvider("http://drools.org/"); final RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); assertNotNull("cannot obtain RuleRuntime", ruleRuntime); assertTrue("not a class instance", ruleRuntime == ruleServiceProvider.getRuleRuntime()); }