Hi Srikant,
I copied your rule and wrote a test:
@Test
public void testCalenderRule() throws InterruptedException {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("drools/"
+ "expert.drl"), ResourceType.DRL);
KnowledgeBaseConfiguration config = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeSessionConfiguration conf = KnowledgeBaseFactory
.newKnowledgeSessionConfiguration();
ksession = kbase.newStatefulKnowledgeSession(conf, null);
ksession.getCalendars().set("weekDayCalendar", new Calendar() {
public boolean isTimeIncluded(long timestamp) {
Date date = new Date(timestamp);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(GregorianCalendar.DAY_OF_WEEK);
if (dayOfWeek != GregorianCalendar.SATURDAY
&& dayOfWeek != GregorianCalendar.SUNDAY) {
return true;
} else {
return false;
}
}
});
ksession.getCalendars().set("holidayCalendar", new Calendar() {
public boolean isTimeIncluded(long timestamp) {
Date date = new Date(timestamp);
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
int dayOfWeek = cal.get(GregorianCalendar.DAY_OF_WEEK);
if (dayOfWeek == GregorianCalendar.SATURDAY
|| dayOfWeek == GregorianCalendar.SUNDAY) {
return true;
} else {
return false;
}
}
});
ksession.insert(new Alarm());
ksession.fireAllRules();
}
Only the "week days rule" is getting executed as excepted. For me it works fine.