Skip to content

Commit e9ac9d4

Browse files
committed
add presence test
1 parent b474fea commit e9ac9d4

9 files changed

Lines changed: 50 additions & 14 deletions

File tree

‎src/main/java/com/pubnub/api/core/Pubnub.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ public final Publish publish() {
127127
return new Publish(this, publishSequenceManager);
128128
}
129129

130-
public final ListAllChannelGroup listChannelsForChannelGroup() {
130+
public final ListAllChannelGroup listAllChannelGroups() {
131131
return new ListAllChannelGroup(this);
132132
}
133133

134-
public final AllChannelsChannelGroup allChannelsInChannelGroup() {
134+
public final AllChannelsChannelGroup listChannelsForChannelGroup() {
135135
return new AllChannelsChannelGroup(this);
136136
}
137137

‎src/main/java/com/pubnub/api/core/models/Envelope.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ public class Envelope<T> {
1515
int occupancy;
1616
Object uuids;
1717
String action;
18+
19+
boolean error;
20+
1821
}

‎src/main/java/com/pubnub/api/endpoints/access/Grant.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected Call<Envelope<PNAccessManagerGrantData>> doWork(Map<String, String> qu
8181
signature = PubnubUtil.signSHA256(this.pubnub.getConfiguration().getSecretKey(), signInput);
8282

8383
queryParams.put("signature", signature);
84-
84+
8585
AccessManagerService service = this.createRetrofit().create(AccessManagerService.class);
8686
return service.grant(pubnub.getConfiguration().getSubscribeKey(), queryParams);
8787
}

‎src/main/java/com/pubnub/api/endpoints/channel_groups/AddChannelChannelGroup.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected boolean validateParams() {
3232
}
3333

3434
@Override
35-
protected Call<Envelope> doWork(Map<String, String> params) {
35+
protected Call<Envelope> doWork(final Map<String, String> params) {
3636
ChannelGroupService service = this.createRetrofit().create(ChannelGroupService.class);
3737

3838
if (channels.size() > 0) {
@@ -44,7 +44,7 @@ protected Call<Envelope> doWork(Map<String, String> params) {
4444

4545
@Override
4646
protected Boolean createResponse(Response<Envelope> input) throws PubnubException {
47-
return true;
47+
return !input.body().isError();
4848
}
4949

5050
protected int getConnectTimeout() {

‎src/main/java/com/pubnub/api/endpoints/channel_groups/ChannelGroupService.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99

1010

1111
public interface ChannelGroupService {
12-
@GET("v2/channel-registration/sub-key/{subKey}/channel-group")
12+
@GET("v1/channel-registration/sub-key/{subKey}/channel-group")
1313
Call<Envelope<Object>> ListAllChannelGroup(@Path("subKey") String subKey,
1414
@QueryMap Map<String, String> options);
1515

16-
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
16+
@GET("v1/channel-registration/sub-key/{subKey}/channel-group/{group}")
1717
Call<Envelope<Object>> AllChannelsChannelGroup(@Path("subKey") String subKey,
1818
@Path("group") String group,
1919
@QueryMap Map<String, String> options);
2020

21-
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
21+
@GET("v1/channel-registration/sub-key/{subKey}/channel-group/{group}")
2222
Call<Envelope> AddChannelChannelGroup(@Path("subKey") String subKey,
2323
@Path("group") String group,
2424
@QueryMap Map<String, String> options);
2525

26-
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group}")
26+
@GET("v1/channel-registration/sub-key/{subKey}/channel-group/{group}")
2727
Call<Envelope> RemoveChannel(@Path("subKey") String subKey,
2828
@Path("group") String group,
2929
@QueryMap Map<String, String> options);
3030

31-
@GET("v2/channel-registration/sub-key/{subKey}/channel-group/{group_name}/remove")
31+
@GET("v1/channel-registration/sub-key/{subKey}/channel-group/{group}/remove")
3232
Call<Envelope> DeleteChannelGroup(@Path("subKey") String subKey,
33-
@Path("group_name") String group,
33+
@Path("group") String group,
3434
@QueryMap Map<String, String> options);
3535
}
3636

‎src/main/java/com/pubnub/api/managers/SubscriptionManager.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public final synchronized void adaptSubscribeBuilder(final SubscribeOperation su
103103
this.timetoken = subscribeOperation.getTimetoken();
104104
}
105105

106-
107106
this.startSubscribeLoop();
108107
this.registerHeartbeatTimer();
109108
}

‎src/test/java/com.pubnub.api/endpoints/channel_groups/AllChannelsChannelGroupEndpointTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class AllChannelsChannelGroupEndpointTest extends TestHarness {
2020

2121
@Before
2222
public void beforeEach() throws IOException {
23-
partialAllChannelsChannelGroup = this.createPubNubInstance(8080).allChannelsInChannelGroup();
23+
partialAllChannelsChannelGroup = this.createPubNubInstance(8080).listChannelsForChannelGroup();
2424
}
2525

2626
@org.junit.Test

‎src/test/java/com.pubnub.api/endpoints/channel_groups/ListAllChannelGroupEndpointTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ListAllChannelGroupEndpointTest extends TestHarness {
2020

2121
@Before
2222
public void beforeEach() throws IOException {
23-
partialChannelGroup = this.createPubNubInstance(8080).listChannelsForChannelGroup();
23+
partialChannelGroup = this.createPubNubInstance(8080).listAllChannelGroups();
2424
}
2525

2626
@org.junit.Test

‎src/test/java/com/pubnub/api/managers/SubscriptionManagerTest.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,40 @@ public void presence(Pubnub pubnub, PNPresenceEventResult presence) {
177177

178178
}
179179

180+
@Test
181+
public void testSubscribePresencePayloadBuilder() {
182+
final AtomicInteger atomic = new AtomicInteger(0);
183+
stubFor(get(urlPathEqualTo("/v2/subscribe/mySubscribeKey/ch2,ch2-pnpres,ch1,ch1-pnpres/0"))
184+
.willReturn(aResponse().withBody("{\"t\":{\"t\":\"14614512228786519\",\"r\":1},\"m\":[{\"a\":\"4\",\"f\":0,\"p\":{\"t\":\"14614512228418349\",\"r\":2},\"k\":\"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\",\"c\":\"coolChannel-pnpres\",\"d\":{\"action\": \"join\", \"timestamp\": 1461451222, \"uuid\": \"4a6d5df7-e301-4e73-a7b7-6af9ab484eb0\", \"occupancy\": 1},\"b\":\"coolChannel-pnpres\"}]}\n")));
185+
186+
pubnub.addListener(new SubscribeCallback() {
187+
@Override
188+
public void status(Pubnub pubnub, PNStatus status) {
189+
}
190+
191+
@Override
192+
public void message(Pubnub pubnub, PNMessageResult message) {
193+
}
194+
195+
@Override
196+
public void presence(Pubnub pubnub, PNPresenceEventResult presence) {
197+
if (atomic.get() == 0) {
198+
assertEquals("join", presence.getData().getPresenceEvent());
199+
assertEquals("4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", presence.getData().getPresence().getUuid());
200+
Assert.assertTrue(presence.getData().getPresence().getOccupancy().equals(1));
201+
Assert.assertTrue(presence.getData().getPresence().getTimestamp().equals(1461451222L));
202+
atomic.incrementAndGet();
203+
}
204+
}
205+
});
206+
207+
pubnub.subscribe().channels(Arrays.asList("ch1", "ch2")).withPresence().execute();
208+
209+
Awaitility.await().atMost(5, TimeUnit.SECONDS)
210+
.untilAtomic(atomic, org.hamcrest.core.IsEqual.equalTo(1));
211+
212+
}
213+
180214
@Test
181215
public void testSubscribeRegionBuilder() {
182216
final AtomicInteger atomic = new AtomicInteger(0);

0 commit comments

Comments
 (0)