From 82117c51c96086cb7afee71497ca46649bda43cf Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Fri, 12 Jul 2024 12:37:12 +0100 Subject: [PATCH] fix: Make timestamp optional in Conversion API --- CHANGELOG.md | 1 + .../client/conversion/ConversionRequest.java | 12 +++++++++- .../conversion/ConversionClientTest.java | 24 +++++++++---------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1b40fb77..461bfd17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). # [8.9.2] - 2024-07-12 - Refactoring to accommodate using v2.0.0 of Vonage JWT library +- Made `timestamp` optional in Conversion API - Fixed `SpeechSettings.Language.NEPALI` (de)serialisation - `fromRandomNumber` true if `from` is not specified in `Call.Builder` - Fixed `com.vonage.client.voice.EventWebhook` deserialisation issue diff --git a/src/main/java/com/vonage/client/conversion/ConversionRequest.java b/src/main/java/com/vonage/client/conversion/ConversionRequest.java index 79a6104d2..b0dbe9f63 100644 --- a/src/main/java/com/vonage/client/conversion/ConversionRequest.java +++ b/src/main/java/com/vonage/client/conversion/ConversionRequest.java @@ -21,6 +21,11 @@ import java.util.LinkedHashMap; import java.util.Map; +/** + * + * @deprecated This class will be made package-private in the next major release. + */ +@Deprecated public class ConversionRequest implements QueryParamsRequest { private final Type type; private final String messageId; @@ -55,10 +60,15 @@ public Map makeParams() { LinkedHashMap params = new LinkedHashMap<>(4); params.put("message-id", messageId); params.put("delivered", String.valueOf(delivered)); - params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp)); + if (timestamp != null) { + params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp)); + } return params; } + /** + * This enum will be moved to its own class in the next major release. + */ public enum Type { SMS, VOICE } diff --git a/src/test/java/com/vonage/client/conversion/ConversionClientTest.java b/src/test/java/com/vonage/client/conversion/ConversionClientTest.java index 9444e3f53..de6c72e67 100644 --- a/src/test/java/com/vonage/client/conversion/ConversionClientTest.java +++ b/src/test/java/com/vonage/client/conversion/ConversionClientTest.java @@ -28,10 +28,7 @@ import org.junit.jupiter.api.*; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; public class ConversionClientTest extends AbstractClientTest { @@ -40,21 +37,24 @@ public ConversionClientTest() { } @Test - public void testSuccessfulResponse() throws Exception { + public void testSuccessWithTimestamp() throws Exception { stubResponse(200); - client.submitConversion(ConversionRequest.Type.VOICE, - "MESSAGE-ID", - true, - new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-03-04 10:11:12")); + client.submitConversion(ConversionRequest.Type.VOICE, UUID.randomUUID().toString(), false, + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-03-04 10:11:12") + ); + } + + @Test + public void testSuccessWithoutTimestamp() throws Exception { + stubResponse(200); + client.submitConversion(ConversionRequest.Type.SMS, "MESSAGE-ID", true, null); } @Test public void testWrongCredentials() throws Exception { stubResponse(401); assertThrows(VonageApiResponseException.class, () -> client.submitConversion( - ConversionRequest.Type.SMS, - "MESSAGE-ID", - true, + ConversionRequest.Type.SMS, "MESSAGE-ID", true, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-03-04 10:11:12") )); }