1 package org.drools.jsr94.benchmark.drools;
2
3 /*
4 $Id: DroolsBenchmarkTestCase.java,v 1.2 2003/03/27 20:42:02 tdiesler Exp $
5
6 Copyright 2002 (C) The Werken Company. All Rights Reserved.
7
8 Redistribution and use of this software and associated documentation
9 ("Software"), with or without modification, are permitted provided
10 that the following conditions are met:
11
12 1. Redistributions of source code must retain copyright
13 statements and notices. Redistributions must also contain a
14 copy of this document.
15
16 2. Redistributions in binary form must reproduce the
17 above copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
20
21 3. The name "drools" must not be used to endorse or promote
22 products derived from this Software without prior written
23 permission of The Werken Company. For written permission,
24 please contact bob@werken.com.
25
26 4. Products derived from this Software may not be called "drools"
27 nor may "drools" appear in their names without prior written
28 permission of The Werken Company. "drools" is a registered
29 trademark of The Werken Company.
30
31 5. Due credit should be given to The Werken Company.
32 (http://drools.werken.com/).
33
34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
45 OF THE POSSIBILITY OF SUCH DAMAGE.
46
47 */
48
49 import org.drools.jsr94.benchmark.BenchmarkTestBase;
50
51 import javax.rules.RuleRuntime;
52 import javax.rules.RuleServiceProviderManager;
53 import javax.rules.StatelessRuleSession;
54 import javax.rules.admin.LocalRuleExecutionSetProvider;
55 import javax.rules.admin.RuleExecutionSet;
56 import java.io.InputStream;
57 import java.io.FileInputStream;
58 import java.util.List;
59
60 /***
61 * Uses the RuleServiceProviderImpl for Drools to solve the Miss Manners problem.
62 *
63 * Miss Manners is a program which handles the problem of finding an acceptable
64 * seating arrangement for guests at a dinner party. It will attempt to match
65 * people with the same hobbies, and to seat everyone next to a member of the
66 * opposite sex. Manners is a small program, which has only few rules, and
67 * employs a depth-first search approach to the problem.
68 *
69 * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler</a>
70 */
71 public class DroolsBenchmarkTestCase extends BenchmarkTestBase
72 {
73
74 /*** Drools <code>RuleServiceProvider</code> URI. */
75 public static final String RULE_SERVICE_PROVIDER = "http://drools.org/RuleServiceProvider";
76
77 /*** manners URI */
78 public static final String RULE_URI = "http://drools.org/manners";
79
80 private static final String TESTDATA_LOCATION = "src/java/test/org/drools/jsr94/benchmark";
81 /***
82 * Setup the test case.
83 */
84 protected void setUp() throws Exception
85 {
86 super.setUp();
87
88 // obtain the RuleServiceProvider
89 RuleServiceProviderManager.registerRuleServiceProvider( RULE_SERVICE_PROVIDER, org.drools.jsr94.rules.RuleServiceProviderImpl.class );
90 ruleServiceProvider = RuleServiceProviderManager.getRuleServiceProvider( RULE_SERVICE_PROVIDER );
91 ruleAdministrator = ruleServiceProvider.getRuleAdministrator();
92
93 // load the rules and register them
94 LocalRuleExecutionSetProvider ruleSetProvider = ruleAdministrator.getLocalRuleExecutionSetProvider( null );
95 InputStream rules = new FileInputStream(TESTDATA_LOCATION + "/drools/manners.xml" );
96 RuleExecutionSet ruleExecutionSet = ruleSetProvider.createRuleExecutionSet( rules, null );
97 ruleAdministrator.registerRuleExecutionSet( RULE_URI, ruleExecutionSet, null );
98
99 RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
100 statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession( RULE_URI, null, RuleRuntime.STATELESS_SESSION_TYPE );
101 }
102
103 /***
104 * Tear down the test case
105 */
106 protected void tearDown() throws Exception
107 {
108 statelessRuleSession.release();
109 ruleAdministrator.unregisterRuleExecutionSet( RULE_URI, null );
110 super.tearDown();
111 }
112
113 public void testMissManners16() throws Exception
114 {
115 List inList = getInputObjects(TESTDATA_LOCATION + "/manners16.dat" );
116 List outList = statelessRuleSession.executeRules( inList );
117 assertEquals( "seated guests", 16, validateResults( inList, outList ) );
118 }
119
120 public void testMissManners32() throws Exception
121 {
122 List inList = getInputObjects(TESTDATA_LOCATION + "/manners32.dat" );
123 List outList = statelessRuleSession.executeRules( inList );
124 assertEquals( "seated guests", 32, validateResults( inList, outList ) );
125 }
126
127 public void testMissManners64() throws Exception
128 {
129 List inList = getInputObjects(TESTDATA_LOCATION + "/manners64.dat" );
130 List outList = statelessRuleSession.executeRules( inList );
131 assertEquals( "seated guests", 64, validateResults( inList, outList ) );
132 }
133
134 public void testMissManners128() throws Exception
135 {
136 List inList = getInputObjects(TESTDATA_LOCATION + "/manners128.dat" );
137 List outList = statelessRuleSession.executeRules( inList );
138 assertEquals( "seated guests", 128, validateResults( inList, outList ) );
139 }
140 }
This page was automatically generated by Maven