From 45aeed91e7039c69b08ff9a4e7a3234ec8e3f259 Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Mon, 6 Jul 2020 08:52:43 +0100 Subject: [PATCH 1/3] Update 'protocol' API version to match client version major.minor. --- lib/src/main/java/io/ably/lib/transport/Defaults.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/io/ably/lib/transport/Defaults.java b/lib/src/main/java/io/ably/lib/transport/Defaults.java index 2530ce107..6f288a309 100644 --- a/lib/src/main/java/io/ably/lib/transport/Defaults.java +++ b/lib/src/main/java/io/ably/lib/transport/Defaults.java @@ -7,7 +7,7 @@ public class Defaults { /* versions */ - public static final float ABLY_VERSION_NUMBER = 1.0f; + public static final float ABLY_VERSION_NUMBER = 1.2f; public static final String ABLY_VERSION = new DecimalFormat("0.0").format(ABLY_VERSION_NUMBER); public static final String ABLY_LIB_VERSION = String.format("%s-%s", BuildConfig.LIBRARY_NAME, BuildConfig.VERSION); From 032dc75b4f87dfd459d0becf23cbcccf0fb55dd0 Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Mon, 6 Jul 2020 09:09:59 +0100 Subject: [PATCH 2/3] Refactor existing system tests to make them more fragile. The aim is to make protocol version bump oversights easier to spot in future. --- .../test/realtime/RealtimeHttpHeaderTest.java | 20 ++++++++++++------- .../io/ably/lib/test/rest/HttpHeaderTest.java | 16 +++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeHttpHeaderTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeHttpHeaderTest.java index f36ff7380..22685a406 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeHttpHeaderTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeHttpHeaderTest.java @@ -79,13 +79,19 @@ public void realtime_websocket_param_test() { assertEquals("Verify correct key param", requestParameters.get("key"), Collections.singletonList(key)); - /* Spec RTN2f */ - assertEquals("Verify correct version", requestParameters.get(Defaults.ABLY_VERSION_PARAM), - Collections.singletonList(Defaults.ABLY_VERSION)); - - /* Spec RTN2g */ - assertEquals("Verify correct lib version", requestParameters.get(Defaults.ABLY_LIB_PARAM), - Collections.singletonList(Defaults.ABLY_LIB_VERSION)); + /* Spec RTN2f + * This test should not directly validate version against Defaults.ABLY_VERSION, nor + * Defaults.ABLY_VERSION_PARAM, as ultimately the request param has been derived from those values. + */ + assertEquals("Verify correct version", requestParameters.get("v"), + Collections.singletonList("1.2")); + + /* Spec RTN2g + * This test should not directly validate version against Defaults.ABLY_LIB_VERSION, nor + * Defaults.ABLY_LIB_PARAM, as ultimately the request param has been derived from those values. + */ + assertEquals("Verify correct lib version", requestParameters.get("lib"), + Collections.singletonList("java-1.2.1")); /* Spec RTN2a */ assertEquals("Verify correct format", requestParameters.get("format"), diff --git a/lib/src/test/java/io/ably/lib/test/rest/HttpHeaderTest.java b/lib/src/test/java/io/ably/lib/test/rest/HttpHeaderTest.java index 9fdddeb32..47a98360e 100644 --- a/lib/src/test/java/io/ably/lib/test/rest/HttpHeaderTest.java +++ b/lib/src/test/java/io/ably/lib/test/rest/HttpHeaderTest.java @@ -77,16 +77,14 @@ public void header_lib_channel_publish() { /* Get last headers */ Map headers = server.getHeaders(); - /* Prepare checked header */ - String ably_version_header = Defaults.ABLY_VERSION_HEADER.toLowerCase(); - String ably_lib_header = Defaults.ABLY_LIB_HEADER.toLowerCase(); - - /* Check header */ + /* Check header + * This test should not directly validate version against Defaults.ABLY_VERSION, Defaults.ABLY_LIB_VERSION, + * Defaults.ABLY_VERSION_HEADER, nor Defaults.ABLY_LIB_HEADER, as ultimately these headers have been derived + * from those values. + */ Assert.assertNotNull("Expected headers", headers); - Assert.assertTrue(String.format("Expected header %s", Defaults.ABLY_VERSION_HEADER), headers.containsKey(ably_version_header)); - Assert.assertEquals(headers.get(ably_version_header), Defaults.ABLY_VERSION); - Assert.assertTrue(String.format("Expected header %s", Defaults.ABLY_LIB_HEADER), headers.containsKey(ably_lib_header)); - Assert.assertEquals(headers.get(ably_lib_header), Defaults.ABLY_LIB_VERSION); + Assert.assertEquals(headers.get("x-ably-version"), "1.2"); + Assert.assertEquals(headers.get("x-ably-lib"), "java-1.2.1"); } catch (AblyException e) { e.printStackTrace(); Assert.fail("header_lib_channel_publish: Unexpected exception"); From 090eba21c2d4148dac0fd3c514c5798c41a4037e Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Mon, 6 Jul 2020 09:18:05 +0100 Subject: [PATCH 3/3] Introduce a pure unit testing 'suite' for the ARTDefault class. Small for now as it's targeting the issue I'm working on right now, however this will grow. --- .../java/io/ably/lib/transport/DefaultsTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/src/test/java/io/ably/lib/transport/DefaultsTest.java diff --git a/lib/src/test/java/io/ably/lib/transport/DefaultsTest.java b/lib/src/test/java/io/ably/lib/transport/DefaultsTest.java new file mode 100644 index 000000000..f33623636 --- /dev/null +++ b/lib/src/test/java/io/ably/lib/transport/DefaultsTest.java @@ -0,0 +1,12 @@ +package io.ably.lib.transport; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DefaultsTest { + @Test + public void versions() { + assertEquals("1.2", Defaults.ABLY_VERSION); + } +}