@@ -84,6 +84,56 @@ public void presence(PubNub pubnub, PNPresenceEventResult presence) {
8484
8585 }
8686
87+ @ Test
88+ public void testSubscribeSlidingBuilder () {
89+ final AtomicBoolean gotMessage1 = new AtomicBoolean ();
90+ final AtomicBoolean gotMessage2 = new AtomicBoolean ();
91+ final AtomicBoolean gotMessage3 = new AtomicBoolean ();
92+
93+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
94+ .withQueryParam ("tt" , matching ("0" ))
95+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 3\" ,\" 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\" :\" Message\" },\" b\" :\" coolChan-bnel\" }]}" )));
96+
97+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
98+ .withQueryParam ("tt" , matching ("3" ))
99+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 10\" ,\" 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\" :\" Message3\" },\" b\" :\" coolChan-bnel\" }]}" )));
100+
101+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
102+ .withQueryParam ("tt" , matching ("10" ))
103+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 20\" ,\" 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\" :\" Message10\" },\" b\" :\" coolChan-bnel\" }]}" )));
104+
105+ pubnub .addListener (new SubscribeCallback () {
106+ @ Override
107+ public void status (PubNub pubnub , PNStatus status ) {
108+
109+ }
110+
111+ @ Override
112+ public void message (PubNub pubnub , PNMessageResult message ) {
113+ List <LoggedRequest > requests = findAll (getRequestedFor (urlMatching ("/v2/subscribe.*" )));
114+
115+ if (message .getMessage ().get ("text" ).asText ().equals ("Message" )) {
116+ gotMessage1 .set (true );
117+ } else if (message .getMessage ().get ("text" ).asText ().equals ("Message3" )) {
118+ gotMessage2 .set (true );
119+ } else if (message .getMessage ().get ("text" ).asText ().equals ("Message10" )) {
120+ gotMessage3 .set (true );
121+ }
122+ }
123+
124+ @ Override
125+ public void presence (PubNub pubnub , PNPresenceEventResult presence ) {
126+ }
127+ });
128+
129+
130+ pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).execute ();
131+
132+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotMessage1 , org .hamcrest .core .IsEqual .equalTo (true ));
133+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotMessage2 , org .hamcrest .core .IsEqual .equalTo (true ));
134+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotMessage3 , org .hamcrest .core .IsEqual .equalTo (true ));
135+ }
136+
87137 @ Test
88138 public void testSubscribeBuilderNumber () {
89139 final AtomicInteger atomic = new AtomicInteger (0 );
0 commit comments