Skip to content

Commit baedef1

Browse files
author
Max Presman
committed
add tests for publishing JSONObject and JSONArray
1 parent e85aac9 commit baedef1

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

‎build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
testCompile group: 'com.github.tomakehurst', name: 'wiremock', version:'1.58'
5252
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
5353
testCompile group: 'com.jayway.awaitility', name: 'awaitility', version:'1.7.0'
54+
testCompile group: 'org.json', name: 'json', version: '20160810'
5455
}
5556

5657
jacoco {

‎src/test/java/com/pubnub/api/endpoints/pubsub/PublishTest.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.pubnub.api.enums.PNOperationType;
1111
import com.pubnub.api.models.consumer.PNPublishResult;
1212
import com.pubnub.api.models.consumer.PNStatus;
13+
import org.json.JSONArray;
14+
import org.json.JSONObject;
1315
import org.junit.Before;
1416
import org.junit.Rule;
1517
import org.junit.Test;
@@ -275,6 +277,39 @@ public void testSuccessPOJOSync() throws PubNubException, InterruptedException {
275277

276278
}
277279

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+
278313
@org.junit.Test(expected=PubNubException.class)
279314
public void testMissingChannel() throws PubNubException, InterruptedException {
280315

0 commit comments

Comments
 (0)