01: package org.drools.decisiontable.model;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import junit.framework.TestCase;
20:
21: /**
22: * @author <a href="mailto:michael.neale@gmail.com"> Michael Neale</a>
23: *
24: * Test rendering and running a whole sample ruleset, from the model classes
25: * down.
26: */
27: public class PackageRenderTest extends TestCase {
28:
29: public Rule buildRule() {
30: final Rule rule = new Rule("myrule", new Integer(42), 1);
31: rule.setComment("rule comments");
32:
33: final Condition cond = new Condition();
34: cond.setComment("cond comment");
35: cond.setSnippet("cond snippet");
36: rule.addCondition(cond);
37:
38: final Consequence cons = new Consequence();
39: cons.setComment("cons comment");
40: cons.setSnippet("cons snippet");
41: rule.addConsequence(cons);
42:
43: return rule;
44: }
45:
46: public void testRulesetRender() {
47: final Package ruleSet = new Package("my ruleset");
48: ruleSet.addFunctions("my functions");
49: ruleSet.addRule(buildRule());
50:
51: final Rule rule = buildRule();
52: rule.setName("other rule");
53: ruleSet.addRule(rule);
54:
55: final Import imp = new Import();
56: imp.setClassName("clazz name");
57: imp.setComment("import comment");
58: ruleSet.addImport(imp);
59:
60: final DRLOutput out = new DRLOutput();
61: ruleSet.renderDRL(out);
62:
63: final String drl = out.getDRL();
64: assertNotNull(drl);
65: System.out.println(drl);
66: assertTrue(drl.indexOf("rule \"myrule\"") > -1);
67: assertTrue(drl.indexOf("salience 42") > -1);
68: assertTrue(drl.indexOf("#rule comments") > -1);
69: assertTrue(drl.indexOf("my functions") > -1);
70: assertTrue(drl.indexOf("package my_ruleset;") > -1);
71: assertTrue(drl.indexOf("rule \"other rule\"") > drl
72: .indexOf("rule \"myrule\""));
73:
74: }
75:
76: }
|