use of org.kie.internal.task.api.model.InternalTask 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());
}
use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest method testDelayedEmailNotificationOnDeadlineTaskFailed.
@Test(timeout = 10000)
public void testDelayedEmailNotificationOnDeadlineTaskFailed() 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.fail(taskId, "Administrator", null);
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// 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.Failed, task.getTaskData().getStatus());
assertEquals(0, task.getDeadlines().getStartDeadlines().size());
assertEquals(0, task.getDeadlines().getEndDeadlines().size());
}
use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.
the class TaskQueryServiceBaseTest method testModifyTaskName.
@Test
public void testModifyTaskName() {
// JBPM-4148
String taskName = "This is my task name";
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = '" + taskName + "' })";
Task task = TaskFactory.evalTask(new StringReader(str));
List<I18NText> names = new ArrayList<I18NText>();
I18NText text = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) text).setLanguage("en-UK");
((InternalI18NText) text).setText(taskName);
names.add(text);
((InternalTask) task).setNames(names);
taskService.addTask(task, new HashMap<String, Object>());
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
assertEquals(1, tasks.size());
assertEquals(taskName, tasks.get(0).getName());
Task newTask = taskService.getTaskById(tasks.get(0).getId());
List<I18NText> updatedNames = new ArrayList<I18NText>();
I18NText updatedName = TaskModelProvider.getFactory().newI18NText();
((InternalI18NText) updatedName).setLanguage(newTask.getNames().get(0).getLanguage());
((InternalI18NText) updatedName).setText("New task name");
updatedNames.add(updatedName);
taskService.setTaskNames(newTask.getId(), updatedNames);
List<TaskSummary> newTasks = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
assertEquals(1, newTasks.size());
newTask = taskService.getTaskById(newTasks.get(0).getId());
assertEquals("New task name", newTask.getNames().get(0).getText());
}
use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.
the class TaskReminderBaseTest method testTaskReminderWithoutNotification.
@Test(timeout = 10000)
public void testTaskReminderWithoutNotification() 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.ReminderWithoutNotification));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
System.out.println("testTaskReminderWithoutNotification " + task.getTaskData().getStatus());
assertNull(task.getDeadlines());
long taskId = taskService.addTask(task, new HashMap<String, Object>());
taskService.executeReminderForTask(taskId, "Luke Cage");
countDownListener.waitTillCompleted();
assertEquals(1, wiser.getMessages().size());
String receiver = wiser.getMessages().get(0).getEnvelopeReceiver();
assertEquals("tony@domain.com", receiver);
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
assertEquals("You have a task ( Simple Test Task ) of process ( taskReminder )", msg.getSubject());
}
use of org.kie.internal.task.api.model.InternalTask in project jbpm by kiegroup.
the class TaskReminderBaseTest method testTaskReminderWithNotificationByTaskNostarted.
@Test(timeout = 10000)
public void testTaskReminderWithNotificationByTaskNostarted() 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.ReminderWithNotificationReserved));
InternalTask task = (InternalTask) TaskFactory.evalTask(reader, vars);
System.out.println("testTaskReminderWithNotificationByTaskNostarted " + task.getTaskData().getStatus());
assertEquals(1, task.getDeadlines().getEndDeadlines().size());
assertEquals(1, task.getDeadlines().getStartDeadlines().size());
long taskId = taskService.addTask(task, new HashMap<String, Object>());
taskService.executeReminderForTask(taskId, "Luke Cage");
countDownListener.waitTillCompleted();
assertEquals(2, wiser.getMessages().size());
final List<String> list = new ArrayList<String>(2);
list.add(wiser.getMessages().get(0).getEnvelopeReceiver());
list.add(wiser.getMessages().get(1).getEnvelopeReceiver());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
MimeMessage msg = ((WiserMessage) wiser.getMessages().get(0)).getMimeMessage();
assertEquals("ReminderWithNotificationReserved:you have new task to be started", msg.getSubject());
assertEquals("task is not started", msg.getContent());
msg = ((WiserMessage) wiser.getMessages().get(1)).getMimeMessage();
assertEquals("ReminderWithNotificationReserved:you have new task to be started", msg.getSubject());
assertEquals("task is not started", msg.getContent());
}
Aggregations