Skip to content

Commit f22a0f8

Browse files
committed
[ECO-5553] Fixed omitted tests responsible for handling vcdiff encoding
1 parent 993b308 commit f22a0f8

1 file changed

Lines changed: 34 additions & 22 deletions

File tree

lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.junit.Test;
3232

3333
import java.util.ArrayList;
34+
import java.util.Arrays;
3435
import java.util.Collections;
3536
import java.util.Comparator;
3637
import java.util.HashMap;
@@ -46,6 +47,7 @@
4647
import static org.junit.Assert.assertNull;
4748
import static org.junit.Assert.assertSame;
4849
import static org.junit.Assert.assertThat;
50+
import static org.junit.Assert.assertThrows;
4951
import static org.junit.Assert.assertTrue;
5052
import static org.junit.Assert.fail;
5153

@@ -150,7 +152,7 @@ public void attach_detach() {
150152
}
151153
}
152154

153-
/*@Test*/
155+
@Test
154156
public void attach_with_channel_params_channels_get() {
155157
String channelName = "attach_with_channel_params_channels_get_" + testParams.name;
156158
AblyRealtime ably = null;
@@ -163,7 +165,7 @@ public void attach_with_channel_params_channels_get() {
163165
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
164166

165167
ChannelOptions options = new ChannelOptions();
166-
options.params = new HashMap<String, String>();
168+
options.params = new HashMap<>();
167169
options.params.put("modes", "subscribe");
168170
options.params.put("delta", "vcdiff");
169171

@@ -183,7 +185,7 @@ public void attach_with_channel_params_channels_get() {
183185
}
184186
}
185187

186-
/*@Test*/
188+
@Test
187189
public void attach_with_channel_params_set_options() {
188190
String channelName = "attach_with_channel_params_set_options_" + testParams.name;
189191
AblyRealtime ably = null;
@@ -196,6 +198,7 @@ public void attach_with_channel_params_set_options() {
196198
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
197199

198200
ChannelOptions options = new ChannelOptions();
201+
options.params = new HashMap<>();
199202
options.params.put("modes", "subscribe");
200203
options.params.put("delta", "vcdiff");
201204

@@ -216,7 +219,7 @@ public void attach_with_channel_params_set_options() {
216219
}
217220
}
218221

219-
/*@Test*/
222+
@Test
220223
public void channels_get_should_throw_when_would_cause_reattach() {
221224
String channelName = "channels_get_should_throw_when_would_cause_reattach_" + testParams.name;
222225
AblyRealtime ably = null;
@@ -228,22 +231,25 @@ public void channels_get_should_throw_when_would_cause_reattach() {
228231
(new ConnectionWaiter(ably.connection)).waitFor(ConnectionState.connected);
229232
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
230233

231-
ChannelOptions options = new ChannelOptions();
232-
options.params.put("modes", "subscribe");
233-
options.params.put("delta", "vcdiff");
234+
ChannelOptions options = new ChannelOptions() {{
235+
params = new HashMap<>();
236+
params.put("modes", "subscribe");
237+
params.put("delta", "vcdiff");
238+
}};
234239

235240
/* create a channel and attach */
236241
final Channel channel = ably.channels.get(channelName, options);
237242
channel.attach();
238243
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
239244

240-
try {
241-
ably.channels.get(channelName, options);
242-
} catch (AblyException e) {
243-
assertEquals("Verify error code", 400, e.errorInfo.code);
244-
assertEquals("Verify error status code", 40000, e.errorInfo.statusCode);
245-
assertTrue("Verify error message", e.errorInfo.message.contains("setOptions"));
246-
}
245+
AblyRealtime finalAbly = ably;
246+
AblyException exception = assertThrows(AblyException.class, () ->
247+
finalAbly.channels.get(channelName, options));
248+
249+
assertEquals("Verify error code", 400, exception.errorInfo.code);
250+
assertEquals("Verify error status code", 40000, exception.errorInfo.statusCode);
251+
assertTrue("Verify error message", exception.errorInfo.message.contains("use Channel.setOptions()"));
252+
247253
} catch (AblyException e) {
248254
e.printStackTrace();
249255
fail("init0: Unexpected exception instantiating library");
@@ -253,7 +259,7 @@ public void channels_get_should_throw_when_would_cause_reattach() {
253259
}
254260
}
255261

256-
/*@Test*/
262+
@Test
257263
public void attach_with_channel_params_modes_and_channel_modes() {
258264
String channelName = "attach_with_channel_params_modes_and_channel_modes_" + testParams.name;
259265
AblyRealtime ably = null;
@@ -289,7 +295,7 @@ public void attach_with_channel_params_modes_and_channel_modes() {
289295
}
290296
}
291297

292-
/*@Test*/
298+
@Test
293299
public void attach_with_channel_modes() {
294300
String channelName = "attach_with_channel_modes_" + testParams.name;
295301
AblyRealtime ably = null;
@@ -312,7 +318,11 @@ public void attach_with_channel_modes() {
312318
channel.attach();
313319
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
314320
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
315-
assertEquals("Verify channel modes", channel.getModes(), options.modes);
321+
assertEquals(2, channel.getModes().length);
322+
323+
assertThat("Verify channel modes",
324+
Arrays.asList(channel.getModes()),
325+
Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.presence_subscribe));
316326
} catch (AblyException e) {
317327
e.printStackTrace();
318328
fail("init0: Unexpected exception instantiating library");
@@ -322,7 +332,7 @@ public void attach_with_channel_modes() {
322332
}
323333
}
324334

325-
/*@Test*/
335+
@Test
326336
public void attach_with_params_delta_and_channel_modes() {
327337
String channelName = "attach_with_params_delta_and_channel_modes_" + testParams.name;
328338
AblyRealtime ably = null;
@@ -335,7 +345,7 @@ public void attach_with_params_delta_and_channel_modes() {
335345
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
336346

337347
ChannelOptions options = new ChannelOptions();
338-
options.params = new HashMap<String, String>();
348+
options.params = new HashMap<>();
339349
options.params.put("delta", "vcdiff");
340350
options.modes = new ChannelMode[] {
341351
ChannelMode.publish,
@@ -348,9 +358,11 @@ public void attach_with_params_delta_and_channel_modes() {
348358
channel.attach();
349359
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
350360
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
351-
options.params.put("modes", "publish,subscribe,presence_subscribe");
352-
assertEquals("Verify channel params", channel.getParams(), options.params);
353-
assertEquals("Verify channel modes", channel.getModes(), options.modes);
361+
362+
assertEquals("Verify channel params", options.params, channel.getParams());
363+
assertThat("Verify channel modes",
364+
Arrays.asList(channel.getModes()),
365+
Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.subscribe, ChannelMode.presence_subscribe));
354366
} catch (AblyException e) {
355367
e.printStackTrace();
356368
fail("init0: Unexpected exception instantiating library");

0 commit comments

Comments
 (0)