Search in sources :

Example 1 with ListenerUnsubscriber

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);
}
Also used : BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) NOTIFICATION_PATH(org.jboss.pnc.integration.setup.RestClientConfiguration.NOTIFICATION_PATH) Handlers(io.undertow.Handlers) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) AdvancedGroupConfigurationClient(org.jboss.pnc.restclient.AdvancedGroupConfigurationClient) Arquillian(org.jboss.arquillian.junit.Arquillian) GroupBuildClient(org.jboss.pnc.client.GroupBuildClient) GroupConfiguration(org.jboss.pnc.dto.GroupConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) Undertow(io.undertow.Undertow) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupBuild(org.jboss.pnc.dto.GroupBuild) Deployments(org.jboss.pnc.integration.setup.Deployments) Method(java.lang.reflect.Method) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) GroupBuildChangedNotificationPredicates.withGConfigId(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGConfigId) AbstractReceiveListener(io.undertow.websockets.core.AbstractReceiveListener) Category(org.junit.experimental.categories.Category) BuildChangedNotificationPredicates.withBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildCompleted) Assertions.fail(org.assertj.core.api.Assertions.fail) WebSocketHttpExchange(io.undertow.websockets.spi.WebSocketHttpExchange) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) WebSocketConnectionCallback(io.undertow.websockets.WebSocketConnectionCallback) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) ResponseUtils(org.jboss.pnc.integration.utils.ResponseUtils) ClientException(org.jboss.pnc.client.ClientException) BufferedBinaryMessage(io.undertow.websockets.core.BufferedBinaryMessage) BuildChangedNotification(org.jboss.pnc.dto.notification.BuildChangedNotification) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) GroupBuildChangedNotification(org.jboss.pnc.dto.notification.GroupBuildChangedNotification) Logger(org.slf4j.Logger) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) GroupBuildChangedNotificationPredicates.withGBuildCompleted(org.jboss.pnc.restclient.websocket.predicates.GroupBuildChangedNotificationPredicates.withGBuildCompleted) Test(org.junit.Test) IOException(java.io.IOException) RestClientConfiguration(org.jboss.pnc.integration.setup.RestClientConfiguration) BuildChangedNotificationPredicates.withBuildConfiguration(org.jboss.pnc.restclient.websocket.predicates.BuildChangedNotificationPredicates.withBuildConfiguration) RemoteResourceNotFoundException(org.jboss.pnc.client.RemoteResourceNotFoundException) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) BuildConfiguration(org.jboss.pnc.dto.BuildConfiguration) Deployment(org.jboss.arquillian.container.test.api.Deployment) WebSocketChannel(io.undertow.websockets.core.WebSocketChannel) GroupBuildRequest(org.jboss.pnc.dto.requests.GroupBuildRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GroupBuildParameters(org.jboss.pnc.rest.api.parameters.GroupBuildParameters) BuildParameters(org.jboss.pnc.rest.api.parameters.BuildParameters) WebSocketClient(org.jboss.pnc.restclient.websocket.WebSocketClient) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) BuildConfigurationClient(org.jboss.pnc.client.BuildConfigurationClient) AdvancedBuildConfigurationClient(org.jboss.pnc.restclient.AdvancedBuildConfigurationClient) ListenerUnsubscriber(org.jboss.pnc.restclient.websocket.ListenerUnsubscriber) VertxWebSocketClient(org.jboss.pnc.restclient.websocket.VertxWebSocketClient) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

Handlers (io.undertow.Handlers)1 Undertow (io.undertow.Undertow)1 WebSocketConnectionCallback (io.undertow.websockets.WebSocketConnectionCallback)1 AbstractReceiveListener (io.undertow.websockets.core.AbstractReceiveListener)1 BufferedBinaryMessage (io.undertow.websockets.core.BufferedBinaryMessage)1 WebSocketChannel (io.undertow.websockets.core.WebSocketChannel)1 WebSocketHttpExchange (io.undertow.websockets.spi.WebSocketHttpExchange)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 Arquillian (org.jboss.arquillian.junit.Arquillian)1 BuildConfigurationClient (org.jboss.pnc.client.BuildConfigurationClient)1 ClientException (org.jboss.pnc.client.ClientException)1 GroupBuildClient (org.jboss.pnc.client.GroupBuildClient)1