From ffd01669037f25b3afb1cdc11030518783dbaa3d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 3 Sep 2024 09:01:51 +0200 Subject: [PATCH] fix (SMS/DryRun): Align SDK with update specs onto DryRun --- .../converters/DryRunDtoConverter.java | 2 +- .../sms/models/DryRunPerRecipientDetails.java | 81 ++++++++++++++++--- .../converters/DryRunDtoConverterTest.java | 9 +-- ...DryRun200ResponsePerRecipientInnerDto.java | 42 +++++----- .../models/dto/v1/DryRunResponseDtoTest.java | 6 +- .../domains/sms/v1/DryRunResponseDto.json | 2 +- 6 files changed, 101 insertions(+), 41 deletions(-) diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java index 16a41b34f..1b7669049 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverter.java @@ -22,7 +22,7 @@ public static DryRun convert(DryRun200ResponseDto dto) { private static DryRunPerRecipientDetails convert(DryRun200ResponsePerRecipientInnerDto dto) { return DryRunPerRecipientDetails.builder() .setRecipient(dto.getRecipient()) - .setMessagePart(dto.getMessagePart()) + .setNumberOfParts(dto.getNumberOfParts()) .setBody(dto.getBody()) .setEncoding(dto.getEncoding()) .build(); diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java b/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java index 2294adfeb..895f7ca8a 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/DryRunPerRecipientDetails.java @@ -8,30 +8,79 @@ public class DryRunPerRecipientDetails { private final String recipient; - private final String messagePart; + private final Integer numberOfParts; private final String body; private final String encoding; + /** + * Due to unused messagePart field, prefer the numberOfParts version + * usage. + * + *

This constructor will be removed in a next major release + * + * @deprecated + */ + @Deprecated public DryRunPerRecipientDetails( String recipient, String messagePart, String body, String encoding) { this.recipient = recipient; - this.messagePart = messagePart; + this.numberOfParts = null; this.body = body; this.encoding = encoding; } + public DryRunPerRecipientDetails( + String recipient, Integer numberOfParts, String body, String encoding) { + this.recipient = recipient; + this.numberOfParts = numberOfParts; + this.body = body; + this.encoding = encoding; + } + + /** + * Get recipient + * + * @return recipient + */ public String getRecipient() { return recipient; } + /** + * Due to unused messagePart field, prefer the {@link #getNumberOfParts()} usage. + * + *

This function will be removed in a next major release + * + * @deprecated + */ + @Deprecated public String getMessagePart() { - return messagePart; + return null; } + /** + * Get number of parts + * + * @return number of parts + */ + public Integer getNumberOfParts() { + return numberOfParts; + } + + /** + * Get body + * + * @return body + */ public String getBody() { return body; } + /** + * Get encoding + * + * @return encoding + */ public String getEncoding() { return encoding; } @@ -42,8 +91,8 @@ public String toString() { + "recipient='" + recipient + '\'' - + ", messagePart='" - + messagePart + + ", numberOfParts='" + + numberOfParts + '\'' + ", body='" + body @@ -61,7 +110,7 @@ public static Builder builder() { public static class Builder { private String recipient; - private String messagePart; + private Integer numberOfParts; private String body; private String encoding; @@ -70,8 +119,22 @@ public Builder setRecipient(String recipient) { return this; } - public Builder setMessagePart(String messagePart) { - this.messagePart = messagePart; + /** + * Due to unused messagePart field, prefer the {@link #setNumberOfParts(Integer)} + * usage. + * + *

This function will be removed in a next major release + * + * @deprecated + */ + @Deprecated + public Builder setMessagePart(String messageParts) { + // Do nothing + return this; + } + + public Builder setNumberOfParts(Integer numberOfParts) { + this.numberOfParts = numberOfParts; return this; } @@ -88,7 +151,7 @@ public Builder setEncoding(String encoding) { private Builder() {} public DryRunPerRecipientDetails build() { - return new DryRunPerRecipientDetails(recipient, messagePart, body, encoding); + return new DryRunPerRecipientDetails(recipient, numberOfParts, body, encoding); } } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java index 51e02ecae..4f53ccaa1 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java @@ -1,10 +1,9 @@ package com.sinch.sdk.domains.sms.adapters.converters; -import static org.assertj.core.api.Assertions.assertThat; - 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.TestHelpers; import com.sinch.sdk.domains.sms.models.DryRun; import com.sinch.sdk.domains.sms.models.DryRunPerRecipientDetails; import com.sinch.sdk.domains.sms.models.dto.v1.DryRun200ResponseDto; @@ -25,7 +24,7 @@ public class DryRunDtoConverterTest extends BaseTest { Collections.singletonList( DryRunPerRecipientDetails.builder() .setRecipient("recipient string") - .setMessagePart("message part string") + .setNumberOfParts(1) .setBody("body string") .setEncoding("encoding string") .build())) @@ -33,8 +32,6 @@ public class DryRunDtoConverterTest extends BaseTest { @Test void testConvertDryRun() { - assertThat(DryRunDtoConverter.convert(loadedDto)) - .usingRecursiveComparison() - .isEqualTo(dryRunClient); + TestHelpers.recursiveEquals(DryRunDtoConverter.convert(loadedDto), dryRunClient); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRun200ResponsePerRecipientInnerDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRun200ResponsePerRecipientInnerDto.java index 84d608ecb..f1d9431aa 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRun200ResponsePerRecipientInnerDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/DryRun200ResponsePerRecipientInnerDto.java @@ -22,7 +22,7 @@ /** DryRun200ResponsePerRecipientInnerDto */ @JsonPropertyOrder({ DryRun200ResponsePerRecipientInnerDto.JSON_PROPERTY_RECIPIENT, - DryRun200ResponsePerRecipientInnerDto.JSON_PROPERTY_MESSAGE_PART, + DryRun200ResponsePerRecipientInnerDto.JSON_PROPERTY_NUMBER_OF_PARTS, DryRun200ResponsePerRecipientInnerDto.JSON_PROPERTY_BODY, DryRun200ResponsePerRecipientInnerDto.JSON_PROPERTY_ENCODING }) @@ -34,9 +34,9 @@ public class DryRun200ResponsePerRecipientInnerDto { private String recipient; private boolean recipientDefined = false; - public static final String JSON_PROPERTY_MESSAGE_PART = "message_part"; - private String messagePart; - private boolean messagePartDefined = false; + public static final String JSON_PROPERTY_NUMBER_OF_PARTS = "number_of_parts"; + private Integer numberOfParts; + private boolean numberOfPartsDefined = false; public static final String JSON_PROPERTY_BODY = "body"; private String body; @@ -77,33 +77,33 @@ public void setRecipient(String recipient) { this.recipientDefined = true; } - public DryRun200ResponsePerRecipientInnerDto messagePart(String messagePart) { - this.messagePart = messagePart; - this.messagePartDefined = true; + public DryRun200ResponsePerRecipientInnerDto numberOfParts(Integer numberOfParts) { + this.numberOfParts = numberOfParts; + this.numberOfPartsDefined = true; return this; } /** - * Get messagePart + * Get number of parts * - * @return messagePart + * @return number of parts */ - @JsonProperty(JSON_PROPERTY_MESSAGE_PART) + @JsonProperty(JSON_PROPERTY_NUMBER_OF_PARTS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public String getMessagePart() { - return messagePart; + public Integer getNumberOfParts() { + return numberOfParts; } @JsonIgnore - public boolean getMessagePartDefined() { - return messagePartDefined; + public boolean getNumberOfPartsDefined() { + return numberOfPartsDefined; } - @JsonProperty(JSON_PROPERTY_MESSAGE_PART) + @JsonProperty(JSON_PROPERTY_NUMBER_OF_PARTS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public void setMessagePart(String messagePart) { - this.messagePart = messagePart; - this.messagePartDefined = true; + public void setNumberOfParts(Integer numberOfParts) { + this.numberOfParts = numberOfParts; + this.numberOfPartsDefined = true; } public DryRun200ResponsePerRecipientInnerDto body(String body) { @@ -176,14 +176,14 @@ public boolean equals(Object o) { DryRun200ResponsePerRecipientInnerDto dryRun200ResponsePerRecipientInner = (DryRun200ResponsePerRecipientInnerDto) o; return Objects.equals(this.recipient, dryRun200ResponsePerRecipientInner.recipient) - && Objects.equals(this.messagePart, dryRun200ResponsePerRecipientInner.messagePart) + && Objects.equals(this.numberOfParts, dryRun200ResponsePerRecipientInner.numberOfParts) && Objects.equals(this.body, dryRun200ResponsePerRecipientInner.body) && Objects.equals(this.encoding, dryRun200ResponsePerRecipientInner.encoding); } @Override public int hashCode() { - return Objects.hash(recipient, messagePart, body, encoding); + return Objects.hash(recipient, numberOfParts, body, encoding); } @Override @@ -191,7 +191,7 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class DryRun200ResponsePerRecipientInnerDto {\n"); sb.append(" recipient: ").append(toIndentedString(recipient)).append("\n"); - sb.append(" messagePart: ").append(toIndentedString(messagePart)).append("\n"); + sb.append(" numberOfParts: ").append(toIndentedString(numberOfParts)).append("\n"); sb.append(" body: ").append(toIndentedString(body)).append("\n"); sb.append(" encoding: ").append(toIndentedString(encoding)).append("\n"); sb.append("}"); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java index 4ca65dc4c..5150bad2f 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java @@ -5,8 +5,8 @@ import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; import java.util.Collections; -import org.assertj.core.api.Assertions; import org.json.JSONException; import org.junit.jupiter.api.Test; import org.skyscreamer.jsonassert.JSONAssert; @@ -28,14 +28,14 @@ class DryRunResponseDtoTest extends BaseTest { Collections.singletonList( new DryRun200ResponsePerRecipientInnerDto() .recipient("recipient string") - .messagePart("message part string") + .numberOfParts(1) .body("body string") .encoding("encoding string"))); @Test void deserialize() { - Assertions.assertThat(loadedDto).usingRecursiveComparison().isEqualTo(dto); + TestHelpers.recursiveEquals(loadedDto, dto); } @Test diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json index 10d9dbe1b..0e437b529 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json @@ -4,7 +4,7 @@ "per_recipient": [ { "recipient": "recipient string", - "message_part": "message part string", + "number_of_parts": 1, "body": "body string", "encoding": "encoding string" }