4
4
import io .ably .lib .realtime .AblyRealtime ;
5
5
import io .ably .lib .realtime .Channel ;
6
6
import io .ably .lib .realtime .ChannelState ;
7
- import io .ably .lib .realtime .ConnectionEvent ;
8
7
import io .ably .lib .realtime .ConnectionState ;
9
8
import io .ably .lib .realtime .ConnectionStateListener ;
10
9
import io .ably .lib .rest .AblyRest ;
@@ -147,7 +146,8 @@ public void realtime_connection_with_auth_url_in_query_string_connects() {
147
146
* Spec: RSA4d, RSA4d1
148
147
*/
149
148
@ Test
150
- public void auth_client_fails_authorize_server_forbidden () {
149
+ public void auth_client_fails () {
150
+ AblyRealtime ablyRealtime = null ;
151
151
try {
152
152
/* init ably for token */
153
153
ClientOptions optsForToken = createOptions (testVars .keys [0 ].keyStr );
@@ -163,25 +163,13 @@ public void auth_client_fails_authorize_server_forbidden() {
163
163
opts .authUrl = "https://echo.ably.io/respondwith" ;
164
164
opts .authParams = new Param []{ new Param ("status" , 403 )};
165
165
166
- final AblyRealtime ablyRealtime = new AblyRealtime (opts );
166
+ ablyRealtime = new AblyRealtime (opts );
167
167
ablyRealtime .connection .connect ();
168
168
169
169
/* wait for connected state */
170
170
Helpers .ConnectionWaiter connectionWaiter = new Helpers .ConnectionWaiter (ablyRealtime .connection );
171
171
connectionWaiter .waitFor (ConnectionState .connected );
172
172
173
- /* create listener for ConnectionEvent.failed */
174
- ablyRealtime .connection .once (ConnectionEvent .failed , new ConnectionStateListener () {
175
- @ Override
176
- public void onConnectionStateChanged (ConnectionStateChange stateChange ) {
177
- /* assert that state changes correctly */
178
- assertEquals (ConnectionState .connected , stateChange .previous );
179
- assertEquals (80019 , stateChange .reason .code );
180
- assertEquals (80019 , ablyRealtime .connection .reason .code );
181
- assertEquals (403 , ablyRealtime .connection .reason .statusCode );
182
- }
183
- });
184
-
185
173
try {
186
174
opts .tokenDetails = null ;
187
175
/* try to authorize */
@@ -194,11 +182,21 @@ public void onConnectionStateChanged(ConnectionStateChange stateChange) {
194
182
195
183
/* wait for failed state */
196
184
connectionWaiter .waitFor (ConnectionState .failed );
185
+ ConnectionStateListener .ConnectionStateChange lastStateChange = connectionWaiter .lastStateChange ();
186
+ assertEquals (ConnectionState .failed , lastStateChange .current );
187
+ assertEquals (80019 , lastStateChange .reason .code );
188
+ assertEquals (403 , lastStateChange .reason .statusCode );
189
+
197
190
assertEquals ("Verify connected state has failed" , ConnectionState .failed , ablyRealtime .connection .state );
198
191
assertEquals ("Check correct cause error code" , 403 , ablyRealtime .connection .reason .statusCode );
192
+ assertEquals (80019 , ablyRealtime .connection .reason .code );
193
+
199
194
} catch (AblyException e ) {
200
195
e .printStackTrace ();
201
196
fail ();
197
+ } finally {
198
+ assert ablyRealtime != null ;
199
+ ablyRealtime .close ();
202
200
}
203
201
}
204
202
@@ -350,7 +348,7 @@ public void auth_client_match_token_null_clientId() {
350
348
assertEquals ("Verify connected state is reached" , ConnectionState .connected , ablyRealtime .connection .state );
351
349
352
350
/* check expected clientId */
353
- assertEquals ("Auth#clientId is expected to be null" , null , ablyRealtime .auth .clientId );
351
+ assertNull ("Auth#clientId is expected to be null" , ablyRealtime .auth .clientId );
354
352
355
353
ablyRealtime .close ();
356
354
} catch (AblyException e ) {
@@ -383,7 +381,7 @@ public void auth_clientid_null_before_auth() {
383
381
AblyRealtime ablyRealtime = new AblyRealtime (opts );
384
382
385
383
/* check expected clientId */
386
- assertEquals ("Auth#clientId is expected to be null" , null , ablyRealtime .auth .clientId );
384
+ assertNull ("Auth#clientId is expected to be null" , ablyRealtime .auth .clientId );
387
385
388
386
/* wait for connected state */
389
387
ablyRealtime .connection .connect ();
@@ -688,7 +686,7 @@ public void auth_client_match_tokendetails_clientId_fail() {
688
686
ClientOptions opts = createOptions ();
689
687
opts .clientId = "options clientId" ;
690
688
opts .tokenDetails = tokenDetails ;
691
- AblyRealtime ablyRealtime = new AblyRealtime (opts );
689
+ new AblyRealtime (opts );
692
690
} catch (AblyException e ) {
693
691
assertEquals ("Verify error code indicates clientId mismatch" , e .errorInfo .code , 40101 );
694
692
}
@@ -773,7 +771,7 @@ public void auth_clientid_publish_implicit() {
773
771
774
772
/* Get sent message */
775
773
Message messagePublished = protocolListener .sentMessages .get (0 ).messages [0 ];
776
- assertEquals ("Sent message does not contain clientId" , messagePublished .clientId , null );
774
+ assertNull ("Sent message does not contain clientId" , messagePublished .clientId );
777
775
778
776
/* wait until message received on transport */
779
777
protocolListener .waitForRecv (1 );
@@ -819,7 +817,7 @@ public void auth_clientid_publish_implicit() {
819
817
channel .publish (messageToPublish , pubComplete .add ());
820
818
pubComplete .waitFor ();
821
819
assertTrue ("Verify publish callback called on completion" , pubComplete .pending .isEmpty ());
822
- assertTrue ("Verify publish callback returns an error" , pubComplete .errors .size () == 1 );
820
+ assertEquals ("Verify publish callback returns an error" , 1 , pubComplete .errors .size ());
823
821
assertEquals ("Verify publish callback error has expected error code" , pubComplete .errors .iterator ().next ().code , 40012 );
824
822
825
823
/* verify no message sent or received on transport */
@@ -838,7 +836,7 @@ public void auth_clientid_publish_implicit() {
838
836
839
837
/* Get sent message */
840
838
messagePublished = protocolListener .sentMessages .get (0 ).messages [0 ];
841
- assertEquals ("Sent message does not contain clientId" , messagePublished .clientId , null );
839
+ assertNull ("Sent message does not contain clientId" , messagePublished .clientId );
842
840
843
841
/* wait until message received on transport */
844
842
protocolListener .waitForRecv (1 );
@@ -927,7 +925,7 @@ public void auth_clientid_publish_explicit_before_identified() {
927
925
928
926
/* Get sent message */
929
927
messagePublished = protocolListener .sentMessages .get (0 ).messages [0 ];
930
- assertEquals ("Sent message does not contain clientId" , messagePublished .clientId , null );
928
+ assertNull ("Sent message does not contain clientId" , messagePublished .clientId );
931
929
932
930
/* wait until message received on transport */
933
931
protocolListener .waitForRecv (1 );
@@ -996,7 +994,7 @@ public Object getTokenRequest(Auth.TokenParams params) {
996
994
ably .connect ();
997
995
try {
998
996
opts .wait ();
999
- } catch (InterruptedException ie ) {}
997
+ } catch (InterruptedException ignored ) {}
1000
998
ably .auth .renew ();
1001
999
}
1002
1000
@@ -1066,7 +1064,7 @@ public Object getTokenRequest(Auth.TokenParams params) {
1066
1064
ably .connect ();
1067
1065
try {
1068
1066
opts .wait ();
1069
- } catch (InterruptedException ie ) {}
1067
+ } catch (InterruptedException ignored ) {}
1070
1068
1071
1069
ably .auth .renewAuth ((success , tokenDetails1 , errorInfo ) -> {
1072
1070
//Ignore completion handling
@@ -1183,7 +1181,7 @@ public void auth_expired_token_expire_before_connect_renew() {
1183
1181
assertNotNull ("Expected token value" , tokenDetails .token );
1184
1182
1185
1183
/* allow to expire */
1186
- try { Thread .sleep (200L ); } catch (InterruptedException ie ) {}
1184
+ try { Thread .sleep (200L ); } catch (InterruptedException ignored ) {}
1187
1185
1188
1186
/* create Ably realtime instance with token and authCallback */
1189
1187
ClientOptions opts = createOptions ();
0 commit comments