Skip to content

Commit 83022d4

Browse files
author
Max Presman
committed
adding filter expression to confiuration
1 parent 7edeaf1 commit 83022d4

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public class PnConfiguration {
7575
*/
7676
private PNHeartbeatNotificationOptions heartbeatNotificationOptions;
7777

78+
/**
79+
* filterExpression used as part of PSV2 specification.
80+
*/
81+
@Setter private String filterExpression;
82+
7883
/**
7984
* Initialize the PnConfiguration with default values
8085
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ private void startSubscribeLoop() {
185185
subscribeCall = new Subscribe(pubnub)
186186
.channels(combinedChannels).channelGroups(combinedChannelGroups)
187187
.timetoken(timetoken).region(region)
188+
.filterExpression(pubnub.getConfiguration().getFilterExpression())
188189
.async(new PNCallback<SubscribeEnvelope>() {
189190
@Override
190191
public void onResponse(SubscribeEnvelope result, PNStatus status) {
191192
if (status.isError()) {
192193
announce(status);
194+
195+
// TODO: handle reachability here.
196+
193197
return;
194198
}
195199

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,41 @@ public void presence(Pubnub pubnub, PNPresenceEventResult presence) {
108108

109109
}
110110

111+
@Test
112+
public void testSubscribeWithFilterExpressionBuilder() {
113+
final AtomicInteger atomic = new AtomicInteger(0);
114+
pubnub.getConfiguration().setFilterExpression("much=filtering");
115+
stubFor(get(urlPathEqualTo("/v2/subscribe/mySubscribeKey/ch2,ch1/0"))
116+
.willReturn(aResponse().withBody("{\"t\":{\"t\":\"14607577960932487\",\"r\":1},\"m\":[{\"a\":\"4\",\"f\":0,\"i\":\"Client-g5d4g\",\"p\":{\"t\":\"14607577960925503\",\"r\":1},\"k\":\"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\",\"c\":\"coolChannel\",\"d\":{\"text\":\"Enter Message Here\"},\"b\":\"coolChan-bnel\"}]}")));
117+
118+
pubnub.addListener(new SubscribeCallback() {
119+
@Override
120+
public void status(Pubnub pubnub, PNStatus status) {
121+
}
122+
123+
@Override
124+
public void message(Pubnub pubnub, PNMessageResult message) {
125+
List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching("/v2/subscribe.*")));
126+
127+
if (requests.size() == 1) {
128+
assertEquals("much%3Dfiltering", requests.get(0).queryParameter("filter-expr").firstValue());
129+
atomic.addAndGet(1);
130+
}
131+
}
132+
133+
@Override
134+
public void presence(Pubnub pubnub, PNPresenceEventResult presence) {
135+
}
136+
});
137+
138+
139+
pubnub.subscribe().channels(Arrays.asList("ch1", "ch2")).execute();
140+
141+
Awaitility.await().atMost(5, TimeUnit.SECONDS)
142+
.untilAtomic(atomic, org.hamcrest.core.IsEqual.equalTo(1));
143+
144+
}
145+
111146
@Test
112147
public void testSubscribePresenceBuilder() {
113148
final AtomicInteger atomic = new AtomicInteger(0);

0 commit comments

Comments
 (0)