01: package org.drools.brms.server.util;
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 java.io.IOException;
20: import java.io.InputStream;
21:
22: import junit.framework.TestCase;
23:
24: public class ClassicDRLImporterTest extends TestCase {
25:
26: public void testStandardDRL() throws Exception {
27:
28: ClassicDRLImporter imp = new ClassicDRLImporter(
29: getDrl("sample_legacy.drl"));
30: assertEquals("foo", imp.getPackageName());
31: assertEquals(2, imp.getRules().size());
32:
33: assertEquals("blah", imp.getRules().get(0).name);
34: assertEquals("cha", imp.getRules().get(1).name);
35:
36: System.err.println(imp.getPackageHeader());
37:
38: assertTrue(imp.getPackageHeader().indexOf("import goo.wee") > -1);
39: assertTrue(imp.getPackageHeader().indexOf("package") == -1);
40:
41: assertFalse(imp.isDSLEnabled());
42:
43: assertEqualsIgnoreWhitespace("when Whee() then goo();", imp
44: .getRules().get(0).content);
45: assertEqualsIgnoreWhitespace("when Sup() then ka();", imp
46: .getRules().get(1).content);
47: assertTrue(imp.getRules().get(0).content.indexOf(" Whee()") > -1);
48:
49: }
50:
51: public void testWithDSL() throws Exception {
52:
53: ClassicDRLImporter imp = new ClassicDRLImporter(
54: getDrl("sample_legacy_with_dsl.drl"));
55:
56: assertTrue(imp.isDSLEnabled());
57: assertEquals(2, imp.getRules().size());
58: assertEquals("foo", imp.getPackageName());
59: assertEqualsIgnoreWhitespace("import goo.wee global ka.cha",
60: imp.getPackageHeader());
61:
62: assertEqualsIgnoreWhitespace("when ka chow then bam", imp
63: .getRules().get(0).content);
64: assertEqualsIgnoreWhitespace("when ka chiga then ka chow", imp
65: .getRules().get(1).content);
66:
67: }
68:
69: private InputStream getDrl(String file) throws IOException {
70: return this .getClass().getResourceAsStream(file);
71: }
72:
73: private void assertEqualsIgnoreWhitespace(final String expected,
74: final String actual) {
75: final String cleanExpected = expected.replaceAll("\\s+", "");
76: final String cleanActual = actual.replaceAll("\\s+", "");
77:
78: assertEquals(cleanExpected, cleanActual);
79: }
80:
81: }
|