From 36ee41138457e78582a70644d9ef8e870d46902d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 30 Sep 2024 18:07:35 +0200 Subject: [PATCH] fix (SMS): DEVEXP-587 Fix invalid class definition for 'parameters' enabling list of parameters grouped by duplicated keys --- .../converters/ParametersDtoConverter.java | 101 ++++++++++-------- .../sdk/domains/sms/models/Parameters.java | 10 +- .../sms/adapters/BatchesServiceTest.java | 31 +++--- .../converters/BatchDtoConverterTest.java | 66 ++++-------- .../domains/sms/models/ParametersTest.java | 33 ++++-- .../models/dto/v1/BinaryResponseDtoTest.java | 2 +- .../models/dto/v1/MediaResponseDtoTest.java | 26 ++--- .../models/dto/v1/SendSMSRequestDtoTest.java | 33 +++--- .../models/dto/v1/SendSMSResponseDtoTest.java | 30 +++--- .../models/dto/v1/TextResponseDtoTest.java | 26 ++--- .../dto/v1/UpdateSMSRequestDtoTest.java | 33 +++--- .../domains/sms/v1/BinaryResponseDto.json | 2 +- .../domains/sms/v1/MediaResponseDto.json | 10 +- .../sms/v1/SendSMSBinaryRequestDto.json | 4 +- .../sms/v1/SendSMSMediaRequestDto.json | 12 ++- .../domains/sms/v1/SendSMSTextRequestDto.json | 12 ++- .../domains/sms/v1/TextResponseDto.json | 10 +- .../sms/v1/UpdateSMSBinaryRequestDto.json | 2 +- .../sms/v1/UpdateSMSMediaRequestDto.json | 10 +- .../sms/v1/UpdateSMSTextRequestDto.json | 10 +- 20 files changed, 241 insertions(+), 222 deletions(-) diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java index a82be3561..95350fc2a 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/ParametersDtoConverter.java @@ -2,11 +2,15 @@ import com.sinch.sdk.core.utils.Pair; import com.sinch.sdk.domains.sms.models.Parameters; +import com.sinch.sdk.domains.sms.models.Parameters.Entry; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.stream.Collectors; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; public class ParametersDtoConverter { @@ -14,38 +18,11 @@ public static Parameters convert(ParameterObjDto dto) { if (null == dto) { return null; } - return new Parameters( - dto.entrySet().stream() - .map( - entry -> { - @SuppressWarnings("unchecked") - Map entryValue = (Map) entry.getValue(); - return new Parameters.Entry( - entry.getKey(), - entryValue.entrySet().stream() - .filter( - value -> - value - .getKey() - .compareTo( - ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT) - != 0) - .map(e -> new Pair<>(e.getKey(), e.getValue())) - .findFirst() - .orElse(null), - entryValue.entrySet().stream() - .filter( - value -> - value - .getKey() - .compareTo( - ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT) - == 0) - .map(Map.Entry::getValue) - .findFirst() - .orElse(null)); - }) - .collect(Collectors.toList())); + + ArrayList client = new ArrayList<>(); + dto.forEach((key, value) -> client.addAll(convertParameters(key, value))); + + return new Parameters(client); } public static ParameterObjDto convert(Parameters parameters) { @@ -54,18 +31,52 @@ public static ParameterObjDto convert(Parameters parameters) { parameters .entrySet() .iterator() - .forEachRemaining( - entry -> { - Map obj = new HashMap<>(); - Pair pair = entry.getValue().getValue(); - obj.put(pair.getLeft(), pair.getRight()); - entry - .getValue() - .getDefaultValue() - .ifPresent( - def -> obj.put(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, def)); - dto.put(entry.getKey(), obj); - }); + .forEachRemaining(entries -> dto.put(entries.getKey(), convert(entries.getValue()))); + return dto; + } + + public static HashMap convert(Collection client) { + if (null == client) { + return null; + } + HashMap dto = new HashMap<>(); + + client.forEach( + entry -> { + dto.put(entry.getValue().getLeft(), entry.getValue().getRight()); + entry + .getDefaultValue() + .ifPresent(def -> dto.put(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, def)); + }); return dto; } + + public static Collection convertParameters(String parameterName, Object _dto) { + if (!(_dto instanceof Map)) { + return null; + } + ArrayList client = new ArrayList<>(); + + @SuppressWarnings("unchecked") + Map dto = (Map) _dto; + + AtomicReference> defValue = + new AtomicReference<>( + dto.entrySet().stream() + .filter( + entry -> + entry.getKey().equals(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT)) + .map(Map.Entry::getValue) + .findFirst()); + + dto.forEach( + (key, value) -> { + if (!key.equals(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT)) { + client.add( + new Entry(parameterName, new Pair<>(key, value), defValue.get().orElse(null))); + defValue.set(Optional.empty()); + } + }); + return client; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/Parameters.java b/client/src/main/com/sinch/sdk/domains/sms/models/Parameters.java index 45e7209b7..c8e6b90a2 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/Parameters.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/Parameters.java @@ -3,15 +3,19 @@ import com.sinch.sdk.core.utils.Pair; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class Parameters extends HashMap { +public class Parameters extends HashMap> { private static final long serialVersionUID = 1L; - public Parameters(Collection list) { - super(list.stream().collect(Collectors.toMap(entry -> entry.key, entry -> entry))); + /** + * @throws NullPointerException – if the specified map is null + */ + public Parameters(Collection list) throws NullPointerException { + super(list.stream().collect(Collectors.groupingBy(Parameters.Entry::getKey))); } public static class Entry { diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index 2018a5078..c1f461e02 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -27,8 +27,6 @@ import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto; import com.sinch.sdk.domains.sms.models.dto.v1.ApiDeliveryFeedbackDto; import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; -import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; -import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest; import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchMediaRequest; @@ -73,7 +71,7 @@ public class BatchesServiceTest extends BaseTest { static final int fromTon = 6; static final int fromNpi = 18; static final String udh = "foo udh"; - static final String body = "Hi ${name}! How are you?"; + static final String body = "Hi ${name} ({an identifier}) ! How are you?"; public static final BatchBinary batchBinary = BatchBinary.builder() .setId(id) @@ -99,16 +97,17 @@ public class BatchesServiceTest extends BaseTest { static final Parameters parameters = new Parameters( Arrays.asList( - new Parameters.Entry("an identifier", new Pair<>("a key", "a value")), new Parameters.Entry( - ParameterObjDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, - new Pair<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), - "default value"))); - public final BatchMedia batchMedia = + "name", new Pair<>("15551231234", "name value for 15551231234"), "default value"), + new Parameters.Entry("name", new Pair<>("15551256344", "name value for 15551256344")), + new Parameters.Entry( + "an identifier", + new Pair<>("15551231234", "an identifier value for 15551231234")), + new Parameters.Entry( + "an identifier", + new Pair<>("15551256344", "an identifier value for 15551256344")))); + + public static final BatchMedia batchMedia = BatchMedia.builder() .setId(id) .setTo(to) @@ -117,7 +116,7 @@ public class BatchesServiceTest extends BaseTest { .setBody( new MediaBody( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", - "Media message from Sinch!")) + "Hi ${name} ({an identifier}) ! How are you?")) .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) .setDeliveryReport(DeliveryReportType.SUMMARY) @@ -128,7 +127,7 @@ public class BatchesServiceTest extends BaseTest { .setFeedbackEnabled(feedbackEnabled) .setParameters(parameters) .build(); - public final BatchText batchText = + public static final BatchText batchText = BatchText.builder() .setId(id) .setTo(to) @@ -177,7 +176,7 @@ public class BatchesServiceTest extends BaseTest { .setBody( new MediaBody( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", - "Media message from Sinch!")) + "Hi ${name} ({an identifier}) ! How are you?")) .setDeliveryReport(DeliveryReportType.SUMMARY) .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) @@ -225,7 +224,7 @@ public class BatchesServiceTest extends BaseTest { .setBody( new MediaBody( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", - "Media message from Sinch!")) + body)) .setDeliveryReport(DeliveryReportType.SUMMARY) .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index c25e5605e..b5428ace0 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -2,32 +2,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertInstanceOf; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; -import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.sms.adapters.BatchesServiceTest; import com.sinch.sdk.domains.sms.models.Batch; import com.sinch.sdk.domains.sms.models.BatchBinary; import com.sinch.sdk.domains.sms.models.BatchMedia; import com.sinch.sdk.domains.sms.models.BatchText; -import com.sinch.sdk.domains.sms.models.Parameters; import com.sinch.sdk.domains.sms.models.dto.v1.BinaryResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.MediaResponseDto; -import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjDto; -import com.sinch.sdk.domains.sms.models.dto.v1.ParameterObjParameterKeyDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.TextResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto; import java.util.Arrays; import java.util.Collection; -import java.util.Map; -import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -113,7 +106,7 @@ private static void compareMedia(BatchMedia client, MediaResponseDto dto) { Assertions.assertEquals(dto.getDeliveryReport(), client.getDeliveryReport().value()); assertEquals(dto.getSendAt().toInstant(), client.getSendAt()); assertEquals(dto.getExpireAt().toInstant(), client.getExpireAt()); - compareParameters(client.getParameters(), dto.getParameters()); + TestHelpers.recursiveEquals(client.getParameters(), dto.getParameters()); assertEquals(dto.getCallbackUrl(), client.getCallbackUrl()); assertEquals(dto.getClientReference(), client.getClientReference()); assertEquals(dto.getFeedbackEnabled(), client.isFeedbackEnabled()); @@ -136,46 +129,28 @@ private static void compareText(BatchText client, TextResponseDto dto) { assertEquals(dto.getFeedbackEnabled(), client.isFeedbackEnabled()); assertEquals(dto.getFlashMessage(), client.isFlashMessage()); assertEquals(dto.getTruncateConcat(), client.isTruncateConcat()); - compareParameters(client.getParameters(), dto.getParameters()); + TestHelpers.recursiveEquals(client.getParameters(), dto.getParameters()); assertEquals(dto.getMaxNumberOfMessageParts(), client.getMaxNumberOfMessageParts()); assertEquals(dto.getFromTon(), client.getFromTon()); assertEquals(dto.getFromNpi(), client.getFromNpi()); } - private static void compareParameters(Parameters client, ParameterObjDto dto) { - assertEquals(dto.size(), client.size()); - Collection values = client.values(); - values.forEach( - e -> { - Pair clientItem = e.getValue(); - assertTrue(dto.containsKey(e.getKey())); - @SuppressWarnings("unchecked") - Map dtoItem = (Map) dto.get(e.getKey()); - assertTrue(dtoItem.containsKey(clientItem.getLeft())); - assertEquals(dtoItem.get(clientItem.getLeft()), clientItem.getRight()); - Optional defaultValue = e.getDefaultValue(); - if (defaultValue.isPresent()) { - assertEquals( - dtoItem.get(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT), defaultValue.get()); - } else { - assertNull(dtoItem.get(ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT)); - } - }); - } - @Test void convertBinaryResponse() { - compareWithDto(BatchDtoConverter.convert(binaryResponseDto), binaryResponseDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(binaryResponseDto), BatchesServiceTest.batchBinary); } @Test void convertMediaResponse() { - compareWithDto(BatchDtoConverter.convert(mediaResponseDto), mediaResponseDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(mediaResponseDto), BatchesServiceTest.batchMedia); } @Test void convertTextResponse() { - compareWithDto(BatchDtoConverter.convert(textResponseDto), textResponseDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(textResponseDto), BatchesServiceTest.batchText); } @Test @@ -187,7 +162,7 @@ void convertSendBinaryRequest() { } @Test - void convertSendtediaRequest() { + void convertSendMediaRequest() { org.assertj.core.api.Assertions.assertThat( BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchMediaRequest)) .usingRecursiveComparison() @@ -204,26 +179,23 @@ void convertSendTextRequest() { @Test void convertUpdateTextRequest() { - org.assertj.core.api.Assertions.assertThat( - BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchTextRequest)) - .usingRecursiveComparison() - .isEqualTo(updateTextRequestDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchTextRequest), + updateTextRequestDto); } @Test void convertUpdateMediaRequest() { - org.assertj.core.api.Assertions.assertThat( - BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchMediaRequest)) - .usingRecursiveComparison() - .isEqualTo(updateMediaRequestDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchMediaRequest), + updateMediaRequestDto); } @Test void convertUpdateBinaryRequest() { - org.assertj.core.api.Assertions.assertThat( - BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchBinaryRequest)) - .usingRecursiveComparison() - .isEqualTo(updateBinaryRequestDto); + TestHelpers.recursiveEquals( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchBinaryRequest), + updateBinaryRequestDto); } @Test diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/ParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/ParametersTest.java index 638607f58..0e193f93d 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/ParametersTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/ParametersTest.java @@ -1,8 +1,9 @@ package com.sinch.sdk.domains.sms.models; +import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.utils.Pair; +import java.util.ArrayList; import java.util.Arrays; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; class ParametersTest { @@ -10,19 +11,33 @@ class ParametersTest { new Parameters( Arrays.asList( new Parameters.Entry("key 1", new Pair<>("value identifier1", "value 1")), + new Parameters.Entry( + "key 1", + new Pair<>("value identifier1 duplicated key", "value 1 duplicated key")), new Parameters.Entry( "key 2", new Pair<>("value identifier2", "value 2"), "default value for "))); @Test void getParameters() { - Assertions.assertThat(parameters.get("key 1")) - .usingRecursiveComparison() - .isEqualTo(new Parameters.Entry("key 1", new Pair<>("value identifier1", "value 1"))); - Assertions.assertThat(parameters.get("key 2")) - .usingRecursiveComparison() - .isEqualTo( - new Parameters.Entry( - "key 2", new Pair<>("value identifier2", "value 2"), "default value for ")); + TestHelpers.recursiveEquals( + parameters.get("key 2"), + new ArrayList( + Arrays.asList( + new Parameters.Entry( + "key 2", new Pair<>("value identifier2", "value 2"), "default value for ")))); + } + + @Test + void duplicatedKey() { + + TestHelpers.recursiveEquals( + parameters.get("key 1"), + new ArrayList( + Arrays.asList( + new Parameters.Entry("key 1", new Pair<>("value identifier1", "value 1")), + new Parameters.Entry( + "key 1", + new Pair<>("value identifier1 duplicated key", "value 1 duplicated key"))))); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java index b53a13c1c..b5d08594f 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java @@ -26,7 +26,7 @@ class BinaryResponseDtoTest extends BaseTest { false, OffsetDateTime.parse("2019-08-24T14:15:22Z"), OffsetDateTime.parse("2019-08-24T14:17:22Z")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .callbackUrl("callback url") .clientReference("myReference") .deliveryReport("none") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java index 680fa888d..83af2afdd 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java @@ -38,7 +38,7 @@ class MediaResponseDtoTest extends BaseTest { new MediaBodyDto() .url( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .message("Media message from Sinch!")) + .message("Hi ${name} ({an identifier}) ! How are you?")) .callbackUrl("callback url") .clientReference("client reference") .deliveryReport("summary") @@ -66,20 +66,20 @@ void serialize() throws JsonProcessingException, JSONException { @BeforeEach void setUp() { - Map entry1 = + parameterObjDto.put( + "an identifier", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + parameterObjDto.put( + "name", + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - Map entry2 = - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, entry1); - parameterObjDto.put("an identifier", entry2); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java index 8c3484bec..a1507cefa 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java @@ -31,7 +31,7 @@ void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { BinaryRequestDto binaryRequestDTO = new BinaryRequestDto() .to(Arrays.asList("+15551231234", "+15551256344")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .udh("foo udh") .from("+15551231234") .type("mt_binary") @@ -59,22 +59,24 @@ void serializeTextRequestDto() throws JsonProcessingException, JSONException { ParameterObjDto parameterObjDto = new ParameterObjDto(); parameterObjDto.put( "an identifier", - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + "name", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + TextRequestDto textRequestDTO = new TextRequestDto() .to(Arrays.asList("+15551231234", "+15551256344")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .from("+15551231234") .type("mt_text") .deliveryReport("none") @@ -103,15 +105,16 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { ParameterObjDto parameterObjDto = new ParameterObjDto(); parameterObjDto.put( "an identifier", - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + "name", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); @@ -123,7 +126,7 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { new MediaBodyDto() .url( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .message("Media message from Sinch!")) + .message("Hi ${name} ({an identifier}) ! How are you?")) .from("+15551231234") .deliveryReport("summary") .sendAt(OffsetDateTime.parse("2019-08-24T14:16:22Z")) diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java index 82c8b95ef..63284a7df 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java @@ -34,7 +34,7 @@ class SendSMSResponseDtoTest extends BaseTest { false, OffsetDateTime.parse("2019-08-24T14:15:22Z"), OffsetDateTime.parse("2019-08-24T14:17:22Z")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .callbackUrl("callback url") .clientReference("myReference") .deliveryReport("none") @@ -58,7 +58,7 @@ class SendSMSResponseDtoTest extends BaseTest { "mt_text", OffsetDateTime.parse("2019-08-24T14:15:22Z"), OffsetDateTime.parse("2019-08-24T14:17:22Z")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .callbackUrl("callback url") .clientReference("myReference") .deliveryReport("none") @@ -85,7 +85,7 @@ class SendSMSResponseDtoTest extends BaseTest { new MediaBodyDto() .url( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .message("Media message from Sinch!")) + .message("Hi ${name} ({an identifier}) ! How are you?")) .callbackUrl("callback url") .clientReference("client reference") .deliveryReport("summary") @@ -119,20 +119,20 @@ void deserializeMediaMessage() throws JsonProcessingException { @BeforeEach void setUp() { - Map entry1 = + parameterObjDto.put( + "an identifier", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + parameterObjDto.put( + "name", + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - Map entry2 = - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, entry1); - parameterObjDto.put("an identifier", entry2); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java index ee1d121ed..2f14db82f 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java @@ -34,7 +34,7 @@ class TextResponseDtoTest extends BaseTest { TextResponseDto.TypeEnum.MT_TEXT.getValue(), OffsetDateTime.parse("2019-08-24T14:15:22Z"), OffsetDateTime.parse("2019-08-24T14:17:22Z")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .callbackUrl("callback url") .clientReference("myReference") .deliveryReport("none") @@ -68,20 +68,20 @@ void serialize() throws JsonProcessingException, JSONException { @BeforeEach void setUp() { - Map entry1 = + parameterObjDto.put( + "an identifier", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + parameterObjDto.put( + "name", + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - Map entry2 = - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, entry1); - parameterObjDto.put("an identifier", entry2); + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java index 66bcddf65..27e7fb007 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java @@ -32,7 +32,7 @@ void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { new ApiUpdateBinaryMtMessageDto() .toAdd(Arrays.asList("+15551231234", "+15987365412")) .toRemove(Arrays.asList("+0123456789", "+9876543210")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .udh("foo udh") .from("+15551231234") .type("mt_binary") @@ -54,22 +54,24 @@ void serializeTextRequestDto() throws JsonProcessingException, JSONException { ParameterObjDto parameterObjDto = new ParameterObjDto(); parameterObjDto.put( "an identifier", - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + "name", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + ApiUpdateTextMtMessageDto textRequestDTO = new ApiUpdateTextMtMessageDto() .toAdd(Arrays.asList("+15551231234", "+15551256344")) - .body("Hi ${name}! How are you?") + .body("Hi ${name} ({an identifier}) ! How are you?") .from("+15551231234") .type("mt_text") .deliveryReport("none") @@ -92,15 +94,16 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { ParameterObjDto parameterObjDto = new ParameterObjDto(); parameterObjDto.put( "an identifier", - Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( - ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + "name", Stream.of( - new AbstractMap.SimpleEntry<>( - ParameterObjParameterKeyDto - .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, - "msisdn value"), + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), new AbstractMap.SimpleEntry<>( ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); @@ -113,7 +116,7 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { new MediaBodyDto() .url( "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .message("Media message from Sinch!")) + .message("Hi ${name} ({an identifier}) ! How are you?")) .from("+15551231234") .deliveryReport("summary") .sendAt(OffsetDateTime.parse("2019-08-24T14:16:22Z")) diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json index 662decb81..19ae8aefe 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json @@ -6,7 +6,7 @@ ], "from": "+15551231234", "canceled": false, - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_binary", "created_at": "2019-08-24T14:15:22Z", "modified_at": "2019-08-24T14:17:22Z", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json index 93cba6838..91949c129 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json @@ -7,16 +7,18 @@ "from": "+15551231234", "canceled": false, "body": { - "message": "Media message from Sinch!", + "message": "Hi ${name} ({an identifier}) ! How are you?", "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" }, "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } }, "type": "mt_media", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json index ce5ac53b4..04609a490 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json @@ -4,7 +4,7 @@ "+15551256344" ], "from": "+15551231234", - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_binary", "delivery_report": "none", "send_at": "2019-08-24T14:19:22Z", @@ -18,4 +18,4 @@ "from_ton": 6, "from_npi": 18, "udh": "foo udh" -} \ No newline at end of file +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json index ea7e7801d..b9622412d 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json @@ -5,16 +5,18 @@ ], "from": "+15551231234", "body": { - "message": "Media message from Sinch!", + "message": "Hi ${name} ({an identifier}) ! How are you?", "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" }, "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } }, "type": "mt_media", @@ -25,4 +27,4 @@ "client_reference": "client reference", "feedback_enabled": false, "strict_validation": true -} \ No newline at end of file +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json index 9d7ff8a6f..994648614 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json @@ -4,7 +4,7 @@ "+15551256344" ], "from": "+15551231234", - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_text", "delivery_report": "none", "send_at": "2019-08-24T14:19:22Z", @@ -18,12 +18,14 @@ "from_ton": 6, "from_npi": 18, "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } } -} \ No newline at end of file +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json index ed8445d8f..9d2da12be 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json @@ -7,15 +7,17 @@ "from": "+15551231234", "canceled": false, "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } }, - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_text", "created_at": "2019-08-24T14:15:22Z", "modified_at": "2019-08-24T14:17:22Z", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json index 2df9a741b..59d5d5e20 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json @@ -8,7 +8,7 @@ "+9876543210" ], "from": "+15551231234", - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_binary", "delivery_report": "full", "send_at": "2019-08-24T14:19:22Z", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json index a17cdf9f8..35b2002fd 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json @@ -5,16 +5,18 @@ ], "from": "+15551231234", "body": { - "message": "Media message from Sinch!", + "message": "Hi ${name} ({an identifier}) ! How are you?", "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" }, "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } }, "type": "mt_media", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json index fe5527255..8f61b228f 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json @@ -4,19 +4,21 @@ "+15551256344" ], "from": "+15551231234", - "body": "Hi ${name}! How are you?", + "body": "Hi ${name} ({an identifier}) ! How are you?", "type": "mt_text", "delivery_report": "none", "send_at": "2019-08-24T14:19:22Z", "expire_at": "2019-08-24T14:21:22Z", "callback_url": "callback url", "parameters": { - "{parameter_key}": { - "{msisdn}": "msisdn value", + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", "default": "default value" }, "an identifier": { - "a key": "a value" + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" } } } \ No newline at end of file