lib/src/test/java/io/ably/lib/test/realtime/RealtimeAuthTest.java
/**
     * Verify message does not have implicit client id
     * if sent before library is identified, so messages
     * are sent with explicit clientId
     * Spec: RTL6g4
     */
Verify message does not have implicit client id
if sent before library is identified, so messages
are sent with explicit clientId
Spec: RTL6g4
Verify message does not have implicit client id if sent before library is identified so messages are sent with explicit clientId Spec : RTL6g4
@Ignore("FIXME: fix exception")
    @Test
    public void auth_clientid_publish_explicit_before_identified() {
        AblyRealtime ably = null;
        try {
            String clientId = "test clientId";
            ClientOptions optsForToken = createOptions(testVars.keys[0].keyStr);
            optsForToken.clientId = clientId;
            AblyRest ablyForToken = new AblyRest(optsForToken);
            TokenDetails tokenDetails = ablyForToken.auth.requestToken(null, null);
            /* create Ably instance with token and implied clientId */
            Helpers.RawProtocolMonitor protocolListener = Helpers.RawProtocolMonitor.createMonitor(ProtocolMessage.Action.message, ProtocolMessage.Action.message);
            DebugOptions options = new DebugOptions(testVars.keys[0].keyStr);
            fillInOptions(options);
            options.token = tokenDetails.token;
            options.protocolListener = protocolListener;
            ably = new AblyRealtime(options);
            /* verify we don't yet know the implied clientId */
            assertNull("Verify clientId is unknown", ably.auth.clientId);
            /* create a channel */
            Channel channel = ably.channels.get("auth_clientid_publish_explicit_before_identified_" + testParams.name);
            /* publish before connection and attach */
            Message messageToPublish = new Message(
                    "I have clientId",	/* name */
                    String.valueOf(System.currentTimeMillis()),
                    clientId /* clientId */
            );
            channel.attach();
            channel.publish(new Message[] { messageToPublish });
            /* wait until connected and attached */
            (new ConnectionWaiter(ably.connection)).waitFor(ConnectionState.connected);
            assertEquals("Verify connected state reached", ably.connection.state, ConnectionState.connected);
            (new ChannelWaiter(channel)).waitFor(ChannelState.attached);
            assertEquals("Verify attached state reached", channel.state, ChannelState.attached);
            /* wait until message seen on transport */
            protocolListener.waitForSend(1);
            /* Get sent message */
            Message messagePublished = protocolListener.sentMessages.get(0).messages[0];
            assertEquals("Sent message does contain explicit clientId", messagePublished.clientId, clientId);
            /* wait until message received on transport */
            protocolListener.waitForRecv(1);
            /* Get received message */
            Message messageReceived = protocolListener.receivedMessages.get(0).messages[0];
            assertEquals("Received message does contain clientId", messageReceived.clientId, clientId);
            /* Publish a message to verify that use of the channel can continue */
            protocolListener.reset();
            messageToPublish = new Message(
                    "I have clientId",	/* name */
                    String.valueOf(System.currentTimeMillis()) /* data */
            );
            channel.publish(new Message[] { messageToPublish });
            /* wait until message seen on transport */
            protocolListener.waitForSend(1);
            /* Get sent message */
            messagePublished = protocolListener.sentMessages.get(0).messages[0];
            assertEquals("Sent message does not contain clientId", messagePublished.clientId, null);
            /* wait until message received on transport */
            protocolListener.waitForRecv(1);
            /* Get received message */
            messageReceived = protocolListener.receivedMessages.get(0).messages[0];
            assertEquals("Received message does contain clientId", messageReceived.clientId, clientId);
        } catch (Exception e) {
            e.printStackTrace();
            fail("auth_clientid_publish_implicit: Unexpected exception");
        } finally {
            if(ably != null) {
                ably.close();
            }
        }
    }
@ Ignore ( "FIXME: fix exception" ) @ Test public void auth_clientid_publish_explicit_before_identified ( ) { AblyRealtime ably = null ; try { String clientId = "test clientId" ; ClientOptions optsForToken = createOptions ( testVars . keys [ 0 ] . keyStr ) ; optsForToken . clientId = clientId ; AblyRest ablyForToken = new AblyRest ( optsForToken ) ; TokenDetails tokenDetails = ablyForToken . auth . requestToken ( null , null ) ; /* create Ably instance with token and implied clientId */ Helpers . RawProtocolMonitor protocolListener = Helpers . RawProtocolMonitor . createMonitor ( ProtocolMessage . Action . message , ProtocolMessage . Action . message ) ; DebugOptions options = new DebugOptions ( testVars . keys [ 0 ] . keyStr ) ; fillInOptions ( options ) ; options . token = tokenDetails . token ; options . protocolListener = protocolListener ; ably = new AblyRealtime ( options ) ; /* verify we don't yet know the implied clientId */ assertNull ( "Verify clientId is unknown" , ably . auth . clientId ) ; /* create a channel */ Channel channel = ably . channels . get ( "auth_clientid_publish_explicit_before_identified_" + testParams . name ) ; /* publish before connection and attach */ Message messageToPublish = new Message ( "I have clientId" , /* name */ String . valueOf ( System . currentTimeMillis ( ) ) , clientId /* clientId */ ) ; channel . attach ( ) ; channel . publish ( new Message [ ] { messageToPublish } ) ; /* wait until connected and attached */ ( new ConnectionWaiter ( ably . connection ) ) . waitFor ( ConnectionState . connected ) ; assertEquals ( "Verify connected state reached" , ably . connection . state , ConnectionState . connected ) ; ( new ChannelWaiter ( channel ) ) . waitFor ( ChannelState . attached ) ; assertEquals ( "Verify attached state reached" , channel . state , ChannelState . attached ) ; /* wait until message seen on transport */ protocolListener . waitForSend ( 1 ) ; /* Get sent message */ Message messagePublished = protocolListener . sentMessages . get ( 0 ) . messages [ 0 ] ; assertEquals ( "Sent message does contain explicit clientId" , messagePublished . clientId , clientId ) ; /* wait until message received on transport */ protocolListener . waitForRecv ( 1 ) ; /* Get received message */ Message messageReceived = protocolListener . receivedMessages . get ( 0 ) . messages [ 0 ] ; assertEquals ( "Received message does contain clientId" , messageReceived . clientId , clientId ) ; /* Publish a message to verify that use of the channel can continue */ protocolListener . reset ( ) ; messageToPublish = new Message ( "I have clientId" , /* name */ String . valueOf ( System . currentTimeMillis ( ) ) /* data */ ) ; channel . publish ( new Message [ ] { messageToPublish } ) ; /* wait until message seen on transport */ protocolListener . waitForSend ( 1 ) ; /* Get sent message */ messagePublished = protocolListener . sentMessages . get ( 0 ) . messages [ 0 ] ; assertEquals ( "Sent message does not contain clientId" , messagePublished . clientId , null ) ; /* wait until message received on transport */ protocolListener . waitForRecv ( 1 ) ; /* Get received message */ messageReceived = protocolListener . receivedMessages . get ( 0 ) . messages [ 0 ] ; assertEquals ( "Received message does contain clientId" , messageReceived . clientId , clientId ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; fail ( "auth_clientid_publish_implicit: Unexpected exception" ) ; } finally { if ( ably != null ) { ably . close ( ) ; } } }
Verify message does not have implicit client id
 if sent before library is identified, so messages
 are sent with explicit clientId
 Spec: RTL6g4
Verify message does not have implicit client id if sent before library is identified so messages are sent with explicit clientId Spec : RTL6g4