Пример #1
0
  @Test
  public void testTaskDataAutomaticMapping() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    MyObject myObject = new MyObject("MyObjectValue");
    workItem.setParameter("MyObject", myObject);
    Map<String, Object> mapParameter = new HashMap<String, Object>();
    mapParameter.put("MyObjectInsideTheMap", myObject);
    workItem.setParameter("MyMap", mapParameter);
    workItem.setParameter("MyObject", myObject);

    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Reserved, taskSummary.getStatus());
    assertEquals("Darth Vader", taskSummary.getActualOwner().getId());

    Task task = taskService.getTaskById(taskSummary.getId());
    assertEquals(AccessType.Inline, task.getTaskData().getDocumentAccessType());
    long contentId = task.getTaskData().getDocumentContentId();
    assertTrue(contentId != -1);

    Map<String, Object> data =
        (Map<String, Object>)
            ContentMarshallerHelper.unmarshall(
                taskService.getContentById(contentId).getContent(), ksession.getEnvironment());

    // Checking that the input parameters are being copied automatically if the Content Element
    // doesn't exist
    assertEquals("MyObjectValue", ((MyObject) data.get("MyObject")).getValue());
    assertEquals("10", data.get("Priority"));
    assertEquals(
        "MyObjectValue",
        ((MyObject) ((Map<String, Object>) data.get("MyMap")).get("MyObjectInsideTheMap"))
            .getValue());

    taskService.start(task.getId(), "Darth Vader");

    Map<String, Object> results = new HashMap<String, Object>();
    results.put("Result", "This is the result");

    taskService.complete(task.getId(), "Darth Vader", results);

    assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
    results = manager.getResults();
    assertNotNull(results);
    assertEquals("Darth Vader", results.get("ActorId"));
    assertEquals("This is the result", results.get("Result"));
  }
Пример #2
0
  @Test
  public void testTaskMultipleActors() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader, Dalai Lama");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertEquals("TaskName", task.getName());
    assertEquals(10, task.getPriority());
    assertEquals("Comment", task.getDescription());
    assertEquals(Status.Ready, task.getStatus());

    taskService.claim(task.getId(), "Darth Vader");

    taskService.start(task.getId(), "Darth Vader");

    taskService.complete(task.getId(), "Darth Vader", null);

    assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
  }
Пример #3
0
  @Test
  public void testTaskExitNonAdministrator() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    getHandler().executeWorkItem(workItem, manager);

    Task task = taskService.getTaskByWorkItemId(workItem.getId());

    try {
      taskService.exit(task.getId(), "Darth Vader");
      fail("Should not allow to exit task for non administrators");
    } catch (PermissionDeniedException e) {

    }

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Reserved, taskSummary.getStatus());
    assertEquals("Darth Vader", taskSummary.getActualOwner().getId());
  }
Пример #4
0
  @Test
  public void testTaskExit() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    getHandler().executeWorkItem(workItem, manager);

    Task task = taskService.getTaskByWorkItemId(workItem.getId());

    taskService.exit(task.getId(), "Administrator");

    task = taskService.getTaskByWorkItemId(workItem.getId());
    assertEquals("TaskName", task.getNames().get(0).getText());
    assertEquals(10, task.getPriority());
    assertEquals("Comment", task.getDescriptions().get(0).getText());
    assertEquals(Status.Exited, task.getTaskData().getStatus());

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(0, tasks.size());
  }
Пример #5
0
  @Test
  public void testTaskSkip() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary task = tasks.get(0);
    assertEquals("TaskName", task.getName());
    assertEquals(10, task.getPriority());
    assertEquals("Comment", task.getDescription());
    assertEquals(Status.Reserved, task.getStatus());
    assertEquals("Darth Vader", task.getActualOwner().getId());

    taskService.skip(task.getId(), "Darth Vader");

    assertTrue(manager.waitTillAborted(MANAGER_ABORT_WAIT_TIME));
  }
Пример #6
0
  @Test
  @Ignore // FIX USER GROUP CALLBACK STUFF
  public void testTaskSingleAndGroupActors() throws Exception {
    //    	Properties userGroups = new Properties();
    //        userGroups.setProperty("Darth Vader", "Crusaders");
    //
    //        UserGroupCallbackManager.getInstance().setCallback(new
    // DefaultUserGroupCallbackImpl(userGroups));
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task One");
    workItem.setParameter("TaskName", "TaskNameOne");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("GroupId", "Crusaders");
    getHandler().executeWorkItem(workItem, manager);

    workItem = new WorkItemImpl();
    workItem.setName("Human Task Two");
    workItem.setParameter("TaskName", "TaskNameTwo");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(2, tasks.size());
  }
Пример #7
0
  @Test
  public void testTaskAbortNotSkippable() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    workItem.setParameter("Skippable", "false");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());

    getHandler().abortWorkItem(workItem, manager);

    // aborting work item will exit task and not skip it
    tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(0, tasks.size());
  }
Пример #8
0
  @Test
  public void testTaskData() throws Exception {
    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("ActorId", "Darth Vader");
    workItem.setParameter("Content", "This is the content");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Reserved, taskSummary.getStatus());
    assertEquals("Darth Vader", taskSummary.getActualOwner().getId());

    Task task = taskService.getTaskById(taskSummary.getId());
    assertEquals(AccessType.Inline, task.getTaskData().getDocumentAccessType());
    assertEquals(
        task.getTaskData().getProcessSessionId(), TestStatefulKnowledgeSession.testSessionId);
    long contentId = task.getTaskData().getDocumentContentId();
    assertTrue(contentId != -1);

    Object data =
        ContentMarshallerHelper.unmarshall(
            taskService.getContentById(contentId).getContent(), ksession.getEnvironment());
    assertEquals("This is the content", data);

    taskService.start(task.getId(), "Darth Vader");

    Map<String, Object> results = new HashMap<String, Object>();
    results.put("Result", "This is the result");
    //        ContentData result = ContentMarshallerHelper.marshal(,
    //                                                                ksession.getEnvironment());
    taskService.complete(task.getId(), "Darth Vader", results);

    assertTrue(manager.waitTillCompleted(MANAGER_COMPLETION_WAIT_TIME));
    results = manager.getResults();
    assertNotNull(results);
    assertEquals("Darth Vader", results.get("ActorId"));
    assertEquals("This is the result", results.get("Result"));
  }
Пример #9
0
  @Ignore
  @Test // FIX UserGROUP CALLBACK
  public void testTaskGroupActors() throws Exception {

    TestWorkItemManager manager = new TestWorkItemManager();
    ksession.setWorkItemManager(manager);
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Human Task");
    workItem.setParameter("TaskName", "TaskName");
    workItem.setParameter("Comment", "Comment");
    workItem.setParameter("Priority", "10");
    workItem.setParameter("GroupId", "Crusaders");
    getHandler().executeWorkItem(workItem, manager);

    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Luke", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary taskSummary = tasks.get(0);
    assertEquals("TaskName", taskSummary.getName());
    assertEquals(10, taskSummary.getPriority());
    assertEquals("Comment", taskSummary.getDescription());
    assertEquals(Status.Ready, taskSummary.getStatus());

    PermissionDeniedException denied = null;
    try {
      taskService.claim(taskSummary.getId(), "Darth Vader");
    } catch (PermissionDeniedException e) {
      denied = e;
    }

    assertNotNull("Should get permissed denied exception", denied);

    // Check if the parent task is InProgress

    Task task = taskService.getTaskById(taskSummary.getId());
    assertEquals(Status.Ready, task.getTaskData().getStatus());
  }