1 package org.drools.rule;
2
3 import junit.framework.TestCase;
4
5 public class RuleSetTest extends TestCase
6 {
7 private RuleSet ruleSet;
8
9 public RuleSetTest(String name)
10 {
11 super( name );
12 }
13
14 public void setUp()
15 {
16 this.ruleSet = new RuleSet( "rule_set" );
17 }
18
19 public void tearDown()
20 {
21 this.ruleSet = null;
22 }
23
24 /*** A RuleSet MUST accept any Rule that does not have
25 * a conflicting name.
26 */
27 public void testAddRule()
28 {
29 InstrumentedRule rule = new InstrumentedRule( "cheese" );
30
31 rule.isValid( true );
32
33 try
34 {
35 this.ruleSet.addRule( rule );
36 }
37 catch (RuleConstructionException e)
38 {
39 fail( e.toString() );
40 }
41 }
42
43 /*** A RuleSet MUST throw a DuplicateRuleNameException
44 * if an attempt to add a Rule whose name conflicts
45 * with an already added Rule.
46 */
47 public void testAddRuleDuplicate()
48 {
49 InstrumentedRule rule1 = new InstrumentedRule( "cheese" );
50 InstrumentedRule rule2 = new InstrumentedRule( "cheese" );
51
52 rule1.isValid( true );
53 rule2.isValid( true );
54
55 try
56 {
57 this.ruleSet.addRule( rule1 );
58
59 try
60 {
61 this.ruleSet.addRule( rule2 );
62
63 fail( "Should have thrown DuplicateRuleNameException" );
64 }
65 catch (DuplicateRuleNameException e)
66 {
67 assertSame( this.ruleSet,
68 e.getRuleSet() );
69
70 assertSame( rule1,
71 e.getOriginalRule() );
72
73 assertSame( rule2,
74 e.getConflictingRule() );
75 }
76 catch (RuleConstructionException e)
77 {
78 fail( e.toString() );
79 }
80 }
81 catch (RuleConstructionException e)
82 {
83 fail( e.toString() );
84 }
85 }
86 }
This page was automatically generated by Maven