|
10 | 10 | import com.pubnub.api.enums.PNOperationType; |
11 | 11 | import com.pubnub.api.models.consumer.PNPublishResult; |
12 | 12 | import com.pubnub.api.models.consumer.PNStatus; |
| 13 | +import org.json.JSONArray; |
| 14 | +import org.json.JSONObject; |
13 | 15 | import org.junit.Before; |
14 | 16 | import org.junit.Rule; |
15 | 17 | import org.junit.Test; |
@@ -275,6 +277,39 @@ public void testSuccessPOJOSync() throws PubNubException, InterruptedException { |
275 | 277 |
|
276 | 278 | } |
277 | 279 |
|
| 280 | + @Test |
| 281 | + public void testJSONObject() throws PubNubException, InterruptedException { |
| 282 | + JSONObject testMessage = new JSONObject(); |
| 283 | + testMessage.put("hi", "test"); |
| 284 | + |
| 285 | + stubFor(get(urlPathEqualTo("/publish/myPublishKey/mySubscribeKey/0/coolChannel/0/%7B%22hi%22%3A%22test%22%7D")) |
| 286 | + .willReturn(aResponse().withBody("[1,\"Sent\",\"14598111595318003\"]"))); |
| 287 | + |
| 288 | + instance.channel("coolChannel").message(testMessage.toMap()).sync(); |
| 289 | + |
| 290 | + List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/.*"))); |
| 291 | + assertEquals(1, requests.size()); |
| 292 | + assertEquals("myUUID", requests.get(0).queryParameter("uuid").firstValue()); |
| 293 | + |
| 294 | + } |
| 295 | + |
| 296 | + @Test |
| 297 | + public void testJSONList() throws PubNubException, InterruptedException { |
| 298 | + JSONArray testMessage = new JSONArray(); |
| 299 | + testMessage.put("hi"); |
| 300 | + testMessage.put("hi2"); |
| 301 | + |
| 302 | + stubFor(get(urlPathEqualTo("/publish/myPublishKey/mySubscribeKey/0/coolChannel/0/%5B%22hi%22%2C%22hi2%22%5D")) |
| 303 | + .willReturn(aResponse().withBody("[1,\"Sent\",\"14598111595318003\"]"))); |
| 304 | + |
| 305 | + instance.channel("coolChannel").message(testMessage.toList()).sync(); |
| 306 | + |
| 307 | + List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/.*"))); |
| 308 | + assertEquals(1, requests.size()); |
| 309 | + assertEquals("myUUID", requests.get(0).queryParameter("uuid").firstValue()); |
| 310 | + |
| 311 | + } |
| 312 | + |
278 | 313 | @org.junit.Test(expected=PubNubException.class) |
279 | 314 | public void testMissingChannel() throws PubNubException, InterruptedException { |
280 | 315 |
|
|
0 commit comments