01: package org.drools.brms.modeldriven;
02:
03: import junit.framework.TestCase;
04:
05: import org.drools.brms.client.modeldriven.brl.CompositeFieldConstraint;
06: import org.drools.brms.client.modeldriven.brl.FactPattern;
07: import org.drools.brms.client.modeldriven.brl.SingleFieldConstraint;
08:
09: public class FactPatternTest extends TestCase {
10:
11: public void testAddConstraint() {
12: final FactPattern p = new FactPattern();
13: final SingleFieldConstraint x = new SingleFieldConstraint("x");
14: p.addConstraint(x);
15:
16: assertEquals(1, p.constraintList.constraints.length);
17: assertEquals(x, p.constraintList.constraints[0]);
18:
19: final SingleFieldConstraint y = new SingleFieldConstraint("y");
20:
21: p.addConstraint(y);
22: assertEquals(2, p.constraintList.constraints.length);
23: assertEquals(x, p.constraintList.constraints[0]);
24: assertEquals(y, p.constraintList.constraints[1]);
25:
26: }
27:
28: public void testWithCompositeNesting() {
29: final FactPattern p = new FactPattern();
30: final SingleFieldConstraint x = new SingleFieldConstraint("x");
31: p.addConstraint(x);
32:
33: assertEquals(1, p.constraintList.constraints.length);
34: assertEquals(x, p.constraintList.constraints[0]);
35:
36: final CompositeFieldConstraint y = new CompositeFieldConstraint();
37:
38: y.addConstraint(new SingleFieldConstraint("y"));
39: y.addConstraint(new SingleFieldConstraint("z"));
40: p.addConstraint(y);
41:
42: assertEquals(2, p.constraintList.constraints.length);
43: assertEquals(x, p.constraintList.constraints[0]);
44: assertEquals(y, p.constraintList.constraints[1]);
45:
46: }
47:
48: public void testRemoveConstraint() {
49: final FactPattern p = new FactPattern();
50: final SingleFieldConstraint x = new SingleFieldConstraint("x");
51: p.addConstraint(x);
52: final SingleFieldConstraint y = new SingleFieldConstraint("y");
53: p.addConstraint(y);
54:
55: assertEquals(2, p.constraintList.constraints.length);
56:
57: p.removeConstraint(1);
58:
59: assertEquals(1, p.constraintList.constraints.length);
60:
61: assertEquals(x, p.constraintList.constraints[0]);
62:
63: }
64:
65: public void testIsBound() {
66: FactPattern pat = new FactPattern();
67: pat.boundName = "x";
68: assertTrue(pat.isBound());
69:
70: pat = new FactPattern();
71: assertFalse(pat.isBound());
72: }
73:
74: public void testGetFieldConstraints() {
75: FactPattern pat = new FactPattern();
76: assertEquals(0, pat.getFieldConstraints().length);
77: assertNull(pat.constraintList);
78:
79: pat.addConstraint(new SingleFieldConstraint());
80: assertNotNull(pat.constraintList);
81: assertEquals(1, pat.getFieldConstraints().length);
82: }
83:
84: }
|