use of org.jboss.pnc.notification.DefaultNotifier 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);
}
use of org.jboss.pnc.notification.DefaultNotifier 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);
}
use of org.jboss.pnc.notification.DefaultNotifier 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);
}
use of org.jboss.pnc.notification.DefaultNotifier 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);
}
use of org.jboss.pnc.notification.DefaultNotifier 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);
}
Aggregations