01: package org.drools.rule;
02:
03: import java.util.Calendar;
04:
05: import junit.framework.TestCase;
06:
07: /**
08: * @author Michael Neale
09: */
10: public class RuleTest extends TestCase {
11:
12: public void testDateEffective() {
13: final Rule rule = new Rule("myrule");
14:
15: assertTrue(rule.isEffective());
16:
17: final Calendar earlier = Calendar.getInstance();
18: earlier.setTimeInMillis(10);
19:
20: rule.setDateEffective(earlier);
21:
22: assertTrue(rule.isEffective());
23:
24: final Calendar later = Calendar.getInstance();
25: later.setTimeInMillis(later.getTimeInMillis() + 100000000);
26:
27: assertTrue(later.after(Calendar.getInstance()));
28:
29: rule.setDateEffective(later);
30: assertFalse(rule.isEffective());
31:
32: }
33:
34: public void testDateExpires() throws Exception {
35: final Rule rule = new Rule("myrule");
36:
37: assertTrue(rule.isEffective());
38:
39: final Calendar earlier = Calendar.getInstance();
40: earlier.setTimeInMillis(10);
41:
42: rule.setDateExpires(earlier);
43:
44: assertFalse(rule.isEffective());
45:
46: final Calendar later = Calendar.getInstance();
47: later.setTimeInMillis(later.getTimeInMillis() + 100000000);
48:
49: rule.setDateExpires(later);
50: assertTrue(rule.isEffective());
51:
52: }
53:
54: public void testDateEffectiveExpires() {
55: final Rule rule = new Rule("myrule");
56:
57: final Calendar past = Calendar.getInstance();
58: past.setTimeInMillis(10);
59:
60: final Calendar future = Calendar.getInstance();
61: future.setTimeInMillis(future.getTimeInMillis() + 100000000);
62:
63: rule.setDateEffective(past);
64: rule.setDateExpires(future);
65:
66: assertTrue(rule.isEffective());
67:
68: rule.setDateExpires(past);
69: assertFalse(rule.isEffective());
70:
71: rule.setDateExpires(future);
72: rule.setDateEffective(future);
73:
74: assertFalse(rule.isEffective());
75:
76: }
77:
78: public void testRuleEnabled() {
79: final Rule rule = new Rule("myrule");
80: rule.setEnabled(false);
81: assertFalse(rule.isEffective());
82:
83: final Calendar past = Calendar.getInstance();
84: past.setTimeInMillis(10);
85:
86: rule.setDateEffective(past);
87: assertFalse(rule.isEffective());
88: rule.setEnabled(true);
89:
90: assertTrue(rule.isEffective());
91: }
92:
93: }
|