01: package org.drools.brms.server.contenthandler;
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: import org.drools.brms.server.contenthandler.DRLFileContentHandler;
21:
22: public class DRLFileContentHandlerTest extends TestCase {
23:
24: public void testSniffDRLType() throws Exception {
25:
26: DRLFileContentHandler h = new DRLFileContentHandler();
27:
28: // in this case we have package, and N rules
29: String classic = "package foobar \n rule boo \n when \n then\n end \n rule boo2 \n when \n then\n end";
30:
31: // in this case we just have rules
32: String moreRuleClassic = "\nrule bar \n when \n then \n end\nrule x \n when \n then \n end ";
33:
34: // in this case we just have a single rule
35: String newRule = "agenda-group 'x' \n when \n then \n";
36:
37: String moreSingle = "rule foo when then end";
38:
39: String moreNewRule = "agenda-group 'x' \n when end.bar \n then rule.end.bar";
40:
41: String emptyRule = "";
42:
43: assertTrue(h.isStandAloneRule(newRule));
44: assertFalse(h.isStandAloneRule(moreRuleClassic));
45: assertFalse(h.isStandAloneRule(classic));
46: assertFalse(h.isStandAloneRule(moreSingle));
47: assertFalse(h.isStandAloneRule(null));
48: assertFalse(h.isStandAloneRule(emptyRule));
49: assertTrue(h.isStandAloneRule(moreNewRule));
50:
51: }
52:
53: public void testRuleWithDialect() {
54: String rule = "rule \"DemoRule\" \n " + " salience 10 \n"
55: + " dialect \"mvel\" \n " + " when \n"
56: + " Driver( age > 65 ) \n" + " then \n"
57: + " insert(new Rejection(\" too old \"));" + "end ";
58: DRLFileContentHandler h = new DRLFileContentHandler();
59: assertFalse(h.isStandAloneRule(rule));
60:
61: assertFalse(h.isStandAloneRule(""));
62:
63: }
64:
65: }
|