use of org.jbpm.services.task.util.CountDownTaskEventListener 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);
}
use of org.jbpm.services.task.util.CountDownTaskEventListener 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);
}
use of org.jbpm.services.task.util.CountDownTaskEventListener 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);
}
use of org.jbpm.services.task.util.CountDownTaskEventListener 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);
}
use of org.jbpm.services.task.util.CountDownTaskEventListener 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());
}
Aggregations