コード例 #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 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"));
  }