Пример #1
0
 public void testGetAssignedTasks() {
   WorkflowDefinition workflowDef = getTestDefinition();
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(
       QName.createQName(NamespaceService.DEFAULT_URI, "reviewer"),
       AuthenticationUtil.getAdminUserName());
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   parameters.put(
       QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "package"),
       packageComponent.createPackage(null));
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   List<WorkflowTask> tasks = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks);
   assertEquals(1, tasks.size());
   WorkflowTask updatedTask =
       taskComponent.endTask(tasks.get(0).getId(), path.getNode().getTransitions()[0].getId());
   assertNotNull(updatedTask);
   List<WorkflowTask> completedTasks =
       taskComponent.getAssignedTasks(
           AuthenticationUtil.getAdminUserName(), WorkflowTaskState.COMPLETED);
   assertNotNull(completedTasks);
   completedTasks = filterTasksByWorkflowInstance(completedTasks, path.getInstance().getId());
   assertEquals(1, completedTasks.size());
   List<WorkflowTask> assignedTasks =
       taskComponent.getAssignedTasks(
           AuthenticationUtil.getAdminUserName(), WorkflowTaskState.IN_PROGRESS);
   assertNotNull(assignedTasks);
   assignedTasks = filterTasksByWorkflowInstance(assignedTasks, path.getInstance().getId());
   assertEquals(1, assignedTasks.size());
   assertEquals("review", assignedTasks.get(0).getName());
 }
Пример #2
0
  public void testStartWorkflow() {
    try {
      workflowComponent.startWorkflow("norfolknchance", null);
      fail("Failed to catch invalid definition id");
    } catch (WorkflowException e) {
      // Do nothing.
    }

    // TODO: Determine why process definition is loaded, even though it doesn't exist
    //        try
    //        {
    //            workflowComponent.startProcess("1000", null);
    //            fail("Failed to catch workflow definition id that does not exist");
    //        }
    //        catch(WorkflowException e)
    //        {
    //        }

    WorkflowDefinition workflowDef = getTestDefinition();
    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), null);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
  }
Пример #3
0
 public void testSignal() {
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   WorkflowDefinition workflowDef = getTestDefinition();
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   WorkflowPath updatedPath =
       workflowComponent.signal(path.getId(), path.getNode().getTransitions()[1].getId());
   assertNotNull(updatedPath);
 }
Пример #4
0
  public void testGetWorkflowById() {
    WorkflowDefinition workflowDef = getTestDefinition();
    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), null);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    WorkflowInstance instance = workflowComponent.getWorkflowById(path.getInstance().getId());
    assertNotNull(instance);
    assertEquals(path.getInstance().getId(), instance.getId());

    workflowComponent.cancelWorkflow(instance.getId());
    WorkflowInstance result = workflowComponent.getWorkflowById(instance.getId());
    assertNull("The workflow isntance should be null!", result);
  }
Пример #5
0
  public void testStartWorkflowParameters() {
    WorkflowDefinition workflowDef = getTestDefinition();

    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.PROP_TASK_ID, 3); // protected - shouldn't be written
    params.put(WorkflowModel.PROP_DUE_DATE, new Date()); // task instance field
    params.put(WorkflowModel.PROP_PRIORITY, 1); // task instance field
    params.put(WorkflowModel.PROP_PERCENT_COMPLETE, 10); // context variable
    params.put(
        QName.createQName("", "Message"),
        "Hello World"); // context variable outside of task definition
    params.put(
        QName.createQName("", "Array"),
        new String[] {"one", "two"}); // context variable outside of task definition
    params.put(
        QName.createQName("", "NodeRef"),
        new NodeRef("workspace://1/1001")); // context variable outside of task definition
    params.put(ContentModel.PROP_OWNER, AuthenticationUtil.getAdminUserName()); // task assignment

    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());

    WorkflowTask task = tasks1.get(0);
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_TASK_ID));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_DUE_DATE));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PRIORITY));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PERCENT_COMPLETE));
    assertTrue(task.getProperties().containsKey(ContentModel.PROP_OWNER));

    NodeRef initiator = path.getInstance().getInitiator();
    String initiatorUsername =
        (String) nodeService.getProperty(initiator, ContentModel.PROP_USERNAME);
    assertEquals(AuthenticationUtil.getAdminUserName(), initiatorUsername);
  }
Пример #6
0
  public void testUpdateTask() {
    WorkflowDefinition workflowDef = getTestDefinition();

    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.PROP_TASK_ID, 3); // protected - shouldn't be written
    params.put(WorkflowModel.PROP_DUE_DATE, new Date()); // task instance field
    params.put(WorkflowModel.PROP_PRIORITY, 1); // task instance field
    params.put(WorkflowModel.PROP_PERCENT_COMPLETE, 10); // context variable
    params.put(
        QName.createQName("", "Message"),
        "Hello World"); // context variable outside of task definition
    params.put(
        QName.createQName("", "Array"),
        new String[] {"one", "two"}); // context variable outside of task definition
    params.put(
        QName.createQName("", "NodeRef"),
        new NodeRef("workspace://1/1001")); // context variable outside of task definition
    params.put(ContentModel.PROP_OWNER, AuthenticationUtil.getAdminUserName()); // task assignment

    WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), params);
    assertNotNull(path);
    assertTrue(path.getId().endsWith("-@"));
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());

    WorkflowTask task = tasks1.get(0);
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_TASK_ID));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_DUE_DATE));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PRIORITY));
    assertTrue(task.getProperties().containsKey(WorkflowModel.PROP_PERCENT_COMPLETE));
    assertTrue(task.getProperties().containsKey(ContentModel.PROP_OWNER));

    // update with null parameters
    try {
      WorkflowTask taskU1 = taskComponent.updateTask(task.getId(), null, null, null);
      assertNotNull(taskU1);
    } catch (Throwable e) {
      fail("Task update failed with null parameters");
    }

    // update property value
    Map<QName, Serializable> updateProperties2 = new HashMap<QName, Serializable>();
    updateProperties2.put(WorkflowModel.PROP_PERCENT_COMPLETE, 100);
    WorkflowTask taskU2 = taskComponent.updateTask(task.getId(), updateProperties2, null, null);
    assertEquals(100, taskU2.getProperties().get(WorkflowModel.PROP_PERCENT_COMPLETE));

    // add to assocation
    QName assocName = QName.createQName("", "TestAssoc");
    List<NodeRef> toAdd = new ArrayList<NodeRef>();
    toAdd.add(new NodeRef("workspace://1/1001"));
    toAdd.add(new NodeRef("workspace://1/1002"));
    toAdd.add(new NodeRef("workspace://1/1003"));
    Map<QName, List<NodeRef>> addAssocs = new HashMap<QName, List<NodeRef>>();
    addAssocs.put(assocName, toAdd);
    WorkflowTask taskU3 = taskComponent.updateTask(task.getId(), null, addAssocs, null);
    assertNotNull(taskU3.getProperties().get(assocName));
    assertEquals(3, ((List<?>) taskU3.getProperties().get(assocName)).size());

    // add to assocation again
    List<NodeRef> toAddAgain = new ArrayList<NodeRef>();
    toAddAgain.add(new NodeRef("workspace://1/1004"));
    toAddAgain.add(new NodeRef("workspace://1/1005"));
    Map<QName, List<NodeRef>> addAssocsAgain = new HashMap<QName, List<NodeRef>>();
    addAssocsAgain.put(assocName, toAddAgain);
    WorkflowTask taskU4 = taskComponent.updateTask(task.getId(), null, addAssocsAgain, null);
    assertNotNull(taskU4.getProperties().get(assocName));
    assertEquals(5, ((List<?>) taskU4.getProperties().get(assocName)).size());

    // remove assocation
    List<NodeRef> toRemove = new ArrayList<NodeRef>();
    toRemove.add(new NodeRef("workspace://1/1002"));
    toRemove.add(new NodeRef("workspace://1/1003"));
    Map<QName, List<NodeRef>> removeAssocs = new HashMap<QName, List<NodeRef>>();
    removeAssocs.put(assocName, toRemove);
    WorkflowTask taskU5 = taskComponent.updateTask(task.getId(), null, null, removeAssocs);
    assertNotNull(taskU5.getProperties().get(assocName));
    assertEquals(3, ((List<?>) taskU5.getProperties().get(assocName)).size());
  }