forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistoryTest.java
More file actions
83 lines (72 loc) · 2.61 KB
/
Copy pathHistoryTest.java
File metadata and controls
83 lines (72 loc) · 2.61 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
package com.pubnub.api.tests;
import static org.junit.Assert.*;
import org.json.JSONArray;
import org.junit.BeforeClass;
import org.junit.Test;
import com.pubnub.api.Pubnub;
import com.pubnub.api.PubnubSync;
public class HistoryTest {
static PubnubSync pubnub = new PubnubSync("demo", "demo");
static String unique = "" + System.currentTimeMillis();
static String channel = "channel-" + unique;
static String message = "message-" + unique + "-";
@BeforeClass
public static void setUpBeforeClass() throws Exception {
for (int i = 0; i < 10; i++) {
try {
JSONArray jsa = (JSONArray) pubnub.publish(channel, message + i);
} catch (Exception e) {
fail("Exception " + e.toString());
}
}
Thread.sleep(5000);
}
@Test
public void historyCount10() {
try {
JSONArray response = (JSONArray) pubnub.history(channel, 10);
JSONArray messages = (JSONArray) response.get(0);
assertEquals(messages.length(), 10);
assertEquals(messages.get(0), message + "0");
assertEquals(messages.get(9), message + "9");
} catch (Exception e) {
fail("Exception " + e.toString());
}
}
@Test
public void historyCount10Reverse() {
try {
JSONArray response = (JSONArray) pubnub.history(channel, 10, true);
JSONArray messages = (JSONArray) response.get(0);
assertEquals(messages.length(), 10);
assertEquals(messages.get(0), message + "0");
assertEquals(messages.get(9), message + "9");
} catch (Exception e) {
fail("Exception " + e.toString());
}
}
@Test
public void historyCount5() {
try {
JSONArray response = (JSONArray) pubnub.history(channel, 5);
JSONArray messages = (JSONArray) response.get(0);
assertEquals(messages.length(), 5);
assertEquals(messages.get(0), message + "5");
assertEquals(messages.get(4), message + "9");
} catch (Exception e) {
fail("Exception " + e.toString());
}
}
@Test
public void historyCount5Reverse() {
try {
JSONArray response = (JSONArray) pubnub.history(channel, 5, true);
JSONArray messages = (JSONArray) response.get(0);
assertEquals(messages.length(), 5);
assertEquals(messages.get(0), message + "0");
assertEquals(messages.get(4), message + "4");
} catch (Exception e) {
fail("Exception " + e.toString());
}
}
}