Esempio n. 1
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());
  }
Esempio n. 2
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());
 }
Esempio n. 3
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);
  }
 public WorkflowInstance build() {
   NodeRef packageRef = packageMgr.create(packageNode);
   params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
   WorkflowPath path = workflowService.startWorkflow(definition.getId(), params);
   signalStartTask(path);
   return path.getInstance();
 }
Esempio n. 5
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);
  }
Esempio n. 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);
  }
Esempio n. 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());
  }