@@ -762,6 +762,61 @@ public void presence(PubNub pubnub, PNPresenceEventResult presence) {
762762 Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (statusRecieved , org .hamcrest .core .IsEqual .equalTo (false ));
763763 }
764764
765+ @ Test
766+ public void testUnsubscribeAll () {
767+
768+ final AtomicBoolean statusRecieved = new AtomicBoolean ();
769+ final AtomicBoolean messageRecieved = new AtomicBoolean ();
770+
771+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1,ch2-pnpres,ch1-pnpres/0" ))
772+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 14607577960932487\" ,\" r\" :1},\" m\" :[{\" a\" :\" 4\" ,\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" p\" :{\" t\" :\" 14607577960925503\" ,\" r\" :1},\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\" ,\" c\" :\" coolChannel\" ,\" d\" :{\" text\" :\" Enter Message Here\" },\" b\" :\" coolChan-bnel\" }]}" )));
773+
774+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch2-pnpres/0" ))
775+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 14607577960932487\" ,\" r\" :1},\" m\" :[{\" a\" :\" 4\" ,\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" p\" :{\" t\" :\" 14607577960925503\" ,\" r\" :1},\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\" ,\" c\" :\" coolChannel\" ,\" d\" :{\" text\" :\" Enter Message Here\" },\" b\" :\" coolChan-bnel\" }]}" )));
776+
777+ stubFor (get (urlPathEqualTo ("/v2/presence/sub-key/mySubscribeKey/channel/ch1/leave" ))
778+ .willReturn (aResponse ().withBody ("{\" status\" : 200, \" message\" : \" OK\" , \" service\" : \" Presence\" , \" action\" : \" leave\" }" )));
779+
780+ stubFor (get (urlPathEqualTo ("/v2/presence/sub-key/mySubscribeKey/channel/ch2/leave" ))
781+ .willReturn (aResponse ().withBody ("{\" status\" : 200, \" message\" : \" OK\" , \" service\" : \" Presence\" , \" action\" : \" leave\" }" )));
782+
783+ SubscribeCallback sub1 = new SubscribeCallback () {
784+ @ Override
785+ public void status (PubNub pubnub , PNStatus status ) {
786+
787+ if (status .getCategory () == PNStatusCategory .PNConnectedCategory ) {
788+ pubnub .unsubscribe ().channels (Arrays .asList ("ch1" )).execute ();
789+ }
790+
791+ if (status .getAffectedChannels ()!=null && status .getAffectedChannels ().size () == 1 && status .getOperation () == PNOperationType .PNUnsubscribeOperation ){
792+ if (status .getAffectedChannels ().get (0 ).equals ("ch1" )) {
793+ pubnub .unsubscribe ().channels (Arrays .asList ("ch2" )).execute ();
794+ }
795+ }
796+
797+ if (status .getAffectedChannels ()!=null && status .getAffectedChannels ().size () == 1 && status .getOperation () == PNOperationType .PNUnsubscribeOperation ){
798+ if (status .getAffectedChannels ().get (0 ).equals ("ch2" )) {
799+ statusRecieved .set (true );
800+ }
801+ }
802+ }
803+
804+ @ Override
805+ public void message (PubNub pubnub , PNMessageResult message ) {
806+ }
807+
808+ @ Override
809+ public void presence (PubNub pubnub , PNPresenceEventResult presence ) {
810+ }
811+ };
812+
813+ pubnub .addListener (sub1 );
814+
815+ pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).withPresence ().execute ();
816+
817+ Awaitility .await ().atMost (4 , TimeUnit .SECONDS ).untilAtomic (statusRecieved , org .hamcrest .core .IsEqual .equalTo (true ));
818+ }
819+
765820
766821 private String joinArray (String [] arr ) {
767822 StringBuilder builder = new StringBuilder ();
0 commit comments