Search in sources :

Example 6 with CountDownTaskEventListener

use of org.jbpm.services.task.util.CountDownTaskEventListener 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"));
}
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) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) ContentData(org.kie.internal.task.api.model.ContentData) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 7 with CountDownTaskEventListener

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

Example 8 with CountDownTaskEventListener

use of org.jbpm.services.task.util.CountDownTaskEventListener 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"));
}
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) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) InternalContent(org.kie.internal.task.api.model.InternalContent) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) ContentData(org.kie.internal.task.api.model.ContentData) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 9 with CountDownTaskEventListener

use of org.jbpm.services.task.util.CountDownTaskEventListener 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());
}
Also used : CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 10 with CountDownTaskEventListener

use of org.jbpm.services.task.util.CountDownTaskEventListener 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());
}
Also used : CountDownTaskEventListener(org.jbpm.services.task.util.CountDownTaskEventListener) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) WiserMessage(org.subethamail.wiser.WiserMessage) Date(java.util.Date) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Aggregations

InputStreamReader (java.io.InputStreamReader)20 Reader (java.io.Reader)20 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)20 Test (org.junit.Test)20 InternalTask (org.kie.internal.task.api.model.InternalTask)20 ContentData (org.kie.internal.task.api.model.ContentData)14 InternalContent (org.kie.internal.task.api.model.InternalContent)14 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)13 Date (java.util.Date)12 HashMap (java.util.HashMap)12 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)12 ArrayList (java.util.ArrayList)11 User (org.kie.api.task.model.User)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)10 Task (org.kie.api.task.model.Task)7 MimeMessage (javax.mail.internet.MimeMessage)5 WiserMessage (org.subethamail.wiser.WiserMessage)5 List (java.util.List)2 Address (javax.mail.Address)2