Skip to content

Commit

Permalink
Merge pull request #141 from sinch/DEVEXP-533-SMS-specs-update
Browse files Browse the repository at this point in the history
DEVEXP-533:  Align SDK with updated specs onto DryRun
  • Loading branch information
JPPortier committed Sep 3, 2024
2 parents 9ba0cfe + ffd0166 commit 17c7bf8
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>messagePart</code> field, prefer the <code>numberOfParts</code> version
* usage.
*
* <p>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 <code>messagePart</code> field, prefer the {@link #getNumberOfParts()} usage.
*
* <p>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;
}
Expand All @@ -42,8 +91,8 @@ public String toString() {
+ "recipient='"
+ recipient
+ '\''
+ ", messagePart='"
+ messagePart
+ ", numberOfParts='"
+ numberOfParts
+ '\''
+ ", body='"
+ body
Expand All @@ -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;

Expand All @@ -70,8 +119,22 @@ public Builder setRecipient(String recipient) {
return this;
}

public Builder setMessagePart(String messagePart) {
this.messagePart = messagePart;
/**
* Due to unused <code>messagePart</code> field, prefer the {@link #setNumberOfParts(Integer)}
* usage.
*
* <p>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;
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,16 +24,14 @@ 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()))
.build();

@Test
void testConvertDryRun() {
assertThat(DryRunDtoConverter.convert(loadedDto))
.usingRecursiveComparison()
.isEqualTo(dryRunClient);
TestHelpers.recursiveEquals(DryRunDtoConverter.convert(loadedDto), dryRunClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -176,22 +176,22 @@ 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
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("}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"per_recipient": [
{
"recipient": "recipient string",
"message_part": "message part string",
"number_of_parts": 1,
"body": "body string",
"encoding": "encoding string"
}
Expand Down

0 comments on commit 17c7bf8

Please sign in to comment.