use of org.jboss.pnc.restclient.websocket.ListenerUnsubscriber in project pnc by project-ncl.
the class WebSocketClientTest method testBuildListener.
@Test
public void testBuildListener() throws Exception {
// with
WebSocketClient wsClient = new VertxWebSocketClient();
wsClient.connect(PNC_SOCKET_URL).get();
BuildConfigurationClient buildConfigurationClient = new BuildConfigurationClient(RestClientConfiguration.asUser());
BuildConfiguration bc = buildConfigurationClient.getAll().iterator().next();
AtomicInteger notificationCounter = new AtomicInteger(0);
// when
ListenerUnsubscriber unsubscriber = wsClient.onBuildChangedNotification((notification -> {
notificationCounter.incrementAndGet();
assertThat(notification).isNotNull();
assertThat(notification.getBuild()).isNotNull();
}), withBuildConfiguration(bc.getId()));
buildConfigurationClient.trigger(bc.getId(), new BuildParameters());
// then
Thread.sleep(1000);
unsubscriber.run();
wsClient.disconnect().get();
assertThat(notificationCounter).hasValueGreaterThanOrEqualTo(2);
}
Aggregations