[seam-commits] Seam SVN: r12622 - in modules/drools/trunk: impl/src/main/java/org/jboss/seam/drools/annotations and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Apr 23 19:22:37 EDT 2010


Author: tsurdilovic
Date: 2010-04-23 19:22:36 -0400 (Fri, 23 Apr 2010)
New Revision: 12622

Added:
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/FireRules.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/FireRulesInterceptor.java
   modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestConfig.java
   modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptorstestflow.drl
   modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptortests.rf
Modified:
   modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/config/CEPPseudoClockConfig.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/SignalEvent.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/StartProcess.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/AbortProcessInterceptor.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/SignalEventInterceptor.java
   modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/StartProcessInterceptor.java
   modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTest.java
   modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestBean.java
   modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/InterceptorsTest-beans.xml
Log:
added more interceptor tests for starting a process (signalling, aborting).

Modified: modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/config/CEPPseudoClockConfig.java
===================================================================
--- modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/config/CEPPseudoClockConfig.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/api/src/main/java/org/jboss/seam/drools/qualifiers/config/CEPPseudoClockConfig.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -28,7 +28,6 @@
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Documented;
-import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -42,7 +41,6 @@
 @Target( { TYPE, METHOD, FIELD, PARAMETER })
 @Documented
 @Retention(RUNTIME)
- at Inherited
 public @interface CEPPseudoClockConfig {
 
 }

Added: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/FireRules.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/FireRules.java	                        (rev 0)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/FireRules.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+package org.jboss.seam.drools.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.interceptor.InterceptorBinding;
+
+/**
+ * 
+ * @author Tihomir Surdilovic
+ */
+ at InterceptorBinding
+ at Target( { TYPE, METHOD })
+ at Documented
+ at Retention(RUNTIME)
+public @interface FireRules
+{
+   @Nonbinding boolean untilHalt() default false;
+   @Nonbinding int limit() default -1;
+}

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/SignalEvent.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/SignalEvent.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/SignalEvent.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -50,5 +50,5 @@
    String event() default "";
 
    @Nonbinding
-   String process() default "";
+   String processName() default "";
 }

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/StartProcess.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/StartProcess.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/annotations/flow/StartProcess.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -44,5 +44,11 @@
 public @interface StartProcess
 {
    @Nonbinding
-   String value() default "";
+   String name() default "";
+   
+   @Nonbinding
+   boolean fire() default false;
+   
+   @Nonbinding 
+   boolean untilHalt() default false;
 }

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/AbortProcessInterceptor.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/AbortProcessInterceptor.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/AbortProcessInterceptor.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -18,9 +18,14 @@
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
+ */
 package org.jboss.seam.drools.interceptor;
 
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import javax.enterprise.inject.Any;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.BeanManager;
@@ -30,6 +35,7 @@
 import javax.interceptor.InvocationContext;
 
 import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.process.ProcessInstance;
 import org.jboss.seam.drools.annotations.flow.AbortProcess;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,15 +46,56 @@
 {
    @Inject
    BeanManager manager;
-   
-   @Inject @Any Instance<StatefulKnowledgeSession> ksessionSource;
-   
+
+   @Inject
+   @Any
+   Instance<StatefulKnowledgeSession> ksessionSource;
+
    private static final Logger log = LoggerFactory.getLogger(AbortProcessInterceptor.class);
-   
+
    @AroundInvoke
    public Object abortProcess(InvocationContext ctx) throws Exception
    {
-      return ctx.proceed();
+
+      String processName = null;
+
+      Annotation[] methodAnnotations = ctx.getMethod().getAnnotations();
+      List<Annotation> annotationTypeList = new ArrayList<Annotation>();
+
+      for (Annotation nextAnnotation : methodAnnotations)
+      {
+         if (manager.isQualifier(nextAnnotation.annotationType()))
+         {
+            annotationTypeList.add(nextAnnotation);
+         }
+         if (manager.isInterceptorBinding(nextAnnotation.annotationType()))
+         {
+            if (nextAnnotation instanceof AbortProcess)
+            {
+               processName = ((AbortProcess) nextAnnotation).value();
+            }
+         }
+      }
+      
+      StatefulKnowledgeSession ksession = ksessionSource.select((Annotation[])annotationTypeList.toArray(new Annotation[annotationTypeList.size()])).get();
+      if(ksession != null) {
+         Object retObj = ctx.proceed();
+         if(processName != null && processName.length() > 0 ) {
+            Iterator<ProcessInstance> iter = ksession.getProcessInstances().iterator();
+            while(iter.hasNext()) {
+               ProcessInstance pi = iter.next();
+               if(pi.getProcessName().equals(processName)) {
+                  ksession.abortProcessInstance(pi.getId());
+               }
+            }
+         } else {
+            log.info("Invalid process name: " + processName);
+         }
+         return retObj;
+      } else {  
+         log.info("Could not obtain StatefulKnowledgeSession.");
+         return ctx.proceed();
+      }
    }
 
 }

Added: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/FireRulesInterceptor.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/FireRulesInterceptor.java	                        (rev 0)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/FireRulesInterceptor.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+package org.jboss.seam.drools.interceptor;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.drools.runtime.StatefulKnowledgeSession;
+import org.jboss.seam.drools.annotations.FireRules;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * @author Tihomir Surdilovic
+ */
+ at FireRules
+ at Interceptor
+public class FireRulesInterceptor
+{
+   @Inject
+   BeanManager manager;
+   
+   @Inject @Any Instance<StatefulKnowledgeSession> ksessionSource;
+   
+   private static final Logger log = LoggerFactory.getLogger(FireRulesInterceptor.class);
+   
+   @AroundInvoke
+   public Object fireRules(InvocationContext ctx) throws Exception
+   {
+      boolean untilHalt = false;
+      int limit = -1;
+      
+      Annotation[] methodAnnotations = ctx.getMethod().getAnnotations();
+      List<Annotation> annotationTypeList = new ArrayList<Annotation>();
+
+      for (Annotation nextAnnotation : methodAnnotations)
+      {
+         if (manager.isQualifier(nextAnnotation.annotationType()))
+         {
+            annotationTypeList.add(nextAnnotation);
+         }
+         if (manager.isInterceptorBinding(nextAnnotation.annotationType()))
+         {
+            if (nextAnnotation instanceof FireRules)
+            {
+               untilHalt = ((FireRules) nextAnnotation).untilHalt();
+               limit = ((FireRules) nextAnnotation).limit();
+            }
+         }
+      }
+      
+      final StatefulKnowledgeSession ksession = ksessionSource.select((Annotation[])annotationTypeList.toArray(new Annotation[annotationTypeList.size()])).get();
+      if(ksession != null) {
+         Object retObj = ctx.proceed();
+         if(untilHalt) {
+            ksession.fireUntilHalt();
+         } else {
+            if(limit > 0) {
+               ksession.fireAllRules(limit);
+            } else {
+               ksession.fireAllRules();
+            }
+         }
+         return retObj;
+      } else {  
+         log.info("Could not obtain StatefulKnowledgeSession.");
+         return ctx.proceed();
+      }
+      
+   }
+   
+}

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/SignalEventInterceptor.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/SignalEventInterceptor.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/SignalEventInterceptor.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -18,9 +18,14 @@
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */ 
+ */
 package org.jboss.seam.drools.interceptor;
 
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import javax.enterprise.inject.Any;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.BeanManager;
@@ -30,24 +35,109 @@
 import javax.interceptor.InvocationContext;
 
 import org.drools.runtime.StatefulKnowledgeSession;
+import org.drools.runtime.process.ProcessInstance;
 import org.jboss.seam.drools.annotations.flow.SignalEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * 
+ * @author Tihomir Surdilovic
+ */
 @SignalEvent
 @Interceptor
 public class SignalEventInterceptor
 {
    @Inject
    BeanManager manager;
-   
-   @Inject @Any Instance<StatefulKnowledgeSession> ksessionSource;
-   
+
+   @Inject
+   @Any
+   Instance<StatefulKnowledgeSession> ksessionSource;
+
    private static final Logger log = LoggerFactory.getLogger(SignalEventInterceptor.class);
-   
+
    @AroundInvoke
-   public Object abortProcess(InvocationContext ctx) throws Exception
+   public Object signalEvent(InvocationContext ctx) throws Exception
    {
-      return ctx.proceed();
+      String processName = null;
+      String type = null;
+      String event = null;
+
+      Annotation[] methodAnnotations = ctx.getMethod().getAnnotations();
+      List<Annotation> annotationTypeList = new ArrayList<Annotation>();
+
+      for (Annotation nextAnnotation : methodAnnotations)
+      {
+         if (manager.isQualifier(nextAnnotation.annotationType()))
+         {
+            annotationTypeList.add(nextAnnotation);
+         }
+         if (manager.isInterceptorBinding(nextAnnotation.annotationType()))
+         {
+            if (nextAnnotation instanceof SignalEvent)
+            {
+               processName = ((SignalEvent) nextAnnotation).processName();
+               type = ((SignalEvent) nextAnnotation).type();
+               event = ((SignalEvent) nextAnnotation).event();
+            }
+         }
+      }
+
+      StatefulKnowledgeSession ksession = ksessionSource.select((Annotation[]) annotationTypeList.toArray(new Annotation[annotationTypeList.size()])).get();
+      System.out.println("***** SEI ksession: " + ksession);
+      if (ksession != null)
+      {
+         Object retObj = ctx.proceed();
+         if (type != null)
+         {
+            if (processName != null && processName.length() > 0)
+            {
+               Iterator<ProcessInstance> iter = ksession.getProcessInstances().iterator();
+               while (iter.hasNext())
+               {
+                  ProcessInstance pi = iter.next();
+                  if (pi.getProcessName().equals(processName))
+                  {
+                     if (event != null && event.length() > 0)
+                     {
+                        System.out.println("***** signalling to process : " + type + " - " + event);
+                        pi.signalEvent(type, event);
+                     }
+                     else
+                     {
+                        System.out.println("***** signalling to process : " + type + " - " + retObj);
+                        pi.signalEvent(type, retObj);
+                     }
+                  }
+               }
+            }
+            else
+            {
+               if (event != null && event.length() > 0)
+               {
+                  System.out.println("***** signalling to ksession : " + type + " - " + event);
+                  ksession.signalEvent(type, event);
+               }
+               else
+               {
+                  System.out.println("***** signalling to ksession : " + type + " - " + retObj);
+                  ksession.signalEvent(type, retObj);
+               }
+
+            }
+         }
+         else
+         {
+            log.error("Invalid type specified: " + type);
+         }
+         return retObj;
+      }
+      else
+      {
+         log.info("Could not obtain StatefulKnowledgeSession.");
+         return ctx.proceed();
+      }
+
    }
 }

Modified: modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/StartProcessInterceptor.java
===================================================================
--- modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/StartProcessInterceptor.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/main/java/org/jboss/seam/drools/interceptor/StartProcessInterceptor.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -21,6 +21,10 @@
  */ 
 package org.jboss.seam.drools.interceptor;
 
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.enterprise.inject.Any;
 import javax.enterprise.inject.Instance;
 import javax.enterprise.inject.spi.BeanManager;
@@ -46,8 +50,47 @@
    private static final Logger log = LoggerFactory.getLogger(StartProcessInterceptor.class);
    
    @AroundInvoke
-   public Object abortProcess(InvocationContext ctx) throws Exception
+   public Object startProcess(InvocationContext ctx) throws Exception
    {
-      return ctx.proceed();
+      String processName = null;
+      boolean fire = false;
+      boolean untilHalt = false;
+      
+      Annotation[] methodAnnotations = ctx.getMethod().getAnnotations();
+      List<Annotation> annotationTypeList = new ArrayList<Annotation>();
+      
+      for(Annotation nextAnnotation : methodAnnotations) {
+         if(manager.isQualifier(nextAnnotation.annotationType())) {
+            annotationTypeList.add(nextAnnotation);
+         }
+         if(manager.isInterceptorBinding(nextAnnotation.annotationType())) {
+            if(nextAnnotation instanceof StartProcess) {
+               processName = ((StartProcess) nextAnnotation).name();
+               fire = ((StartProcess) nextAnnotation).fire();
+               untilHalt = ((StartProcess) nextAnnotation).untilHalt();
+            }
+         }
+      }
+      
+      final StatefulKnowledgeSession ksession = ksessionSource.select((Annotation[])annotationTypeList.toArray(new Annotation[annotationTypeList.size()])).get();
+      if(ksession != null) {
+         Object retObj = ctx.proceed();
+         if(processName != null && processName.length() > 0 ) {
+            ksession.startProcess(processName);
+            if(fire) {
+               if(untilHalt) {                
+                  ksession.fireUntilHalt();
+               } else {
+                  ksession.fireAllRules();
+               }
+            }
+         } else {
+            log.info("Invalid process name: " + processName);
+         }
+         return retObj;
+      } else {  
+         log.info("Could not obtain StatefulKnowledgeSession.");
+         return ctx.proceed();
+      }
    }
 }

Modified: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTest.java
===================================================================
--- modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTest.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTest.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -29,20 +29,18 @@
 import java.util.Collection;
 
 import javax.enterprise.inject.Default;
-import javax.inject.Inject;
-import javax.validation.constraints.AssertTrue;
 
 import org.drools.runtime.ObjectFilter;
 import org.drools.runtime.StatefulKnowledgeSession;
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
 import org.jboss.seam.drools.KnowledgeBaseProducer;
+import org.jboss.seam.drools.config.DroolsConfig;
 import org.jboss.seam.drools.qualifiers.config.CEPPseudoClockConfig;
 import org.jboss.seam.drools.qualifiers.config.DefaultConfig;
 import org.jboss.seam.drools.test.DroolsModuleFilter;
 import org.jboss.shrinkwrap.api.ArchivePaths;
 import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.formatter.Formatters;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.weld.extensions.resources.ResourceProvider;
 import org.junit.Test;
@@ -59,8 +57,11 @@
       .addPackages(true, new DroolsModuleFilter("interceptors"), KnowledgeBaseProducer.class.getPackage())
       .addPackages(true, ResourceProvider.class.getPackage())
       .addClass(Person.class).addClass(InterceptorsTestBean.class)
+      .addClass(InterceptorsTestConfig.class)
       .addResource(pkgPath + "/interceptorstest.drl", ArchivePaths.create("interceptorstest.drl"))
       .addResource(pkgPath + "/interceptorstestcep.drl", ArchivePaths.create("interceptorstestcep.drl"))
+      .addResource(pkgPath + "/interceptorstestflow.drl", ArchivePaths.create("interceptorstestflow.drl"))
+      .addResource(pkgPath + "/interceptortests.rf", ArchivePaths.create("interceptortests.rf"))
       .addManifestResource(pkgPath + "/InterceptorsTest-beans.xml", ArchivePaths.create("beans.xml"));
       // System.out.println(archive.toString(Formatters.VERBOSE));
       return archive;
@@ -107,4 +108,41 @@
       assertNotNull(p);
       assertTrue(p.isEligible());
    }
+   
+   @Test
+   public void testProcessStartAndSignal(InterceptorsTestBean ibean,
+         @Default @InterceptorsTestConfig StatefulKnowledgeSession ksession) {
+      assertNotNull(ibean);
+      assertNotNull(ksession);
+      
+      ibean.getPersonForFlow();
+      Collection<?> allPeople1 = ksession.getObjects(new ObjectFilter()
+      {
+         public boolean accept(Object object)
+         {
+            return object instanceof Person;
+         }
+      });
+      
+      Person p1 = (Person) allPeople1.toArray(new Object[0])[0];
+      assertNotNull(p1);
+      assertTrue(!p1.isEligible());
+   
+      ibean.startProcess();
+      
+      Collection<?> allPeople2 = ksession.getObjects(new ObjectFilter()
+      {
+         public boolean accept(Object object)
+         {
+            return object instanceof Person;
+         }
+      });
+      
+      Person p2 = (Person) allPeople2.toArray(new Object[0])[0];
+      assertNotNull(p2);
+      assertTrue(p2.isEligible());
+
+      
+
+   }
 }

Modified: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestBean.java
===================================================================
--- modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestBean.java	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestBean.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -24,6 +24,9 @@
 import javax.enterprise.inject.Default;
 
 import org.jboss.seam.drools.annotations.InsertFact;
+import org.jboss.seam.drools.annotations.flow.AbortProcess;
+import org.jboss.seam.drools.annotations.flow.SignalEvent;
+import org.jboss.seam.drools.annotations.flow.StartProcess;
 import org.jboss.seam.drools.qualifiers.config.CEPPseudoClockConfig;
 import org.jboss.seam.drools.qualifiers.config.DefaultConfig;
 
@@ -44,4 +47,27 @@
       p.setAge(33);
       return p;
    }
+   
+   @InsertFact @Default @InterceptorsTestConfig
+   public Person getPersonForFlow() {
+      Person p = new Person();
+      p.setEligible(false);
+      p.setAge(55);
+      return p;
+   }
+   
+   @StartProcess(name="interceptorstestflow", fire=true) @Default @InterceptorsTestConfig
+   public void startProcess() {
+      // this will start the process....
+   }
+   
+   @SignalEvent(type="signal", processName="interceptorstestflow") @Default @InterceptorsTestConfig
+   public String signalEvent() {
+      return "continue";
+   }
+   
+   @AbortProcess("interceptorstestflow") @Default @InterceptorsTestConfig
+   public void abortProcess() {
+      // this will abort the process....
+   }
 }

Added: modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestConfig.java
===================================================================
--- modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestConfig.java	                        (rev 0)
+++ modules/drools/trunk/impl/src/test/java/org/jboss/seam/drools/test/interceptors/InterceptorsTestConfig.java	2010-04-23 23:22:36 UTC (rev 12622)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */ 
+package org.jboss.seam.drools.test.interceptors;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * 
+ * @author Tihomir Surdilovic
+ */
+ at Qualifier
+ at Target( { TYPE, METHOD, FIELD, PARAMETER })
+ at Documented
+ at Retention(RUNTIME)
+public @interface InterceptorsTestConfig
+{
+
+}

Modified: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/InterceptorsTest-beans.xml
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/InterceptorsTest-beans.xml	2010-04-23 23:12:28 UTC (rev 12621)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/InterceptorsTest-beans.xml	2010-04-23 23:22:36 UTC (rev 12622)
@@ -26,6 +26,10 @@
 
 	<interceptors>
     	<class>org.jboss.seam.drools.interceptor.InsertFactInterceptor</class>
+    	<class>org.jboss.seam.drools.interceptor.FireRulesInterceptor</class>
+    	<class>org.jboss.seam.drools.interceptor.StartProcessInterceptor</class>
+    	<class>org.jboss.seam.drools.interceptor.SignalEventInterceptor</class>
+    	<class>org.jboss.seam.drools.interceptor.AbortProcessInterceptor</class>
     </interceptors>
     
 	<d:DefaultRuleResources>
@@ -41,5 +45,23 @@
    			<s:value>classpath;interceptorstestcep.drl;DRL</s:value>
    		</d:resources>
 	</d:CEPPseudoClockRuleResources>
+	
+	
+	<d:RuleResources>
+		<s:overrides/>
+		<test:InterceptorsTestConfig/>
+		<d:resources>
+   			<s:value>classpath;interceptorstestflow.drl;DRL</s:value>
+   			<s:value>classpath;interceptortests.rf;DRF</s:value>
+   		</d:resources>
+	</d:RuleResources>
+	<d:DroolsConfig>
+		<test:InterceptorsTestConfig/>
+		<d:ruleResources>
+			<s:Inject/>
+			<test:InterceptorsTestConfig/>
+		</d:ruleResources>
+	</d:DroolsConfig>
+	
 		
 </beans>       

Added: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptorstestflow.drl
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptorstestflow.drl	                        (rev 0)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptorstestflow.drl	2010-04-23 23:22:36 UTC (rev 12622)
@@ -0,0 +1,15 @@
+package org.jboss.seam.drools.test.interceptors
+
+import org.jboss.seam.drools.test.interceptors.Person;
+
+rule "is person eligible for buss pass"
+lock-on-active 
+ruleflow-group "BusinessRules"
+when
+	$p : Person( age >=18 )
+then
+	System.out.println("*****************\nIN RULE \n ***************");
+	modify($p) {
+		setEligible(true);
+	}
+end

Added: modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptortests.rf
===================================================================
--- modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptortests.rf	                        (rev 0)
+++ modules/drools/trunk/impl/src/test/resources/org/jboss/seam/drools/test/interceptors/interceptortests.rf	2010-04-23 23:22:36 UTC (rev 12622)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?> 
+<process xmlns="http://drools.org/drools-5.0/process"
+         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+         xs:schemaLocation="http://drools.org/drools-5.0/process drools-processes-5.0.xsd"
+         type="RuleFlow" name="interceptorstestflow" id="interceptorstestflow" package-name="org.jboss.seam.drools.test.interceptors" >
+
+  <header>
+  </header>
+
+  <nodes>
+    <start id="1" name="Start" x="32" y="16" width="48" height="48" />
+    <end id="2" name="End" x="16" y="168" width="80" height="40" />
+    <ruleSet id="4" name="BusinessRules" x="16" y="96" width="80" height="40" ruleFlowGroup="BusinessRules" />
+  </nodes>
+
+  <connections>
+    <connection from="4" to="2" />
+    <connection from="1" to="4" />
+  </connections>
+
+</process>
\ No newline at end of file



More information about the seam-commits mailing list