Package com.pusher.client.connection

Examples of com.pusher.client.connection.ConnectionStateChange


        channelManager.subscribeTo(mockInternalChannel, mockEventListener);
        verify(mockConnection, never()).sendMessage(anyString());

        when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTING, ConnectionState.CONNECTED));
        verify(mockConnection).sendMessage(OUTGOING_SUBSCRIBE_MESSAGE);
    }
View Full Code Here


        channelManager.subscribeTo(mockPrivateChannel,
                mockPrivateChannelEventListener);
        verify(mockConnection, never()).sendMessage(anyString());

        when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTING, ConnectionState.CONNECTED));
        verify(mockPrivateChannelEventListener).onAuthenticationFailure(
                "Unable to contact auth server", exception);
        verify(mockConnection, never()).sendMessage(anyString());
    }
View Full Code Here

        channelManager.subscribeTo(mockInternalChannel, mockEventListener);
        verify(mockConnection, never()).sendMessage(anyString());

        // when the connection is made the first subscribe attempt should be made
        when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTING, ConnectionState.CONNECTED));
        verify(mockConnection, times(1)).sendMessage(anyString());

        // when the connection fails and comes back up the channel should be
        // subscribed again
        when(mockConnection.getState()).thenReturn(ConnectionState.DISCONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTED, ConnectionState.DISCONNECTED));

        when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.DISCONNECTED, ConnectionState.CONNECTED));

        verify(mockConnection, times(2)).sendMessage(OUTGOING_SUBSCRIBE_MESSAGE);
    }
View Full Code Here

        channelManager.subscribeTo(mockInternalChannel, mockEventListener);
        verify(mockInternalChannel, never()).updateState(any(ChannelState.class));

        when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTING, ConnectionState.CONNECTED));
        verify(mockInternalChannel).updateState(ChannelState.SUBSCRIBE_SENT);
    }
View Full Code Here

    @Test
    public void testSubscriptionIsReSubscribedFollowingDisconnectThenConnect() {
        when(mockConnection.getState()).thenReturn(ConnectionState.DISCONNECTED);

        channelManager.subscribeTo(mockInternalChannel, mockEventListener);
        channelManager.onConnectionStateChange(new ConnectionStateChange(
                ConnectionState.CONNECTING, ConnectionState.CONNECTED));

        verify(mockConnection, never()).sendMessage(anyString());
    }
View Full Code Here

    @Test
    public void testConnectUpdatesStateAndNotifiesListener() {
        connection.connect();
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.DISCONNECTED, ConnectionState.CONNECTING));
        assertEquals(ConnectionState.CONNECTING, connection.getState());
    }
View Full Code Here

    @Test
    public void testReceivePusherConnectionEstablishedMessageIsTranslatedToAConnectedCallback() {
        connection.connect();
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.DISCONNECTED, ConnectionState.CONNECTING));

        connection.onMessage(CONN_ESTABLISHED_EVENT);
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.CONNECTING, ConnectionState.CONNECTED));

        assertEquals(ConnectionState.CONNECTED, connection.getState());
    }
View Full Code Here

    @Test
    public void testReceivePusherErrorMessageRaisesErrorEvent() {
        connection.connect();
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.DISCONNECTED, ConnectionState.CONNECTING));

        connection.onMessage(
                "{\"event\":\"pusher:error\",\"data\":{\"code\":4001,\"message\":\"Could not find app by key 12345\"}}");
        verify(mockEventListener).onError("Could not find app by key 12345", "4001", null);
    }
View Full Code Here

    @Test
    public void testOnCloseCallbackUpdatesStateToDisconnected() {
        connection.connect();
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.DISCONNECTED, ConnectionState.CONNECTING));

        connection.onClose(1, "reason", true);
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.CONNECTING, ConnectionState.DISCONNECTED));
    }
View Full Code Here

    @Test
    public void testOnErrorCallbackRaisesErrorEvent() {
        connection.connect();
        verify(mockEventListener).onConnectionStateChange(
                new ConnectionStateChange(ConnectionState.DISCONNECTED, ConnectionState.CONNECTING));

        Exception e = new Exception();
        connection.onError(e);
        verify(mockEventListener).onError("An exception was thrown by the websocket", null, e);
    }
View Full Code Here

TOP

Related Classes of com.pusher.client.connection.ConnectionStateChange

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.