use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleTest method testTimeMachine.
@Test
public void testTimeMachine() {
SessionConfiguration conf = SessionConfiguration.newInstance();
conf.setClockType(ClockType.PSEUDO_CLOCK);
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession(conf, null);
final Calendar future = Calendar.getInstance();
((PseudoClockScheduler) wm.getSessionClock()).setStartupTime(future.getTimeInMillis());
final RuleImpl rule = new RuleImpl("myrule");
rule.setEnabled(EnabledBoolean.ENABLED_TRUE);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
future.setTimeInMillis(future.getTimeInMillis() + 100000000);
rule.setDateEffective(future);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
((PseudoClockScheduler) wm.getSessionClock()).advanceTime(1000000000000L, TimeUnit.MILLISECONDS);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleTest method testGetSalienceValue.
@Test
public void testGetSalienceValue() {
final RuleImpl rule = new RuleImpl("myrule");
final int salienceValue = 100;
Salience salience = new SalienceInteger(salienceValue);
rule.setSalience(salience);
assertEquals(salienceValue, rule.getSalienceValue());
assertFalse(rule.isSalienceDynamic());
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleTest method testIsSalienceDynamic.
@Test
public void testIsSalienceDynamic() {
final RuleImpl rule = new RuleImpl("myrule");
Salience salience = new MVELSalienceExpression();
rule.setSalience(salience);
assertTrue(rule.isSalienceDynamic());
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleTest method testDateExpires.
@Test
public void testDateExpires() throws Exception {
WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl("x", null).newKieSession();
final RuleImpl rule = new RuleImpl("myrule");
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar earlier = Calendar.getInstance();
earlier.setTimeInMillis(10);
rule.setDateExpires(earlier);
assertFalse(rule.isEffective(null, new RuleTerminalNode(), wm));
final Calendar later = Calendar.getInstance();
later.setTimeInMillis(later.getTimeInMillis() + 100000000);
rule.setDateExpires(later);
assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm));
}
use of org.drools.core.definitions.rule.impl.RuleImpl in project drools by kiegroup.
the class RuleBuilder method buildMetaAttributes.
public static void buildMetaAttributes(final RuleBuildContext context) {
RuleImpl rule = context.getRule();
for (String metaAttr : context.getRuleDescr().getAnnotationNames()) {
AnnotationDescr ad = context.getRuleDescr().getAnnotation(metaAttr);
String adFqn = ad.getFullyQualifiedName();
if (adFqn != null) {
AnnotationDefinition annotationDefinition;
try {
annotationDefinition = AnnotationDefinition.build(context.getDialect().getTypeResolver().resolveType(adFqn), ad.getValueMap(), context.getDialect().getTypeResolver());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (annotationDefinition.getValues().size() == 1 && annotationDefinition.getValues().containsKey(AnnotationDescr.VALUE)) {
rule.addMetaAttribute(metaAttr, annotationDefinition.getPropertyValue(AnnotationDescr.VALUE));
} else {
Map<String, Object> map = new HashMap<String, Object>(annotationDefinition.getValues().size());
for (String key : annotationDefinition.getValues().keySet()) {
map.put(key, annotationDefinition.getPropertyValue(key));
}
rule.addMetaAttribute(metaAttr, map);
}
} else {
if (ad.hasValue()) {
if (ad.getValues().size() == 1) {
rule.addMetaAttribute(metaAttr, resolveValue(ad.getSingleValueAsString()));
} else {
rule.addMetaAttribute(metaAttr, ad.getValueMap());
}
} else {
rule.addMetaAttribute(metaAttr, null);
}
}
}
}
Aggregations