01: package org.drools.decisiontable.parser;
02:
03: import org.drools.decisiontable.parser.LhsBuilder.FieldType;
04:
05: import junit.framework.TestCase;
06:
07: public class LhsBuilderTest extends TestCase {
08:
09: public void testBuildItUp() throws Exception {
10: LhsBuilder builder = new LhsBuilder("Person");
11:
12: builder.addTemplate(1, "age");
13: builder.addTemplate(2, "size != $param");
14: builder.addTemplate(3, "date <");
15:
16: builder.addCellValue(1, "42");
17: builder.addCellValue(2, "20");
18: builder.addCellValue(3, "30");
19:
20: assertEquals(
21: "Person(age == \"42\", size != 20, date < \"30\")",
22: builder.getResult());
23:
24: builder.clearValues();
25:
26: builder.addCellValue(2, "42");
27: assertEquals("Person(size != 42)", builder.getResult());
28: }
29:
30: public void testEmptyCells() {
31: LhsBuilder builder = new LhsBuilder("Person");
32: assertFalse(builder.hasValues());
33: }
34:
35: public void testClassicMode() {
36: LhsBuilder builder = new LhsBuilder("");
37: builder.addTemplate(1, "Person(age < $param)");
38: builder.addCellValue(1, "42");
39:
40: assertEquals("Person(age < 42)", builder.getResult());
41:
42: builder = new LhsBuilder(null);
43: builder.addTemplate(3, "Foo(bar == $param)");
44: builder.addTemplate(4, "eval(true)");
45:
46: builder.addCellValue(3, "42");
47: builder.addCellValue(4, "Y");
48:
49: assertEquals("Foo(bar == 42)\neval(true)", builder.getResult());
50: }
51:
52: public void testIdentifyFieldTypes() {
53: LhsBuilder builder = new LhsBuilder("");
54: assertEquals(FieldType.SINGLE_FIELD, builder
55: .calcFieldType("age"));
56: assertEquals(FieldType.OPERATOR_FIELD, builder
57: .calcFieldType("age <"));
58: assertEquals(FieldType.NORMAL_FIELD, builder
59: .calcFieldType("age < $param"));
60:
61: }
62:
63: public void testIdentifyColumnCorrectly() {
64: LhsBuilder builder = new LhsBuilder(null);
65: assertFalse(builder.isMultipleConstraints());
66:
67: //will be added to Foo
68: builder = new LhsBuilder("Foo");
69: assertTrue(builder.isMultipleConstraints());
70:
71: //will be added to eval
72: builder = new LhsBuilder("f:Foo() eval ");
73: assertTrue(builder.isMultipleConstraints());
74:
75: //will just be verbatim
76: builder = new LhsBuilder("f: Foo()");
77: assertFalse(builder.isMultipleConstraints());
78:
79: }
80:
81: }
|