예제 #1
0
 public void testEndTask() {
   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> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks1);
   assertEquals(1, tasks1.size());
   assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).getState());
   WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).getId(), null);
   assertNotNull(updatedTask);
   assertEquals(WorkflowTaskState.COMPLETED, updatedTask.getState());
   List<WorkflowTask> completedTasks =
       taskComponent.getAssignedTasks(
           AuthenticationUtil.getAdminUserName(), WorkflowTaskState.COMPLETED);
   assertNotNull(completedTasks);
   completedTasks = filterTasksByWorkflowInstance(completedTasks, path.getInstance().getId());
   assertEquals(1, completedTasks.size());
   assertEquals(WorkflowTaskState.COMPLETED, completedTasks.get(0).getState());
 }
예제 #2
0
  public void testScript() throws IOException {
    // deploy test script definition
    ClassPathResource processDef = new ClassPathResource("jbpmresources/test_script.xml");
    assertFalse(
        workflowComponent.isDefinitionDeployed(
            processDef.getInputStream(), MimetypeMap.MIMETYPE_XML));
    WorkflowDeployment deployment =
        workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
    assertNotNull(deployment);

    WorkflowDefinition workflowDef = deployment.getDefinition();
    Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
    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> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    assertEquals(WorkflowTaskState.IN_PROGRESS, tasks1.get(0).getState());
    WorkflowTask updatedTask = taskComponent.endTask(tasks1.get(0).getId(), null);
    assertNotNull(updatedTask);
  }
예제 #3
0
  /**
   * See Alf-2764 in Jira.
   *
   * @throws Exception
   */
  public void testCancelForEachFork() throws Exception {
    // Deploy Parallel Loop Review process definition.
    ClassPathResource processDef =
        new ClassPathResource("test/alfresco/parallel_loop_review_processdefinition.xml");
    WorkflowDeployment deployment =
        workflowComponent.deployDefinition(processDef.getInputStream(), MimetypeMap.MIMETYPE_XML);
    WorkflowDefinition parallelDef = deployment.getDefinition();
    assertNotNull(parallelDef);

    // Set Current User to USER1.
    AuthenticationUtil.setFullyAuthenticatedUser(USER1);

    // Set up parameters
    QName approvePercentName =
        QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "requiredApprovePercent");
    NodeRef pckgNode = packageComponent.createPackage(null);
    List<NodeRef> assignees = Arrays.asList(person1, person2, person3);
    Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
    parameters.put(WorkflowModel.ASSOC_ASSIGNEES, (Serializable) assignees);
    parameters.put(WorkflowModel.ASSOC_PACKAGE, pckgNode);
    parameters.put(approvePercentName, 60f);

    // Start workflow
    WorkflowPath path = workflowComponent.startWorkflow(parallelDef.getId(), parameters);
    WorkflowTask startTask = workflowComponent.getTasksForWorkflowPath(path.getId()).get(0);
    taskComponent.endTask(startTask.getId(), null);
    checkInstanceExists(path.getInstance().getId(), parallelDef.getId(), true);

    // Set all users to reject document.
    ParallelReject(USER1);
    ParallelReject(USER2);
    ParallelReject(USER3);

    // Send review back round the loop.
    List<WorkflowTask> tasks = workflowComponent.getTasksForWorkflowPath(path.getId());
    assertEquals(1, tasks.size());
    taskComponent.endTask(tasks.get(0).getId(), "again");

    // Try to cancel workflow
    WorkflowInstance cancelledWf = workflowComponent.cancelWorkflow(path.getInstance().getId());
    checkInstanceExists(cancelledWf.getId(), parallelDef.getId(), false);
  }
예제 #4
0
 public void testGetTask() {
   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);
   WorkflowPath path = workflowComponent.startWorkflow(workflowDef.getId(), parameters);
   assertNotNull(path);
   assertNotNull(path);
   List<WorkflowTask> tasks1 = workflowComponent.getTasksForWorkflowPath(path.getId());
   assertNotNull(tasks1);
   assertEquals(1, tasks1.size());
   WorkflowTask getTask = taskComponent.getTaskById(tasks1.get(0).getId());
   assertNotNull(getTask);
   assertEquals(getTask.getId(), tasks1.get(0).getId());
 }
예제 #5
0
 public void xtestMultiAssign() {
   WorkflowDefinition workflowDef = getTestDefinition();
   List<String> bpm_assignees = new ArrayList<String>();
   bpm_assignees.add(AuthenticationUtil.getAdminUserName());
   bpm_assignees.add("bob");
   bpm_assignees.add("fred");
   Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
   parameters.put(
       QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "assignees"),
       (Serializable) bpm_assignees);
   parameters.put(QName.createQName(NamespaceService.DEFAULT_URI, "testNode"), rootNodeRef);
   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(), "multi");
   assertNotNull(updatedTask);
 }
예제 #6
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);
  }
예제 #7
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());
  }