Search in sources :

Example 1 with MessageCallback

use of org.jboss.pnc.spi.notifications.MessageCallback in project pnc by project-ncl.

the class DefaultNotifierTest method shouldRemoveAttachedClientWhenItGetsAnException.

@Test
public void shouldRemoveAttachedClientWhenItGetsAnException() throws Exception {
    ArgumentCaptor<MessageCallback> messageCallback = ArgumentCaptor.forClass(MessageCallback.class);
    // given
    Notifier notifier = new DefaultNotifier();
    AttachedClient attachedClient = mock(AttachedClient.class);
    doReturn(true).when(attachedClient).isEnabled();
    notifier.attachClient(attachedClient);
    // when
    notifier.sendMessage(new Object());
    // then
    verify(attachedClient).sendMessage(any(), messageCallback.capture());
    messageCallback.getValue().failed(attachedClient, new Throwable());
    assertThat(notifier.getAttachedClientsCount()).isEqualTo(0);
}
Also used : AttachedClient(org.jboss.pnc.spi.notifications.AttachedClient) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) MessageCallback(org.jboss.pnc.spi.notifications.MessageCallback) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) Notifier(org.jboss.pnc.spi.notifications.Notifier) Test(org.junit.Test)

Example 2 with MessageCallback

use of org.jboss.pnc.spi.notifications.MessageCallback in project pnc by project-ncl.

the class DefaultNotifierTest method shouldSendAsynchAMessage.

@Test
public void shouldSendAsynchAMessage() throws Exception {
    ArgumentCaptor<MessageCallback> messageCallback = ArgumentCaptor.forClass(MessageCallback.class);
    // given
    Notifier notifier = new DefaultNotifier();
    AttachedClient attachedClient = mock(AttachedClient.class);
    doReturn(true).when(attachedClient).isEnabled();
    notifier.attachClient(attachedClient);
    // when
    notifier.sendMessage(new Object());
    // then
    verify(attachedClient).sendMessage(any(), messageCallback.capture());
    messageCallback.getValue().successful(attachedClient);
    assertThat(notifier.getAttachedClientsCount()).isEqualTo(1);
}
Also used : AttachedClient(org.jboss.pnc.spi.notifications.AttachedClient) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) MessageCallback(org.jboss.pnc.spi.notifications.MessageCallback) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) Notifier(org.jboss.pnc.spi.notifications.Notifier) Test(org.junit.Test)

Aggregations

DefaultNotifier (org.jboss.pnc.notification.DefaultNotifier)2 AttachedClient (org.jboss.pnc.spi.notifications.AttachedClient)2 MessageCallback (org.jboss.pnc.spi.notifications.MessageCallback)2 Notifier (org.jboss.pnc.spi.notifications.Notifier)2 Test (org.junit.Test)2