@Override
  protected void setUp() throws Exception {
    super.setUp();

    ActiveMQConnectionFactory factory =
        new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

    this.context = EasyMock.createMock(Context.class);
    EasyMock.expect(context.lookup("ConnectionFactory")).andReturn(factory).anyTimes();
    EasyMock.replay(context);

    Properties serverProperties = new Properties();
    serverProperties.setProperty("JMSTaskServer.connectionFactory", "ConnectionFactory");
    serverProperties.setProperty("JMSTaskServer.transacted", "true");
    serverProperties.setProperty("JMSTaskServer.acknowledgeMode", "AUTO_ACKNOWLEDGE");
    serverProperties.setProperty("JMSTaskServer.queueName", "tasksQueue");
    serverProperties.setProperty("JMSTaskServer.responseQueueName", "tasksResponseQueue");

    server = new JMSTaskServer(taskService, serverProperties, context);
    Thread thread = new Thread(server);
    thread.start();
    System.out.println("Waiting for the JMS Task Server to come up");
    while (!server.isRunning()) {
      System.out.print(".");
      Thread.sleep(50);
    }

    Properties clientProperties = new Properties();
    clientProperties.setProperty("JMSTaskClient.connectionFactory", "ConnectionFactory");
    clientProperties.setProperty("JMSTaskClient.transactedQueue", "true");
    clientProperties.setProperty("JMSTaskClient.acknowledgeMode", "AUTO_ACKNOWLEDGE");
    clientProperties.setProperty("JMSTaskClient.queueName", "tasksQueue");
    clientProperties.setProperty("JMSTaskClient.responseQueueName", "tasksResponseQueue");

    client =
        new TaskClient(
            new JMSTaskClientConnector(
                "client 1",
                new JMSTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()),
                clientProperties,
                context));
    client.connect();

    MockUserInfo userInfo = new MockUserInfo();
    userInfo.getEmails().put(users.get("tony"), "*****@*****.**");
    userInfo.getEmails().put(users.get("steve"), "*****@*****.**");

    userInfo.getLanguages().put(users.get("tony"), "en-UK");
    userInfo.getLanguages().put(users.get("steve"), "en-UK");
    taskService.setUserinfo(userInfo);
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    server = new MinaTaskServer(taskService);
    System.out.println("Waiting for the MinaTask Server to come up");
    try {
      startTaskServerThread(server, false);
    } catch (Exception e) {
      startTaskServerThread(server, true);
    }

    client = new AsyncMinaTaskClient();
    client.connect("127.0.0.1", 9123);

    MockUserInfo userInfo = new MockUserInfo();
    userInfo.getEmails().put(users.get("tony"), "*****@*****.**");
    userInfo.getEmails().put(users.get("steve"), "*****@*****.**");

    userInfo.getLanguages().put(users.get("tony"), "en-UK");
    userInfo.getLanguages().put(users.get("steve"), "en-UK");
    taskService.setUserinfo(userInfo);
  }
예제 #3
0
  public void testDelayedEmailNotificationOnDeadline() throws Exception {
    Map vars = new HashMap();
    vars.put("users", users);
    vars.put("groups", groups);
    vars.put("now", new Date());

    DefaultEscalatedDeadlineHandler notificationHandler =
        new DefaultEscalatedDeadlineHandler(getConf());
    WorkItemManager manager = new DefaultWorkItemManager(null);
    notificationHandler.setManager(manager);

    MockUserInfo userInfo = new MockUserInfo();
    userInfo.getEmails().put(users.get("tony"), emailAddressTony);
    userInfo.getEmails().put(users.get("darth"), emailAddressDarth);

    userInfo.getLanguages().put(users.get("tony"), "en-UK");
    userInfo.getLanguages().put(users.get("darth"), "en-UK");
    notificationHandler.setUserInfo(userInfo);

    taskService.setEscalatedDeadlineHandler(notificationHandler);

    Reader reader =
        new InputStreamReader(
            getClass().getResourceAsStream(MvelFilePath.DeadlineWithNotification));
    Task task = (Task) eval(reader, vars);

    BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
    client.addTask(task, null, addTaskResponseHandler);
    long taskId = addTaskResponseHandler.getTaskId();

    Content content = new Content();
    content.setContent("['subject' : 'My Subject', 'body' : 'My Body']".getBytes());
    BlockingSetContentResponseHandler setContentResponseHandler =
        new BlockingSetContentResponseHandler();
    client.setDocumentContent(taskId, content, setContentResponseHandler);
    long contentId = setContentResponseHandler.getContentId();
    BlockingGetContentResponseHandler getResponseHandler = new BlockingGetContentResponseHandler();
    client.getContent(contentId, getResponseHandler);
    content = getResponseHandler.getContent();
    assertEquals(
        "['subject' : 'My Subject', 'body' : 'My Body']", new String(content.getContent()));

    // emails should not be set yet
    assertEquals(0, getWiser().getMessages().size());
    Thread.sleep(100);

    // nor yet
    assertEquals(0, getWiser().getMessages().size());

    long time = 0;
    while (getWiser().getMessages().size() != 2 && time < 15000) {
      Thread.sleep(500);
      time += 500;
    }

    // 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(emailAddressTony));
    assertTrue(list.contains(emailAddressDarth));

    MimeMessage msg = ((WiserMessage) getWiser().getMessages().get(0)).getMimeMessage();
    assertEquals("My Body", msg.getContent());
    assertEquals("My Subject", msg.getSubject());
    assertEquals("*****@*****.**", ((InternetAddress) msg.getFrom()[0]).getAddress());
    assertEquals("*****@*****.**", ((InternetAddress) msg.getReplyTo()[0]).getAddress());
    boolean tonyMatched = false;
    boolean darthMatched = false;
    for (int i = 0; i < msg.getRecipients(RecipientType.TO).length; ++i) {
      String emailAddress = ((InternetAddress) msg.getRecipients(RecipientType.TO)[i]).getAddress();
      if ("*****@*****.**".equals(emailAddress)) {
        tonyMatched = true;
      } else if ("*****@*****.**".equals(emailAddress)) {
        darthMatched = true;
      }
    }
    assertTrue("Could not find tony in recipients list.", tonyMatched);
    assertTrue("Could not find darth in recipients list.", darthMatched);
  }
예제 #4
0
  public void testDelayedReassignmentOnDeadline() throws Exception {
    Map vars = new HashMap();
    vars.put("users", users);
    vars.put("groups", groups);
    vars.put("now", new Date());

    DefaultEscalatedDeadlineHandler notificationHandler =
        new DefaultEscalatedDeadlineHandler(getConf());
    WorkItemManager manager = new DefaultWorkItemManager(null);
    notificationHandler.setManager(manager);

    MockUserInfo userInfo = new MockUserInfo();
    userInfo.getEmails().put(users.get("tony"), "*****@*****.**");
    userInfo.getEmails().put(users.get("luke"), "*****@*****.**");
    userInfo.getEmails().put(users.get("bobba"), "*****@*****.**");
    userInfo.getEmails().put(users.get("jabba"), "*****@*****.**");

    userInfo.getLanguages().put(users.get("tony"), "en-UK");
    userInfo.getLanguages().put(users.get("luke"), "en-UK");
    userInfo.getLanguages().put(users.get("bobba"), "en-UK");
    userInfo.getLanguages().put(users.get("jabba"), "en-UK");
    notificationHandler.setUserInfo(userInfo);

    taskService.setEscalatedDeadlineHandler(notificationHandler);

    Reader reader =
        new InputStreamReader(
            getClass().getResourceAsStream(MvelFilePath.DeadlineWithReassignment));

    BlockingAddTaskResponseHandler addTaskResponseHandler = new BlockingAddTaskResponseHandler();
    Task task = (Task) eval(reader, vars);
    client.addTask(task, null, addTaskResponseHandler);
    long taskId = addTaskResponseHandler.getTaskId();

    // Shouldn't have re-assigned yet
    Thread.sleep(1000);
    BlockingGetTaskResponseHandler getTaskHandler = new BlockingGetTaskResponseHandler();
    client.getTask(taskId, getTaskHandler);
    task = getTaskHandler.getTask();
    List<OrganizationalEntity> potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    List<String> ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
      ids.add(entity.getId());
    }
    assertTrue(ids.contains(users.get("tony").getId()));
    assertTrue(ids.contains(users.get("luke").getId()));

    // should have re-assigned by now
    long time = 0;
    while (getWiser().getMessages().size() != 2 && time < 15000) {
      Thread.sleep(500);
      time += 500;
    }

    getTaskHandler = new BlockingGetTaskResponseHandler();
    client.getTask(taskId, getTaskHandler);
    task = getTaskHandler.getTask();
    assertEquals(Status.Ready, task.getTaskData().getStatus());
    potentialOwners = task.getPeopleAssignments().getPotentialOwners();
    System.out.println(potentialOwners);
    ids = new ArrayList<String>(potentialOwners.size());
    for (OrganizationalEntity entity : potentialOwners) {
      ids.add(entity.getId());
    }
    assertTrue(ids.contains(users.get("bobba").getId()));
    assertTrue(ids.contains(users.get("jabba").getId()));
  }