/**
* Tests the getObject() and afterPropertiesSet() methods
*/
public void testInitialization() throws Exception {
DefaultRuleSource source = new DefaultRuleSource();
// test the afterPropertiesSet() calls
try {
source.afterPropertiesSet();
fail("ruleServiceProvider, bindUri and source not set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setBindUri(BIND_URI);
try {
source.afterPropertiesSet();
fail("ruleAdministrator, ruleRuntime and source not set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setSource(new ClassPathResource(RULES_RESOURCE));
try {
source.afterPropertiesSet();
fail("ruleAdministrator, ruleRuntime not set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setRuleServiceProvider(getProvider());
source.setRuleAdministrator(ruleAdministrator);
try {
source.afterPropertiesSet();
fail("ruleServiceProvider AND ruleAdministrator set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setRuleAdministrator(null);
source.setRuleRuntime(ruleRuntime);
try {
source.afterPropertiesSet();
fail("ruleServiceProvider AND ruleRuntime set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setRuleAdministrator(ruleAdministrator);
try {
source.afterPropertiesSet();
fail("ruleServiceProvider AND ruleRuntime and ruleAdministrator set");
}
catch (IllegalArgumentException ex) {
// expected
}
source.setRuleAdministrator(null);
source.setRuleRuntime(null);
source.afterPropertiesSet();
try {
source.createSession(BIND_URI + "-foo", null, RuleRuntime.STATELESS_SESSION_TYPE);
fail("Ruleset at uri " + BIND_URI + "-foo exists!");
}
catch (RuleExecutionSetNotFoundException ex) {
// expected
}
StatelessRuleSession session = (StatelessRuleSession) source.createSession(BIND_URI, null, RuleRuntime.STATELESS_SESSION_TYPE);
assertNotNull("Created session is null", session);
session.release();
}