@Test
  public void testGo() {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();

    KieSession ksession = kContainer.newKieSession();

    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);

    ksession.fireAllRules();

    assertEquals(2, list.size());
    assertTrue(list.contains("car"));
    assertTrue(list.contains("ball"));

    list.clear();

    ksession.insert("Debbie");
    ksession.fireAllRules();
    ksession.fireAllRules();

    assertEquals(1, list.size());
    assertTrue(list.contains("doll"));
  }
Exemplo n.º 2
0
  private static KieSession readKnowledgeBase() throws Exception {

    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieSession kSession = kContainer.newKieSession();

    return kSession;
  }
Exemplo n.º 3
0
 @Test
 public void testKieScannerOnClasspathContainerMustFail() {
   KieServices ks = KieServices.Factory.get();
   KieContainer kieContainer = ks.getKieClasspathContainer();
   try {
     KieScanner scanner = ks.newKieScanner(kieContainer);
     fail("Creating a KieScanner from a KieClasspathContainer must fail");
   } catch (RuntimeException e) {
   }
 }
Exemplo n.º 4
0
  @Test
  public void testLocalTaskService() throws Exception {

    // Create the task service
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
    DefaultUserGroupCallbackImpl userGroupCallback = new DefaultUserGroupCallbackImpl();
    // create mock groups
    userGroupCallback.addUser("john", "users");
    userGroupCallback.addUser("Administrator", "users");
    // start taskService
    TaskService taskService =
        HumanTaskServiceFactory.newTaskServiceConfigurator()
            .entityManagerFactory(emf)
            .userGroupCallback(userGroupCallback)
            .getTaskService();

    // Create the KIE session
    KieServices ks = KieServices.Factory.get();
    KieContainer kc = ks.getKieClasspathContainer();
    KieSession ksession = kc.newKieSession();

    // create the work item handler for human task
    WorkItemHandler humanTaskHandler = new NonManagedLocalHTWorkItemHandler(ksession, taskService);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

    WorkflowProcessInstance instance =
        (WorkflowProcessInstance) ksession.startProcess("htHomeworkProcess", null);
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, instance.getState());

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    Assert.assertNotNull(tasks);
    Assert.assertEquals(1, tasks.size());

    TaskSummary firstTask = tasks.iterator().next();

    Assert.assertNotNull(instance.getVariable("requestId"));
    String requestId = instance.getVariable("requestId").toString();

    InternalTask actualFirstTask = (InternalTask) taskService.getTaskById(firstTask.getId());
    System.out.println("requestId = " + requestId);
    System.out.println("formName = " + actualFirstTask.getFormName());
    Assert.assertNotNull(actualFirstTask.getFormName());
    Assert.assertTrue(actualFirstTask.getFormName().contains(requestId));

    taskService.claim(firstTask.getId(), "john");
    taskService.start(firstTask.getId(), "john");
    taskService.complete(firstTask.getId(), "john", null);

    // now that the second task is completed, the process is completed as well
    Assert.assertEquals(ProcessInstance.STATE_COMPLETED, instance.getState());
  }
  @Test
  public void testKJar() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieSession kSession = kContainer.newKieSession("FireAlarmKBase.session");

    Room room = new Room("101");
    kSession.insert(room);
    Sprinkler sprinkler = new Sprinkler(room);
    kSession.insert(sprinkler);
    Fire fire = new Fire(room);
    FactHandle fireFH = kSession.insert(fire);

    int rules = kSession.fireAllRules();
    assertEquals(2, rules);

    kSession.delete(fireFH);
    rules = kSession.fireAllRules();
    assertEquals(3, rules);
  }
  @Test
  public void testImplicit() {
    KieServices ks = KieServices.Factory.get();
    KieContainer kContainer = ks.getKieClasspathContainer();
    KieSession ksession = kContainer.newKieSession("ksession-samples");
    ProcessInstance processInstance = ksession.startProcess("approveorder");

    Purchase purchase = new Purchase();
    purchase.setCustomerName("sekhar");
    purchase.setPaymentMethod(PaymentMethod.DEBIT);
    purchase.setSubtotal(0);
    ksession.insert(purchase);
    int rulesFired = ksession.fireAllRules();
    System.out.println("facthandles count -->" + ksession.getFactHandles().size());
    // Check the count
    Assert.assertEquals(1, rulesFired);
    // Check the node exists
    // assertNodeExists(processInstance, "Discount","printout");
    // Check the node names
    // assertNodeTriggered(processInstance.getId(),"Discount","printout");
    // Assert completed
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
  }
Exemplo n.º 7
0
 static {
   KieServices ks = KieServices.Factory.get();
   kc = ks.getKieClasspathContainer();
 }