Search in sources :

Example 6 with ContentData

use of org.kie.internal.task.api.model.ContentData 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 7 with ContentData

use of org.kie.internal.task.api.model.ContentData 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 8 with ContentData

use of org.kie.internal.task.api.model.ContentData 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)

Example 9 with ContentData

use of org.kie.internal.task.api.model.ContentData 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 10 with ContentData

use of org.kie.internal.task.api.model.ContentData 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)

Aggregations

ContentData (org.kie.internal.task.api.model.ContentData)30 InternalContent (org.kie.internal.task.api.model.InternalContent)21 InternalTask (org.kie.internal.task.api.model.InternalTask)21 Test (org.junit.Test)19 Task (org.kie.api.task.model.Task)16 InputStreamReader (java.io.InputStreamReader)14 Reader (java.io.Reader)14 HashMap (java.util.HashMap)14 CountDownTaskEventListener (org.jbpm.services.task.util.CountDownTaskEventListener)14 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)14 Content (org.kie.api.task.model.Content)11 User (org.kie.api.task.model.User)11 InternalOrganizationalEntity (org.kie.internal.task.api.model.InternalOrganizationalEntity)11 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)10 InternalPeopleAssignments (org.kie.internal.task.api.model.InternalPeopleAssignments)10 Date (java.util.Date)8 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 ContentMarshallerContext (org.kie.internal.task.api.ContentMarshallerContext)6 StringReader (java.io.StringReader)5