lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Authenticate using wildcard token, initialize AblyRealtime so clientId is not known a priori,
     * call enter() without attaching first, start connection
     *
     * Expect NACK from the server because client is unidentified
     *
     * Tests RTP8i, RTP8f, partial tests for RTP9e, RTP10e
     */
Authenticate using wildcard token, initialize AblyRealtime so clientId is not known a priori,
call enter() without attaching first, start connection

Expect NACK from the server because client is unidentified


Authenticate using wildcard token initialize AblyRealtime so clientId is not known a priori call enter () without attaching first start connection Expect NACK from the server because client is unidentified
@Test
    public void enter_before_clientid_is_known() throws AblyException {
        AblyRealtime ably = null;
        try {
            ClientOptions restOpts = createOptions(testVars.keys[0].keyStr);
            AblyRest ablyForToken = new AblyRest(restOpts);
            /* Initialize connection so clientId is not known before actual connection */
            Auth.TokenParams tokenParams = new Auth.TokenParams();
            Capability capability = new Capability();
            tokenParams.capability = capability.toString();
            tokenParams.clientId = "*";
            Auth.TokenDetails token = ablyForToken.auth.requestToken(tokenParams, null);
            assertNotNull("Expected token value", token.token);
            ClientOptions opts = createOptions();
            opts.defaultTokenParams.clientId = "*";
            opts.token = token.token;
            opts.autoConnect = false;
            ably = new AblyRealtime(opts);
            /* enter without attaching first */
            Channel channel = ably.channels.get("enter_before_clientid_is_known"+testParams.name);
            CompletionWaiter completionWaiter = new CompletionWaiter();
            channel.presence.enter(null, completionWaiter);
            ably.connection.connect();
            completionWaiter.waitFor(1);
            assertFalse("Verify enter() failed", completionWaiter.success);
            assertEquals("Verify error code", completionWaiter.error.code, 40012);
            /* Now clientId is known to be "*" and subsequent enter() should fail immediately */
            completionWaiter.reset();
            channel.presence.enter(null, completionWaiter);
            completionWaiter.waitFor(1);
            assertFalse("Verify enter() failed", completionWaiter.success);
            assertEquals("Verify error code", completionWaiter.error.code, 91000);
            /* and so should update() and leave() */
            completionWaiter.reset();
            channel.presence.update(null, completionWaiter);
            completionWaiter.waitFor(1);
            assertFalse("Verify update() failed", completionWaiter.success);
            assertEquals("Verify error code", completionWaiter.error.code, 91000);
            completionWaiter.reset();
            channel.presence.leave(null, completionWaiter);
            completionWaiter.waitFor(1);
            assertFalse("Verify update() failed", completionWaiter.success);
            assertEquals("Verify error code", completionWaiter.error.code, 91000);
        } finally {
            if (ably != null)
                ably.close();
        }
    }
@ Test public void enter_before_clientid_is_known ( ) throws AblyException { AblyRealtime ably = null ; try { ClientOptions restOpts = createOptions ( testVars . keys [ 0 ] . keyStr ) ; AblyRest ablyForToken = new AblyRest ( restOpts ) ; /* Initialize connection so clientId is not known before actual connection */ Auth . TokenParams tokenParams = new Auth . TokenParams ( ) ; Capability capability = new Capability ( ) ; tokenParams . capability = capability . toString ( ) ; tokenParams . clientId = "*" ; Auth . TokenDetails token = ablyForToken . auth . requestToken ( tokenParams , null ) ; assertNotNull ( "Expected token value" , token . token ) ; ClientOptions opts = createOptions ( ) ; opts . defaultTokenParams . clientId = "*" ; opts . token = token . token ; opts . autoConnect = false ; ably = new AblyRealtime ( opts ) ; /* enter without attaching first */ Channel channel = ably . channels . get ( "enter_before_clientid_is_known" + testParams . name ) ; CompletionWaiter completionWaiter = new CompletionWaiter ( ) ; channel . presence . enter ( null , completionWaiter ) ; ably . connection . connect ( ) ; completionWaiter . waitFor ( 1 ) ; assertFalse ( "Verify enter() failed" , completionWaiter . success ) ; assertEquals ( "Verify error code" , completionWaiter . error . code , 40012 ) ; /* Now clientId is known to be "*" and subsequent enter() should fail immediately */ completionWaiter . reset ( ) ; channel . presence . enter ( null , completionWaiter ) ; completionWaiter . waitFor ( 1 ) ; assertFalse ( "Verify enter() failed" , completionWaiter . success ) ; assertEquals ( "Verify error code" , completionWaiter . error . code , 91000 ) ; /* and so should update() and leave() */ completionWaiter . reset ( ) ; channel . presence . update ( null , completionWaiter ) ; completionWaiter . waitFor ( 1 ) ; assertFalse ( "Verify update() failed" , completionWaiter . success ) ; assertEquals ( "Verify error code" , completionWaiter . error . code , 91000 ) ; completionWaiter . reset ( ) ; channel . presence . leave ( null , completionWaiter ) ; completionWaiter . waitFor ( 1 ) ; assertFalse ( "Verify update() failed" , completionWaiter . success ) ; assertEquals ( "Verify error code" , completionWaiter . error . code , 91000 ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Authenticate using wildcard token, initialize AblyRealtime so clientId is not known a priori,
 call enter() without attaching first, start connection
Authenticate using wildcard token initialize AblyRealtime so clientId is not known a priori call enter () without attaching first start connection