Пример #1
0
  /** Test the sending of a notification. */
  @Test
  public void testEventConsuming() {

    // set up
    service.removeAdaptor(adaptor);

    final DummyNotificationAdaptor adaptor1 = new DummyNotificationAdaptor();
    final DummyNotificationAdaptor adaptor2 = new DummyNotificationAdaptor();

    service.addAdaptor(adaptor1);
    service.addAdaptor(adaptor2);

    final Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("test", "test01");
    final Notification notification =
        new Notification(DummyNotificationAdaptor.TEST_TYPE, parameters);

    // test not consume
    adaptor1.setConsumeEvent(false);
    adaptor2.setConsumeEvent(false);

    service.send(notification);

    boolean adaptor1Contains = adaptor1.getNotifications().contains(notification);
    boolean adaptor2Contains = adaptor2.getNotifications().contains(notification);
    Assert.assertTrue(adaptor1Contains);
    Assert.assertTrue(adaptor2Contains);

    // clean notifications
    adaptor1.getNotifications().clear();
    adaptor2.getNotifications().clear();

    // test consume
    adaptor1.setConsumeEvent(true);
    adaptor2.setConsumeEvent(true);

    service.send(notification);
    adaptor1Contains = adaptor1.getNotifications().contains(notification);
    adaptor2Contains = adaptor2.getNotifications().contains(notification);
    Assert.assertFalse(adaptor1Contains && adaptor2Contains);
    Assert.assertTrue(adaptor1Contains || adaptor2Contains);

    // clean up
    service.removeAdaptor(adaptor1);
    service.removeAdaptor(adaptor2);

    service.addAdaptor(adaptor);
  }
Пример #2
0
 /** Initialized test adaptor and service. */
 @BeforeClass
 public static void setUpBeforeClass() {
   adaptor = new DummyNotificationAdaptor();
   service.addAdaptor(adaptor);
 }