Пример #1
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();
 }
Пример #2
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();
  }
Пример #3
0
  public void testNewSessionDispose() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2);
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase);
    final SessionManager sessionManager = factory.getSessionManager();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
    TransactionManagerServices.getTransactionManager()
        .getTransaction()
        .registerSynchronization(
            new Synchronization() {
              public void beforeCompletion() {}

              public void afterCompletion(int status) {
                try {
                  sessionManager.dispose();
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            });
    ut.commit();
    factory.dispose();
  }
Пример #4
0
  public void testNewSessionFailAfter() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("sampleFailAfter.bpmn"), ResourceType.BPMN2);
    KnowledgeBase kbase = kbuilder.newKnowledgeBase();
    SessionManagerFactory factory = new NewSessionSessionManagerFactory(kbase);
    SessionManager sessionManager = factory.getSessionManager();

    ProcessInstance processInstance =
        sessionManager.getKnowledgeSession().startProcess("com.sample.bpmn.hello", null);
    long workItemId =
        ((HumanTaskNodeInstance)
                ((WorkflowProcessInstance) processInstance).getNodeInstances().iterator().next())
            .getWorkItemId();
    long taskId = sessionManager.getTaskService().getTaskByWorkItemId(workItemId).getId();
    sessionManager.getTaskService().claim(taskId, "mary");

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

    List<TaskSummary> tasks =
        sessionManager.getTaskService().getTasksOwned("mary", statusses, "en-UK");
    assertEquals(1, tasks.size());

    taskId = tasks.get(0).getId();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    try {
      ut.begin();
      sessionManager.getTaskService().start(taskId, "mary");
      sessionManager.getTaskService().complete(taskId, "mary", null);
      fail("Task completed");
    } catch (RuntimeException e) {
      // do nothing
    }
    ut.rollback();

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

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

    sessionManager.dispose();
    factory.dispose();
  }