From 787b0713f5560a2e0d64f432f24955dc58aa15dc Mon Sep 17 00:00:00 2001 From: Sina Madani Date: Thu, 17 Oct 2024 16:52:35 +0100 Subject: [PATCH] feat: Add Voice.leg_persistence_time field --- .../application/capabilities/Voice.java | 32 +++++++++++++++++-- .../application/ApplicationClientTest.java | 2 ++ .../application/capabilities/VoiceTest.java | 26 +++++++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/vonage/client/application/capabilities/Voice.java b/src/main/java/com/vonage/client/application/capabilities/Voice.java index f7410f539..f1be59420 100644 --- a/src/main/java/com/vonage/client/application/capabilities/Voice.java +++ b/src/main/java/com/vonage/client/application/capabilities/Voice.java @@ -24,7 +24,7 @@ public final class Voice extends Capability { private Region region; private Boolean signedCallbacks; - private Integer conversationsTtl; + private Integer conversationsTtl, legPersistenceTime; private Voice() { } @@ -36,6 +36,9 @@ private Voice(Builder builder) { if ((conversationsTtl = builder.conversationsTtl) != null && (conversationsTtl < 0 || conversationsTtl > 744)) { throw new IllegalArgumentException("Conversations TTL cannot be negative."); } + if ((legPersistenceTime = builder.legPersistenceTime) != null && (legPersistenceTime < 0 || legPersistenceTime > 31)) { + throw new IllegalArgumentException("Leg persistence time must be positive and less than 31 days."); + } } /** @@ -77,6 +80,18 @@ public Integer getConversationsTtl() { return conversationsTtl; } + /** + * Persistence duration for conversation legs, in days. Maximum value is 31, default is 7. + * + * @return The leg persistence time in dats as an integer, or {@code null} if unknown. + * + * @since 8.12.0 + */ + @JsonProperty("leg_persistence_time") + public Integer getLegPersistenceTime() { + return legPersistenceTime; + } + @Override public Type getType() { return Type.VOICE; @@ -94,7 +109,7 @@ public static Builder builder() { public static class Builder extends Capability.Builder { private Region region; private Boolean signedCallbacks; - private Integer conversationsTtl; + private Integer conversationsTtl, legPersistenceTime; /** * Selecting a region means all inbound, programmable SIP and SIP connect calls will be sent to the selected @@ -140,6 +155,19 @@ public Builder conversationsTtl(int ttl) { return this; } + /** + * Persistence duration for conversation legs, in days. Maximum value is 31, default is 7. + * + * @param legPersistenceTime The leg persistence time in days. + * + * @return This builder. + * @since 8.12.0 + */ + public Builder legPersistenceTime(int legPersistenceTime) { + this.legPersistenceTime = legPersistenceTime; + return this; + } + @Override public Builder addWebhook(Webhook.Type type, Webhook webhook) { return super.addWebhook(type, webhook); diff --git a/src/test/java/com/vonage/client/application/ApplicationClientTest.java b/src/test/java/com/vonage/client/application/ApplicationClientTest.java index 1f2db3f2b..9eb839c83 100644 --- a/src/test/java/com/vonage/client/application/ApplicationClientTest.java +++ b/src/test/java/com/vonage/client/application/ApplicationClientTest.java @@ -57,6 +57,7 @@ public class ApplicationClientTest extends AbstractClientTest " \"payment_enabled\": false,\n" + " \"signed_callbacks\": true,\n" + " \"conversations_ttl\": 24,\n" + + " \"leg_persistence_time\": 7,\n" + " \"region\": \"eu-west\",\n" + " \"payments\": {\n" + " \"gateways\": []\n" + @@ -130,6 +131,7 @@ static void assertEqualsSampleApplication(Application response) { assertEquals(3000, fallback.getSocketTimeout().intValue()); assertEquals(Region.EU_WEST, voice.getRegion()); assertEquals(24, voice.getConversationsTtl().intValue()); + assertEquals(7, voice.getLegPersistenceTime().intValue()); assertTrue(voice.getSignedCallbacks()); Messages message = capabilities.getMessages(); diff --git a/src/test/java/com/vonage/client/application/capabilities/VoiceTest.java b/src/test/java/com/vonage/client/application/capabilities/VoiceTest.java index 6878cf525..8600784c7 100644 --- a/src/test/java/com/vonage/client/application/capabilities/VoiceTest.java +++ b/src/test/java/com/vonage/client/application/capabilities/VoiceTest.java @@ -30,6 +30,10 @@ public void testEmpty() { assertEquals(Capability.Type.VOICE, voice.getType()); assertNull(voice.getWebhooks()); + assertNull(voice.getRegion()); + assertNull(voice.getSignedCallbacks()); + assertNull(voice.getConversationsTtl()); + assertNull(voice.getLegPersistenceTime()); } @Test @@ -70,11 +74,15 @@ public void testRemoveWebhook() { .addWebhook(Webhook.Type.ANSWER, new Webhook("https://example.com/answer", HttpMethod.POST)) .addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET)) .removeWebhook(Webhook.Type.ANSWER) + .legPersistenceTime(3).signedCallbacks(false) .build(); assertEquals(Capability.Type.VOICE, voice.getType()); assertEquals("https://example.com/event", voice.getWebhooks().get(Webhook.Type.EVENT).getAddress()); assertEquals(HttpMethod.GET, voice.getWebhooks().get(Webhook.Type.EVENT).getMethod()); + assertNull(voice.getWebhooks().get(Webhook.Type.ANSWER)); + assertEquals(3, voice.getLegPersistenceTime()); + assertFalse(voice.getSignedCallbacks()); } @Test @@ -119,13 +127,18 @@ public void testWebhookProperties() { @Test public void testSerializeAdditionalFields() { Voice request = Voice.builder() - .conversationsTtl(51).signedCallbacks(false).region(Region.APAC_SNG).build(); + .conversationsTtl(51) + .signedCallbacks(false) + .region(Region.APAC_SNG) + .legPersistenceTime(14) + .build(); class Internal implements Jsonable { @JsonProperty final Voice voice = request; } String expectedJson = "{\"voice\":{" + - "\"region\":\"apac-sng\",\"signed_callbacks\":false,\"conversations_ttl\":51}}"; + "\"region\":\"apac-sng\",\"signed_callbacks\":false,\"conversations_ttl\":51" + + ",\"leg_persistence_time\":14}}"; assertEquals(expectedJson, new Internal().toJson()); } @@ -137,4 +150,13 @@ public void testConversationsTtlBounds() { assertThrows(IllegalArgumentException.class, () -> Voice.builder().conversationsTtl(min-1).build()); assertThrows(IllegalArgumentException.class, () -> Voice.builder().conversationsTtl(max+1).build()); } + + @Test + public void testLegPersistenceTimeBounds() { + Integer min = 0, max = 31; + assertEquals(min, Voice.builder().legPersistenceTime(min).build().getLegPersistenceTime()); + assertEquals(max, Voice.builder().legPersistenceTime(max).build().getLegPersistenceTime()); + assertThrows(IllegalArgumentException.class, () -> Voice.builder().legPersistenceTime(min-1).build()); + assertThrows(IllegalArgumentException.class, () -> Voice.builder().legPersistenceTime(max+1).build()); + } }