Package org.cometd.bayeux.client

Examples of org.cometd.bayeux.client.ClientSessionChannel


    @Test
    public final void shouldSuccesfulySubscribeWhenConnected() throws SDKException {
        //Given
        final String channelId = "/channel";
        final ClientSessionChannel channel = givenChannel(channelId);
        //When
        subscriber.subscribe(channelId, listener);
        //Then
        verify(channel).subscribe(Mockito.any(MessageListener.class));
    }
View Full Code Here


    @Test
    public final void shouldSuccesfulySubscribeAndMakeHandshake() throws SDKException {
        //Given
        final String channelId = "/channel";
        final ClientSessionChannel channel = givenChannel(channelId);
        //When
        subscriber.subscribe(channelId, listener);
        verifyConnected();
        verifySubscribed(channel);
    }
View Full Code Here

    @Test
    public final void shouldSuccesfulyUnSubscribeAfterSubscribe() throws SDKException {
        //Given
        final String channelId = "/channel";
        final ClientSessionChannel channel = givenChannel(channelId);
        //When
        final Subscription<Object> subscription = subscriber.subscribe(channelId, listener);
        subscription.unsubscribe();
        //Then
        verifyConnected();
View Full Code Here

    @Test
    public final void shouldNotifySubscriberAboutSubscribeOperationFail() throws SDKException {
        //Given
        final String channelId = "/channel";
        final ClientSessionChannel channel = givenChannel(channelId);
        final Subscription<Object> subscription = subscriber.subscribe(channelId, listener);
        verify(metaSubscribeChannel).addListener(listenerCaptor.capture());
        listenerCaptor.getValue().onMessage(metaSubscribeChannel, mockSubscribeMessge(channelId, false));
        //Then
        verifyConnected();
View Full Code Here

    }

    @Test
    public final void shouldResubscribeAllSubscriptionsOnReconnect() throws SDKException {
        //Given
        final ClientSessionChannel channel = givenChannelWithSubscription("/channel");
        final ClientSessionChannel channelSecond = givenChannelWithSubscription("/channelSecond");
        //When
        reconnect();
        //Then
        verifyConnected();
        verifySubscribed(channel, 2);
View Full Code Here

    }

    @Test
    public final void shouldNotResubscribeToUnsubscribedSubscriptionsOnReconnect() throws SDKException {
        //Given
        final ClientSessionChannel channel = givenChannelWithSubscription("/channel");
        final ClientSessionChannel secondChannel = givenChannel("/channelSecond");
        final Subscription<Object> subscription = givenSubscription(secondChannel);
        givenSubsciptionsSuccessfulySubscribed("/channelSecond");
        //When
        subscription.unsubscribe();
        sendUnsubscribeMessage("/channelSecond");
View Full Code Here

    public final void onMessageShouldPassMessageData() {
        final SubscriptionListener listenerMock = Mockito.mock(SubscriptionListener.class);
        final Message message = Mockito.mock(Message.class);
        //Given
        String subscribedOn = "channelId";
        final ClientSessionChannel channel = givenChannel(subscribedOn);

        //When
        Subscription<Object> subscription = subscriber.subscribe(subscribedOn, listenerMock);
        Mockito.verify(channel).subscribe(listenerCaptor.capture());
        listenerCaptor.getValue().onMessage(channel, message);
View Full Code Here

        final Subscription<Object> subscribe = subscriber.subscribe(channel.getId(), listener);
        return subscribe;
    }

    private ClientSessionChannel givenChannelWithSubscription(final String channelId) {
        final ClientSessionChannel channel = givenChannel(channelId);
        subscriber.subscribe(channelId, listener);
        givenSubsciptionsSuccessfulySubscribed(channelId);
        return channel;
    }
View Full Code Here

        verify(bayeuxSessionProvider).get();
    }

    private ClientSessionChannel givenChannel(String channelId) {
        when(subscriptionNameResolver.apply(channelId)).thenReturn(channelId);
        ClientSessionChannel channel = Mockito.mock(ClientSessionChannel.class);
        when(client.getChannel(channelId)).thenReturn(channel);
        when(channel.getId()).thenReturn(channelId);
        return channel;
    }
View Full Code Here

    public Subscription<T> subscribe(T object, final SubscriptionListener<T, Message> handler) throws SDKException {

        checkArgument(object != null, "object can't be null");
        checkArgument(handler != null, "handler can't be null");
        ensureConnection();
        final ClientSessionChannel channel = getChannel(object);
        final MessageListenerAdapter listener = new MessageListenerAdapter(handler, channel, object);
        final ClientSessionChannel metaSubscribeChannel = session.getChannel(ClientSessionChannel.META_SUBSCRIBE);
        metaSubscribeChannel.addListener(new SubscriptionSuccessListener(new SubscriptionRecord(object, handler) , listener, metaSubscribeChannel, channel));
        channel.subscribe(listener);

        return listener.getSubscription();
    }
View Full Code Here

TOP

Related Classes of org.cometd.bayeux.client.ClientSessionChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.