Skip to content

Commit

Permalink
Merge pull request #178 from sinch/DEVEXP-693-query-parametres-as-class
Browse files Browse the repository at this point in the history
DEVEXP-693: query parametres as class
  • Loading branch information
JPPortier authored Dec 18, 2024
2 parents e1b1b22 + ad79ce4 commit bc4ac46
Show file tree
Hide file tree
Showing 22 changed files with 791 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.sinch.sdk.core.exceptions.ApiException;
import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
Expand All @@ -13,9 +14,9 @@ public interface BatchesService {

BatchResponse send(BatchRequest batch) throws ApiException;

ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException;
ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException;

DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch);
DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch);

BatchResponse get(String batchId) throws ApiException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi;
import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator;
import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse;
import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse;
import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse;
import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList;
import com.sinch.sdk.models.SmsContext;
import java.time.Instant;
import java.util.Map;

public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService {
Expand All @@ -40,20 +40,12 @@ public BatchResponse send(BatchRequest batch) throws ApiException {
return getApi().send(batch);
}

public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException {
public ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException {

ListBatchesRequest guardParameters =
null != parameters ? parameters : ListBatchesRequest.builder().build();
ListBatchesQueryParameters guardParameters =
null != parameters ? parameters : ListBatchesQueryParameters.builder().build();

ApiBatchList response =
getApi()
.list(
guardParameters.getPage().orElse(null),
guardParameters.getPageSize().orElse(null),
guardParameters.getFrom().orElse(null),
guardParameters.getStartDate().map(Instant::toString).orElse(null),
guardParameters.getEndDate().map(Instant::toString).orElse(null),
guardParameters.getClientReference().orElse(null));
ApiBatchList response = getApi().list(parameters);

SMSCursorPageNavigator navigator =
new SMSCursorPageNavigator(response.getPage(), response.getPageSize());
Expand All @@ -62,8 +54,8 @@ public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiExcepti
this, new Page<>(guardParameters, response.getBatches(), navigator));
}

public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) {
return getApi().dryRun(perRecipient, numberOfRecipient, batch);
public DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch) {
return getApi().dryRun(queryParameters, batch);
}

public BatchResponse get(String batchId) throws ApiException {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
import com.sinch.sdk.core.models.pagination.ListResponse;
import com.sinch.sdk.core.models.pagination.Page;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters;
import java.util.Collection;
import java.util.NoSuchElementException;

public class ListBatchesResponse extends ListResponse<BatchResponse> {

private final Page<ListBatchesRequest, BatchResponse, Integer> page;
private final Page<ListBatchesQueryParameters, BatchResponse, Integer> page;
private final BatchesService service;
private ListBatchesResponse nextPage;

public ListBatchesResponse(
BatchesService service, Page<ListBatchesRequest, BatchResponse, Integer> page) {
BatchesService service, Page<ListBatchesQueryParameters, BatchResponse, Integer> page) {
this.service = service;
this.page = page;
}

public boolean hasNextPage() {

if (null == nextPage) {
ListBatchesRequest.Builder newParameters = ListBatchesRequest.builder(page.getParameters());
ListBatchesQueryParameters.Builder newParameters =
ListBatchesQueryParameters.builder(page.getParameters());
newParameters.setPage(page.getNextPageToken());
nextPage = service.list(newParameters.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody;
import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.BinaryRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.MediaRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest;
Expand Down Expand Up @@ -347,23 +349,27 @@ void sendText() throws ApiException {
@Test
void dryRun() throws ApiException {

when(api.dryRun(eq(true), eq(456), eq(sendSmsBatchTextRequest))).thenReturn(dryRunResponseDto);
DryRunQueryParameters queryParameters =
DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build();
when(api.dryRun(eq(queryParameters), eq(sendSmsBatchTextRequest)))
.thenReturn(dryRunResponseDto);

DryRunResponse response = service.dryRun(true, 456, sendSmsBatchTextRequest);
DryRunResponse response = service.dryRun(queryParameters, sendSmsBatchTextRequest);

TestHelpers.recursiveEquals(response, dryRunResponseDto);
}

@Test
void list() throws ApiException {

when(api.list(eq(null), eq(null), eq(null), eq(null), eq(null), eq(null)))
.thenReturn(listBatchesResponseDtoPage0);
when(api.list(eq(1), eq(null), eq(null), eq(null), eq(null), eq(null)))
.thenReturn(listBatchesResponseDtoPage1);
when(api.list(eq(2), eq(null), eq(null), eq(null), eq(null), eq(null)))
.thenReturn(listBatchesResponseDtoPage2);
ListBatchesResponse response = service.list(null);
ListBatchesQueryParameters initialRequest = ListBatchesQueryParameters.builder().build();
ListBatchesQueryParameters page1 = ListBatchesQueryParameters.builder().setPage(1).build();
ListBatchesQueryParameters page2 = ListBatchesQueryParameters.builder().setPage(2).build();

when(api.list(initialRequest)).thenReturn(listBatchesResponseDtoPage0);
when(api.list(page1)).thenReturn(listBatchesResponseDtoPage1);
when(api.list(page2)).thenReturn(listBatchesResponseDtoPage2);
ListBatchesResponse response = service.list(initialRequest);

Iterator<BatchResponse> iterator = response.iterator();
BatchResponse batch = iterator.next();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.sinch.sdk.core.TestHelpers;
import com.sinch.sdk.domains.sms.api.v1.BatchesService;
import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters;
import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest;
import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest;
Expand Down Expand Up @@ -117,26 +118,31 @@ public void dryRun() {
.setDeliveryReport(DeliveryReportType.NONE)
.build();

dryRunResponse = service.dryRun(true, 3, request);
DryRunQueryParameters queryParameters =
DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(3).build();
dryRunResponse = service.dryRun(queryParameters, request);
}

@When("^I send a request to list the SMS batches$")
public void listOnePage() {
ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build();
ListBatchesQueryParameters request =
ListBatchesQueryParameters.builder().setPageSize(2).build();

listOnePageResponse = service.list(request);
}

@When("^I send a request to list all the SMS batches$")
public void listAll() {
ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build();
ListBatchesQueryParameters request =
ListBatchesQueryParameters.builder().setPageSize(2).build();

listAllResponse = service.list(request);
}

@When("^I iterate manually over the SMS batches pages$")
public void listAllByPage() {
ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build();
ListBatchesQueryParameters request =
ListBatchesQueryParameters.builder().setPageSize(2).build();

listAllByPageResponse = service.list(request);
}
Expand Down
Loading

0 comments on commit bc4ac46

Please sign in to comment.