lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Attempt to enterClient() etc with a null clientId; check exception
     */
Attempt to enterClient() etc with a null clientId; check exception
Attempt to enterClient () etc with a null clientId ; check exception
@Test
    public void presence_enterclient_null_clientid() throws AblyException {
        String channelName = "presence_enterclient_null_clientid_" + testParams.name;
        AblyRealtime ably = null;
        try {
            /* init ably for token */
            ClientOptions optsForToken = createOptions(testVars.keys[0].keyStr);
            final AblyRest ablyForToken = new AblyRest(optsForToken);
            /* get first token */
            Auth.TokenParams tokenParams = new Auth.TokenParams();
            tokenParams.clientId = testClientId1;
            Auth.TokenDetails token = ablyForToken.auth.requestToken(tokenParams, null);
            assertNotNull("Expected token value", token.token);
            ClientOptions opts = createOptions(token.token);
            opts.clientId = testClientId1;
            ably = new AblyRealtime(opts);
            Channel channel = ably.channels.get(channelName);
            channel.attach();
            ChannelWaiter channelWaiter = new ChannelWaiter(channel);
            channelWaiter.waitFor(ChannelState.attached);
            CompletionWaiter presenceWaiter = new CompletionWaiter();
            /* should fail with null clientId */
            channel.presence.enterClient(null, null, presenceWaiter);
            ErrorInfo enterErr = presenceWaiter.waitFor();
            assertNotNull("Verify error result", enterErr);
            assertEquals("Verify error result with expected error code", enterErr.code, 40000);
            /* should fail with null clientId */
            presenceWaiter.reset();
            channel.presence.leaveClient(null, null, presenceWaiter);
            ErrorInfo leaveErr = presenceWaiter.waitFor();
            assertNotNull("Verify error result", leaveErr);
            assertEquals("Verify error result with expected error code", leaveErr.code, 40000);
            /* should fail with null clientId */
            presenceWaiter.reset();
            channel.presence.updateClient(null, null, presenceWaiter);
            ErrorInfo updateErr = presenceWaiter.waitFor();
            assertNotNull("Verify error result", updateErr);
            assertEquals("Verify error result with expected error code", updateErr.code, 40000);
        } finally {
            if (ably != null)
                ably.close();
        }
    }
@ Test public void presence_enterclient_null_clientid ( ) throws AblyException { String channelName = "presence_enterclient_null_clientid_" + testParams . name ; AblyRealtime ably = null ; try { /* init ably for token */ ClientOptions optsForToken = createOptions ( testVars . keys [ 0 ] . keyStr ) ; final AblyRest ablyForToken = new AblyRest ( optsForToken ) ; /* get first token */ Auth . TokenParams tokenParams = new Auth . TokenParams ( ) ; tokenParams . clientId = testClientId1 ; Auth . TokenDetails token = ablyForToken . auth . requestToken ( tokenParams , null ) ; assertNotNull ( "Expected token value" , token . token ) ; ClientOptions opts = createOptions ( token . token ) ; opts . clientId = testClientId1 ; ably = new AblyRealtime ( opts ) ; Channel channel = ably . channels . get ( channelName ) ; channel . attach ( ) ; ChannelWaiter channelWaiter = new ChannelWaiter ( channel ) ; channelWaiter . waitFor ( ChannelState . attached ) ; CompletionWaiter presenceWaiter = new CompletionWaiter ( ) ; /* should fail with null clientId */ channel . presence . enterClient ( null , null , presenceWaiter ) ; ErrorInfo enterErr = presenceWaiter . waitFor ( ) ; assertNotNull ( "Verify error result" , enterErr ) ; assertEquals ( "Verify error result with expected error code" , enterErr . code , 40000 ) ; /* should fail with null clientId */ presenceWaiter . reset ( ) ; channel . presence . leaveClient ( null , null , presenceWaiter ) ; ErrorInfo leaveErr = presenceWaiter . waitFor ( ) ; assertNotNull ( "Verify error result" , leaveErr ) ; assertEquals ( "Verify error result with expected error code" , leaveErr . code , 40000 ) ; /* should fail with null clientId */ presenceWaiter . reset ( ) ; channel . presence . updateClient ( null , null , presenceWaiter ) ; ErrorInfo updateErr = presenceWaiter . waitFor ( ) ; assertNotNull ( "Verify error result" , updateErr ) ; assertEquals ( "Verify error result with expected error code" , updateErr . code , 40000 ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Attempt to enterClient() etc with a null clientId; check exception
Attempt to enterClient () etc with a null clientId ; check exception