diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java index 7ec6593b..9afca142 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java @@ -126,7 +126,9 @@ public static class Builder extends BaseBatch.Builder { private Integer fromNpi; private String udh; - private Builder() {} + private Builder() { + super(); + } public Builder setFlashMessage(boolean flashMessage) { this.flashMessage = flashMessage; @@ -158,6 +160,7 @@ public Builder setUdh(String udh) { return this; } + @Override public SendSmsBatchBinaryRequest build() { return new SendSmsBatchBinaryRequest( to, diff --git a/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java b/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java index c5299955..5067b38e 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/VerificationsService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.verification; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse; /** * Verifications Service @@ -17,11 +18,11 @@ public interface VerificationsService { * Start verification * *

This method is used by the mobile and web Verification SDKs to start a verification. It can - * also be used to request a verification from your backend, by making an request. + * also be used to request a verification from your backend, by making a request. * - * @param parameters Parameters to be used to start verification return service instance for - * project + * @param parameters Parameters to be used to start verification + * @return Verification response * @since 1.0 */ - void start(StartVerificationRequestParameters parameters); + StartVerificationResponse start(StartVerificationRequestParameters parameters); } diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java index b7a66d54..3319feee 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/VerificationsService.java @@ -6,6 +6,7 @@ import com.sinch.sdk.domains.verification.adapters.api.v1.SendingAndReportingVerificationsApi; import com.sinch.sdk.domains.verification.adapters.converters.VerificationsDtoConverter; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse; import com.sinch.sdk.models.Configuration; import java.util.Map; @@ -27,7 +28,8 @@ private SendingAndReportingVerificationsApi getApi() { return this.api; } - public void start(StartVerificationRequestParameters parameters) { - getApi().startVerification(VerificationsDtoConverter.convert(parameters)); + public StartVerificationResponse start(StartVerificationRequestParameters parameters) { + return VerificationsDtoConverter.convert( + getApi().startVerification(VerificationsDtoConverter.convert(parameters))); } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverter.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverter.java new file mode 100644 index 00000000..80ee60fa --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverter.java @@ -0,0 +1,23 @@ +package com.sinch.sdk.domains.verification.adapters.converters; + +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.LinkRelType; +import com.sinch.sdk.domains.verification.models.dto.v1.VerificationResourceLinkDto; +import java.util.Collection; +import java.util.stream.Collectors; + +public class LinkDtoConverter { + + public static Collection convert(Collection dto) { + return dto.stream().map(LinkDtoConverter::convert).collect(Collectors.toList()); + } + + public static Link convert(VerificationResourceLinkDto dto) { + return Link.builder() + .setRel(LinkRelType.from(dto.getRel())) + .setHref(dto.getHref()) + .setMethod(HttpMethod.valueOf(dto.getMethod())) + .build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java index 8079a282..3f7c81b3 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverter.java @@ -3,15 +3,27 @@ import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethod; +import com.sinch.sdk.domains.verification.models.dto.v1.FlashCallInitiateVerificationResponseDto; import com.sinch.sdk.domains.verification.models.dto.v1.FlashcallOptionsDto; import com.sinch.sdk.domains.verification.models.dto.v1.IdentityDto; import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceDto; import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceFlashCallOptionsDto; import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceIdentityDto; import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceMethodDto; +import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseDto; +import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseFlashCallDto; +import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseSeamlessDto; +import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResponseSmsDto; +import com.sinch.sdk.domains.verification.models.dto.v1.SeamlessInitiateVerificationResponseDto; +import com.sinch.sdk.domains.verification.models.dto.v1.SmsInitiateVerificationResponseDto; import com.sinch.sdk.domains.verification.models.dto.v1.VerificationMethodDto; import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters; import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseCallout; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseFlashCall; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSMS; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSeamless; public class VerificationsDtoConverter { @@ -52,4 +64,64 @@ public static InitiateVerificationResourceMethodDto convert(VerificationMethod c VerificationMethodDto dto = VerificationMethodDto.fromValue(client.value()); return new InitiateVerificationResourceMethodDto(dto); } + + public static StartVerificationResponse convert(InitiateVerificationResponseDto dto) { + StartVerificationResponse.Builder builder; + switch (dto.getMethod()) { + case SMS: + { + StartVerificationResponseSMS.Builder aBuilder = StartVerificationResponseSMS.builder(); + InitiateVerificationResponseSmsDto aresponse = dto.getSms(); + if (null != aresponse) { + SmsInitiateVerificationResponseDto response = + aresponse.getSmsInitiateVerificationResponseDto(); + aBuilder + .setTemplate(response.getTemplate()) + .setInterceptionTimeOut(response.getInterceptionTimeout()); + } + builder = aBuilder; + break; + } + case FLASHCALL: + { + StartVerificationResponseFlashCall.Builder aBuilder = + StartVerificationResponseFlashCall.builder(); + InitiateVerificationResponseFlashCallDto aresponse = dto.getFlashCall(); + if (null != aresponse) { + FlashCallInitiateVerificationResponseDto response = + aresponse.getFlashCallInitiateVerificationResponseDto(); + aBuilder + .setCliFilter(response.getCliFilter()) + .setInterceptionTimeOut(response.getInterceptionTimeout()) + .setReportTimeout(response.getReportTimeout()) + .setDenyCallAfter(response.getDenyCallAfter()); + } + builder = aBuilder; + break; + } + case CALLOUT: + { + // noop: no specific parameters for callout but we create a specific builder for trace + // purpose + builder = StartVerificationResponseCallout.builder(); + break; + } + case SEAMLESS: + { + StartVerificationResponseSeamless.Builder aBuilder = + StartVerificationResponseSeamless.builder(); + InitiateVerificationResponseSeamlessDto aresponse = dto.getSeamless(); + if (null != aresponse) { + SeamlessInitiateVerificationResponseDto response = + aresponse.getSeamlessInitiateVerificationResponseDto(); + aBuilder.setTargetUri(response.getTargetUri()); + } + builder = aBuilder; + break; + } + default: + builder = StartVerificationResponse.builder(); + } + return builder.setId(dto.getId()).setLinks(LinkDtoConverter.convert(dto.getLinks())).build(); + } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java b/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java index d8d0d5e0..72f3032a 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/Identity.java @@ -1,3 +1,10 @@ package com.sinch.sdk.domains.verification.models; -public abstract class Identity {} +/** Base class for Identity based objects */ +public abstract class Identity { + + @Override + public String toString() { + return "Identity{}"; + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/Link.java b/client/src/main/com/sinch/sdk/domains/verification/models/Link.java new file mode 100644 index 00000000..959e8a2c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/Link.java @@ -0,0 +1,71 @@ +package com.sinch.sdk.domains.verification.models; + +import com.sinch.sdk.core.http.HttpMethod; + +/** Available methods and actions which can be done after a successful Verification */ +public class Link { + private final LinkRelType rel; + private final String href; + private final HttpMethod method; + + /** + * @param rel The related action that can be performed on the initiated Verification + * @param href The complete URL to perform the specified action, localized to the DataCenter which + * handled the original Verification request + * @param method The HTTP method to use when performing the action using the linked localized URL + */ + public Link(LinkRelType rel, String href, HttpMethod method) { + this.rel = rel; + this.href = href; + this.method = method; + } + + public LinkRelType getRel() { + return rel; + } + + public String getHref() { + return href; + } + + public HttpMethod getMethod() { + return method; + } + + @Override + public String toString() { + return "Link{" + "rel='" + rel + '\'' + ", href='" + href + '\'' + ", method=" + method + '}'; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + LinkRelType rel; + String href; + HttpMethod method; + + private Builder() {} + + public Builder setRel(LinkRelType rel) { + this.rel = rel; + return this; + } + + public Builder setHref(String href) { + this.href = href; + return this; + } + + public Builder setMethod(HttpMethod method) { + this.method = method; + return this; + } + + public Link build() { + return new Link(rel, href, method); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java b/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java new file mode 100644 index 00000000..846a7e82 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/LinkRelType.java @@ -0,0 +1,38 @@ +package com.sinch.sdk.domains.verification.models; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * Link rel authorized values + * + * @since 1.0 + */ +public class LinkRelType extends EnumDynamic { + + /** Get the status of a Verification. */ + public static final LinkRelType STATUS = new LinkRelType("status"); + /** Report a verification */ + public static final LinkRelType REPORT = new LinkRelType("report"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(LinkRelType.class, LinkRelType::new, Arrays.asList(STATUS, REPORT)); + + private LinkRelType(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static LinkRelType from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(LinkRelType e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java b/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java index 2cee0877..bfa1ce79 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/NumberIdentity.java @@ -1,7 +1,6 @@ package com.sinch.sdk.domains.verification.models; -import com.sinch.sdk.domains.sms.models.Group.Builder; - +/** Identity based onto a number */ public class NumberIdentity extends Identity { private final String endpoint; @@ -9,6 +8,7 @@ public String getEndpoint() { return endpoint; } + /** @param endpoint An E.164-compatible phone number. */ public NumberIdentity(String endpoint) { this.endpoint = endpoint; } @@ -27,7 +27,6 @@ public static class Builder { String endpoint; private Builder() {} - ; public Builder setEndpoint(String endpoint) { this.endpoint = endpoint; diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethod.java b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethod.java index 5f317d94..9441731d 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethod.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/VerificationMethod.java @@ -18,7 +18,7 @@ public class VerificationMethod extends EnumDynamic * Verification by placing a flashcall (missed call) and detecting the incoming calling number * (CLI). */ - public static final VerificationMethod FLASH_CALL = new VerificationMethod("flashCall"); + public static final VerificationMethod FLASH_CALL = new VerificationMethod("flashcall"); /** * Verification by placing a PSTN call to the user's phone and playing an announcement, asking the * user to press a particular digit to verify the phone number. diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java index d851477b..764a6472 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParameters.java @@ -1,21 +1,26 @@ package com.sinch.sdk.domains.verification.models.requests; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest.Builder; import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.VerificationMethod; import java.util.Optional; +/** Dedicated request parameters to be use for a flash call verification */ public class StartVerificationFlashCallRequestParameters extends StartVerificationRequestParameters { private final Integer dialTimeOut; + /** + * @param identity Specifies the type of endpoint that will be verified and the particular + * endpoint. number is currently the only supported endpoint type + * @param reference Used to pass your own reference in the request for tracking purposes. + * @param custom Can be used to pass custom data in the request. + * @param dialTimeOut The dial timeout in seconds. + */ public StartVerificationFlashCallRequestParameters( - Identity identity, - VerificationMethod method, - String reference, - String custom, - Integer dialTimeOut) { - super(identity, method, reference, custom); + Identity identity, String reference, String custom, Integer dialTimeOut) { + super(identity, VerificationMethod.FLASH_CALL, reference, custom); this.dialTimeOut = dialTimeOut; } @@ -36,18 +41,28 @@ public static Builder builder() { return new Builder(); } - public static class Builder extends StartVerificationRequestParameters.Builder { + public static class Builder extends StartVerificationRequestParameters.Builder { Integer dialTimeOut; + public Builder() { + super(VerificationMethod.FLASH_CALL); + } + public Builder setDialTimeOut(Integer dialTimeOut) { this.dialTimeOut = dialTimeOut; return this; } + @Override public StartVerificationFlashCallRequestParameters build() { return new StartVerificationFlashCallRequestParameters( - identity, method, reference, custom, dialTimeOut); + identity, reference, custom, dialTimeOut); + } + + @Override + protected Builder self() { + return this; } } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java index 8e2d2b96..9d7bbe16 100644 --- a/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java +++ b/client/src/main/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParameters.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.verification.models.requests; +import com.sinch.sdk.domains.sms.models.BaseDeliveryReport.Builder; import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.VerificationMethod; import java.util.Objects; @@ -17,6 +18,13 @@ public class StartVerificationRequestParameters { private final String reference; private final String custom; + /** + * @param identity Specifies the type of endpoint that will be verified and the particular + * endpoint. number is currently the only supported endpoint type + * @param method The type of the verification request. + * @param reference Used to pass your own reference in the request for tracking purposes. + * @param custom Can be used to pass custom data in the request. + */ public StartVerificationRequestParameters( Identity identity, VerificationMethod method, String reference, String custom) { Objects.requireNonNull(identity); @@ -60,39 +68,54 @@ public String toString() { + '}'; } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new Builder<>(); } - public static class Builder { + public static Builder builder(VerificationMethod method) { + return new Builder<>(method); + } + + public static class Builder> { Identity identity; VerificationMethod method; String reference; String custom; - public Builder setIdentity(Identity identity) { + public Builder() {} + + public Builder(VerificationMethod method) { + this.method = method; + } + + public B setIdentity(Identity identity) { this.identity = identity; - return this; + return self(); } - public Builder setMethod(VerificationMethod method) { + protected B setMethod(VerificationMethod method) { this.method = method; - return this; + return self(); } - public Builder setReference(String reference) { + public B setReference(String reference) { this.reference = reference; - return this; + return self(); } - public Builder setCustom(String custom) { + public B setCustom(String custom) { this.custom = custom; - return this; + return self(); } public StartVerificationRequestParameters build() { return new StartVerificationRequestParameters(identity, method, reference, custom); } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } } } diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java new file mode 100644 index 00000000..66574600 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponse.java @@ -0,0 +1,63 @@ +package com.sinch.sdk.domains.verification.models.response; + +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters.Builder; +import java.util.Collection; + +/** Comme class to all Start verification requests */ +public class StartVerificationResponse { + + private final String id; + private final Collection links; + + /** + * @param id Verification identifier used to query for status. + * @param links Available methods and actions which can be done after a successful Verification + */ + public StartVerificationResponse(String id, Collection links) { + this.id = id; + this.links = links; + } + + public String getId() { + return id; + } + + public Collection getLinks() { + return links; + } + + @Override + public String toString() { + return "StartVerificationResponse{" + "id='" + id + '\'' + ", links=" + links + '}'; + } + + public static Builder builder() { + return new Builder<>(); + } + + public static class Builder> { + + String id; + Collection links; + + public B setId(String id) { + this.id = id; + return self(); + } + + public B setLinks(Collection links) { + this.links = links; + return self(); + } + + public StartVerificationResponse build() { + return new StartVerificationResponse(id, links); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java new file mode 100644 index 00000000..0e34ed70 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseCallout.java @@ -0,0 +1,38 @@ +package com.sinch.sdk.domains.verification.models.response; + +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters.Builder; +import java.util.Collection; + +/** Dedicated response type for a callout verification */ +public class StartVerificationResponseCallout extends StartVerificationResponse { + + /** + * @param id Verification identifier used to query for status. + * @param links Available methods and actions which can be done after a successful Verification + */ + public StartVerificationResponseCallout(String id, Collection links) { + super(id, links); + } + + @Override + public String toString() { + return "StartVerificationResponseCallout{} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends StartVerificationResponse.Builder { + + public StartVerificationResponseCallout build() { + return new StartVerificationResponseCallout(id, links); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java new file mode 100644 index 00000000..478b458f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseFlashCall.java @@ -0,0 +1,112 @@ +package com.sinch.sdk.domains.verification.models.response; + +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.response.VerificationResponseCallout.Builder; +import java.util.Collection; + +/** Dedicated response type for a flashcall verification */ +public class StartVerificationResponseFlashCall extends StartVerificationResponse { + + private final String cliFilter; + private final Integer interceptionTimeOut; + private final Integer reportTimeout; + private final Integer denyCallAfter; + + /** + * @param id Verification identifier used to query for status. + * @param links Available methods and actions which can be done after a successful Verification + * @param cliFilter Filter that should be applied for incoming calls to intercept the Flashcall. + * @param interceptionTimeOut Amount of seconds client should wait for the Flashcall. + * @param reportTimeout The time in seconds allowed for reporting the code after which the + * verification will expire. + * @param denyCallAfter Used by the SDKs, this setting makes the handset deny the flashcall after + * the set time in seconds. + */ + public StartVerificationResponseFlashCall( + String id, + Collection links, + String cliFilter, + Integer interceptionTimeOut, + Integer reportTimeout, + Integer denyCallAfter) { + super(id, links); + this.cliFilter = cliFilter; + this.interceptionTimeOut = interceptionTimeOut; + this.reportTimeout = reportTimeout; + this.denyCallAfter = denyCallAfter; + } + + public String getCliFilter() { + return cliFilter; + } + + public Integer getInterceptionTimeOut() { + return interceptionTimeOut; + } + + public Integer getReportTimeout() { + return reportTimeout; + } + + public Integer getDenyCallAfter() { + return denyCallAfter; + } + + @Override + public String toString() { + return "StartVerificationResponseFlashCall{" + + "cliFilter='" + + cliFilter + + '\'' + + ", interceptionTimeOut=" + + interceptionTimeOut + + ", reportTimeout=" + + reportTimeout + + ", denyCallAfter=" + + denyCallAfter + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends StartVerificationResponse.Builder { + + String cliFilter; + Integer interceptionTimeOut; + Integer reportTimeout; + Integer denyCallAfter; + + public Builder setCliFilter(String cliFilter) { + this.cliFilter = cliFilter; + return self(); + } + + public Builder setInterceptionTimeOut(Integer interceptionTimeOut) { + this.interceptionTimeOut = interceptionTimeOut; + return self(); + } + + public Builder setReportTimeout(Integer reportTimeout) { + this.reportTimeout = reportTimeout; + return self(); + } + + public Builder setDenyCallAfter(Integer denyCallAfter) { + this.denyCallAfter = denyCallAfter; + return self(); + } + + public StartVerificationResponseFlashCall build() { + return new StartVerificationResponseFlashCall( + id, links, cliFilter, interceptionTimeOut, reportTimeout, denyCallAfter); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java new file mode 100644 index 00000000..4c4c7579 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSMS.java @@ -0,0 +1,75 @@ +package com.sinch.sdk.domains.verification.models.response; + +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.response.VerificationResponseSeamless.Builder; +import java.util.Collection; + +/** Dedicated response type for a sms verification */ +public class StartVerificationResponseSMS extends StartVerificationResponse { + + private final String template; + private final Integer interceptionTimeOut; + + /** + * @param id Verification identifier used to query for status. + * @param links Available methods and actions which can be done after a successful Verification + * @param template The expected template for the SMS response + * @param interceptionTimeOut The amount of time in seconds that the client should wait for the + * SMS. + */ + public StartVerificationResponseSMS( + String id, Collection links, String template, Integer interceptionTimeOut) { + super(id, links); + this.template = template; + this.interceptionTimeOut = interceptionTimeOut; + } + + public String getTemplate() { + return template; + } + + public Integer getInterceptionTimeOut() { + return interceptionTimeOut; + } + + @Override + public String toString() { + return "StartVerificationResponseSMS{" + + "template='" + + template + + '\'' + + ", interceptionTimeOut=" + + interceptionTimeOut + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends StartVerificationResponse.Builder { + + String template; + Integer interceptionTimeOut; + + public Builder setTemplate(String template) { + this.template = template; + return this; + } + + public Builder setInterceptionTimeOut(Integer interceptionTimeOut) { + this.interceptionTimeOut = interceptionTimeOut; + return this; + } + + public StartVerificationResponseSMS build() { + return new StartVerificationResponseSMS(id, links, template, interceptionTimeOut); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java new file mode 100644 index 00000000..aaeca8b9 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/verification/models/response/StartVerificationResponseSeamless.java @@ -0,0 +1,58 @@ +package com.sinch.sdk.domains.verification.models.response; + +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.response.VerificationResponseCallout.Builder; +import java.util.Collection; + +/** Dedicated response type for a seamless verification */ +public class StartVerificationResponseSeamless extends StartVerificationResponse { + + private final String targetUri; + + /** + * @param id Verification identifier used to query for status. + * @param links Available methods and actions which can be done after a successful Verification + * @param targetUri The target URI + */ + public StartVerificationResponseSeamless(String id, Collection links, String targetUri) { + super(id, links); + this.targetUri = targetUri; + } + + public String getTargetUri() { + return targetUri; + } + + @Override + public String toString() { + return "StartVerificationResponseSeamless{" + + "targetUri='" + + targetUri + + '\'' + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends StartVerificationResponse.Builder { + + String targetUri; + + public Builder setTargetUri(String targetUri) { + this.targetUri = targetUri; + return this; + } + + public StartVerificationResponseSeamless build() { + return new StartVerificationResponseSeamless(id, links, targetUri); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsServiceTest.java new file mode 100644 index 00000000..3a2b2ab9 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/VerificationsServiceTest.java @@ -0,0 +1,49 @@ +package com.sinch.sdk.domains.verification.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +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.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.dto.v1.ApiDeliveryFeedbackDto; +import com.sinch.sdk.domains.verification.adapters.api.v1.SendingAndReportingVerificationsApi; +import com.sinch.sdk.domains.verification.adapters.converters.VerificationsDtoConverterTest; +import com.sinch.sdk.domains.verification.models.dto.v1.InitiateVerificationResourceDto; +import com.sinch.sdk.domains.verification.models.dto.v1.StartStartVerificationResponseDtoTest; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse; +import com.sinch.sdk.models.Configuration; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +@TestWithResources +public class VerificationsServiceTest extends BaseTest { + + @GivenJsonResource("/domains/verification/v1/StartVerificationSMSRequestDto.json") + public InitiateVerificationResourceDto startVerificationSMSRequestDto; + + @Mock Configuration configuration; + @Mock SendingAndReportingVerificationsApi api; + @InjectMocks VerificationsService service; + + @Captor ArgumentCaptor recipientsCaptor; + + @Test + void start() throws ApiException { + + when(api.startVerification(eq(startVerificationSMSRequestDto))) + .thenReturn(StartStartVerificationResponseDtoTest.expectedStartVerificationSMSDto); + + StartVerificationResponse response = + service.start(VerificationsDtoConverterTest.startVerificationSMSRequest); + + Assertions.assertThat(response) + .usingRecursiveComparison() + .isEqualTo(VerificationsDtoConverterTest.expectedStartVerificationSMSResponse); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverterTest.java new file mode 100644 index 00000000..042a9a51 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/LinkDtoConverterTest.java @@ -0,0 +1,48 @@ +package com.sinch.sdk.domains.verification.adapters.converters; + +import static org.junit.jupiter.api.Assertions.*; + +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.http.HttpMethod; +import com.sinch.sdk.domains.verification.models.Link; +import com.sinch.sdk.domains.verification.models.LinkRelType; +import com.sinch.sdk.domains.verification.models.dto.v1.VerificationResourceLinkDto; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class LinkDtoConverterTest extends BaseTest { + + @GivenJsonResource("/domains/verification/v1/LinksDto.json") + public Collection linksDto; + + public static Collection linksClient = + Arrays.asList( + Link.builder() + .setRel(LinkRelType.STATUS) + .setHref("an href for status") + .setMethod(HttpMethod.GET) + .build(), + Link.builder() + .setRel(LinkRelType.REPORT) + .setHref("an href for report") + .setMethod(HttpMethod.PUT) + .build()); + + public static void compareWithDto(Link client, VerificationResourceLinkDto dto) { + assertEquals(dto.getRel(), client.getRel().value()); + assertEquals(dto.getHref(), client.getHref()); + assertEquals(dto.getMethod(), client.getMethod().name()); + } + + @Test + void convert() { + Iterator dtoIterator = linksDto.stream().iterator(); + Iterator clientIterator = linksClient.stream().iterator(); + dtoIterator.forEachRemaining(dtoItem -> compareWithDto(clientIterator.next(), dtoItem)); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java new file mode 100644 index 00000000..c49e85d1 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/adapters/converters/VerificationsDtoConverterTest.java @@ -0,0 +1,145 @@ +package com.sinch.sdk.domains.verification.adapters.converters; + +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationMethod; +import com.sinch.sdk.domains.verification.models.dto.v1.StartStartVerificationResponseDtoTest; +import com.sinch.sdk.domains.verification.models.dto.v1.StartVerificationRequestDtoTest; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseCallout; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseFlashCall; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSMS; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponseSeamless; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +public class VerificationsDtoConverterTest extends BaseTest { + + public static StartVerificationRequestParameters startVerificationCalloutRequest = + StartVerificationRequestParameters.builder(VerificationMethod.CALLOUT) + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) + .build(); + + public static StartVerificationResponseCallout expectedStartVerificationCalloutResponse = + StartVerificationResponseCallout.builder() + .setId("the id") + .setLinks(LinkDtoConverterTest.linksClient) + .build(); + + public static StartVerificationRequestParameters startVerificationFlashCallRequest = + StartVerificationFlashCallRequestParameters.builder() + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) + .setDialTimeOut(17) + .build(); + public static StartVerificationResponseFlashCall expectedStartVerificationFlashCallResponse = + StartVerificationResponseFlashCall.builder() + .setId("the id") + .setLinks(LinkDtoConverterTest.linksClient) + .setCliFilter("(.*)5312(.*)") + .setInterceptionTimeOut(45) + .setReportTimeout(75) + .setDenyCallAfter(0) + .build(); + public static StartVerificationRequestParameters startVerificationSeamlessRequest = + StartVerificationRequestParameters.builder(VerificationMethod.SEAMLESS) + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) + .build(); + public static StartVerificationResponseSeamless expectedStartVerificationSeamlessResponse = + StartVerificationResponseSeamless.builder() + .setId("the id") + .setLinks(LinkDtoConverterTest.linksClient) + .setTargetUri("target URI") + .build(); + public static StartVerificationRequestParameters startVerificationSMSRequest = + StartVerificationRequestParameters.builder(VerificationMethod.SMS) + .setCustom("a custom") + .setReference("a reference") + .setIdentity(NumberIdentity.builder().setEndpoint("+endpoint").build()) + .build(); + public static StartVerificationResponseSMS expectedStartVerificationSMSResponse = + StartVerificationResponseSMS.builder() + .setId("the id") + .setLinks(LinkDtoConverterTest.linksClient) + .setTemplate("Your verification code is {{CODE}}. Verified by Sinch") + .setInterceptionTimeOut(298) + .build(); + + @Test + void convertStartCalloutRequest() { + + Assertions.assertThat(VerificationsDtoConverter.convert(startVerificationCalloutRequest)) + .usingRecursiveComparison() + .isEqualTo(StartVerificationRequestDtoTest.startVerificationCalloutDto); + } + + @Test + void convertStartFlashCallRequest() { + + Assertions.assertThat(VerificationsDtoConverter.convert(startVerificationFlashCallRequest)) + .usingRecursiveComparison() + .isEqualTo(StartVerificationRequestDtoTest.startVerificationFlashCallDto); + } + + @Test + void convertStartSeamlessRequest() { + + Assertions.assertThat(VerificationsDtoConverter.convert(startVerificationSeamlessRequest)) + .usingRecursiveComparison() + .isEqualTo(StartVerificationRequestDtoTest.startVerificationSeamlessDto); + } + + @Test + void convertStartSMSRequest() { + + Assertions.assertThat(VerificationsDtoConverter.convert(startVerificationSMSRequest)) + .usingRecursiveComparison() + .isEqualTo(StartVerificationRequestDtoTest.startVerificationSMSDto); + } + + @Test + void convertStartCalloutResponse() { + + Assertions.assertThat( + VerificationsDtoConverter.convert( + StartStartVerificationResponseDtoTest.expectedStartVerificationCalloutDto)) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationCalloutResponse); + } + + @Test + void convertStartFlashCallResponse() { + + Assertions.assertThat( + VerificationsDtoConverter.convert( + StartStartVerificationResponseDtoTest.expectedStartVerificationFlashCallDto)) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationFlashCallResponse); + } + + @Test + void convertStartSeamlessResponse() { + + Assertions.assertThat( + VerificationsDtoConverter.convert( + StartStartVerificationResponseDtoTest.expectedStartVerificationSeamlessDto)) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationSeamlessResponse); + } + + @Test + void convertStartSMSResponse() { + + Assertions.assertThat( + VerificationsDtoConverter.convert( + StartStartVerificationResponseDtoTest.expectedStartVerificationSMSDto)) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationSMSResponse); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java new file mode 100644 index 00000000..433f8b57 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationFlashCallRequestParametersTest.java @@ -0,0 +1,49 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationMethod; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class StartVerificationFlashCallRequestParametersTest { + + final Identity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final VerificationMethod method = VerificationMethod.FLASH_CALL; + final String reference = "foo reference"; + final String custom = "foo custom"; + + final Integer dialTimeOut = 123; + final StartVerificationFlashCallRequestParameters value = + StartVerificationFlashCallRequestParameters.builder() + .setIdentity(identity) + .setReference(reference) + .setCustom(custom) + .setDialTimeOut(dialTimeOut) + .build(); + + @Test + void getIdentity() { + Assertions.assertThat(value.getIdentity()).isEqualTo(identity); + } + + @Test + void getMethod() { + Assertions.assertThat(value.getMethod()).isEqualTo(method); + } + + @Test + void getReference() { + Assertions.assertThat(value.getReference().get()).isEqualTo(reference); + } + + @Test + void getCustom() { + Assertions.assertThat(value.getCustom().get()).isEqualTo(custom); + } + + @Test + void getDialTimeOut() { + Assertions.assertThat(value.getDialTimeOut().get()).isEqualTo(dialTimeOut); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java new file mode 100644 index 00000000..a8399a80 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/verification/models/requests/StartVerificationRequestParametersTest.java @@ -0,0 +1,43 @@ +package com.sinch.sdk.domains.verification.models.requests; + +import com.sinch.sdk.domains.verification.models.Identity; +import com.sinch.sdk.domains.verification.models.NumberIdentity; +import com.sinch.sdk.domains.verification.models.VerificationMethod; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class StartVerificationRequestParametersTest { + + final Identity identity = NumberIdentity.builder().setEndpoint("foo identity").build(); + final VerificationMethod method = VerificationMethod.CALLOUT; + final String reference = "foo reference"; + final String custom = "foo custom"; + + final StartVerificationRequestParameters value = + StartVerificationRequestParameters.builder() + .setIdentity(identity) + .setMethod(method) + .setReference(reference) + .setCustom(custom) + .build(); + + @Test + void getIdentity() { + Assertions.assertThat(value.getIdentity()).isEqualTo(identity); + } + + @Test + void getMethod() { + Assertions.assertThat(value.getMethod()).isEqualTo(method); + } + + @Test + void getReference() { + Assertions.assertThat(value.getReference().get()).isEqualTo(reference); + } + + @Test + void getCustom() { + Assertions.assertThat(value.getCustom().get()).isEqualTo(custom); + } +} diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameter.java b/core/src/main/com/sinch/sdk/core/http/URLParameter.java index 46f65593..5d6e063d 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameter.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameter.java @@ -7,8 +7,8 @@ public class URLParameter { private final boolean explode; /** - * Create a URL parameter from an object and a style: matrix, label, form, ... (see OAS - * https://spec.openapis.org/oas/latest.html#parameter-object) + * Create a URL parameter from an object and a style: matrix, label, form, ... (see OAS OAS site) * * @param name The name of the parameter. * @param value The value of the parameter. Could be a collection of object values for name diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java index e68a36a5..09c6e08e 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java @@ -12,7 +12,8 @@ import java.util.stream.Stream; /** - * See https://spec.openapis.org/oas/latest.html#parameter-object for encoding and rendering details + * See OAS site for + * encoding and rendering details */ public class URLParameterUtils { diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/dto/v1/VerificationResponseDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/dto/v1/VerificationResponseDto.java index c11e3016..fee86e3c 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/dto/v1/VerificationResponseDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/verification/models/dto/v1/VerificationResponseDto.java @@ -336,7 +336,7 @@ public void setCallResult(String callResult) { this.callResult = callResult; } - /** Return true if this VerificationResponse object is equal to o. */ + /** Return true if this StartVerificationResponse object is equal to o. */ @Override public boolean equals(Object o) { if (this == o) { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/LinksDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/LinksDtoTest.java new file mode 100644 index 00000000..abf3336c --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/LinksDtoTest.java @@ -0,0 +1,26 @@ +package com.sinch.sdk.domains.verification.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class LinksDtoTest extends BaseTest { + @GivenJsonResource("/domains/verification/v1/LinksDto.json") + static Collection linksDto; + + public static List expectedLinks = + Arrays.asList( + new VerificationResourceLinkDto().rel("status").href("an href for status").method("GET"), + new VerificationResourceLinkDto().rel("report").href("an href for report").method("PUT")); + + @Test + void deserialize() { + Assertions.assertThat(linksDto).usingRecursiveComparison().isEqualTo(expectedLinks); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartStartVerificationResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartStartVerificationResponseDtoTest.java new file mode 100644 index 00000000..37ac1660 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartStartVerificationResponseDtoTest.java @@ -0,0 +1,94 @@ +package com.sinch.sdk.domains.verification.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class StartStartVerificationResponseDtoTest extends BaseTest { + + @GivenJsonResource("/domains/verification/v1/StartVerificationCalloutResponseDto.json") + InitiateVerificationResponseDto loadedStartVerificationCalloutDto; + + public static InitiateVerificationResponseDto expectedStartVerificationCalloutDto = + new InitiateVerificationResponseDto() + .id("the id") + .method(VerificationMethodDto.CALLOUT) + .links(LinksDtoTest.expectedLinks) + .callout( + new InitiateVerificationResponseCalloutDto( + new CalloutInitiateVerificationResponseDto())); + + @GivenJsonResource("/domains/verification/v1/StartVerificationFlashCallResponseDto.json") + InitiateVerificationResponseDto loadedStartVerificationFlashCallDto; + + public static InitiateVerificationResponseDto expectedStartVerificationFlashCallDto = + new InitiateVerificationResponseDto() + .id("the id") + .method(VerificationMethodDto.FLASHCALL) + .links(LinksDtoTest.expectedLinks) + .flashCall( + new InitiateVerificationResponseFlashCallDto( + new FlashCallInitiateVerificationResponseDto() + .cliFilter("(.*)5312(.*)") + .interceptionTimeout(45) + .reportTimeout(75) + .denyCallAfter(0) + .callId("a call id"))); + + @GivenJsonResource("/domains/verification/v1/StartVerificationSeamlessResponseDto.json") + InitiateVerificationResponseDto loadedStartVerificationSeamlessDto; + + public static InitiateVerificationResponseDto expectedStartVerificationSeamlessDto = + new InitiateVerificationResponseDto() + .id("the id") + .method(VerificationMethodDto.SEAMLESS) + .links(LinksDtoTest.expectedLinks) + .seamless( + new InitiateVerificationResponseSeamlessDto( + new SeamlessInitiateVerificationResponseDto().targetUri("target URI"))); + + @GivenJsonResource("/domains/verification/v1/StartVerificationSMSResponseDto.json") + InitiateVerificationResponseDto loadedStartVerificationSMSDto; + + public static InitiateVerificationResponseDto expectedStartVerificationSMSDto = + new InitiateVerificationResponseDto() + .id("the id") + .method(VerificationMethodDto.SMS) + .links(LinksDtoTest.expectedLinks) + .sms( + new InitiateVerificationResponseSmsDto( + new SmsInitiateVerificationResponseDto() + .template("Your verification code is {{CODE}}. Verified by Sinch") + .interceptionTimeout(298))); + + @Test + void deserializeStartCallout() { + Assertions.assertThat(loadedStartVerificationCalloutDto) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationCalloutDto); + } + + @Test + void deserializeStartFlashCall() { + Assertions.assertThat(loadedStartVerificationFlashCallDto) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationFlashCallDto); + } + + @Test + void deserializeStartSeamless() { + Assertions.assertThat(loadedStartVerificationSeamlessDto) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationSeamlessDto); + } + + @Test + void deserializeSMS() { + Assertions.assertThat(loadedStartVerificationSMSDto) + .usingRecursiveComparison() + .isEqualTo(expectedStartVerificationSMSDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartVerificationRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartVerificationRequestDtoTest.java new file mode 100644 index 00000000..93aca6ac --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/verification/models/dto/v1/StartVerificationRequestDtoTest.java @@ -0,0 +1,92 @@ +package com.sinch.sdk.domains.verification.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class StartVerificationRequestDtoTest extends BaseTest { + + @GivenTextResource("/domains/verification/v1/StartVerificationCalloutRequestDto.json") + String jsonStartVerificationCallout; + + public static InitiateVerificationResourceDto startVerificationCalloutDto = + new InitiateVerificationResourceDto() + .method(new InitiateVerificationResourceMethodDto(VerificationMethodDto.CALLOUT)) + .custom("a custom") + .reference("a reference") + .identity( + new InitiateVerificationResourceIdentityDto( + new IdentityDto().type("number").endpoint("+endpoint"))); + + @GivenTextResource("/domains/verification/v1/StartVerificationFlashCallRequestDto.json") + String jsonStartVerificationFlashCall; + + public static InitiateVerificationResourceDto startVerificationFlashCallDto = + new InitiateVerificationResourceDto() + .method(new InitiateVerificationResourceMethodDto(VerificationMethodDto.FLASHCALL)) + .custom("a custom") + .reference("a reference") + .identity( + new InitiateVerificationResourceIdentityDto( + new IdentityDto().type("number").endpoint("+endpoint"))) + .flashCallOptions( + new InitiateVerificationResourceFlashCallOptionsDto( + new FlashcallOptionsDto().dialTimeout(17))); + + @GivenTextResource("/domains/verification/v1/StartVerificationSeamlessRequestDto.json") + String jsonStartVerificationSeamless; + + public static InitiateVerificationResourceDto startVerificationSeamlessDto = + new InitiateVerificationResourceDto() + .method(new InitiateVerificationResourceMethodDto(VerificationMethodDto.SEAMLESS)) + .custom("a custom") + .reference("a reference") + .identity( + new InitiateVerificationResourceIdentityDto( + new IdentityDto().type("number").endpoint("+endpoint"))); + + @GivenTextResource("/domains/verification/v1/StartVerificationSMSRequestDto.json") + String jsonStartVerificationSMS; + + public static InitiateVerificationResourceDto startVerificationSMSDto = + new InitiateVerificationResourceDto() + .method(new InitiateVerificationResourceMethodDto(VerificationMethodDto.SMS)) + .custom("a custom") + .reference("a reference") + .identity( + new InitiateVerificationResourceIdentityDto( + new IdentityDto().type("number").endpoint("+endpoint"))); + + @Test + void serializeStartCallout() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(startVerificationCalloutDto); + + JSONAssert.assertEquals(jsonStartVerificationCallout, serializedString, true); + } + + @Test + void serializeStartFlashCall() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(startVerificationFlashCallDto); + + JSONAssert.assertEquals(jsonStartVerificationFlashCall, serializedString, true); + } + + @Test + void serializeSeamlessCall() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(startVerificationSeamlessDto); + + JSONAssert.assertEquals(jsonStartVerificationSeamless, serializedString, true); + } + + @Test + void serializeSMSCall() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(startVerificationSMSDto); + + JSONAssert.assertEquals(jsonStartVerificationSMS, serializedString, true); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java b/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java index 3324f130..89036986 100644 --- a/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java +++ b/sample-app/src/main/java/com/sinch/sample/verification/verifications/Start.java @@ -1,9 +1,12 @@ package com.sinch.sample.verification.verifications; import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.verification.models.Identity; import com.sinch.sdk.domains.verification.models.NumberIdentity; import com.sinch.sdk.domains.verification.models.VerificationMethod; import com.sinch.sdk.domains.verification.models.requests.StartVerificationFlashCallRequestParameters; +import com.sinch.sdk.domains.verification.models.requests.StartVerificationRequestParameters; +import com.sinch.sdk.domains.verification.models.response.StartVerificationResponse; import java.io.IOException; import java.util.logging.Logger; @@ -26,15 +29,23 @@ public void run() { LOGGER.info("Start verification for : " + phoneNumber); - client - .verification() - .verifications() - .start( - StartVerificationFlashCallRequestParameters.builder() - .setIdentity(NumberIdentity.builder().setEndpoint("+33444555666").build()) - .setMethod(VerificationMethod.SMS) - .build()); - - // LOGGER.info("Response :" + response); + Identity identity = NumberIdentity.builder().setEndpoint(phoneNumber).build(); + + VerificationMethod method = VerificationMethod.SMS; + + StartVerificationRequestParameters parameters; + if (method != VerificationMethod.FLASH_CALL) { + parameters = StartVerificationRequestParameters.builder(method).setIdentity(identity).build(); + } else { + // Dedicated flashcall builder usage do not require setting explicit verification method + // parameter + parameters = + StartVerificationFlashCallRequestParameters.builder() + .setIdentity(identity) + .setDialTimeOut(17) + .build(); + } + StartVerificationResponse response = client.verification().verifications().start(parameters); + LOGGER.info("Response :" + response); } } diff --git a/test-resources/src/test/resources/domains/verification/v1/LinksDto.json b/test-resources/src/test/resources/domains/verification/v1/LinksDto.json new file mode 100644 index 00000000..b5ed322a --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/LinksDto.json @@ -0,0 +1,12 @@ +[ + { + "rel": "status", + "href": "an href for status", + "method": "GET" + }, + { + "rel": "report", + "href": "an href for report", + "method": "PUT" + } +] \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutRequestDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutRequestDto.json new file mode 100644 index 00000000..a814baa9 --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutRequestDto.json @@ -0,0 +1,9 @@ +{ + "identity": { + "type": "number", + "endpoint": "+endpoint" + }, + "reference": "a reference", + "custom": "a custom", + "method": "callout" +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutResponseDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutResponseDto.json new file mode 100644 index 00000000..ca690dcd --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationCalloutResponseDto.json @@ -0,0 +1,17 @@ +{ + "id": "the id", + "method": "callout", + "callout": {}, + "_links": [ + { + "rel": "status", + "href": "an href for status", + "method": "GET" + }, + { + "rel": "report", + "href": "an href for report", + "method": "PUT" + } + ] +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallRequestDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallRequestDto.json new file mode 100644 index 00000000..4a294b66 --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallRequestDto.json @@ -0,0 +1,12 @@ +{ + "identity": { + "type": "number", + "endpoint": "+endpoint" + }, + "reference": "a reference", + "custom": "a custom", + "method": "flashcall", + "flashCallOptions": { + "dialTimeout": 17 + } +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallResponseDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallResponseDto.json new file mode 100644 index 00000000..f8ea64ab --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationFlashCallResponseDto.json @@ -0,0 +1,23 @@ +{ + "id": "the id", + "method": "flashcall", + "flashCall": { + "cliFilter": "(.*)5312(.*)", + "interceptionTimeout": 45, + "reportTimeout": 75, + "denyCallAfter": 0, + "callId": "a call id" + }, + "_links": [ + { + "rel": "status", + "href": "an href for status", + "method": "GET" + }, + { + "rel": "report", + "href": "an href for report", + "method": "PUT" + } + ] +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSRequestDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSRequestDto.json new file mode 100644 index 00000000..0d6ea498 --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSRequestDto.json @@ -0,0 +1,9 @@ +{ + "identity": { + "type": "number", + "endpoint": "+endpoint" + }, + "reference": "a reference", + "custom": "a custom", + "method": "sms" +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSResponseDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSResponseDto.json new file mode 100644 index 00000000..5046187f --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSMSResponseDto.json @@ -0,0 +1,20 @@ +{ + "id": "the id", + "method": "sms", + "sms": { + "template": "Your verification code is {{CODE}}. Verified by Sinch", + "interceptionTimeout": 298 + }, + "_links": [ + { + "rel": "status", + "href": "an href for status", + "method": "GET" + }, + { + "rel": "report", + "href": "an href for report", + "method": "PUT" + } + ] +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessRequestDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessRequestDto.json new file mode 100644 index 00000000..17b01f14 --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessRequestDto.json @@ -0,0 +1,9 @@ +{ + "identity": { + "type": "number", + "endpoint": "+endpoint" + }, + "reference": "a reference", + "custom": "a custom", + "method": "seamless" +} diff --git a/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessResponseDto.json b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessResponseDto.json new file mode 100644 index 00000000..a2637267 --- /dev/null +++ b/test-resources/src/test/resources/domains/verification/v1/StartVerificationSeamlessResponseDto.json @@ -0,0 +1,19 @@ +{ + "id": "the id", + "method": "seamless", + "seamless": { + "targetUri": "target URI" + }, + "_links": [ + { + "rel": "status", + "href": "an href for status", + "method": "GET" + }, + { + "rel": "report", + "href": "an href for report", + "method": "PUT" + } + ] +}