1 /*
2 * Created by IntelliJ IDEA.
3 * User: RefuX Zanzeebarr
4 * Date: Aug 25, 2002
5 * Time: 5:42:53 PM
6 *
7 * Current issue: if a rule has 2 params, and the 2nd param is modified the condition isn't reeval'd
8 *
9 */
10 package org.drools.misc;
11
12 import org.drools.io.RuleSetLoader;
13
14 import junit.framework.TestCase;
15
16 import org.drools.RuleBase;
17 import org.drools.WorkingMemory;
18 import org.drools.rule.RuleSet;
19
20 import java.net.URL;
21 import java.util.*;
22
23 public class DROOLS_25_Test extends TestCase {
24 private WorkingMemory workingMemory;
25
26 public DROOLS_25_Test(String name) {
27 super( name );
28 }
29
30 public void setUp() {
31 try {
32 // First, construct an empty RuleBase to be the
33 // container for your rule logic.
34 RuleBase ruleBase = new RuleBase();
35
36 // Then, use the [org.drools.semantic.java.RuleLoader]
37 // static method to load a rule-set from a local File.
38 RuleSetLoader loader = new RuleSetLoader();
39 URL url = getClass().getResource( "DROOLS_25_Test.drl" );
40 assertNotNull( url );
41 List ruleSets = loader.load( url );
42
43 Iterator ruleSetIter = ruleSets.iterator();
44 RuleSet eachRuleSet = null;
45 while ( ruleSetIter.hasNext() )
46 {
47 eachRuleSet = (RuleSet) ruleSetIter.next();
48 ruleBase.addRuleSet( eachRuleSet );
49 }
50
51 // Create a [org.drools.WorkingMemory] to be the
52 // container for your facts
53 workingMemory = ruleBase.createWorkingMemory();
54 }
55 catch( Exception e ) {
56 fail( "Failed to setup test [" + e.getMessage() + "]" );
57 }
58 }
59
60 public void testSuccessWithRetractAndAssert() {
61 try {
62 //create vars to place in working memory
63 String string = "blah";
64 Properties props = new Properties();
65
66 // Now, simply assert them into the [org.drools.WorkingMemory]
67 // and let the logic engine do the rest.
68
69 workingMemory.assertObject( string );
70 workingMemory.assertObject( props );
71
72 //change the props the notify the system
73
74 props.setProperty( "test", "test" );
75
76 //retract and assert method
77
78 workingMemory.retractObject( props );
79 workingMemory.assertObject( props );
80
81 //the test property should be set to success
82
83 String testResult = props.getProperty( "test" );
84
85 if( !"success".equals( testResult) ) {
86 fail( "the property[test] in rule[test:1] wasn't set to 'success'" );
87 }
88 }
89 catch( Exception e ) {
90 fail( e.getMessage() );
91 }
92 }
93
94 public void testSuccessWithModify() {
95 try {
96 //create vars to place in working memory
97 String string = "blah";
98 Properties props = new Properties();
99
100 // Now, simply assert them into the [org.drools.WorkingMemory]
101 // and let the logic engine do the rest.
102
103 System.err.println( "\n\n\n####### 1 #######\n\n\n" );
104 workingMemory.assertObject( string );
105 System.err.println( "\n\n\n####### 2 #######\n\n\n" );
106 workingMemory.assertObject( props );
107
108 //change the props the notify the system
109
110 props.setProperty( "test", "test" );
111
112 //modify method
113 System.err.println( "\n\n\n####### 3 #######\n\n\n" );
114 workingMemory.modifyObject( props );
115 System.err.println( "\n\n\n####### 4 #######\n\n\n" );
116
117 //the test property should be set to success
118 String testResult = props.getProperty( "test" );
119 if( !"success".equals( testResult) ) {
120 fail( "the property[test] in rule[test:1] wasn't set to 'success'" );
121 }
122 }
123 catch( Exception e ) {
124 fail( e.getMessage() );
125 }
126 }
127 }
This page was automatically generated by Maven