Esempio n. 1
0
  public void testSignalBoundaryEvent() {
    KnowledgeBase kbase =
        createKnowledgeBase(
            "BPMN2-BoundarySignalEventOnTaskbpmn2.bpmn",
            "BPMN2-IntermediateThrowEventSignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("BoundarySignalOnTask");

    ProcessInstance processInstance2 = ksession.startProcess("SignalIntermediateEvent");
    assertProcessInstanceCompleted(processInstance2.getId(), ksession);

    assertProcessInstanceCompleted(processInstance.getId(), ksession);
  }
Esempio n. 2
0
 private void testStartProcess(SessionManagerFactory factory) throws Exception {
   SessionManager sessionManager = factory.getSessionManager();
   long taskId;
   synchronized (
       (SingleSessionCommandService)
           ((CommandBasedStatefulKnowledgeSession) sessionManager.getKnowledgeSession())
               .getCommandService()) {
     UserTransaction ut =
         (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
     ut.begin();
     System.out.println(
         "Starting process on ksession " + sessionManager.getKnowledgeSession().getId());
     ProcessInstance processInstance =
         sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
     System.out.println(
         "Started process instance "
             + processInstance.getId()
             + " on ksession "
             + sessionManager.getKnowledgeSession().getId());
     long workItemId =
         ((HumanTaskNodeInstance)
                 ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next())
             .getWorkItemId();
     taskId = sessionManager.getTaskService().getTaskByWorkItemId(workItemId).getId();
     System.out.println("Created task " + taskId);
     ut.commit();
   }
   sessionManager.getTaskService().claim(taskId, "mary");
   sessionManager.dispose();
 }
Esempio n. 3
0
  public void testNewSessionFailBefore() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("sampleFailBefore.bpmn"), ResourceType.BPMN2);
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase);
    SessionManager sessionManager = factory.getSessionManager();

    try {
      ProcessInstance processInstance =
          sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
      fail("Started process instance " + processInstance.getId());
    } catch (RuntimeException e) {
      // do nothing
    }

    // TODO: whenever transaction fails, do we need to dispose? can we?
    // sessionManager.dispose();

    List<Status> statusses = new ArrayList<Status>();
    statusses.add(Status.Reserved);

    sessionManager = factory.getSessionManager();
    List<TaskSummary> tasks =
        sessionManager.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, tasks.size());

    sessionManager.dispose();
    factory.dispose();
  }
Esempio n. 4
0
  public void testSignalBetweenProcesses() {
    KnowledgeBase kbase =
        createKnowledgeBase(
            "BPMN2-IntermediateCatchSignalSingle.bpmn2",
            "BPMN2-IntermediateThrowEventSignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);

    ProcessInstance processInstance = ksession.startProcess("BPMN2-IntermediateCatchSignalSingle");
    ksession.getWorkItemManager().completeWorkItem(handler.getWorkItem().getId(), null);

    ProcessInstance processInstance2 = ksession.startProcess("SignalIntermediateEvent");
    assertProcessInstanceCompleted(processInstance2.getId(), ksession);

    assertProcessInstanceCompleted(processInstance.getId(), ksession);
  }
Esempio n. 5
0
  public void testSignalToStartProcess() {
    KnowledgeBase kbase =
        createKnowledgeBase("BPMN2-SignalStart.bpmn2", "BPMN2-IntermediateThrowEventSignal.bpmn2");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    TestWorkItemHandler handler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    final List<String> startedProcesses = new ArrayList<String>();
    ksession.addEventListener(
        new DefaultProcessEventListener() {

          @Override
          public void beforeProcessStarted(ProcessStartedEvent event) {
            startedProcesses.add(event.getProcessInstance().getProcessId());
          }
        });

    ProcessInstance processInstance2 = ksession.startProcess("SignalIntermediateEvent");
    assertProcessInstanceCompleted(processInstance2.getId(), ksession);
    assertEquals(2, startedProcesses.size());
  }
Esempio n. 6
0
  public void testNewSessionFail() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase);
    SessionManager sessionManager = factory.getSessionManager();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    ProcessInstance processInstance =
        sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
    System.out.println("Started process instance " + processInstance.getId());
    long workItemId =
        ((HumanTaskNodeInstance)
                ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next())
            .getWorkItemId();
    long taskId = sessionManager.getTaskService().getTaskByWorkItemId(workItemId).getId();
    sessionManager.getTaskService().claim(taskId, "mary");
    ut.rollback();
    System.out.println("Rolled back");
    // TODO: whenever transaction fails, do we need to dispose? can we?
    // sessionManager.dispose();

    List<Status> statusses = new ArrayList<Status>();
    statusses.add(Status.Reserved);

    sessionManager = factory.getSessionManager();
    assertNull(sessionManager.getKnowledgeSession().getProcessInstance(processInstance.getId()));
    List<TaskSummary> tasks =
        sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK");
    assertEquals(0, tasks.size());

    ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    processInstance =
        sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
    workItemId =
        ((HumanTaskNodeInstance)
                ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next())
            .getWorkItemId();
    taskId = sessionManager.getTaskService().getTaskByWorkItemId(workItemId).getId();
    sessionManager.getTaskService().claim(taskId, "mary");
    System.out.println("Started process instance " + processInstance.getId());
    ut.commit();

    assertNotNull(sessionManager.getKnowledgeSession().getProcessInstance(processInstance.getId()));
    tasks = sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK");
    assertEquals(1, tasks.size());

    taskId = tasks.get(0).getId();
    ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    sessionManager.getTaskService().start(taskId, "mary");
    sessionManager.getTaskService().complete(taskId, "mary", null);
    ut.rollback();
    sessionManager.dispose();

    sessionManager = factory.getSessionManager();
    assertNotNull(sessionManager.getKnowledgeSession().getProcessInstance(processInstance.getId()));
    tasks = sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK");
    assertEquals(1, tasks.size());

    taskId = tasks.get(0).getId();
    ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    sessionManager.getTaskService().start(taskId, "mary");
    sessionManager.getTaskService().complete(taskId, "mary", null);
    ut.commit();

    assertNull(sessionManager.getKnowledgeSession().getProcessInstance(processInstance.getId()));
    tasks = sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK");
    assertEquals(0, tasks.size());
    sessionManager.dispose();

    factory.dispose();
  }