001: package org.drools.jsr94.rules.admin;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.InputStreamReader;
022: import java.io.Reader;
023:
024: import javax.rules.admin.LocalRuleExecutionSetProvider;
025: import javax.rules.admin.RuleAdministrator;
026: import javax.rules.admin.RuleExecutionSet;
027:
028: import org.drools.compiler.PackageBuilder;
029: import org.drools.jsr94.rules.RuleEngineTestBase;
030: import org.drools.rule.Package;
031:
032: /**
033: * Test the LocalRuleExecutionSetProvider implementation.
034: *
035: * @author N. Alex Rupp (n_alex <at>codehaus.org)
036: * @author <a href="mailto:thomas.diesler@softcon-itec.de">thomas diesler </a>
037: * @author <a href="mailto:michael.frandsen@syngenio.de">michael frandsen </a>
038: */
039: public class LocalRuleExecutionSetProviderTest extends
040: RuleEngineTestBase {
041: private RuleAdministrator ruleAdministrator;
042:
043: private LocalRuleExecutionSetProvider ruleSetProvider;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047: this .ruleAdministrator = this .ruleServiceProvider
048: .getRuleAdministrator();
049: this .ruleSetProvider = this .ruleAdministrator
050: .getLocalRuleExecutionSetProvider(null);
051: }
052:
053: public void testCreateFromInputStream() throws Exception {
054: final InputStream rulesStream = RuleEngineTestBase.class
055: .getResourceAsStream(this .bindUri);
056: final RuleExecutionSet ruleSet = this .ruleSetProvider
057: .createRuleExecutionSet(rulesStream, null);
058: assertEquals("rule set name", "SistersRules", ruleSet.getName());
059: assertEquals("number of rules", 1, ruleSet.getRules().size());
060: }
061:
062: public void testCreateFromObject() throws Exception {
063: final InputStream inputStream = null;
064: try {
065: final PackageBuilder builder = new PackageBuilder();
066: builder.addPackageFromDrl(new InputStreamReader(
067: RuleEngineTestBase.class
068: .getResourceAsStream(this .bindUri)));
069: final Package pkg = builder.getPackage();
070: final RuleExecutionSet ruleExecutionSet = this .ruleSetProvider
071: .createRuleExecutionSet(pkg, null);
072: assertEquals("rule set name", "SistersRules",
073: ruleExecutionSet.getName());
074: assertEquals("number of rules", 1, ruleExecutionSet
075: .getRules().size());
076: } catch (final IOException e) {
077: fail("Couldn't create the RuleExecutionSet. "
078: + "Test threw an IOException.");
079: } finally {
080: if (inputStream != null) {
081: try {
082: inputStream.close();
083: } catch (final IOException e) {
084: e.printStackTrace();
085: }
086: }
087: }
088: }
089:
090: /**
091: * Test createRuleExecutionSet from Reader.
092: */
093: public void testCreateFromReader() throws Exception {
094: final Reader ruleReader = new InputStreamReader(
095: RuleEngineTestBase.class
096: .getResourceAsStream(this .bindUri));
097: final RuleExecutionSet ruleSet = this .ruleSetProvider
098: .createRuleExecutionSet(ruleReader, null);
099: assertEquals("rule set name", "SistersRules", ruleSet.getName());
100: assertEquals("number of rules", 1, ruleSet.getRules().size());
101: }
102: }
|