forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublishEncTest.java
More file actions
101 lines (89 loc) · 2.82 KB
/
Copy pathPublishEncTest.java
File metadata and controls
101 lines (89 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.pubnub.api.tests;
import static org.junit.Assert.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import com.pubnub.api.PubnubSync;
public class PublishEncTest {
PubnubSync pubnub = new PubnubSync("demo", "demo", "", "enigma", false);
@Test
public void String() {
String message = "hi";
String channel = "hello";
try {
JSONArray jso = (JSONArray) pubnub.publish(channel, message);
assertEquals(jso.get(0), 1);
assertEquals(jso.get(1), "Sent");
} catch (JSONException e) {
fail("Not an array response 1");
} catch (ClassCastException c) {
fail("Not an array response 2");
}
}
@Test
public void Integer() {
Integer message = 123;
String channel = "hello";
try {
JSONArray jso = (JSONArray) pubnub.publish(channel, message);
assertEquals(jso.get(0), 1);
assertEquals(jso.get(1), "Sent");
} catch (JSONException e) {
fail("Not an array response 1");
} catch (ClassCastException c) {
fail("Not an array response 2");
}
}
@Test
public void Double() {
Double message = 1.2;
String channel = "hello";
try {
JSONArray jso = (JSONArray) pubnub.publish(channel, message);
assertEquals(jso.get(0), 1);
assertEquals(jso.get(1), "Sent");
} catch (JSONException e) {
fail("Not an array response 1");
} catch (ClassCastException c) {
fail("Not an array response 2");
}
}
@Test
public void JsonArray() {
JSONArray jsa = new JSONArray();
jsa.put("a");
jsa.put("b");
String channel = "hello";
try {
JSONArray jso = (JSONArray) pubnub.publish(channel, jsa);
assertEquals(jso.get(0), 1);
assertEquals(jso.get(1), "Sent");
} catch (JSONException e) {
fail("Not an array response 1");
} catch (ClassCastException c) {
fail("Not an array response 2");
}
}
@Test
public void JsonObject() {
JSONObject js = new JSONObject();
try {
js.put("a", 1);
js.put("b", 2);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String channel = "hello";
try {
JSONArray jso = (JSONArray) pubnub.publish(channel, js);
assertEquals(jso.get(0), 1);
assertEquals(jso.get(1), "Sent");
} catch (JSONException e) {
fail("Not an array response 1");
} catch (ClassCastException c) {
fail("Not an array response 2");
}
}
}