[jboss-svn-commits] JBL Code SVN: r15160 - in labs/jbossrules/trunk/drools-core/src: test/java/org/drools/agent and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Sep 16 22:42:16 EDT 2007
Author: michael.neale at jboss.com
Date: 2007-09-16 22:42:16 -0400 (Sun, 16 Sep 2007)
New Revision: 15160
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java
labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
Log:
JBRULES-1196
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java 2007-09-17 01:04:39 UTC (rev 15159)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java 2007-09-17 02:42:16 UTC (rev 15160)
@@ -24,45 +24,45 @@
/**
* This manages a single rulebase, based on the properties given.
* You should only have ONE instance of this agent per rulebase configuration.
- * You can get the rulebase from this agent repeatedly, as needed, or if you keep the rulebase,
- * under most configurations it will be automatically updated.
- *
+ * You can get the rulebase from this agent repeatedly, as needed, or if you keep the rulebase,
+ * under most configurations it will be automatically updated.
+ *
* How this behaves depends on the properties that you pass into it (documented below)
*
* CONFIG OPTIONS (to be passed in as properties):
* <code>newInstance</code>: setting this to "true" means that each time the rules are changed
* a new instance of the rulebase is created (as opposed to updated in place)
- * the default is to update in place. DEFAULT: false. If you set this to true,
- * then you will need to call getRuleBase() each time you want to use it. If it is false,
+ * the default is to update in place. DEFAULT: false. If you set this to true,
+ * then you will need to call getRuleBase() each time you want to use it. If it is false,
* then it means you can keep your reference to the rulebase and it will be updated automatically
- * (as well as any stateful sessions).
+ * (as well as any stateful sessions).
*
- * <code>poll</code>The number of seconds to poll for changes. Polling
+ * <code>poll</code>The number of seconds to poll for changes. Polling
* happens in a background thread. eg: poll=30 #30 second polling.
*
- * <code>file</code>: a space seperated listing of files that make up the
- * packages of the rulebase. Each package can only be in one file. You can't have
+ * <code>file</code>: a space seperated listing of files that make up the
+ * packages of the rulebase. Each package can only be in one file. You can't have
* packages spread across files. eg: file=/your/dir/file1.pkg file=/your/dir/file2.pkg
- *
+ *
* <code>dir</code>: a single file system directory to monitor for packages.
* As with files, each package must be in its own file.
* eg: dir=/your/dir
- *
+ *
* <code>url</code>: A space seperated URL to a binary rulebase in the BRMS.
* eg: url=http://server/drools-jbrms/packages/somePakage/VERSION_1
* For URL you will also want a local cache directory setup:
* eg: localCacheDir=/some/dir/that/exists
* This is needed so that the runtime can startup and load packages even if the BRMS
* is not available (or the network).
- *
+ *
* <code>name</code>
* the Name is used in any logging, so each agent can be differentiated (you may have one agent per rulebase
* that you need in your application).
- *
- * There is also an AgentEventListener interface which you can provide which will call back when lifecycle
+ *
+ * There is also an AgentEventListener interface which you can provide which will call back when lifecycle
* events happen, or errors/warnings occur. As the updating happens in a background thread, this may be important.
* The default event listener logs to the System.err output stream.
- *
+ *
* @author Michael Neale
*/
public class RuleAgent {
@@ -77,7 +77,7 @@
public static final String URLS = "url";
public static final String POLL_INTERVAL = "poll";
public static final String CONFIG_NAME = "name"; //name is optional
-
+
//this is needed for cold starting when BRMS is down (ie only for URL).
public static final String LOCAL_URL_CACHE = "localCacheDir";
@@ -104,14 +104,14 @@
* The rule base that is being managed.
*/
private RuleBase ruleBase;
-
+
/**
* the configuration for the RuleBase
*/
private RuleBaseConfiguration ruleBaseConf;
/**
- * The timer that is used to monitor for changes and deal with them.
+ * The timer that is used to monitor for changes and deal with them.
*/
private Timer timer;
@@ -129,7 +129,7 @@
* For logging events (important for stuff that happens in the background).
*/
AgentEventListener listener = getDefaultListener();
-
+
/**
* Polling interval value, in seconds, used in the Timer.
*/
@@ -144,15 +144,15 @@
public static RuleAgent newRuleAgent(Properties config) {
return newRuleAgent(config, null, null);
}
-
+
/**
* Properties configured to load up packages into a rulebase with the provided
- * configuration (and monitor them for changes).
+ * configuration (and monitor them for changes).
*/
public static RuleAgent newRuleAgent(Properties config, RuleBaseConfiguration ruleBaseConf) {
return newRuleAgent(config, null, ruleBaseConf);
- }
-
+ }
+
/**
* This allows an optional listener to be passed in.
* The default one prints some stuff out to System.err only when really needed.
@@ -160,7 +160,7 @@
public static RuleAgent newRuleAgent(Properties config, AgentEventListener listener) {
return newRuleAgent(config, listener, null);
}
-
+
/**
* This allows an optional listener to be passed in.
* The default one prints some stuff out to System.err only when really needed.
@@ -172,7 +172,7 @@
}
agent.init(config);
return agent;
- }
+ }
@@ -183,12 +183,12 @@
int secondsToRefresh = Integer.parseInt( config.getProperty( POLL_INTERVAL,
"-1" ) );
final String name = config.getProperty( CONFIG_NAME, "default" );
-
+
listener.setAgentName( name );
-
- listener.info( "Configuring with newInstance=" + newInstance + ", secondsToRefresh="
- + secondsToRefresh);
-
+
+ listener.info( "Configuring with newInstance=" + newInstance + ", secondsToRefresh="
+ + secondsToRefresh);
+
List provs = new ArrayList();
for ( Iterator iter = config.keySet().iterator(); iter.hasNext(); ) {
@@ -202,37 +202,37 @@
}
- configure( newInstance, provs,
+ configure( newInstance, provs,
secondsToRefresh );
}
/**
- * Pass in the name and full path to a config file that is on the classpath.
+ * Pass in the name and full path to a config file that is on the classpath.
*/
public static RuleAgent newRuleAgent(String propsFileName) {
return newRuleAgent( loadFromProperties( propsFileName ) );
}
-
+
/**
- * Pass in the name and full path to a config file that is on the classpath.
- */
+ * Pass in the name and full path to a config file that is on the classpath.
+ */
public static RuleAgent newRuleAgent(String propsFileName, RuleBaseConfiguration ruleBaseConfiguration) {
return newRuleAgent( loadFromProperties( propsFileName ), ruleBaseConfiguration );
- }
-
+ }
+
/**
* This takes in an optional listener. Listener must not be null in this case.
*/
public static RuleAgent newRuleAgent(String propsFileName, AgentEventListener listener) {
return newRuleAgent( loadFromProperties( propsFileName ), listener );
}
-
+
/**
* This takes in an optional listener and RuleBaseConfiguration. Listener must not be null in this case.
- */
+ */
public static RuleAgent newRuleAgent(String propsFileName, AgentEventListener listener, RuleBaseConfiguration ruleBaseConfiguration) {
return newRuleAgent( loadFromProperties( propsFileName ), listener, ruleBaseConfiguration );
- }
+ }
static Properties loadFromProperties(String propsFileName) {
InputStream in = RuleAgent.class.getResourceAsStream( propsFileName );
@@ -276,7 +276,7 @@
this.newInstance = newInstance;
this.providers = provs;
-
+
//run it the first time for each.
refreshRuleBase();
@@ -289,7 +289,7 @@
public void refreshRuleBase() {
List changedPackages = new ArrayList();
-
+
for ( Iterator iter = providers.iterator(); iter.hasNext(); ) {
PackageProvider prov = (PackageProvider) iter.next();
Package[] changes = checkForChanges( prov );
@@ -297,7 +297,7 @@
changedPackages.addAll( Arrays.asList( changes ) );
}
}
-
+
if (changedPackages.size() > 0) {
listener.info( "Applying changes to the rulebase." );
//we have a change
@@ -305,7 +305,7 @@
listener.info( "Creating a new rulebase as per settings." );
//blow away old
this.ruleBase = RuleBaseFactory.newRuleBase( this.ruleBaseConf );
-
+
//need to store ALL packages
for ( Iterator iter = changedPackages.iterator(); iter.hasNext(); ) {
Package element = (Package) iter.next();
@@ -317,8 +317,8 @@
PackageProvider.applyChanges( this.ruleBase, true, changedPackages, this.listener );
}
}
-
+
}
private synchronized Package[] checkForChanges(PackageProvider prov) {
@@ -330,25 +330,52 @@
/**
* Convert a space seperated list into a List of stuff.
- * @param property
- * @return
+ * If a filename or whatnot has a space in it, you can put double quotes around it
+ * and it will read it in as one token.
*/
static List list(String property) {
if ( property == null ) return Collections.EMPTY_LIST;
- StringTokenizer st = new StringTokenizer( property,
- "\n\r\t " );
- List list = new ArrayList();
- while ( st.hasMoreTokens() ) {
- list.add( st.nextToken() );
+ char[] cs = property.toCharArray();
+ boolean inquotes = false;
+ List items = new ArrayList();
+ String current = "";
+ for ( int i = 0; i < cs.length; i++ ) {
+ char c = cs[i];
+ switch ( c ) {
+ case '\"' :
+ if (inquotes) {
+ items.add( current );
+ current = "";
+ }
+ inquotes = !inquotes;
+ break;
+
+
+ default :
+ if (!inquotes &&
+ (c == ' ' || c == '\n' || c == '\r' || c == '\t')) {
+ if (current.trim() != "") {
+ items.add( current );
+ current = "";
+ }
+ } else {
+ current = current + c;
+ }
+ break;
+ }
}
- return list;
+ if (current.trim() != "") {
+ items.add( current );
+ }
+
+ return items;
}
/**
* Return a current rulebase.
* Depending on the configuration, this may be a new object each time
* the rules are updated.
- *
+ *
*/
public synchronized RuleBase getRuleBase() {
return this.ruleBase;
@@ -369,7 +396,7 @@
if ( this.timer != null ) timer.cancel();
timer = null;
}
-
+
/**
* Will start polling. If polling is already running it does nothing.
*
@@ -379,7 +406,7 @@
startPolling( this.secondsToRefresh );
}
}
-
+
/**
* Will start polling. If polling is already happening and of the same interval
* it will do nothing, if the interval is different it will stop the current Timer
@@ -395,7 +422,7 @@
return;
}
}
-
+
this.secondsToRefresh = secondsToRefresh;
int interval = this.secondsToRefresh * 1000;
//now schedule it for polling
@@ -403,18 +430,18 @@
timer.schedule( new TimerTask() {
public void run() {
try {
-
+
listener.debug( "Checking for updates." );
refreshRuleBase();
-
+
} catch (Exception e) {
- //don't want to stop execution here.
+ //don't want to stop execution here.
listener.exception( e );
}
}
},
interval,
- interval );
+ interval );
}
boolean isNewInstance() {
@@ -439,30 +466,30 @@
Date d = new Date();
return d.toString();
}
-
+
public void exception(Exception e) {
System.err.println("RuleAgent(" + name + ") EXCEPTION (" + time() + "): " + e.getMessage() + ". Stack trace should follow.");
e.printStackTrace( System.err );
}
public void info(String message) {
- System.err.println("RuleAgent(" + name + ") INFO (" + time() + "): " + message);
+ System.err.println("RuleAgent(" + name + ") INFO (" + time() + "): " + message);
}
public void warning(String message) {
- System.err.println("RuleAgent(" + name + ") WARNING (" + time() + "): " + message);
+ System.err.println("RuleAgent(" + name + ") WARNING (" + time() + "): " + message);
}
public void debug(String message) {
- //do nothing...
+ //do nothing...
}
public void setAgentName(String name) {
this.name = name;
-
+
}
-
+
};
}
-
+
}
Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java 2007-09-17 01:04:39 UTC (rev 15159)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java 2007-09-17 02:42:16 UTC (rev 15160)
@@ -24,16 +24,33 @@
assertEquals("foo.bar", result.get( 0 ));
assertEquals("baz.bar", result.get(1));
assertEquals("whee", result.get(2));
-
+
s = null;
result = RuleAgent.list( s );
assertNotNull(result);
assertEquals(0, result.size());
+
+ s = "\"yeah man\" \"another one\"";
+ result = RuleAgent.list( s );
+ assertEquals(2, result.size());
+ assertEquals("yeah man", result.get( 0 ));
+ assertEquals("another one", result.get(1));
+
+ s = "\"yeah man\"";
+ result = RuleAgent.list( s );
+ assertEquals(1, result.size());
+ assertEquals("yeah man", result.get( 0 ));
+
+ s = "YEAH";
+ result = RuleAgent.list( s );
+ assertEquals(1, result.size());
+ assertEquals("YEAH", result.get( 0 ));
+
}
-
- public void testFiles() throws Exception {
+
+ public void testFiles() throws Exception {
File dir = RuleBaseAssemblerTest.getTempDirectory();
-
+
Package p1 = new Package("p1");
File p1f = new File(dir, "p1.pkg");
RuleBaseAssemblerTest.writePackage( p1, p1f );
@@ -41,70 +58,81 @@
Package p2 = new Package("p2");
File p2f = new File(dir, "p2.pkg");
RuleBaseAssemblerTest.writePackage( p2, p2f );
-
+
String path = dir.getPath() + "/" + "p1.pkg " + dir.getPath() + "/" + "p2.pkg";
-
+
Properties props = new Properties();
props.setProperty( "file", path );
RuleAgent ag = RuleAgent.newRuleAgent(props);
RuleBase rb = ag.getRuleBase();
assertNotNull(rb);
assertEquals(2, rb.getPackages().length);
-
+
assertFalse(ag.isPolling());
-
+
props.setProperty( "poll", "1" );
ag = RuleAgent.newRuleAgent(props);
assertTrue(ag.isPolling());
-
+
ag.stopPolling();
assertFalse(ag.isPolling());
-
+
}
-
+
+// public void testSpaces() throws Exception {
+// File dir = RuleBaseAssemblerTest.getTempDirectory();
+// File dir_ = new File(dir, "whee waah");
+// dir_.mkdir();
+// System.err.println(dir_.getPath());
+//
+//
+// File x = new File("/tmp/__temp_test_drools_packages/whee waah");
+// assertTrue(x.exists());
+// }
+
public void testPollingFilesRuleBaseUpdate() throws Exception {
//RuleBaseAssemblerTest.clearTempDirectory();
final File dir = RuleBaseAssemblerTest.getTempDirectory();
-
+
Random rnd = new Random(System.currentTimeMillis());
-
+
final Package p1 = new Package("p1");
final File p1f = new File(dir, rnd.nextLong() + ".pkg");
RuleBaseAssemblerTest.writePackage( p1, p1f );
-
+
String path = p1f.getPath();
-
+
Properties props = new Properties();
props.setProperty( "file", path );
-
+
RuleAgent ag = RuleAgent.newRuleAgent(props);
-
-
+
+
RuleBase rb = ag.getRuleBase();
- assertEquals(1, rb.getPackages().length);
+ assertEquals(1, rb.getPackages().length);
assertEquals(0, rb.getPackages()[0].getGlobals().size());
-
+
p1.addGlobal( "goo", String.class );
-
+
Thread.sleep( 1000 );
-
+
RuleBaseAssemblerTest.writePackage( p1, p1f );
-
+
RuleBase rb_ = ag.getRuleBase();
assertSame(rb, rb_);
- assertEquals(1, rb.getPackages().length);
+ assertEquals(1, rb.getPackages().length);
assertEquals(0, rb.getPackages()[0].getGlobals().size());
-
+
Thread.sleep( 1000 );
-
+
ag.refreshRuleBase();
-
+
RuleBase rb2 = ag.getRuleBase();
assertSame(rb, rb2);
-
+
assertEquals(1, rb2.getPackages().length);
assertEquals(1, rb2.getPackages()[0].getGlobals().size());
-
+
//now check subsequent changes
p1.addGlobal( "goo2", String.class );
System.err.println("-->WRITING CHANGE");
@@ -113,29 +141,29 @@
System.err.println("-->WROTE CHANGE");
Thread.sleep( 1000 );
ag.refreshRuleBase();
-
- RuleBase rb2_ = ag.getRuleBase();
+
+ RuleBase rb2_ = ag.getRuleBase();
assertSame(rb2_, rb2);
assertEquals(1, rb2_.getPackages().length);
assertEquals(2, rb2_.getPackages()[0].getGlobals().size());
-
+
ag.refreshRuleBase();
RuleBase rb3 = ag.getRuleBase();
- assertSame(rb3, rb2);
-
+ assertSame(rb3, rb2);
+
assertEquals(1, rb3.getPackages().length);
assertEquals(2, rb3.getPackages()[0].getGlobals().size());
-
+
ag.refreshRuleBase();
ag.refreshRuleBase();
-
+
assertEquals(1, rb3.getPackages().length);
assertEquals(2, rb3.getPackages()[0].getGlobals().size());
-
-
+
+
}
-
+
public void testPollingFilesRuleBaseReplace() throws Exception {
File dir = RuleBaseAssemblerTest.getTempDirectory();
@@ -145,60 +173,60 @@
Package p2 = new Package("p2");
File p2f = new File(dir, "p44_.pkg");
- RuleBaseAssemblerTest.writePackage( p2, p2f );
-
-
+ RuleBaseAssemblerTest.writePackage( p2, p2f );
+
+
String path = dir.getPath() + "/" + "p43_.pkg " + dir.getPath() + "/p44_.pkg";
-
+
Properties props = new Properties();
props.setProperty( "file", path );
-
+
props.setProperty( "newInstance", "true" );
RuleAgent ag = RuleAgent.newRuleAgent(props);
-
+
assertTrue(ag.isNewInstance());
-
+
RuleBase rb = ag.getRuleBase();
assertEquals(2, rb.getPackages().length);
RuleBase rb_ = ag.getRuleBase();
assertSame(rb, rb_);
-
-
+
+
ag.refreshRuleBase();
-
+
assertSame(rb, ag.getRuleBase());
Thread.sleep( 1000 );
//only change one
RuleBaseAssemblerTest.writePackage( p1, p1f );
Thread.sleep( 1000 );
ag.refreshRuleBase();
-
-
+
+
rb_ = ag.getRuleBase();
assertNotSame( rb, rb_ );
-
-
+
+
//check we will have 2
assertEquals(2, rb_.getPackages().length);
ag.refreshRuleBase();
ag.refreshRuleBase();
-
+
RuleBase rb__ = ag.getRuleBase();
assertSame(rb_, rb__);
-
-
-
-
+
+
+
+
}
-
-
+
+
public void testDirectory() throws Exception {
File dir = RuleBaseAssemblerTest.getTempDirectory();
-
+
Package p1 = new Package("p1");
File p1f = new File(dir, "p43_.pkg");
RuleBaseAssemblerTest.writePackage( p1, p1f );
@@ -206,44 +234,44 @@
Properties props = new Properties();
props.setProperty( RuleAgent.DIRECTORY, dir.getPath() );
props.setProperty( RuleAgent.CONFIG_NAME, "goo" );
-
-
+
+
RuleAgent ag = RuleAgent.newRuleAgent(props);
-
+
ag.refreshRuleBase();
-
+
RuleBase rb = ag.getRuleBase();
assertNotNull(rb);
- assertEquals(1, rb.getPackages().length);
+ assertEquals(1, rb.getPackages().length);
}
-
+
public void testCustomRuleBaseConfiguration() throws Exception {
final File dir = RuleBaseAssemblerTest.getTempDirectory();
-
+
Random rnd = new Random(System.currentTimeMillis());
-
+
final Package p1 = new Package("p1");
final File p1f = new File(dir, rnd.nextLong() + ".pkg");
RuleBaseAssemblerTest.writePackage( p1, p1f );
-
+
String path = p1f.getPath();
-
+
Properties props = new Properties();
props.setProperty( "file", path );
-
- // Check a default value for the RuleBase's RuleBaseConfiguration
+
+ // Check a default value for the RuleBase's RuleBaseConfiguration
RuleAgent agent = RuleAgent.newRuleAgent( props );
RuleBaseConfiguration conf = ((InternalRuleBase) agent.getRuleBase()).getConfiguration();
assertEquals( false, conf.isSequential() );
-
+
// Pass in a RuleBaseConfiguration and make sure the RuleBase was created with it
conf = new RuleBaseConfiguration();
conf.setSequential( true );
agent = RuleAgent.newRuleAgent( props, conf );
conf = ((InternalRuleBase) agent.getRuleBase()).getConfiguration();
- assertEquals( true, conf.isSequential() );
+ assertEquals( true, conf.isSequential() );
}
-
+
public void testLoadSampleConfig() {
RuleAgent ag = new RuleAgent( new RuleBaseConfiguration() );
Properties props = ag.loadFromProperties( "/sample-agent-config.properties" );
@@ -252,7 +280,7 @@
assertEquals("true", props.getProperty( RuleAgent.NEW_INSTANCE ));
assertEqualsIgnoreWhitespace( "/foo/bar.pkg /wee/waa.pkg /wee/waa2.pkg", props.getProperty( RuleAgent.FILES ));
}
-
+
private void assertEqualsIgnoreWhitespace(final String expected,
final String actual) {
final String cleanExpected = expected.replaceAll( "\\s+",
@@ -263,13 +291,13 @@
assertEquals( cleanExpected,
cleanActual );
}
-
+
public void testEventListenerSetup() throws Exception {
RuleAgent ag = new RuleAgent( new RuleBaseConfiguration() );
assertNotNull(ag.listener);
final String[] name = new String[1];
-
+
AgentEventListener list = new AgentEventListener() {
public void debug(String message) {
}
@@ -278,20 +306,20 @@
public void info(String message) {
}
public void warning(String message) {
- }
+ }
public void setAgentName(String n) {
name[0] = n;
}
};
-
+
File dir = RuleBaseAssemblerTest.getTempDirectory();
-
+
Package p1 = new Package("p1");
File p1f = new File(dir, "p42_.pkg");
RuleBaseAssemblerTest.writePackage( p1, p1f );
-
+
String path = dir.getPath() + "/" + "p42_.pkg";
-
+
Properties props = new Properties();
props.setProperty( "file", path );
props.setProperty( "poll", "1" );
@@ -300,20 +328,20 @@
assertEquals(list, ag.listener);
assertEquals("poo", name[0]);
- ag.stopPolling();
+ ag.stopPolling();
}
-
-
+
+
public void testPollSetup() throws Exception {
//this is the only method that will actually run the polling timer
-
-
+
+
Properties props = new Properties();
//props.setProperty( "file", "/foo/bar" );
props.setProperty( "poll", "1" );
MockRuleAgent ag = new MockRuleAgent();
ag.init(props);
-
+
assertTrue(ag.isPolling());
assertTrue(ag.refreshCalled);
ag.refreshCalled = false;
@@ -328,38 +356,38 @@
Thread.sleep( 1500 );
assertTrue(ag.refreshCalled);
ag.stopPolling();
-
+
}
-
+
public void testProviderMap() throws Exception {
-
+
assertEquals(3, RuleAgent.PACKAGE_PROVIDERS.size());
assertTrue(RuleAgent.PACKAGE_PROVIDERS.containsKey( "url" ));
assertTrue(RuleAgent.PACKAGE_PROVIDERS.containsKey( "file" ));
assertTrue(RuleAgent.PACKAGE_PROVIDERS.containsKey( "dir" ));
assertFalse(RuleAgent.PACKAGE_PROVIDERS.containsKey( "XXX" ));
assertTrue(RuleAgent.PACKAGE_PROVIDERS.get( "url" ).equals( URLScanner.class ));
-
+
}
-
+
public void testLoadUpFromProperties() throws Exception {
AnotherRuleAgentMock ag = new AnotherRuleAgentMock();
Map oldMap = ag.PACKAGE_PROVIDERS;
-
+
ag.PACKAGE_PROVIDERS = new HashMap();
ag.PACKAGE_PROVIDERS.put( RuleAgent.URLS, MockProvider.class );
ag.PACKAGE_PROVIDERS.put( RuleAgent.FILES, MockProvider.class );
ag.PACKAGE_PROVIDERS.put( RuleAgent.DIRECTORY, MockProvider.class );
-
-
+
+
Properties props = new Properties();
props.load( this.getClass().getResourceAsStream( "/rule-agent-config.properties" ) );
MockEventListener evl = new MockEventListener();
- ag.listener = evl;
-
+ ag.listener = evl;
+
ag.init( props );
-
-
+
+
assertTrue(ag.newInstance);
assertEquals(3, ag.provs.size());
assertEquals(30, ag.secondsToRefresh);
@@ -367,34 +395,34 @@
assertFalse(evl.exceptionCalled);
assertFalse(evl.warningCalled);
assertTrue(evl.infoCalled);
-
+
ag.PACKAGE_PROVIDERS = oldMap;
}
-
-
-
+
+
+
class AnotherRuleAgentMock extends RuleAgent {
public int secondsToRefresh;
public List provs;
public boolean newInstance;
-
+
public AnotherRuleAgentMock() {
super( new RuleBaseConfiguration() );
- }
+ }
synchronized void configure(boolean newInstance, List provs, int secondsToRefresh) {
this.newInstance = newInstance;
this.provs = provs;
this.secondsToRefresh = secondsToRefresh;
}
-
-
-
+
+
+
}
-
+
class MockEventListener implements AgentEventListener {
@@ -405,7 +433,7 @@
public void debug(String message) {
-
+
}
public void exception(Exception e) {
@@ -413,7 +441,7 @@
}
public void info(String message) {
- if (message != null) this.infoCalled = true;
+ if (message != null) this.infoCalled = true;
}
public void setAgentName(String name) {
@@ -422,10 +450,10 @@
public void warning(String message) {
this.warningCalled = false;
-
+
}
-
-
+
+
}
-
+
}
More information about the jboss-svn-commits
mailing list