forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNamespaceTest.java
More file actions
94 lines (70 loc) · 3.26 KB
/
NamespaceTest.java
File metadata and controls
94 lines (70 loc) · 3.26 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
package com.pubnub.api;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static com.pubnub.api.matchers.JSONAssert.assertJSONArrayHas;
import static com.pubnub.api.matchers.JSONAssert.assertJSONArrayHasNo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
public class NamespaceTest {
Pubnub pubnub = new Pubnub("demo", "demo");
String random;
@Before
public void setUp() {
pubnub.setCacheBusting(false);
random = UUID.randomUUID().toString().substring(0, 8);
}
@Test
public void testGetAllNamespacesAndRemoveThem() throws InterruptedException, JSONException, PubnubException {
JSONObject result;
JSONArray resultNamespaces;
final CountDownLatch latch1 = new CountDownLatch(3);
final CountDownLatch latch2 = new CountDownLatch(1);
final CountDownLatch latch3 = new CountDownLatch(3);
final CountDownLatch latch4 = new CountDownLatch(1);
final TestHelper.SimpleCallback cb1 = new TestHelper.SimpleCallback(latch1);
final TestHelper.SimpleCallback cb2 = new TestHelper.SimpleCallback(latch2);
final TestHelper.SimpleCallback cb3 = new TestHelper.SimpleCallback(latch3);
final TestHelper.SimpleCallback cb4 = new TestHelper.SimpleCallback(latch4);
String[] groups = new String[]{"jtest1" + random, "jtest2" + random, "jtest3" + random};
String[] namespaces = new String[]{"jspace1" + random, "jspace2" + random, "jspace13" + random};
// add
for (int i = 0; i < groups.length; i++) {
String group = groups[i];
String namespace = namespaces[i];
pubnub.channelGroupAddChannel(namespace + ":" + group, "ch1", cb1);
}
latch1.await(10, TimeUnit.SECONDS);
// get
pubnub.channelGroupListNamespaces(cb2);
latch2.await(10, TimeUnit.SECONDS);
result = (JSONObject) cb2.getResponse();
resultNamespaces = result.getJSONArray("namespaces");
assertFalse("Error is thrown", cb1.responseIsError());
assertEquals("OK", cb1.getResponse());
assertJSONArrayHas(namespaces[0], resultNamespaces);
assertJSONArrayHas(namespaces[1], resultNamespaces);
assertJSONArrayHas(namespaces[2], resultNamespaces);
// remove
pubnub.channelGroupRemoveNamespace(namespaces[0], cb3);
pubnub.channelGroupRemoveNamespace(namespaces[1], cb3);
pubnub.channelGroupRemoveNamespace(namespaces[2], cb3);
latch3.await(10, TimeUnit.SECONDS);
Thread.sleep(1000);
// get again
pubnub.channelGroupListNamespaces(cb4);
latch4.await(10, TimeUnit.SECONDS);
result = (JSONObject) cb4.getResponse();
resultNamespaces = result.getJSONArray("namespaces");
assertFalse("Error is thrown", cb3.responseIsError());
assertEquals("OK", cb3.getResponse());
assertJSONArrayHasNo(namespaces[0], resultNamespaces);
assertJSONArrayHasNo(namespaces[1], resultNamespaces);
assertJSONArrayHasNo(namespaces[2], resultNamespaces);
}
}