[jboss-svn-commits] JBL Code SVN: r12995 - in labs/jbossrules/trunk/drools-core/src: test/java/org/drools/agent and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 2 03:52:04 EDT 2007


Author: michael.neale at jboss.com
Date: 2007-07-02 03:52:04 -0400 (Mon, 02 Jul 2007)
New Revision: 12995

Added:
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/MockProvider.java
   labs/jbossrules/trunk/drools-core/src/test/resources/rule-agent-config.properties
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-752 Rule agent

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-07-02 06:17:28 UTC (rev 12994)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/agent/RuleAgent.java	2007-07-02 07:52:04 UTC (rev 12995)
@@ -24,7 +24,7 @@
  * This manages a single rulebase, based on the properties given
  * This one does most of the actual work !
  *
- * CONFIG OPTIONS:
+ * CONFIG OPTIONS (to be passed in as properties):
  *  <code>newInstance</code>: 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, 
@@ -71,6 +71,8 @@
                                                               FileScanner.class );
                                                          put( DIRECTORY,
                                                               DirectoryScanner.class );
+                                                         put ( URLS,
+                                                               URLScanner.class );
                                                      }
                                                  };
 

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/MockProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/MockProvider.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/MockProvider.java	2007-07-02 07:52:04 UTC (rev 12995)
@@ -0,0 +1,20 @@
+package org.drools.agent;
+
+import java.util.Properties;
+
+import org.drools.rule.Package;
+public  class MockProvider extends PackageProvider {
+
+        public MockProvider() {
+        }
+        
+        public void configure(Properties config) {
+        }
+
+        Package[] loadPackageChanges() {
+            return null;
+        }
+
+
+        
+    }
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/MockProvider.java
___________________________________________________________________
Name: svn:eol-style
   + native

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-07-02 06:17:28 UTC (rev 12994)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/agent/RuleAgentTest.java	2007-07-02 07:52:04 UTC (rev 12995)
@@ -1,7 +1,10 @@
 package org.drools.agent;
 
 import java.io.File;
+import java.io.InputStream;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Random;
 
@@ -302,5 +305,97 @@
        
     }
     
+    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.init( props );
+        
+        
+        assertTrue(ag.newInstance);
+        assertEquals(3, ag.provs.size());
+        assertEquals(30, ag.secondsToRefresh);
+        assertEquals("MyConfig", evl.name);
+        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;
+
+        synchronized void configure(boolean newInstance, List provs, int secondsToRefresh) {
+            this.newInstance = newInstance;
+            this.provs = provs;
+            this.secondsToRefresh = secondsToRefresh;
+        }
+        
+        
+        
+    }
+    
+
+    class MockEventListener implements AgentEventListener {
+
+
+        public String name;
+        boolean exceptionCalled = false;
+        boolean infoCalled = false;
+        boolean warningCalled;
+
+        public void debug(String message) {
+
+            
+        }
+
+        public void exception(Exception e) {
+            this.exceptionCalled = true;
+        }
+
+        public void info(String message) {
+            if (message != null) this.infoCalled = true;                
+        }
+
+        public void setAgentName(String name) {
+            this.name = name;
+        }
+
+        public void warning(String message) {
+            this.warningCalled = false;
+            
+        }
+        
+            
+    }
+    
 }

Added: labs/jbossrules/trunk/drools-core/src/test/resources/rule-agent-config.properties
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/resources/rule-agent-config.properties	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/resources/rule-agent-config.properties	2007-07-02 07:52:04 UTC (rev 12995)
@@ -0,0 +1,33 @@
+##
+## RuleAgent configuration file example
+##
+
+#setting this means the rulebase will be created fresh whenever there are 
+#changes
+newInstance=true
+
+#this points to a binary compiled rule package, you can have spaces
+#seperating multiple files
+file=/foo/bar/boo.pkg /foo/bar/boo2.pkg
+
+#this specifies that packages may appear in a directory
+#it will pick up whatever files are dumped in there (.pkg files like above)
+dir=/my/dir
+
+#this specifies a list of urls for packages - these urls 
+#are those that are exposed by the BRMS
+url=http://some.url/here http://some.url/here
+
+#the following can be used with the urls to keep a local cache
+#so if the runtime server is restarted, the BRMS does not need
+#to be available
+localCacheDir=/foo/bar/cache
+
+#this specifies the frequency at which the sources will be checked for
+#changes (in seconds). If you don't set this, it will mean that you have
+#to manually poll
+poll=30
+
+
+#this specifies the name of this config, necessary in case logging is used.
+name=MyConfig
\ No newline at end of file


Property changes on: labs/jbossrules/trunk/drools-core/src/test/resources/rule-agent-config.properties
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list