01: package org.drools.rule.builder.dialect;
02:
03: import java.io.InputStreamReader;
04: import java.io.Reader;
05:
06: import junit.framework.Assert;
07: import junit.framework.TestCase;
08:
09: import org.drools.RuleBase;
10: import org.drools.RuleBaseFactory;
11: import org.drools.compiler.PackageBuilder;
12: import org.drools.rule.Package;
13:
14: public class JavaAndMVELCombinedTest extends TestCase {
15:
16: private final static String FN1 = "mveljavarules.drl";
17: private final static String FN2 = "mvelonly.drl";
18: private final static String FN3 = "javaonly.drl";
19:
20: public void testMixed() {
21: timing(FN1, "mveljava: ");
22: }
23:
24: public void testMVEL() {
25: timing(FN2, " mvel: ");
26: }
27:
28: public void testJAVA() {
29: timing(FN3, " java: ");
30: }
31:
32: // public void testJavaMVELCombination() throws Exception {
33: // long time1 = timing( new Runnable() {
34: // public void run() {
35: // readDRL( FN1 );
36: // }
37: // } );
38: // long time2 = timing( new Runnable() {
39: // public void run() {
40: // readDRL( FN2 );
41: // }
42: // } );
43: // long time3 = timing( new Runnable() {
44: // public void run() {
45: // readDRL( FN3 );
46: // }
47: // } );
48: //
49: // System.out.println("mveljava: "+time1/1000.);
50: // System.out.println(" mvel: "+time2/1000.);
51: // System.out.println(" java: "+time3/1000.);
52: //
53: // }
54:
55: private void timing(String name, String msg) {
56: long start = System.currentTimeMillis();
57: readDRL(name);
58: long time = System.currentTimeMillis() - start;
59: System.out.println(msg + time / 1000.);
60: }
61:
62: private void readDRL(String fn) {
63: try {
64: Reader source = new InputStreamReader(
65: JavaAndMVELCombinedTest.class
66: .getResourceAsStream(fn));
67:
68: PackageBuilder builder = new PackageBuilder();
69: builder.addPackageFromDrl(source);
70: Assert.assertEquals(0,
71: builder.getErrors().getErrors().length);
72:
73: Package pkg = builder.getPackage();
74: RuleBase ruleBase = RuleBaseFactory.newRuleBase();
75: ruleBase.addPackage(pkg);
76:
77: Assert.assertEquals(2, pkg.getRules().length);
78: } catch (Throwable t) {
79: throw new RuntimeException(t);
80: }
81:
82: }
83:
84: }
|