Search in sources :

Example 1 with Notifier

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

the class DefaultNotifierTest method shouldSendAMessage.

@Test
public void shouldSendAMessage() throws Exception {
    // given
    Object messageBody = new Object();
    Notifier notifier = new DefaultNotifier();
    AttachedClient attachedClient = mock(AttachedClient.class);
    doReturn(true).when(attachedClient).isEnabled();
    notifier.attachClient(attachedClient);
    // when
    notifier.sendMessage(messageBody);
    // then
    verify(attachedClient).sendMessage(messageBody, notifier.getCallback());
    assertThat(notifier.getAttachedClientsCount()).isEqualTo(1);
}
Also used : AttachedClient(org.jboss.pnc.spi.notifications.AttachedClient) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) Notifier(org.jboss.pnc.spi.notifications.Notifier) Test(org.junit.Test)

Example 2 with Notifier

use of org.jboss.pnc.spi.notifications.Notifier 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 3 with Notifier

use of org.jboss.pnc.spi.notifications.Notifier 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)

Example 4 with Notifier

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

the class DefaultNotifierTest method shouldAddNotifier.

@Test
public void shouldAddNotifier() throws Exception {
    // given
    Notifier notifier = new DefaultNotifier();
    AttachedClient attachedClient = mock(AttachedClient.class);
    // when
    notifier.attachClient(attachedClient);
    // then
    assertThat(notifier.getAttachedClientsCount()).isEqualTo(1);
}
Also used : AttachedClient(org.jboss.pnc.spi.notifications.AttachedClient) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) Notifier(org.jboss.pnc.spi.notifications.Notifier) Test(org.junit.Test)

Example 5 with Notifier

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

the class DefaultNotifierTest method shouldNotSendAMessageToDisabledClient.

@Test
public void shouldNotSendAMessageToDisabledClient() throws Exception {
    // given
    Object messageBody = new Object();
    Notifier notifier = new DefaultNotifier();
    AttachedClient attachedClient = mock(AttachedClient.class);
    doReturn(false).when(attachedClient).isEnabled();
    notifier.attachClient(attachedClient);
    // when
    notifier.sendMessage(messageBody);
    // then
    verify(attachedClient, new Times(0)).sendMessage(messageBody, notifier.getCallback());
    assertThat(notifier.getAttachedClientsCount()).isEqualTo(1);
}
Also used : Times(org.mockito.internal.verification.Times) AttachedClient(org.jboss.pnc.spi.notifications.AttachedClient) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) DefaultNotifier(org.jboss.pnc.notification.DefaultNotifier) Notifier(org.jboss.pnc.spi.notifications.Notifier) Test(org.junit.Test)

Aggregations

DefaultNotifier (org.jboss.pnc.notification.DefaultNotifier)5 AttachedClient (org.jboss.pnc.spi.notifications.AttachedClient)5 Notifier (org.jboss.pnc.spi.notifications.Notifier)5 Test (org.junit.Test)5 MessageCallback (org.jboss.pnc.spi.notifications.MessageCallback)2 Times (org.mockito.internal.verification.Times)1