Search in sources :

Example 1 with InternalContent

use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompleted.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskCompleted() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    taskService.complete(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should ne sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 2 with InternalContent

use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadline.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadline() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    Task task = (Task) TaskFactory.evalTask(reader, vars);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // 1 email with two recipients should now exist
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 3 with InternalContent

use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineContentSingleObject.

@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineContentSingleObject() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(1, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotificationContentSingleObject));
    Task task = (Task) TaskFactory.evalTask(reader, vars);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, "'singleobject'", null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    assertThat(unmarshallObject.toString()).isEqualTo("'singleobject'");
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // 1 email with two recipients should now exist
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 4 with InternalContent

use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.

the class DeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskCompletedMultipleTasks.

@Test(timeout = 12000)
public void testDelayedEmailNotificationOnDeadlineTaskCompletedMultipleTasks() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(2, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    // create task 1
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    // create task 2
    reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task2 = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task2.getTaskData()).setSkipable(true);
    task2.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    taskService.addTask(task2, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, 5);
    task.getDeadlines().getStartDeadlines().get(0).setDate(cal.getTime());
    task2.getDeadlines().getStartDeadlines().get(0).setDate(cal.getTime());
    taskService.start(taskId, "Administrator");
    taskService.complete(taskId, "Administrator", null);
    // emails should not be set yet
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(0);
    countDownListener.waitTillCompleted();
    // no email should be sent as task was completed before deadline was triggered
    assertThat(((MockNotificationListener) notificationListener).getEventsRecieved().size()).isEqualTo(1);
    task = (InternalTask) taskService.getTaskById(taskId);
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
    taskService.start(task2.getId(), "Administrator");
    taskService.complete(task2.getId(), "Administrator", null);
    task = (InternalTask) taskService.getTaskById(task2.getId());
    assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Completed);
    assertThat(((InternalTask) task).getDeadlines().getStartDeadlines().size()).isEqualTo(0);
    assertThat(((InternalTask) task).getDeadlines().getEndDeadlines().size()).isEqualTo(0);
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Example 5 with InternalContent

use of org.kie.internal.task.api.model.InternalContent in project jbpm by kiegroup.

the class EmailDeadlinesBaseTest method testDelayedEmailNotificationStartDeadlineStatusDoesNotMatch.

@Test(timeout = 10000)
public void testDelayedEmailNotificationStartDeadlineStatusDoesNotMatch() throws Exception {
    CountDownTaskEventListener countDownListener = new CountDownTaskEventListener(2, false, true);
    addCountDownListner(countDownListener);
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("now", new Date());
    Reader reader = new InputStreamReader(getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
    ((InternalTaskData) task.getTaskData()).setSkipable(true);
    InternalPeopleAssignments assignments = (InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
    List<OrganizationalEntity> ba = new ArrayList<OrganizationalEntity>();
    User user = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user).setId("Administrator");
    ba.add(user);
    assignments.setBusinessAdministrators(ba);
    List<OrganizationalEntity> po = new ArrayList<OrganizationalEntity>();
    User user2 = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) user2).setId("Administrator");
    po.add(user2);
    assignments.setPotentialOwners(po);
    task.setPeopleAssignments(assignments);
    taskService.addTask(task, new HashMap<String, Object>());
    long taskId = task.getId();
    InternalContent content = (InternalContent) TaskModelProvider.getFactory().newContent();
    Map<String, String> params = fillMarshalSubjectAndBodyParams();
    ContentData marshalledObject = ContentMarshallerHelper.marshal(task, params, null);
    content.setContent(marshalledObject.getContent());
    taskService.addContent(taskId, content);
    long contentId = content.getId();
    content = (InternalContent) taskService.getContentById(contentId);
    Object unmarshallObject = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    checkContentSubjectAndBody(unmarshallObject);
    taskService.start(taskId, "Administrator");
    // emails should not be set yet
    assertEquals(0, getWiser().getMessages().size());
    // since we don't want the notification to be invoked we need to rely on timeout
    countDownListener.waitTillCompleted(3000);
    // no email should ne sent as task was completed before deadline was triggered
    assertEquals(0, getWiser().getMessages().size());
    task = (InternalTask) taskService.getTaskById(taskId);
    assertEquals(Status.InProgress, task.getTaskData().getStatus());
    assertEquals(0, task.getDeadlines().getStartDeadlines().size());
    assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
Also used : User(org.kie.api.task.model.User) CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTaskData(org.kie.internal.task.api.model.InternalTaskData) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Date(java.util.Date) InternalPeopleAssignments(org.kie.internal.task.api.model.InternalPeopleAssignments) ContentData(org.kie.internal.task.api.model.ContentData) Test(org.junit.Test)

Aggregations

InternalContent (org.kie.internal.task.api.model.InternalContent)25 ContentData (org.kie.internal.task.api.model.ContentData)20 InternalTask (org.kie.internal.task.api.model.InternalTask)17 Test (org.junit.Test)15 InputStreamReader (java.io.InputStreamReader)14 Reader (java.io.Reader)14 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 Task (org.kie.api.task.model.Task)13 Content (org.kie.api.task.model.Content)11 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 User (org.kie.api.task.model.User)11 HashMap (java.util.HashMap)10 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 Date (java.util.Date)8 ArrayList (java.util.ArrayList)7 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)5 Map (java.util.Map)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4