use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class SubTasksBaseTest method onParentAbortCompleteAllSubTasksStrategy.
@Test
public void onParentAbortCompleteAllSubTasksStrategy() throws Exception {
// One potential owner, should go straight to state Reserved
// Notice skippable in task data
String parentTaskstr = "(with (new Task()) { subTaskStrategy = SubTasksStrategy.SkipAllSubTasksOnParentSkip , priority = 55, " + "taskData = (with( new TaskData()) { skipable = true } ), ";
parentTaskstr += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('salaboy') ],businessAdministrators = [ new User('Administrator') ], }),";
parentTaskstr += "names = [ new I18NText( 'en-UK', 'This is my task Parent name')] })";
// By default the task will contain a SubTask SubTasksStrategy.NoAction
Task parentTask = TaskFactory.evalTask(new StringReader(parentTaskstr));
taskService.addTask(parentTask, new HashMap<String, Object>());
long taskParentId = parentTask.getId();
// Task should remain in Created state with no actual owner
Task parentTask1 = taskService.getTaskById(taskParentId);
assertEquals(parentTask1.getTaskData().getStatus(), Status.Reserved);
taskService.start(taskParentId, "salaboy");
String child1Taskstr = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = true, parentId= " + taskParentId + " } ), ";
child1Taskstr += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
child1Taskstr += "names = [ new I18NText( 'en-UK', 'This is my task Child 1 name')] })";
Task child1Task = TaskFactory.evalTask(new StringReader(child1Taskstr));
taskService.addTask(child1Task, new HashMap<String, Object>());
long child1TaskId = child1Task.getId();
// Test if the task is succesfully created
assertEquals(1, taskService.getPendingSubTasksByParent(taskParentId));
Task childTask1 = taskService.getTaskById(child1TaskId);
assertEquals(taskParentId, childTask1.getTaskData().getParentId());
taskService.start(child1TaskId, "Darth Vader");
taskService.skip(taskParentId, "salaboy");
parentTask1 = taskService.getTaskById(taskParentId);
assertEquals(0, taskService.getPendingSubTasksByParent(taskParentId));
assertEquals(Status.Obsolete, parentTask1.getTaskData().getStatus());
childTask1 = taskService.getTaskById(child1TaskId);
assertEquals(Status.Obsolete, childTask1.getTaskData().getStatus());
}
use of org.kie.api.task.model.Task 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.kie.api.task.model.Task 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.kie.api.task.model.Task in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest 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
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
for (WiserMessage msg : getWiser().getMessages()) {
logger.info(msg.getEnvelopeReceiver());
}
// 1 email with two recipients should now exist
assertEquals(2, getWiser().getMessages().size());
List<String> list = new ArrayList<String>(2);
list.add(getWiser().getMessages().get(0).getEnvelopeReceiver());
list.add(getWiser().getMessages().get(1).getEnvelopeReceiver());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
MimeMessage msg = ((WiserMessage) getWiser().getMessages().get(0)).getMimeMessage();
assertEquals(myBody, msg.getContent());
assertEquals(mySubject, msg.getSubject());
assertEquals("from@domain.com", ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals("replyTo@domain.com", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
final Address[] recipients = msg.getRecipients(RecipientType.TO);
assertNotNull(recipients);
assertTrue(recipients.length == 2);
list = new ArrayList<String>(2);
list.add(((InternetAddress) recipients[0]).getAddress());
list.add(((InternetAddress) recipients[1]).getAddress());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class EmailDeadlinesBaseTest 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);
assertEquals("'singleobject'", unmarshallObject.toString());
// emails should not be set yet
assertEquals(0, getWiser().getMessages().size());
countDownListener.waitTillCompleted();
// 1 email with two recipients should now exist
assertEquals(2, getWiser().getMessages().size());
List<String> list = new ArrayList<String>(2);
list.add(getWiser().getMessages().get(0).getEnvelopeReceiver());
list.add(getWiser().getMessages().get(1).getEnvelopeReceiver());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
MimeMessage msg = ((WiserMessage) getWiser().getMessages().get(0)).getMimeMessage();
assertEquals("'singleobject'", msg.getContent());
assertEquals("'singleobject'", msg.getSubject());
assertEquals("from@domain.com", ((InternetAddress) msg.getFrom()[0]).getAddress());
assertEquals("replyTo@domain.com", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
final Address[] recipients = msg.getRecipients(RecipientType.TO);
assertNotNull(recipients);
assertTrue(recipients.length == 2);
list = new ArrayList<String>(2);
list.add(((InternetAddress) recipients[0]).getAddress());
list.add(((InternetAddress) recipients[1]).getAddress());
assertTrue(list.contains("tony@domain.com"));
assertTrue(list.contains("darth@domain.com"));
}
Aggregations