From a5aaeaabb4e2c2f462e2c0defe034e71d0c3b81c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 28 Feb 2024 09:05:22 +0100 Subject: [PATCH 1/3] refactor: use 'uriUUID' in place of 'uriPathID' --- .../domains/sms/adapters/BatchesService.java | 22 +++++++++---------- .../sms/adapters/DeliveryReportsService.java | 12 +++++----- .../domains/sms/adapters/GroupsService.java | 20 ++++++++--------- .../domains/sms/adapters/InboundsService.java | 10 ++++----- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java index eebc4c352..0465df71d 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java @@ -23,15 +23,15 @@ public class BatchesService implements com.sinch.sdk.domains.sms.BatchesService { - private final String uriPathID; + private final String uriUUID; private final BatchesApi api; public BatchesService( - String uriPathID, + String uriUUID, SmsContext context, HttpClient httpClient, Map authManagers) { - this.uriPathID = uriPathID; + this.uriUUID = uriUUID; this.api = new BatchesApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper()); } @@ -40,17 +40,17 @@ protected BatchesApi getApi() { } public > T get(String batchId) throws ApiException { - return BatchDtoConverter.convert(getApi().getBatchMessage(uriPathID, batchId)); + return BatchDtoConverter.convert(getApi().getBatchMessage(uriUUID, batchId)); } public > T send(BaseBatch batch) throws ApiException { - return BatchDtoConverter.convert(getApi().sendSMS(uriPathID, BatchDtoConverter.convert(batch))); + return BatchDtoConverter.convert(getApi().sendSMS(uriUUID, BatchDtoConverter.convert(batch))); } public DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch batch) { return DryRunDtoConverter.convert( getApi() - .dryRun(uriPathID, perRecipient, numberOfRecipient, BatchDtoConverter.convert(batch))); + .dryRun(uriUUID, perRecipient, numberOfRecipient, BatchDtoConverter.convert(batch))); } public BatchesListResponse list() throws ApiException { @@ -65,7 +65,7 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiBatchListDto response = getApi() .listBatches( - uriPathID, + uriUUID, guardParameters.getPage().orElse(null), guardParameters.getPageSize().orElse(null), guardParameters.getFrom().orElse(null), @@ -83,20 +83,20 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws public > T update(String batchId, UpdateBaseBatchRequest batch) throws ApiException { return BatchDtoConverter.convert( - getApi().updateBatchMessage(uriPathID, batchId, BatchDtoConverter.convert(batch))); + getApi().updateBatchMessage(uriUUID, batchId, BatchDtoConverter.convert(batch))); } public > T replace(String batchId, BaseBatch batch) throws ApiException { return BatchDtoConverter.convert( - getApi().replaceBatch(uriPathID, batchId, BatchDtoConverter.convert(batch))); + getApi().replaceBatch(uriUUID, batchId, BatchDtoConverter.convert(batch))); } public > T cancel(String batchId) throws ApiException { - return BatchDtoConverter.convert(getApi().cancelBatchMessage(uriPathID, batchId)); + return BatchDtoConverter.convert(getApi().cancelBatchMessage(uriUUID, batchId)); } public void sendDeliveryFeedback(String batchId, Collection recipients) throws ApiException { - getApi().deliveryFeedback(uriPathID, batchId, BatchDtoConverter.convert(recipients)); + getApi().deliveryFeedback(uriUUID, batchId, BatchDtoConverter.convert(recipients)); } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java index 77cb2b1f0..26c88bd5e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/DeliveryReportsService.java @@ -36,7 +36,7 @@ */ public class DeliveryReportsService implements com.sinch.sdk.domains.sms.DeliveryReportsService { - private final String uriPathID; + private final String uriUUID; private final DeliveryReportsApi api; protected DeliveryReportsApi getApi() { @@ -44,11 +44,11 @@ protected DeliveryReportsApi getApi() { } public DeliveryReportsService( - String uriPathID, + String uriUUID, SmsContext context, HttpClient httpClient, Map authManagers) { - this.uriPathID = uriPathID; + this.uriUUID = uriUUID; this.api = new DeliveryReportsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper()); } @@ -62,7 +62,7 @@ public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestPara return DeliveryReportDtoConverter.convert( getApi() .getDeliveryReportByBatchId( - uriPathID, + uriUUID, batchId, guardParameters.getType().map(DeliveryReportType::value).orElse(null), guardParameters @@ -78,7 +78,7 @@ public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestPara public DeliveryReportRecipient getForNumber(String batchId, String recipient) throws ApiException { return DeliveryReportDtoConverter.convert( - getApi().getDeliveryReportByPhoneNumber(uriPathID, batchId, recipient)); + getApi().getDeliveryReportByPhoneNumber(uriUUID, batchId, recipient)); } public DeliveryReportsListResponse list() throws ApiException { @@ -93,7 +93,7 @@ public DeliveryReportsListResponse list(DeliveryReportListRequestParameters para DeliveryReportListDto response = getApi() .getDeliveryReports( - uriPathID, + uriUUID, guardParameters.getPage().orElse(null), guardParameters.getPageSize().orElse(null), guardParameters.getStartDate().map(Instant::toString).orElse(null), diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java index f04c4c0d0..8ba612ea9 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/GroupsService.java @@ -22,7 +22,7 @@ public class GroupsService implements com.sinch.sdk.domains.sms.GroupsService { - private final String uriPathID; + private final String uriUUID; private final GroupsApi api; protected GroupsApi getApi() { @@ -30,17 +30,17 @@ protected GroupsApi getApi() { } public GroupsService( - String uriPathID, + String uriUUID, SmsContext context, HttpClient httpClient, Map authManagers) { - this.uriPathID = uriPathID; + this.uriUUID = uriUUID; this.api = new GroupsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper()); } public Group get(String groupId) throws ApiException { - CreateGroupResponseDto response = getApi().retrieveGroup(uriPathID, groupId); + CreateGroupResponseDto response = getApi().retrieveGroup(uriUUID, groupId); return GroupsDtoConverter.convert(response); } @@ -53,7 +53,7 @@ public Group create(GroupCreateRequestParameters parameters) throws ApiException null != parameters ? parameters : GroupCreateRequestParameters.builder().build(); CreateGroupResponseDto response = - getApi().createGroup(uriPathID, GroupsDtoConverter.convert(guardParameters)); + getApi().createGroup(uriUUID, GroupsDtoConverter.convert(guardParameters)); return GroupsDtoConverter.convert(response); } @@ -68,7 +68,7 @@ public GroupsListResponse list(GroupsListRequestParameters parameters) throws Ap ApiGroupListDto response = getApi() .listGroups( - uriPathID, + uriUUID, guardParameters.getPage().orElse(null), guardParameters.getPageSize().orElse(null)); @@ -85,7 +85,7 @@ public Group replace(String groupId, GroupReplaceRequestParameters parameters) null != parameters ? parameters : GroupReplaceRequestParameters.builder().build(); CreateGroupResponseDto response = - getApi().replaceGroup(uriPathID, groupId, GroupsDtoConverter.convert(guardParameters)); + getApi().replaceGroup(uriUUID, groupId, GroupsDtoConverter.convert(guardParameters)); return GroupsDtoConverter.convert(response); } @@ -94,15 +94,15 @@ public Group update(String groupId, GroupUpdateRequestParameters parameters) thr null != parameters ? parameters : GroupUpdateRequestParameters.builder().build(); CreateGroupResponseDto response = - getApi().updateGroup(uriPathID, groupId, GroupsDtoConverter.convert(guardParameters)); + getApi().updateGroup(uriUUID, groupId, GroupsDtoConverter.convert(guardParameters)); return GroupsDtoConverter.convert(response); } public void delete(String groupId) throws ApiException { - getApi().deleteGroup(uriPathID, groupId); + getApi().deleteGroup(uriUUID, groupId); } public Collection listMembers(String groupId) throws ApiException { - return getApi().getMembers(uriPathID, groupId); + return getApi().getMembers(uriUUID, groupId); } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java index 92a63399d..3faf51db3 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/InboundsService.java @@ -20,7 +20,7 @@ public class InboundsService implements com.sinch.sdk.domains.sms.InboundsService { - private final String uriPathID; + private final String uriUUID; private final InboundsApi api; protected InboundsApi getApi() { @@ -28,11 +28,11 @@ protected InboundsApi getApi() { } public InboundsService( - String uriPathID, + String uriUUID, SmsContext context, HttpClient httpClient, Map authManagers) { - this.uriPathID = uriPathID; + this.uriUUID = uriUUID; this.api = new InboundsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper()); } @@ -47,7 +47,7 @@ public InboundsListResponse list(InboundsListRequestParameters parameters) throw ApiInboundListDto response = getApi() .listInboundMessages( - uriPathID, + uriUUID, guardParameters.getPage().orElse(null), guardParameters.getPageSize().orElse(null), guardParameters.getTo().map(f -> String.join(",", f)).orElse(null), @@ -64,7 +64,7 @@ public InboundsListResponse list(InboundsListRequestParameters parameters) throw public Inbound get(String inboundId) throws ApiException { - InboundDto response = getApi().retrieveInboundMessage(uriPathID, inboundId); + InboundDto response = getApi().retrieveInboundMessage(uriUUID, inboundId); return InboundsDtoConverter.convert(response); } } From 1f0d3edbc7fa6b41b6983b7e3cfcb90643a9d7b7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 28 Feb 2024 09:07:09 +0100 Subject: [PATCH 2/3] refactor: SMS context enable undefined region and default value is managed by SinchClient --- .../main/com/sinch/sdk/models/SmsContext.java | 4 ++-- .../test/java/com/sinch/sdk/SinchClientTest.java | 9 +++++++++ .../com/sinch/sdk/models/SmsContextTest.java | 16 ---------------- 3 files changed, 11 insertions(+), 18 deletions(-) delete mode 100644 client/src/test/java/com/sinch/sdk/models/SmsContextTest.java diff --git a/client/src/main/com/sinch/sdk/models/SmsContext.java b/client/src/main/com/sinch/sdk/models/SmsContext.java index 4b4b34dbc..30ca2cf79 100644 --- a/client/src/main/com/sinch/sdk/models/SmsContext.java +++ b/client/src/main/com/sinch/sdk/models/SmsContext.java @@ -9,8 +9,8 @@ public class SmsContext { private final SMSRegion smsRegion; private final String smsUrl; - public SmsContext(SMSRegion smsRegion, String smsUrl) { - this.smsRegion = null == smsRegion ? SMSRegion.US : smsRegion; + private SmsContext(SMSRegion smsRegion, String smsUrl) { + this.smsRegion = smsRegion; this.smsUrl = smsUrl; } diff --git a/client/src/test/java/com/sinch/sdk/SinchClientTest.java b/client/src/test/java/com/sinch/sdk/SinchClientTest.java index 9ac490cfb..6ea229b0d 100644 --- a/client/src/test/java/com/sinch/sdk/SinchClientTest.java +++ b/client/src/test/java/com/sinch/sdk/SinchClientTest.java @@ -34,6 +34,15 @@ void defaultSmsUrlAvailable() { assertNotNull(client.getConfiguration().getSmsContext().get().getSmsUrl()); } + @Test + void defaultSmsRegion() { + Configuration configuration = + Configuration.builder().setKeyId("foo").setKeySecret("foo").setProjectId("foo").build(); + SinchClient client = new SinchClient(configuration); + System.out.println(client.getConfiguration().getSmsContext().get().getSmsRegion()); + assertNotNull(client.getConfiguration().getSmsContext().get().getSmsRegion()); + } + @Test void defaultVerificationUrlAvailable() { Configuration configuration = diff --git a/client/src/test/java/com/sinch/sdk/models/SmsContextTest.java b/client/src/test/java/com/sinch/sdk/models/SmsContextTest.java deleted file mode 100644 index fc8d3b918..000000000 --- a/client/src/test/java/com/sinch/sdk/models/SmsContextTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sinch.sdk.models; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -class SmsContextTest { - - static final String SMS_SERVER = "%sfooSMS_SERVER"; - - @Test - void defaultUSForSmSRegion() { - SmsContext context = SmsContext.builder().setSmsUrl(SMS_SERVER).build(); - assertEquals(context.getSmsRegion(), SMSRegion.US); - } -} From 0c7de288732decbab346ffbc80f5c92b7d8e5359 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 28 Feb 2024 18:20:36 +0100 Subject: [PATCH 3/3] feature: PR's comment --- .../test/java/com/sinch/sdk/SinchClientTest.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/src/test/java/com/sinch/sdk/SinchClientTest.java b/client/src/test/java/com/sinch/sdk/SinchClientTest.java index 6ea229b0d..35d6f916d 100644 --- a/client/src/test/java/com/sinch/sdk/SinchClientTest.java +++ b/client/src/test/java/com/sinch/sdk/SinchClientTest.java @@ -4,6 +4,7 @@ import com.sinch.sdk.core.utils.StringUtil; import com.sinch.sdk.models.Configuration; +import com.sinch.sdk.models.SMSRegion; import com.sinch.sdk.models.VoiceContext; import com.sinch.sdk.models.VoiceRegion; import org.junit.jupiter.api.Test; @@ -36,11 +37,9 @@ void defaultSmsUrlAvailable() { @Test void defaultSmsRegion() { - Configuration configuration = - Configuration.builder().setKeyId("foo").setKeySecret("foo").setProjectId("foo").build(); + Configuration configuration = Configuration.builder().build(); SinchClient client = new SinchClient(configuration); - System.out.println(client.getConfiguration().getSmsContext().get().getSmsRegion()); - assertNotNull(client.getConfiguration().getSmsContext().get().getSmsRegion()); + assertEquals(SMSRegion.US, client.getConfiguration().getSmsContext().get().getSmsRegion()); } @Test @@ -51,6 +50,14 @@ void defaultVerificationUrlAvailable() { assertNotNull(client.getConfiguration().getVerificationContext().get().getVerificationUrl()); } + @Test + void defaultVoiceRegion() { + Configuration configuration = Configuration.builder().build(); + SinchClient client = new SinchClient(configuration); + assertEquals( + VoiceRegion.GLOBAL, client.getConfiguration().getVoiceContext().get().getVoiceRegion()); + } + @Test void defaultVoiceUrl() { Configuration configuration =