Package org.drools.compiler

Examples of org.drools.compiler.PackageBuilder$RuleInvokerErrorHandler


public class ProcessTimerTest extends JbpmTestCase {
 
  @SuppressWarnings("unchecked")
  public void testSimpleProcess() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.jbpm\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <imports>\n" +
      "      <import name=\"org.jbpm.Message\" />\n" +
      "    </imports>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <end id=\"2\" name=\"End\" />\n" +
      "    <timerNode id=\"3\" name=\"Timer\" delay=\"800ms\" period=\"200ms\" />\n" +
      "    <actionNode id=\"4\" name=\"Action\" >\n" +
      "      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" +
      "myList.add( new Message() );\n" +
      "insert( new Message() );\n" +
      "</action>\n" +
      "    </actionNode>\n" +
      "    <milestone id=\"5\" name=\"Wait\" >\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >Number( intValue &gt;= 5 ) from accumulate ( m: Message( ), count( m ) )</constraint>\n" +
      "    </milestone>\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"5\" to=\"2\" />\n" +
      "    <connection from=\"1\" to=\"3\" />\n" +
      "    <connection from=\"3\" to=\"4\" />\n" +
      "    <connection from=\"4\" to=\"5\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
    if (!builder.getErrors().isEmpty()) {
      for (DroolsError error: builder.getErrors().getErrors()) {
        System.err.println(error);
      }
      fail("Could not build process");
    }
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<Message> myList = new ArrayList<Message>();
    session.setGlobal("myList", myList);
View Full Code Here


        session2.halt();
  }
 
  @SuppressWarnings("unchecked")
  public void testVariableSimpleProcess() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.jbpm\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <imports>\n" +
      "      <import name=\"org.jbpm.Message\" />\n" +
      "    </imports>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
            "    <variables>\n" +
            "      <variable name=\"x\" >\n" +
            "        <type name=\"org.drools.process.core.datatype.impl.type.IntegerDataType\" />\n" +
            "      </variable>\n" +
            "      <variable name=\"y\" >\n" +
            "        <type name=\"org.drools.process.core.datatype.impl.type.IntegerDataType\" />\n" +
            "      </variable>\n" +
            "    </variables>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <end id=\"2\" name=\"End\" />\n" +
      "    <timerNode id=\"3\" name=\"Timer\" delay=\"#{x}ms\" period=\"#{y}ms\" />\n" +
      "    <actionNode id=\"4\" name=\"Action\" >\n" +
      "      <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" +
      "myList.add( new Message() );\n" +
      "insert( new Message() );\n" +
      "</action>\n" +
      "    </actionNode>\n" +
      "    <milestone id=\"5\" name=\"Wait\" >\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >Number( intValue &gt;= 5 ) from accumulate ( m: Message( ), count( m ) )</constraint>\n" +
      "    </milestone>\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"5\" to=\"2\" />\n" +
      "    <connection from=\"1\" to=\"3\" />\n" +
      "    <connection from=\"3\" to=\"4\" />\n" +
      "    <connection from=\"4\" to=\"5\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
    if (!builder.getErrors().isEmpty()) {
      for (DroolsError error: builder.getErrors().getErrors()) {
        System.err.println(error);
      }
      fail("Could not build process");
    }
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<Message> myList = new ArrayList<Message>();
    session.setGlobal("myList", myList);
View Full Code Here

       
        session2.halt();
  }
 
  public void testIncorrectTimerNode() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <end id=\"2\" name=\"End\" />\n" +
      "    <timerNode id=\"3\" name=\"Timer\" delay=\"800msdss\" period=\"200mssds\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"3\" />\n" +
      "    <connection from=\"3\" to=\"2\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
    assertEquals(2, builder.getErrors().size());
    for (DroolsError error: builder.getErrors().getErrors()) {
      System.err.println(error);
    }
  }
View Full Code Here

    }
  }

  @SuppressWarnings("unchecked")
  public void testOnEntryTimerExecuted() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"300\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

        session2.halt();
  }

  @SuppressWarnings("unchecked")
  public void testOnEntryTimerVariableExecuted() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
            "    <variables>\n" +
            "      <variable name=\"x\" >\n" +
            "        <type name=\"org.drools.process.core.datatype.impl.type.IntegerDataType\" />\n" +
            "      </variable>\n" +
            "    </variables>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"#{x}\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

        session2.halt();
  }

  @SuppressWarnings("unchecked")
  public void testOnEntryTimerWorkItemExecuted() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
            "    <workItem id=\"2\" name=\"Work\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"300\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
            "      <work name=\"Human Task\" >\n" +
            "      </work>\n" +
            "    </workItem>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

       
        session2.halt();
  }

  public void testIncorrectOnEntryTimer() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"300asdf\" period=\"asfd\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    assertEquals(2, builder.getErrors().size());
    for (DroolsError error: builder.getErrors().getErrors()) {
      System.err.println(error);
    }
  }
View Full Code Here

    }
  }

  @SuppressWarnings("unchecked")
  public void testOnEntryTimerExecutedMultipleTimes() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"300\" period =\"200\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

        session2.halt();
  }
 
  @SuppressWarnings("unchecked")
  public void testMultipleTimers() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"600\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer1\");</action>\n" +
      "        </timer>\n" +
      "        <timer id=\"2\" delay=\"200\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer2\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >eval(false)</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

        session3.halt();
  }
 
  @SuppressWarnings("unchecked")
  public void testOnEntryTimerCancelled() throws Exception {
    PackageBuilder builder = new PackageBuilder();
    Reader source = new StringReader(
      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
      "         xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
      "         xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
      "         type=\"RuleFlow\" name=\"flow\" id=\"org.drools.timer\" package-name=\"org.drools\" version=\"1\" >\n" +
      "\n" +
      "  <header>\n" +
      "    <globals>\n" +
      "      <global identifier=\"myList\" type=\"java.util.List\" />\n" +
      "    </globals>\n" +
      "  </header>\n" +
      "\n" +
      "  <nodes>\n" +
      "    <start id=\"1\" name=\"Start\" />\n" +
      "    <milestone id=\"2\" name=\"Wait\" >\n" +
      "      <timers>\n" +
      "        <timer id=\"1\" delay=\"2000\" >\n" +
      "          <action type=\"expression\" dialect=\"java\" >myList.add(\"Executing timer\");</action>\n" +
      "        </timer>\n" +
      "      </timers>\n" +
      "      <constraint type=\"rule\" dialect=\"mvel\" >org.jbpm.Message( )</constraint>\n" +
      "    </milestone>\n" +
      "    <end id=\"3\" name=\"End\" />\n" +
      "  </nodes>\n" +
      "\n" +
      "  <connections>\n" +
      "    <connection from=\"1\" to=\"2\" />\n" +
      "    <connection from=\"2\" to=\"3\" />\n" +
      "  </connections>\n" +
      "\n" +
      "</process>");
    builder.addRuleFlow(source);
   
    Package pkg = builder.getPackage();
    RuleBase ruleBase = RuleBaseFactory.newRuleBase();
    ruleBase.addPackage( pkg );
    final StatefulSession session = ruleBase.newStatefulSession();
    List<String> myList = new ArrayList<String>();
    session.setGlobal("myList", myList);
View Full Code Here

TOP

Related Classes of org.drools.compiler.PackageBuilder$RuleInvokerErrorHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.