01: package org.drools.decisiontable.parser;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import junit.framework.TestCase;
07:
08: public class DefaultGeneratorTest extends TestCase {
09: private DefaultGenerator g;
10:
11: protected void setUp() throws Exception {
12: Map t = new HashMap();
13: RuleTemplate rt1 = new RuleTemplate("rt1");
14: rt1.setContents("Test template 1");
15: RuleTemplate rt2 = new RuleTemplate("rt2");
16: rt2.setContents("Test template 2");
17: RuleTemplate rt3 = new RuleTemplate("rt3");
18: rt3.addColumn("col1");
19: rt3.addColumn("col2");
20: rt3.setContents("@{row.rowNumber} @{col1} @{col2}");
21: t.put("rt1", rt1);
22: t.put("rt2", rt2);
23: t.put("rt3", rt3);
24: g = new DefaultGenerator(t);
25: }
26:
27: public void testSelectTemplate() {
28: g.generate("rt2", new Row());
29: String drl = g.getDrl();
30: assertEquals("Test template 2\n\n", drl);
31: }
32:
33: public void testGenerate() {
34: g.generate("rt2", new Row());
35: g.generate("rt1", new Row());
36: String drl = g.getDrl();
37: assertEquals("Test template 2\n\nTest template 1\n\n", drl);
38: }
39:
40: public void testAddColumns() {
41: Column[] columns = { new Column("col1"), new Column("col2") };
42: Row r = new Row(1, columns);
43: r.getCell(0).setValue("value1");
44: r.getCell(1).setValue("value2");
45: // r.addCell(new Cell(r, new Column("col1"), "value1"));
46: // r.addCell(new Cell(r, new Column("col2"), "value2"));
47: g.generate("rt3", r);
48: String drl = g.getDrl();
49: assertEquals("1 value1 value2\n\n", drl);
50: }
51:
52: }
|