Example #1
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);
  }
Example #2
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());
  }
Example #3
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());
  }
Example #4
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());
  }
Example #5
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()));
    }
  }
Example #6
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);
  }
Example #7
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());
  }
Example #8
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);
  }
Example #9
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());
    }
  }
Example #10
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);
  }
Example #11
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);
  }
Example #12
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);
  }
Example #13
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());
  }
Example #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);
  }
Example #15
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());
  }
Example #16
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()));
    }
  }
Example #17
0
  @After
  public void tearDown() throws Exception {

    AccessorUtil.getRuntimeAPI().deleteAllProcessInstances(bonitaProcess.getUUID());
    AccessorUtil.getManagementAPI().disable(bonitaProcess.getUUID());
    AccessorUtil.getManagementAPI().deleteProcess(bonitaProcess.getUUID());

    loginContext.logout();
  }
Example #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);
  }
Example #19
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());
  }
Example #20
0
 @Test
 public void testGetAnyTodoListTaskForProcessDefinition() throws Exception {
   IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
   ActivityInstanceUUID activityInstanceUUID =
       api.getAnyTodoListTaskForProcessDefinition(bonitaProcess.getUUID());
   Assert.assertEquals("Request", activityInstanceUUID.getActivityName());
 }
Example #21
0
 @Test
 public void testGetProcessDefinitionDate() throws Exception {
   IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
   Assert.assertEquals(
       bonitaProcess.getDeployedDate(),
       api.getProcessDefinitionDate(processInstanceUUID.getProcessDefinitionUUID()));
 }
Example #22
0
 @Test
 public void testExecuteActionsAndStartInstance() throws Exception {
   IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
   Map<String, FormFieldValue> fieldValues = new HashMap<String, FormFieldValue>();
   FormFieldValue value1 = new FormFieldValue("Excel", String.class.getName());
   fieldValues.put("fieldId1", value1);
   List<FormAction> formActions = new ArrayList<FormAction>();
   formActions.add(
       new FormAction(
           ActionType.SET_VARIABLE,
           "Applications",
           "APPLICATION",
           "field_fieldId1",
           "submitButtonId"));
   ProcessInstanceUUID newProcessInstanceUUID =
       api.executeActionsAndStartInstance(
           bonitaProcess.getUUID(),
           fieldValues,
           formActions,
           Locale.ENGLISH,
           "submitButtonId",
           new HashMap<String, Object>());
   Assert.assertNotNull(newProcessInstanceUUID);
   QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
   Object variableValue =
       queryRuntimeAPI.getProcessInstanceVariable(newProcessInstanceUUID, "Applications");
   Assert.assertEquals("Excel", variableValue.toString());
   AccessorUtil.getRuntimeAPI().deleteProcessInstance(newProcessInstanceUUID);
 }
Example #23
0
 @Test
 public void testGetDefinitionFieldValue() throws Exception {
   IFormWorkflowAPI api = FormAPIFactory.getFormWorkflowAPI();
   Object result = null;
   result = api.getFieldValue(bonitaProcess.getUUID(), "${Applications}", Locale.ENGLISH);
   Assert.assertEquals("Word", result);
 }
Example #24
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());
  }
Example #25
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());
    }
  }
Example #26
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());
  }
Example #27
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());
  }
Example #28
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);
  }
Example #29
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);
  }
Example #30
0
  @Before
  public void setUp() throws Exception {

    login("john", "bpm");

    URL testBarURL = getClass().getResource("/approvalWorkflow.bar");
    if (testBarURL == null) {
      throw new RuntimeException("File approvalWorkflow.bar was not found.");
    }
    BusinessArchive businessArchive =
        BusinessArchiveFactory.getBusinessArchive(new File(testBarURL.toURI()));
    bonitaProcess = AccessorUtil.getManagementAPI().deploy(businessArchive);
    processInstanceUUID = AccessorUtil.getRuntimeAPI().instantiateProcess(bonitaProcess.getUUID());
  }