01: package org.drools.decisiontable;
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.util.ArrayList;
20: import java.util.HashMap;
21: import java.util.List;
22: import java.util.Map;
23:
24: import javax.rules.RuleRuntime;
25: import javax.rules.RuleServiceProvider;
26: import javax.rules.RuleServiceProviderManager;
27: import javax.rules.StatefulRuleSession;
28: import javax.rules.admin.LocalRuleExecutionSetProvider;
29: import javax.rules.admin.RuleAdministrator;
30: import javax.rules.admin.RuleExecutionSet;
31:
32: import junit.framework.TestCase;
33:
34: import org.drools.jsr94.rules.Constants;
35: import org.drools.jsr94.rules.ExampleRuleEngineFacade;
36: import org.drools.jsr94.rules.RuleServiceProviderImpl;
37:
38: public class SpreadsheetIntegrationTest extends TestCase {
39:
40: public void testExecute() throws Exception {
41: Map properties = new HashMap();
42: properties.put(Constants.RES_SOURCE,
43: Constants.RES_SOURCE_TYPE_DECISION_TABLE);
44:
45: RuleServiceProviderManager.registerRuleServiceProvider(
46: ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER,
47: RuleServiceProviderImpl.class);
48:
49: RuleServiceProvider ruleServiceProvider = RuleServiceProviderManager
50: .getRuleServiceProvider(ExampleRuleEngineFacade.RULE_SERVICE_PROVIDER);
51: RuleAdministrator ruleAdministrator = ruleServiceProvider
52: .getRuleAdministrator();
53: LocalRuleExecutionSetProvider ruleSetProvider = ruleAdministrator
54: .getLocalRuleExecutionSetProvider(null);
55:
56: RuleExecutionSet ruleExecutionSet = ruleSetProvider
57: .createRuleExecutionSet(
58: SpreadsheetIntegrationTest.class
59: .getResourceAsStream("IntegrationExampleTest.xls"),
60: properties);
61:
62: ruleAdministrator.registerRuleExecutionSet(
63: "IntegrationExampleTest.xls", ruleExecutionSet,
64: properties);
65:
66: properties.clear();
67: final List list = new ArrayList();
68: properties.put("list", list);
69:
70: RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
71: StatefulRuleSession session = (StatefulRuleSession) ruleRuntime
72: .createRuleSession("IntegrationExampleTest.xls",
73: properties, RuleRuntime.STATEFUL_SESSION_TYPE);
74:
75: //ASSERT AND FIRE
76: session.addObject(new Cheese("stilton", 42));
77: session.addObject(new Person("michael", "stilton", 42));
78:
79: session.executeRules();
80: assertEquals(1, list.size());
81: }
82:
83: }
|