forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveTest.java
More file actions
93 lines (68 loc) · 2.93 KB
/
RemoveTest.java
File metadata and controls
93 lines (68 loc) · 2.93 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
package com.pubnub.api.datasync;
import com.pubnub.api.Pubnub;
import com.pubnub.api.PubnubException;
import com.pubnub.api.SyncedObject;
import com.pubnub.api.TestHelper;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import java.util.Hashtable;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
public class RemoveTest {
Pubnub pubnub;
String playerString;
@Before
public void setUp() throws InterruptedException {
pubnub = new Pubnub("demo-36", "demo-36");
pubnub.setCacheBusting(false);
playerString = "player" + TestHelper.random();
}
@Test
public void testRemoveResponse() throws InterruptedException, JSONException {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
TestHelper.SimpleCallback cb1 = new TestHelper.SimpleCallback(latch1);
TestHelper.SimpleCallback cb2 = new TestHelper.SimpleCallback(latch2);
Hashtable mergeArgs = new Hashtable();
mergeArgs.put("location", "player.settings.volume");
mergeArgs.put("data", 70);
pubnub.merge(mergeArgs, cb1);
latch1.await(5, TimeUnit.SECONDS);
Hashtable removeArgs = new Hashtable();
removeArgs.put("location", "player.settings.volume");
pubnub.remove(removeArgs, cb2);
latch2.await(5, TimeUnit.SECONDS);
JSONObject response = (JSONObject) cb2.getResponse();
System.out.println(response.toString());
assertEquals("settings.volume", response.getString("location"));
assertEquals("delete", response.getString("op"));
assertEquals(0, latch2.getCount());
}
@Test
public void testRemoveObjectCallback() throws InterruptedException, JSONException, PubnubException {
DataSyncTestHelper.setupSettingsOn(playerString, pubnub);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
TestHelper.SimpleDataSyncCallback cb1 = new TestHelper.SimpleDataSyncCallback(latch1) {
@Override
public void removeCallback(List updates, String path) {
latch2.countDown();
}
};
SyncedObject player = pubnub.sync(playerString, cb1);
latch1.await(5, TimeUnit.SECONDS);
assertEquals(70, player.getInteger("settings.volume"));
assertEquals("en", player.getString("settings.locale"));
assertTrue(player.getBoolean("settings.mute"));
player.remove("settings.volume");
latch2.await(5, TimeUnit.SECONDS);
assertEquals(0, player.optInteger("settings.volume"));
assertEquals("en", player.getString("settings.locale"));
assertTrue(player.getBoolean("settings.mute"));
assertEquals(0, latch1.getCount());
}
}