Beispiel #1
0
  public void testStartAProcessUsingTwoStartEvents() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("itSTime", "1.3")
            .addHuman(getLogin())
            .addTimerTask("every_second", "${new Date(timerLastExecution + 2000)}")
            .addHumanTask("step1", getLogin())
            .addSystemTask("start")
            .addDecisionNode("join")
            .addJoinType(JoinType.XOR)
            .addTransition("every_second", "join")
            .addTransition("start", "join")
            .addTransition("join", "step1")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(0, instances.size());

    Thread.sleep(2100);
    instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(1, instances.size());

    getRuntimeAPI().instantiateProcess(process.getUUID());
    instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(2, instances.size());

    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #2
0
  public void testDeleteBoundaryEventTest() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("boundaryTimer", "1.1")
            .addHuman(getLogin())
            .addHumanTask("step1", getLogin())
            .addTimerBoundaryEvent("In_a_minute", "5000")
            .addHumanTask("normal", getLogin())
            .addHumanTask("exception", getLogin())
            .addTransition("step1", "normal")
            .addExceptionTransition("step1", "In_a_minute", "exception")
            .done();

    BusinessArchive archive = getBusinessArchive(process);
    process = getManagementAPI().deploy(archive);
    final ProcessDefinitionUUID processUUID = process.getUUID();

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    Set<LightTaskInstance> tasks = getQueryRuntimeAPI().getLightTasks(instanceUUID);
    assertEquals(1, tasks.size());
    LightTaskInstance task = tasks.iterator().next();
    assertEquals("step1", task.getActivityName());
    executeTask(instanceUUID, "step1");

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #3
0
  public void testBoundaryEventTest() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("boundaryTimer", "1.0")
            .addHuman(getLogin())
            .addHumanTask("step1", getLogin())
            .addTimerBoundaryEvent("In_5_seconds", "5000")
            .addHumanTask("normal", getLogin())
            .addHumanTask("exception", getLogin())
            .addTransition("step1", "normal")
            .addExceptionTransition("step1", "In_5_seconds", "exception")
            .done();

    BusinessArchive archive = getBusinessArchive(process);
    process = getManagementAPI().deploy(archive);
    final ProcessDefinitionUUID processUUID = process.getUUID();

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    Set<LightTaskInstance> tasks = getQueryRuntimeAPI().getLightTasks(instanceUUID);
    assertEquals(1, tasks.size());
    LightTaskInstance task = tasks.iterator().next();
    assertEquals("step1", task.getActivityName());

    Thread.sleep(8000);
    tasks = getQueryRuntimeAPI().getLightTasks(instanceUUID);
    for (LightTaskInstance lightTaskInstance : tasks) {
      System.out.println(lightTaskInstance);
    }

    assertEquals(2, tasks.size());
    //    task = tasks.iterator().next();
    //    assertEquals("exception", task.getActivityName());

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #4
0
  public void testCancelTimerWithAHugeCondition() throws Exception {
    String timerCondition =
        "${new Date(System.currentTimeMillis() + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10+ 10 + 10 + 10 + 10 + 10 +"
            + " 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 +"
            + " 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10)}";

    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addTimerTask("timer", timerCondition)
            .addDecisionNode("join")
            .addJoinType(JoinType.XOR)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    final ProcessDefinitionUUID processUUID = process.getUUID();

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    getRuntimeAPI().cancelProcessInstance(instanceUUID);
    assertEquals(
        InstanceState.CANCELLED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());
    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #5
0
  public void testStartAProcessOnce() throws Exception {
    long now = System.currentTimeMillis();
    ProcessDefinition process =
        ProcessBuilder.createProcess("itSTime", "1.0")
            .addHuman(getLogin())
            .addTimerTask("InASecond", "${new Date(" + now + "+ 1000)}")
            .addHumanTask("step1", getLogin())
            .addTransition("InASecond", "step1")
            .done();
    process = getManagementAPI().deploy(getBusinessArchive(process));

    Thread.sleep(1500);
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(1, instances.size());
    LightProcessInstance instance = instances.iterator().next();
    assertEquals("SYSTEM", instance.getStartedBy());
    assertTrue(new Date(now + 100).getTime() <= instance.getStartedDate().getTime());

    Thread.sleep(1500);
    instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(1, instances.size());
    instance = instances.iterator().next();
    assertEquals("SYSTEM", instance.getStartedBy());
    assertTrue(new Date(now + 100).getTime() <= instance.getStartedDate().getTime());

    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #6
0
  public void testGroovyNumber() throws Exception {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("mulitple", "1.0")
            .addHuman(getLogin())
            .addHumanTask("multi", getLogin())
            .addMultipleActivitiesInstantiator(FixedNumberInstantiator.class.getName())
            .addInputParameter("activityNumber", 10)
            .addMultipleActivitiesJoinChecker(FixedNumberJoinChecker.class.getName())
            .addInputParameter("activityNumber", 3)
            .addHumanTask("next", getLogin())
            .addTransition("multi", "next")
            .done();

    definition =
        getManagementAPI()
            .deploy(
                getBusinessArchive(
                    definition, null, FixedNumberInstantiator.class, FixedNumberJoinChecker.class));
    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(definition.getUUID());
    Collection<TaskInstance> tasks =
        getQueryRuntimeAPI().getTaskList(getLogin(), ActivityState.READY);
    assertEquals(10, tasks.size());
    Iterator<TaskInstance> iterator = tasks.iterator();
    for (int i = 0; i < 3; i++) {
      TaskInstance task = iterator.next();
      executeTask(instanceUUID, task.getActivityName());
    }
    tasks = getQueryRuntimeAPI().getTaskList(getLogin(), ActivityState.READY);
    assertEquals(1, tasks.size());
    assertEquals("next", tasks.iterator().next().getActivityName());
    getManagementAPI().deleteProcess(definition.getUUID());
  }
Beispiel #7
0
  public void testSimpleTimerSystemTask() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addSystemTask("start")
            .addSystemTask("system")
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 100)}")
            .addDecisionNode("join")
            .addJoinType(JoinType.AND)
            .addTransition("start", "system")
            .addTransition("start", "timer")
            .addTransition("system", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    this.waitForInstanceEnd(3000, 10, instanceUUID);

    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #8
0
  public void testDeployBigBusinessArchive() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("bigProcess", "1.0")
            .addHuman(getLogin())
            .addHumanTask("step1", getLogin())
            .done();

    final int count = 1000;
    byte[] jar = Misc.generateJar(QuerierAPITest.class);
    Map<String, byte[]> resources = new HashMap<String, byte[]>();
    byte[] tmp;
    for (int i = 0; i < count; i++) {
      tmp = (byte[]) jar.clone();
      resources.put("resource" + i, tmp);
    }

    System.out.println(jar.length);
    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(process, resources);

    process = getManagementAPI().deploy(businessArchive);

    ProcessDefinition dbProcess = getQueryDefinitionAPI().getProcess(process.getUUID());
    assertNotNull(dbProcess);

    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #9
0
  public void testGetNumberOfCommendFeed() throws Exception {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("feed", "1.0")
            .addHuman(getLogin())
            .addHumanTask("sala", getLogin())
            .done();
    definition = getManagementAPI().deploy(getBusinessArchive(definition));

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(definition.getUUID());
    getRuntimeAPI().addComment(instanceUUID, "This is a process instance comment", "john");
    getRuntimeAPI().addComment(instanceUUID, "This is another process instance comment", "jack");

    Set<TaskInstance> tasks = getQueryRuntimeAPI().getTasks(instanceUUID);
    TaskInstance task = tasks.iterator().next();

    getRuntimeAPI().addComment(task.getUUID(), "This is an activity instance comment", "jack");
    getRuntimeAPI().addComment(task.getUUID(), "This is another activity instance comment", "jane");
    getRuntimeAPI().addComment(task.getUUID(), "This is my activity instance comment", "john");

    assertEquals(3, getQueryRuntimeAPI().getNumberOfActivityInstanceComments(task.getUUID()));
    assertEquals(2, getQueryRuntimeAPI().getNumberOfProcessInstanceComments(instanceUUID));
    assertEquals(5, getQueryRuntimeAPI().getNumberOfComments(instanceUUID));

    getManagementAPI().deleteProcess(definition.getUUID());
  }
Beispiel #10
0
  @Test
  public void testGetDefinitionAttachmentFileName() throws Exception {
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();

    File attachmentFile = File.createTempFile("attachment-test", ".txt");
    FileOutputStream fileOutputStream = new FileOutputStream(attachmentFile);
    fileOutputStream.write("test".getBytes("UTF-8"));
    fileOutputStream.close();

    ProcessDefinition attachmentProcess =
        ProcessBuilder.createProcess("attachment_process", "1.0")
            .addAttachment("attachment", attachmentFile.getPath(), attachmentFile.getName())
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addTransition("transition", "task1", "task2")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(attachmentProcess);
    attachmentProcess = managementAPI.deploy(businessArchive);

    try {
      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      String fileName = api.getAttachmentFileName(attachmentProcess.getUUID(), "${attachment}");
      Assert.assertEquals(attachmentFile.getName(), fileName);
    } finally {
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteDocumentsOfProcessCommand(attachmentProcess.getUUID()));
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteProcessCommand(attachmentProcess.getUUID()));
    }
  }
Beispiel #11
0
  @Test
  public void testGetActivityAttributesRemainingTime() throws Exception {
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();

    ProcessDefinition simpleProcess =
        ProcessBuilder.createProcess("simple_process", "1.0")
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addActivityExecutingTime(100000000L)
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(simpleProcess);
    simpleProcess = managementAPI.deploy(businessArchive);

    ProcessInstanceUUID processInstanceUUID =
        AccessorUtil.getRuntimeAPI().instantiateProcess(simpleProcess.getUUID());

    try {
      Collection<TaskInstance> tasks =
          AccessorUtil.getQueryRuntimeAPI().getTaskList(processInstanceUUID, ActivityState.READY);
      ActivityInstanceUUID uuid = null;
      for (TaskInstance activityInstance : tasks) {
        uuid = activityInstance.getUUID();
      }
      Assert.assertNotNull(uuid);

      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      String remainingTime =
          (String)
              api.getAttributes(uuid, Locale.ENGLISH).get(ActivityAttribute.remainingTime.name());
      Assert.assertTrue(remainingTime.contains("1day 3hours"));
    } finally {
      AccessorUtil.getManagementAPI().deleteProcess(simpleProcess.getUUID());
    }
  }
Beispiel #12
0
  public void testAddHugeComment() throws Exception {
    StringBuilder message = new StringBuilder();
    for (int i = 0; i < 255; i++) {
      message.append(i);
    }

    ProcessDefinition definition =
        ProcessBuilder.createProcess("huge", "1.0")
            .addHuman(getLogin())
            .addHumanTask("test", getLogin())
            .done();

    final ProcessDefinition process =
        this.getManagementAPI().deploy(getBusinessArchive(definition));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = this.getRuntimeAPI().instantiateProcess(processUUID);

    this.getRuntimeAPI().addComment(instanceUUID, message.toString(), "john");

    List<Comment> feed = this.getQueryRuntimeAPI().getCommentFeed(instanceUUID);
    assertEquals(1, feed.size());
    Comment c = new CommentImpl(feed.get(0));
    assertEquals(message.toString(), c.getMessage());
    assertEquals("john", c.getUserId());
    assertNotNull(c.getDate());
    assertNull(c.getActivityUUID());

    this.getRuntimeAPI().deleteProcessInstance(instanceUUID);
    this.getManagementAPI().disable(processUUID);
    this.getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #13
0
  public void testCancelAProcessUsingAStartTimerEvent() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("CancelitSTime", "1.0")
            .addHuman(getLogin())
            .addTimerTask("every_second", "${new Date(timerLastExecution + 100000)}")
            .addHumanTask("step1", getLogin())
            .addTransition("every_second", "step1")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    final ProcessDefinitionUUID processUUID = process.getUUID();

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    Set<LightActivityInstance> activities =
        getQueryRuntimeAPI().getLightActivityInstances(instanceUUID);
    assertEquals(2, activities.size());

    Set<LightTaskInstance> tasks = getQueryRuntimeAPI().getLightTasks(instanceUUID);
    assertEquals(1, tasks.size());
    LightTaskInstance task = tasks.iterator().next();
    assertEquals("step1", task.getActivityName());

    getRuntimeAPI().cancelProcessInstance(instanceUUID);
    assertEquals(
        InstanceState.CANCELLED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());
    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #14
0
  public void testAddComments() throws BonitaException {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("feed", "1.0")
            .addHuman(getLogin())
            .addHumanTask("sala", getLogin())
            .done();
    definition = getManagementAPI().deploy(getBusinessArchive(definition));
    final ProcessDefinitionUUID processUUID = definition.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    Collection<ActivityInstance> acts =
        this.getQueryRuntimeAPI().getActivityInstances(instanceUUID, "sala");
    assertEquals(1, acts.size());
    ActivityInstance activityInst = acts.iterator().next();

    getRuntimeAPI().addComment(instanceUUID, "First comment", "john");
    getRuntimeAPI().addComment(activityInst.getUUID(), "Done", "joe");

    List<Comment> feed = this.getQueryRuntimeAPI().getCommentFeed(instanceUUID);
    assertEquals(2, feed.size());
    Comment c = new CommentImpl(feed.get(0));
    assertEquals("First comment", c.getMessage());
    assertEquals("john", c.getUserId());
    assertNotNull(c.getDate());
    assertNull(c.getActivityUUID());

    Comment c1 = new CommentImpl(feed.get(1));
    assertEquals("Done", c1.getMessage());
    assertEquals("joe", c1.getUserId());
    assertNotNull(c1.getDate());
    assertEquals(activityInst.getUUID(), c1.getActivityUUID());

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #15
0
  @Test
  public void testGetActivityAttachmentFileName() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
    QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();

    File attachmentFile = File.createTempFile("attachment-test", ".txt");
    FileOutputStream fileOutputStream = new FileOutputStream(attachmentFile);
    fileOutputStream.write("test".getBytes("UTF-8"));
    fileOutputStream.close();

    ProcessDefinition attachmentProcess =
        ProcessBuilder.createProcess("attachment_process", "1.0")
            .addAttachment("attachment", attachmentFile.getPath(), attachmentFile.getName())
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addTransition("transition", "task1", "task2")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(attachmentProcess);
    attachmentProcess = managementAPI.deploy(businessArchive);

    ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(attachmentProcess.getUUID());

    try {
      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      ActivityInstanceUUID activityInstanceUUID = null;
      Collection<TaskInstance> tasks =
          queryRuntimeAPI.getTaskList(instanceUUID, ActivityState.READY);
      for (TaskInstance activityInstance : tasks) {
        activityInstanceUUID = activityInstance.getUUID();
      }
      Assert.assertNotNull(activityInstanceUUID);
      String fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile.getName(), fileName);

      runtimeAPI.executeTask(activityInstanceUUID, true);
      fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile.getName(), fileName);

      File attachmentFile2 = File.createTempFile("new-attachment-test", ".txt");
      tasks = queryRuntimeAPI.getTaskList(instanceUUID, ActivityState.READY);
      for (TaskInstance activityInstance : tasks) {
        activityInstanceUUID = activityInstance.getUUID();
      }
      Assert.assertNotNull(activityInstanceUUID);
      runtimeAPI.addAttachment(
          instanceUUID, "attachment", attachmentFile2.getName(), "test".getBytes("UTF-8"));
      fileName = api.getAttachmentFileName(activityInstanceUUID, "${attachment}", true);
      Assert.assertEquals(attachmentFile2.getName(), fileName);
    } finally {
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteDocumentsOfProcessCommand(attachmentProcess.getUUID(), true));
      AccessorUtil.getRuntimeAPI().deleteProcessInstance(instanceUUID);
      AccessorUtil.getCommandAPI()
          .execute(new WebDeleteProcessCommand(attachmentProcess.getUUID()));
    }
  }
Beispiel #16
0
  public void testGetCommentFeed() throws Exception {
    ProcessDefinition definition =
        ProcessBuilder.createProcess("feed", "1.0")
            .addHuman(getLogin())
            .addHumanTask("sala", getLogin())
            .done();
    definition = getManagementAPI().deploy(getBusinessArchive(definition));

    ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(definition.getUUID());

    Set<TaskInstance> tasks = getQueryRuntimeAPI().getTasks(instanceUUID);
    TaskInstance task = tasks.iterator().next();

    getRuntimeAPI().addComment(instanceUUID, "This is a process instance comment", "john");
    getRuntimeAPI().addComment(task.getUUID(), "This is an activity instance comment", "jack");
    getRuntimeAPI().addComment(task.getUUID(), "This is another activity instance comment", "jane");
    getRuntimeAPI().addComment(instanceUUID, "This is another process instance comment", "jack");
    getRuntimeAPI().addComment(task.getUUID(), "This is my activity instance comment", "john");

    List<Comment> comments = getQueryRuntimeAPI().getCommentFeed(instanceUUID);
    assertEquals(5, comments.size());

    CommentImpl instanceComment1 = new CommentImpl(comments.get(0));
    assertEquals("This is a process instance comment", instanceComment1.getMessage());
    assertEquals("john", instanceComment1.getUserId());
    assertNotNull(instanceComment1.getDate());
    assertEquals(null, instanceComment1.getActivityUUID());

    CommentImpl activityComment1 = new CommentImpl(comments.get(1));
    assertEquals("This is an activity instance comment", activityComment1.getMessage());
    assertEquals("jack", activityComment1.getUserId());
    assertNotNull(activityComment1.getDate());
    assertEquals(task.getUUID(), activityComment1.getActivityUUID());

    CommentImpl activityComment2 = new CommentImpl(comments.get(2));
    assertEquals("This is another activity instance comment", activityComment2.getMessage());
    assertEquals("jane", activityComment2.getUserId());
    assertNotNull(activityComment2.getDate());
    assertEquals(task.getUUID(), activityComment2.getActivityUUID());

    CommentImpl instanceComment2 = new CommentImpl(comments.get(3));
    assertEquals("This is another process instance comment", instanceComment2.getMessage());
    assertEquals("jack", instanceComment2.getUserId());
    assertNotNull(instanceComment2.getDate());
    assertEquals(null, instanceComment2.getActivityUUID());

    CommentImpl activityComment3 = new CommentImpl(comments.get(4));
    assertEquals("This is my activity instance comment", activityComment3.getMessage());
    assertEquals("john", activityComment3.getUserId());
    assertNotNull(activityComment3.getDate());
    assertEquals(task.getUUID(), activityComment3.getActivityUUID());

    assertTrue(equalsOrBefore(instanceComment1.getDate(), activityComment1.getDate()));
    assertTrue(equalsOrBefore(activityComment1.getDate(), activityComment2.getDate()));
    assertTrue(equalsOrBefore(activityComment2.getDate(), instanceComment2.getDate()));
    assertTrue(equalsOrBefore(instanceComment2.getDate(), activityComment3.getDate()));

    getManagementAPI().deleteProcess(definition.getUUID());
  }
Beispiel #17
0
  @Test
  public void testGetSubprocessNextTask() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();

    ProcessDefinition childProcess =
        ProcessBuilder.createProcess("child_process", "1.0")
            .addHuman("john")
            .addHumanTask("childTask", "john")
            .done();

    ProcessDefinition parentProcess =
        ProcessBuilder.createProcess("parent_process", "1.0")
            .addHuman("john")
            .addSubProcess("subTask", "child_process")
            .addHumanTask("parentTask", "john")
            .addTransition("transition", "subTask", "parentTask")
            .done();

    BusinessArchive childBusinessArchive = BusinessArchiveFactory.getBusinessArchive(childProcess);
    childProcess = managementAPI.deploy(childBusinessArchive);

    BusinessArchive parentBusinessArchive =
        BusinessArchiveFactory.getBusinessArchive(parentProcess);
    parentProcess = managementAPI.deploy(parentBusinessArchive);

    ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(parentProcess.getUUID());

    try {
      IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
      ActivityInstanceUUID activityInstanceUUID = api.getProcessInstanceNextTask(instanceUUID);
      Assert.assertNull(activityInstanceUUID);
      activityInstanceUUID = api.getRelatedProcessesNextTask(instanceUUID);
      Assert.assertEquals("childTask", activityInstanceUUID.getActivityName());

      runtimeAPI.executeTask(activityInstanceUUID, true);
      activityInstanceUUID =
          api.getRelatedProcessesNextTask(activityInstanceUUID.getProcessInstanceUUID());
      Assert.assertEquals("parentTask", activityInstanceUUID.getActivityName());
    } finally {
      runtimeAPI.deleteProcessInstance(instanceUUID);

      managementAPI.deleteProcess(parentProcess.getUUID());
      managementAPI.deleteProcess(childProcess.getUUID());
    }
  }
Beispiel #18
0
  public void testSimpleTimerHumanWithConnectorOnFinish() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addStringData("var")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addConnector(Event.taskOnFinish, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "var")
            .addInputParameter("value", "human")
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 10)}")
            .addConnector(Event.onTimer, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "var")
            .addInputParameter("value", "timer")
            .addDecisionNode("join")
            .addJoinType(JoinType.AND)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process, null, SetVarConnector.class));
    final ProcessDefinitionUUID processUUID = process.getUUID();

    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    // wait the timer is executed so the connector is executed to
    Thread.sleep(2000);

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());
    getRuntimeAPI().executeTask(human.getUUID(), true);

    this.waitForInstanceEnd(5000, 10, instanceUUID);

    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    checkExecutedOnce(instanceUUID, "timer");
    checkExecutedOnce(instanceUUID, "human");

    assertEquals("human", getQueryRuntimeAPI().getProcessInstanceVariable(instanceUUID, "var"));

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #19
0
  private ProcessDefinition buildSubProcess() throws Exception {
    ProcessDefinition subProcess =
        ProcessBuilder.createProcess("sub_process", "1.0")
            .addBooleanData("terminateit", false)
            .addHuman("john")
            .addHumanTask("task1sub", "john")
            .addSystemTask("activity2sub")
            .addTransition("transition1", "task1sub", "activity2sub")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(subProcess);
    return AccessorUtil.getManagementAPI().deploy(businessArchive);
  }
Beispiel #20
0
  public void testDeleteAProcessUsingATimer() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("itSTime", "1.2")
            .addHuman(getLogin())
            .addTimerTask("every_10_seconds", "${new Date(timerLastExecution + 10000)}")
            .addHumanTask("step1", getLogin())
            .addTransition("every_10_seconds", "step1")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(0, instances.size());
    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #21
0
  public void testStartTimerContinuesEventIfTheInstanceFails() throws Exception {
    final String script =
        "import org.ow2.bonita.facade.ManagementAPI;"
            + "import org.ow2.bonita.facade.impl.StandardAPIAccessorImpl;"
            + "StandardAPIAccessorImpl accessor = new StandardAPIAccessorImpl();"
            + "ManagementAPI managementAPI = accessor.getManagementAPI();"
            + "def count = managementAPI.getMetaData(\"count\");"
            + "def number = Integer.parseInt(count);"
            + "if (number == 0) {"
            + "  return 1 / 0;"
            + "} else {"
            + "  return 0;"
            + "}";

    getManagementAPI().addMetaData("count", "0");
    ProcessDefinition process =
        ProcessBuilder.createProcess("stillContinue", "1.0")
            .addHuman(getLogin())
            .addStringData("vars", "null")
            .addTimerTask(
                "every_second",
                "${random = new Random(); return new Date("
                    + BonitaConstants.TIMER_LAST_EXECUTION
                    + "- random.nextInt(200-100+1)+100)}")
            .addSystemTask("system")
            .addConnector(Event.automaticOnEnter, GroovyConnector.class.getName(), true)
            .addInputParameter("script", script)
            .addHumanTask("next", getLogin())
            .addTransition("every_second", "system")
            .addTransition("system", "next")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process, null, GroovyConnector.class));
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(0, instances.size());

    Thread.sleep(3000);
    getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(0, instances.size());
    getManagementAPI().addMetaData("count", "1");
    Thread.sleep(3000);

    instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertTrue(instances.size() > 0);

    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #22
0
  public void testStartProcess() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("itSTime", "1.1")
            .addHuman(getLogin())
            .addTimerTask(
                "every_5_seconds",
                "${new Date(" + BonitaConstants.TIMER_LAST_EXECUTION + " + 5000)}")
            .addHumanTask("step1", getLogin())
            .addTransition("every_5_seconds", "step1")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));

    Thread.sleep(12000);
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertEquals(2, instances.size());
    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #23
0
  private ProcessDefinition buildIterationProcess() throws Exception {
    ProcessDefinition iterationProcess =
        ProcessBuilder.createProcess("complex_iteration_process", "1.0")
            .addBooleanData("terminateit", false)
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addSubProcess("subprocess", "sub_process")
            .addSubProcessInParameter("terminateit", "terminateit")
            .addSubProcessOutParameter("terminateit", "terminateit")
            .addHumanTask("task2", "john")
            .addTransition("transition1", "task1", "subprocess")
            .addTransition("transition2", "subprocess", "subprocess")
            .addCondition("!terminateit")
            .addTransition("transition3", "subprocess", "task2")
            .addCondition("terminateit")
            .done();

    BusinessArchive businessArchive = BusinessArchiveFactory.getBusinessArchive(iterationProcess);
    return AccessorUtil.getManagementAPI().deploy(businessArchive);
  }
Beispiel #24
0
  public void testStartAProcessXTimes() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("itSTime", "1.0")
            .addHuman(getLogin())
            .addTimerTask(
                "InASecond",
                "${random = new Random(); return new Date("
                    + BonitaConstants.TIMER_LAST_EXECUTION
                    + "- random.nextInt(200-100+1)+100)}")
            .addHumanTask("step1", getLogin())
            .addTransition("InASecond", "step1")
            .done();
    process = getManagementAPI().deploy(getBusinessArchive(process));

    Thread.sleep(1500);
    Set<LightProcessInstance> instances = getQueryRuntimeAPI().getLightProcessInstances();
    assertTrue(instances.size() > 1);

    getManagementAPI().deleteProcess(process.getUUID());
  }
Beispiel #25
0
  public void testSimpleTimerHumanTask() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 1000)}")
            .addDecisionNode("join")
            .addJoinType(JoinType.AND)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());

    getRuntimeAPI().executeTask(human.getUUID(), true);

    Thread.sleep(300);
    this.waitForInstanceEnd(5000, 10, instanceUUID);
    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());
    checkExecutedOnce(instanceUUID, "human", "timer");
    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #26
0
  public void testTimerDeletion() throws Exception {
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addSystemTask("start")
            .addSystemTask("system")
            .addTimerTask("timer", "${new Date(System.currentTimeMillis() + 100000)}")
            .addDecisionNode("join")
            .addJoinType(JoinType.XOR)
            .addTransition("start", "system")
            .addTransition("start", "timer")
            .addTransition("system", "join")
            .addTransition("timer", "join")
            .done();

    process =
        getManagementAPI()
            .deploy(
                getBusinessArchive(
                    process,
                    null,
                    GetIncomingEventInstancesCommand.class,
                    GetOutgoingEventInstancesCommand.class));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);
    this.waitForInstanceEnd(3000, 10, instanceUUID);

    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());
    assertEquals(
        0,
        (int) getCommandAPI().execute(new GetIncomingEventInstancesCommand(), processUUID).size());
    assertEquals(
        0,
        (int) getCommandAPI().execute(new GetOutgoingEventInstancesCommand(), processUUID).size());

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #27
0
  public void testSimpleTimerXOR() throws Exception {
    final long aDay = 1 * 1000 * 60 * 60 * 24;
    ProcessDefinition process =
        ProcessBuilder.createProcess("p", "d")
            .addHuman(getLogin())
            .addSystemTask("start")
            .addHumanTask("human", getLogin())
            .addTimerTask("timer", Long.toString(aDay))
            .addDecisionNode("join")
            .addJoinType(JoinType.XOR)
            .addTransition("start", "human")
            .addTransition("start", "timer")
            .addTransition("human", "join")
            .addTransition("timer", "join")
            .done();

    process = getManagementAPI().deploy(getBusinessArchive(process, null));
    final ProcessDefinitionUUID processUUID = process.getUUID();
    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(processUUID);

    assertEquals(
        InstanceState.STARTED,
        getQueryRuntimeAPI().getProcessInstance(instanceUUID).getInstanceState());

    Collection<TaskInstance> tasks = getQueryRuntimeAPI().getTaskList(ActivityState.READY);
    assertEquals(1, tasks.size());
    final TaskInstance human = tasks.iterator().next();
    assertEquals("human", human.getActivityName());

    executeTask(instanceUUID, "human");
    ProcessInstance instance = getQueryRuntimeAPI().getProcessInstance(instanceUUID);
    assertEquals(InstanceState.FINISHED, instance.getInstanceState());
    checkExecutedOnce(instanceUUID, "human");

    getManagementAPI().deleteProcess(processUUID);
  }
Beispiel #28
0
  public void testExecuteTimerBoundaryEventOnASubFlowUsingATimer2() throws Exception {
    ProcessDefinition subflow =
        ProcessBuilder.createProcess("sub", "atomic")
            .addHuman(getLogin())
            .addSystemTask("end")
            .addHumanTask("subStep", getLogin())
            .addTimerBoundaryEvent("In_a_second", "1000")
            .addExceptionTransition("subStep", "In_a_second", "end")
            .done();

    ProcessDefinition mainflow =
        ProcessBuilder.createProcess("main", "frame")
            .addHuman(getLogin())
            .addSubProcess("step1", "sub")
            .addTimerBoundaryEvent("In_5_seconds", "5000")
            .addHumanTask("normalStep", getLogin())
            .addHumanTask("exceptionStep", getLogin())
            .addTransition("step1", "normalStep")
            .addExceptionTransition("step1", "In_5_seconds", "exceptionStep")
            .done();

    subflow = getManagementAPI().deploy(getBusinessArchive(subflow));
    mainflow = getManagementAPI().deploy(getBusinessArchive(mainflow));

    final ProcessInstanceUUID instanceUUID = getRuntimeAPI().instantiateProcess(mainflow.getUUID());
    final ProcessInstanceUUID subflowInstanceUUID =
        getQueryRuntimeAPI()
            .getLightProcessInstances(subflow.getUUID())
            .iterator()
            .next()
            .getUUID();

    final Set<LightActivityInstance> parentActivities =
        getQueryRuntimeAPI().getLightActivityInstances(instanceUUID);
    assertEquals(1, parentActivities.size());
    LightActivityInstance activity = parentActivities.iterator().next();
    assertEquals("step1", activity.getActivityName());
    assertEquals(ActivityState.EXECUTING, activity.getState());

    final Set<LightActivityInstance> subflowActivities =
        getQueryRuntimeAPI().getLightActivityInstances(subflowInstanceUUID);
    assertEquals(1, subflowActivities.size());
    LightActivityInstance subActivity = subflowActivities.iterator().next();
    assertEquals("subStep", subActivity.getActivityName());
    assertEquals(ActivityState.READY, subActivity.getState());

    Thread.sleep(6000);
    Set<LightTaskInstance> tasks = getQueryRuntimeAPI().getLightTasks(instanceUUID);
    assertEquals(1, tasks.size());
    LightTaskInstance task = tasks.iterator().next();
    assertEquals("normalStep", task.getActivityName());

    assertEquals(
        0, getQueryRuntimeAPI().getLightTaskList(subflowInstanceUUID, ActivityState.READY).size());
    assertEquals(
        ActivityState.FINISHED,
        getQueryRuntimeAPI()
            .getLightActivityInstances(instanceUUID, "step1")
            .iterator()
            .next()
            .getState());
    assertEquals(
        InstanceState.FINISHED,
        getQueryRuntimeAPI().getLightProcessInstance(subflowInstanceUUID).getInstanceState());
    assertEquals(
        ActivityState.ABORTED,
        getQueryRuntimeAPI()
            .getLightActivityInstances(subflowInstanceUUID, "subStep")
            .iterator()
            .next()
            .getState());

    getManagementAPI().deleteProcess(mainflow.getUUID());
    getManagementAPI().deleteProcess(subflow.getUUID());
  }
Beispiel #29
0
  @Test
  public void testGetSubprocessLoopNextTask() throws Exception {
    RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
    ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
    QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
    IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();

    ProcessDefinition childProcess =
        ProcessBuilder.createProcess("sub_process", "1.0")
            .addIntegerData("counter")
            .addHuman("john")
            .addHumanTask("task1", "john")
            .addHumanTask("task2", "john")
            .addConnector(Event.taskOnFinish, SetVarConnector.class.getName(), true)
            .addInputParameter("variableName", "counter")
            .addInputParameter("value", "${++counter}")
            .addTransition("transition1", "task1", "task2")
            .done();

    ProcessDefinition processWithSubProcess =
        ProcessBuilder.createProcess("parent_process", "1.0")
            .addHuman("john")
            .addIntegerData("counter", 0)
            .addSubProcess("subprocess", "sub_process")
            .addSubProcessInParameter("counter", "counter")
            .addSubProcessOutParameter("counter", "counter")
            .addLoop("counter < 10", false)
            .addHumanTask("task3", "john")
            .addTransition("transition2", "subprocess", "task3")
            .done();

    BusinessArchive childBusinessArchive = BusinessArchiveFactory.getBusinessArchive(childProcess);
    childProcess = managementAPI.deploy(childBusinessArchive);

    BusinessArchive parentBusinessArchive =
        BusinessArchiveFactory.getBusinessArchive(processWithSubProcess);
    processWithSubProcess = managementAPI.deploy(parentBusinessArchive);

    ProcessInstanceUUID processInstanceUUID =
        runtimeAPI.instantiateProcess(processWithSubProcess.getUUID());

    try {
      for (int i = 0; i < 10; i++) {
        Set<ActivityInstance> activityInstances =
            queryRuntimeAPI.getActivityInstances(processInstanceUUID);
        Assert.assertEquals(i + 1, activityInstances.size());
        for (ActivityInstance activityInstance : activityInstances) {
          Assert.assertEquals("subprocess", activityInstance.getActivityName());
        }

        ProcessInstance processInstance = queryRuntimeAPI.getProcessInstance(processInstanceUUID);
        Set<ProcessInstanceUUID> childrenInstanceUUID = processInstance.getChildrenInstanceUUID();
        for (ProcessInstanceUUID childInstanceUUID : childrenInstanceUUID) {
          ProcessInstance childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
          if (InstanceState.STARTED.equals(childInstance.getInstanceState())) {
            Collection<TaskInstance> taskInstances =
                queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            TaskInstance childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task1", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            taskInstances = queryRuntimeAPI.getTaskList(childInstanceUUID, ActivityState.READY);
            Assert.assertEquals(1, taskInstances.size());
            childTaskInstance = taskInstances.iterator().next();
            Assert.assertEquals("task2", childTaskInstance.getActivityName());
            Assert.assertEquals(ActivityState.READY, childTaskInstance.getState());
            runtimeAPI.executeTask(childTaskInstance.getUUID(), true);

            if (i < 9) {
              ActivityInstanceUUID activityInstanceUUID =
                  api.getRelatedProcessesNextTask(childInstance.getUUID());
              Assert.assertEquals("task1", activityInstanceUUID.getActivityName());
            }

            childInstance = queryRuntimeAPI.getProcessInstance(childInstanceUUID);
            Assert.assertEquals(InstanceState.FINISHED, childInstance.getInstanceState());
          }
        }
      }

      Collection<TaskInstance> taskInstances =
          queryRuntimeAPI.getTaskList(processInstanceUUID, ActivityState.READY);
      Assert.assertEquals(1, taskInstances.size());
      TaskInstance taskInstance = taskInstances.iterator().next();
      Assert.assertEquals("task3", taskInstance.getActivityName());
      Assert.assertEquals(ActivityState.READY, taskInstance.getState());
      runtimeAPI.executeTask(taskInstance.getUUID(), true);
    } finally {
      managementAPI.deleteProcess(processWithSubProcess.getUUID());
      managementAPI.deleteProcess(childProcess.getUUID());
    }
  }