Repository navigation
Expand file tree
/
Copy pathGetTest.java
More file actions
60 lines (44 loc) · 1.79 KB
/
Copy pathGetTest.java
File metadata and controls
60 lines (44 loc) · 1.79 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
package com.pubnub.api.datasync;
import com.pubnub.api.Pubnub;
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.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class GetTest {
Pubnub pubnub;
@Before
public void setUp() throws InterruptedException {
pubnub = new Pubnub("demo-36", "demo-36");
pubnub.setCacheBusting(false);
}
@Test
public void testGetResponse() 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<String, Object> mergeArgs = new Hashtable<String, Object>();
mergeArgs.put("location", "player.settings.volume");
mergeArgs.put("data", 70);
pubnub.merge(mergeArgs, cb1);
latch1.await(5, TimeUnit.SECONDS);
Hashtable<String, Object> getArgs = new Hashtable<String, Object>();
getArgs.put("location", "player");
pubnub.get(getArgs, cb2);
latch2.await(5, TimeUnit.SECONDS);
JSONObject response = (JSONObject) cb2.getResponse();
Number volume = response.getJSONObject("data")
.getJSONObject("settings")
.getJSONObject("volume")
.getInt("pn_val");
assertEquals("", response.getString("location"));
assertEquals("get", response.getString("op"));
assertEquals(70, volume);
assertEquals(0, latch2.getCount());
}
}