diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java index d9824da31..6ea352819 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java @@ -31,6 +31,7 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -46,6 +47,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -150,7 +152,7 @@ public void attach_detach() { } } - /*@Test*/ + @Test public void attach_with_channel_params_channels_get() { String channelName = "attach_with_channel_params_channels_get_" + testParams.name; AblyRealtime ably = null; @@ -163,7 +165,7 @@ public void attach_with_channel_params_channels_get() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); - options.params = new HashMap(); + options.params = new HashMap<>(); options.params.put("modes", "subscribe"); options.params.put("delta", "vcdiff"); @@ -172,7 +174,7 @@ public void attach_with_channel_params_channels_get() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel params", channel.getParams(), options.params); + assertEquals("Verify channel params", options.params, channel.getParams()); assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes()); } catch (AblyException e) { e.printStackTrace(); @@ -183,7 +185,7 @@ public void attach_with_channel_params_channels_get() { } } - /*@Test*/ + @Test public void attach_with_channel_params_set_options() { String channelName = "attach_with_channel_params_set_options_" + testParams.name; AblyRealtime ably = null; @@ -196,6 +198,7 @@ public void attach_with_channel_params_set_options() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); + options.params = new HashMap<>(); options.params.put("modes", "subscribe"); options.params.put("delta", "vcdiff"); @@ -205,7 +208,7 @@ public void attach_with_channel_params_set_options() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel params", channel.getParams(), options.params); + assertEquals("Verify channel params", options.params, channel.getParams()); assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes()); } catch (AblyException e) { e.printStackTrace(); @@ -216,7 +219,7 @@ public void attach_with_channel_params_set_options() { } } - /*@Test*/ + @Test public void channels_get_should_throw_when_would_cause_reattach() { String channelName = "channels_get_should_throw_when_would_cause_reattach_" + testParams.name; AblyRealtime ably = null; @@ -228,22 +231,25 @@ public void channels_get_should_throw_when_would_cause_reattach() { (new ConnectionWaiter(ably.connection)).waitFor(ConnectionState.connected); assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); - ChannelOptions options = new ChannelOptions(); - options.params.put("modes", "subscribe"); - options.params.put("delta", "vcdiff"); + ChannelOptions options = new ChannelOptions() {{ + params = new HashMap<>(); + params.put("modes", "subscribe"); + params.put("delta", "vcdiff"); + }}; /* create a channel and attach */ final Channel channel = ably.channels.get(channelName, options); channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); - try { - ably.channels.get(channelName, options); - } catch (AblyException e) { - assertEquals("Verify error code", 400, e.errorInfo.code); - assertEquals("Verify error status code", 40000, e.errorInfo.statusCode); - assertTrue("Verify error message", e.errorInfo.message.contains("setOptions")); - } + AblyRealtime finalAbly = ably; + AblyException exception = assertThrows(AblyException.class, () -> + finalAbly.channels.get(channelName, options)); + + assertEquals("Verify error code", 400, exception.errorInfo.code); + assertEquals("Verify error status code", 40000, exception.errorInfo.statusCode); + assertTrue("Verify error message", exception.errorInfo.message.contains("use Channel.setOptions()")); + } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -253,7 +259,7 @@ public void channels_get_should_throw_when_would_cause_reattach() { } } - /*@Test*/ + @Test public void attach_with_channel_params_modes_and_channel_modes() { String channelName = "attach_with_channel_params_modes_and_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -279,7 +285,10 @@ public void attach_with_channel_params_modes_and_channel_modes() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); assertEquals("Verify channel params", channel.getParams(), options.params); - assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe, ChannelMode.presence }, channel.getModes()); + // modes in params overrides individual modes in options + assertThat("Verify channel modes", Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.presence, ChannelMode.subscribe)); + } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -289,7 +298,7 @@ public void attach_with_channel_params_modes_and_channel_modes() { } } - /*@Test*/ + @Test public void attach_with_channel_modes() { String channelName = "attach_with_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -312,7 +321,11 @@ public void attach_with_channel_modes() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel modes", channel.getModes(), options.modes); + assertEquals(2, channel.getModes().length); + + assertThat("Verify channel modes", + Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.presence_subscribe)); } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -322,7 +335,7 @@ public void attach_with_channel_modes() { } } - /*@Test*/ + @Test public void attach_with_params_delta_and_channel_modes() { String channelName = "attach_with_params_delta_and_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -335,7 +348,7 @@ public void attach_with_params_delta_and_channel_modes() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); - options.params = new HashMap(); + options.params = new HashMap<>(); options.params.put("delta", "vcdiff"); options.modes = new ChannelMode[] { ChannelMode.publish, @@ -348,9 +361,11 @@ public void attach_with_params_delta_and_channel_modes() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - options.params.put("modes", "publish,subscribe,presence_subscribe"); - assertEquals("Verify channel params", channel.getParams(), options.params); - assertEquals("Verify channel modes", channel.getModes(), options.modes); + + assertEquals("Verify channel params", options.params, channel.getParams()); + assertThat("Verify channel modes", + Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.subscribe, ChannelMode.presence_subscribe)); } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -2546,7 +2561,7 @@ public void connect_on_closing_client_should_reinitialize_channels() throws Ably new ConnectionWaiter(ably.connection).waitFor(ConnectionState.closing); new ConnectionWaiter(ably.connection).waitFor(ConnectionState.connected); - assertEquals(List.of(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates); + assertEquals(Arrays.asList(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates); assertEquals(ChannelState.initialized, channel.state); channel.attach(); @@ -2554,7 +2569,7 @@ public void connect_on_closing_client_should_reinitialize_channels() throws Ably assertNull(channel.reason); assertEquals(0, ably.connection.connectionManager.msgSerial); - assertEquals(List.of(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates); + assertEquals(Arrays.asList(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates); } } diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java index 78d2ea026..7cffb3940 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java @@ -11,6 +11,7 @@ import io.ably.lib.transport.ConnectionManager; import io.ably.lib.transport.ITransport; import io.ably.lib.transport.WebSocketTransport; +import io.ably.lib.types.ChannelOptions; import io.ably.lib.types.ClientOptions; import io.ably.lib.types.Message; import io.ably.lib.types.MessageExtras; @@ -20,6 +21,7 @@ import org.junit.Test; import org.junit.rules.Timeout; +import java.util.Collections; import java.util.Objects; import static org.junit.Assert.assertEquals; @@ -52,6 +54,8 @@ public void simple_delta_codec() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); + assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams()); + for (int i = 0; i < testData.length; i++) { channel.publish(Integer.toString(i), testData[i]); } @@ -90,14 +94,18 @@ private void delta_failure_recovery(final ITransport.Factory websocketFactory, S opts.transportFactory = websocketFactory; ably = new AblyRealtime(opts); - /* create a channel */ - final Channel channel = ably.channels.get("[?delta=vcdiff]" + testName); + ChannelOptions options = new ChannelOptions(); + options.params = Collections.singletonMap("delta", "vcdiff"); + /* create a channel with channelOptions set to vcdiff*/ + final Channel channel = ably.channels.get(testName, options); /* attach */ channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", channel.state, ChannelState.attached); + assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams()); + /* subscribe */ MessageWaiter messageWaiter = new MessageWaiter(channel); diff --git a/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java b/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java index 40d87748d..584a53f3c 100644 --- a/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java +++ b/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java @@ -87,7 +87,7 @@ public void rest_presencehistory_simple() { * Get presence history data in the forward direction and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_order_f() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -114,7 +114,7 @@ public void rest_presencehistory_order_f() { * Get presence history data in the backwards direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_order_b() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -141,7 +141,7 @@ public void rest_presencehistory_order_b() { * Get limited presence history data in the forward direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_limit_f() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -168,7 +168,7 @@ public void rest_presencehistory_limit_f() { * Get limited presence history data in the backwards direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_limit_b() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -195,7 +195,7 @@ public void rest_presencehistory_limit_b() { * Get paginated presence history data in the forward direction using text protocol * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_paginate_f() { /* get channel */ String channelName = "persisted:restpresence_persisted"; @@ -263,7 +263,7 @@ public void rest_presencehistory_paginate_f() { * Get paginated presence history data in the backwards direction using text protocol * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_paginate_text_b() { /* get channel */ String channelName = "persisted:restpresence_persisted";