Search in sources :

Example 1 with AttachedClient

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

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

the class DefaultNotifierTest method shouldCleanItself.

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

Example 3 with AttachedClient

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

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

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

Aggregations

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