-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
820 additions
and
2 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sinch.sdk.domains.sms.api.v1; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; | ||
|
||
public interface InboundsService { | ||
|
||
ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) throws ApiException; | ||
|
||
InboundMessage get(String inboundId) throws ApiException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
public interface SMSService { | ||
|
||
BatchesService batches(); | ||
|
||
InboundsService inbounds(); | ||
} |
53 changes: 53 additions & 0 deletions
53
client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.sinch.sdk.domains.sms.api.v1.adapters; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.core.http.HttpMapper; | ||
import com.sinch.sdk.core.models.pagination.Page; | ||
import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; | ||
import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; | ||
import com.sinch.sdk.models.SmsContext; | ||
import java.util.Map; | ||
|
||
public class InboundsService implements com.sinch.sdk.domains.sms.api.v1.InboundsService { | ||
|
||
private final InboundsApi api; | ||
|
||
public InboundsService( | ||
String uriUUID, | ||
SmsContext context, | ||
HttpClient httpClient, | ||
Map<String, AuthManager> authManagers) { | ||
this.api = | ||
new InboundsApi( | ||
httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); | ||
} | ||
|
||
protected InboundsApi getApi() { | ||
return this.api; | ||
} | ||
|
||
public ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) | ||
throws ApiException { | ||
|
||
ListInboundMessagesQueryParameters guardParameters = | ||
null != parameters ? parameters : ListInboundMessagesQueryParameters.builder().build(); | ||
|
||
ApiInboundList response = getApi().list(parameters); | ||
|
||
SMSCursorPageNavigator navigator = | ||
new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); | ||
|
||
return new ListInboundsResponse( | ||
this, new Page<>(guardParameters, response.getInbounds(), navigator)); | ||
} | ||
|
||
public InboundMessage get(String inboundId) throws ApiException { | ||
return getApi().get(inboundId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.sinch.sdk.domains.sms.models.v1.inbounds; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.InboundInternalImpl; | ||
|
||
@JsonDeserialize(using = InboundInternalImpl.Deserializer.class) | ||
public interface InboundMessage {} |
54 changes: 54 additions & 0 deletions
54
.../src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.sinch.sdk.domains.sms.models.v1.inbounds.response; | ||
|
||
import com.sinch.sdk.core.models.pagination.ListResponse; | ||
import com.sinch.sdk.core.models.pagination.Page; | ||
import com.sinch.sdk.domains.sms.api.v1.InboundsService; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; | ||
import java.util.Collection; | ||
import java.util.NoSuchElementException; | ||
|
||
public class ListInboundsResponse extends ListResponse<InboundMessage> { | ||
|
||
private final Page<ListInboundMessagesQueryParameters, InboundMessage, Integer> page; | ||
private final InboundsService service; | ||
private ListInboundsResponse nextPage; | ||
|
||
public ListInboundsResponse( | ||
InboundsService service, | ||
Page<ListInboundMessagesQueryParameters, InboundMessage, Integer> page) { | ||
this.service = service; | ||
this.page = page; | ||
} | ||
|
||
public boolean hasNextPage() { | ||
|
||
if (null == nextPage) { | ||
ListInboundMessagesQueryParameters.Builder newParameters = | ||
ListInboundMessagesQueryParameters.builder(page.getParameters()); | ||
newParameters.setPage(page.getNextPageToken()); | ||
nextPage = service.list(newParameters.build()); | ||
} | ||
return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); | ||
} | ||
|
||
public ListInboundsResponse nextPage() { | ||
|
||
if (!hasNextPage()) { | ||
throw new NoSuchElementException("Reached the last page of the API response"); | ||
} | ||
|
||
ListInboundsResponse response = nextPage; | ||
nextPage = null; | ||
return response; | ||
} | ||
|
||
public Collection<InboundMessage> getContent() { | ||
return page.getEntities(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ListInboundsResponse{" + "page=" + page + '}'; | ||
} | ||
} |
162 changes: 162 additions & 0 deletions
162
client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.sinch.sdk.domains.sms.api.v1.adapters; | ||
|
||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.spy; | ||
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.TestHelpers; | ||
import com.sinch.sdk.core.exceptions.ApiException; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.BinaryMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; | ||
import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; | ||
import com.sinch.sdk.models.SmsContext; | ||
import java.time.Instant; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
@TestWithResources | ||
class InboundsServiceTest extends BaseTest { | ||
|
||
@Mock SmsContext context; | ||
@Mock HttpClient httpClient; | ||
@Mock Map<String, AuthManager> authManagers; | ||
@Mock InboundsApi api; | ||
InboundsService service; | ||
|
||
String uriPartID = "foovalue"; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") | ||
InboundMessage binary; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") | ||
InboundMessage text; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/MOMediaDto.json") | ||
InboundMessage media; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") | ||
ApiInboundList inboundsLisResponseDtoPage0; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") | ||
ApiInboundList inboundsLisResponseDtoPage1; | ||
|
||
@GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json") | ||
ApiInboundList inboundsLisResponseDtoPage2; | ||
|
||
@BeforeEach | ||
public void initMocks() { | ||
service = spy(new InboundsService(uriPartID, context, httpClient, authManagers)); | ||
doReturn(api).when(service).getApi(); | ||
} | ||
|
||
@Test | ||
void getBinary() throws ApiException { | ||
|
||
when(api.get(eq("foo inbound ID"))).thenReturn(binary); | ||
|
||
InboundMessage response = service.get("foo inbound ID"); | ||
|
||
TestHelpers.recursiveEquals(response, binary); | ||
} | ||
|
||
@Test | ||
void getText() throws ApiException { | ||
|
||
when(api.get(eq("foo inbound ID"))).thenReturn(text); | ||
|
||
InboundMessage response = service.get("foo inbound ID"); | ||
|
||
TestHelpers.recursiveEquals(response, text); | ||
} | ||
|
||
@Test | ||
void getMedia() throws ApiException { | ||
|
||
when(api.get(eq("foo inbound ID"))).thenReturn(media); | ||
|
||
InboundMessage response = service.get("foo inbound ID"); | ||
|
||
TestHelpers.recursiveEquals(response, media); | ||
} | ||
|
||
@Test | ||
void list() throws ApiException { | ||
|
||
ListInboundMessagesQueryParameters initialRequest = | ||
ListInboundMessagesQueryParameters.builder().build(); | ||
ListInboundMessagesQueryParameters page1 = | ||
ListInboundMessagesQueryParameters.builder().setPage(1).build(); | ||
ListInboundMessagesQueryParameters page2 = | ||
ListInboundMessagesQueryParameters.builder().setPage(2).build(); | ||
|
||
when(api.list(initialRequest)).thenReturn(inboundsLisResponseDtoPage0); | ||
when(api.list(page1)).thenReturn(inboundsLisResponseDtoPage1); | ||
when(api.list(page2)).thenReturn(inboundsLisResponseDtoPage2); | ||
|
||
ListInboundsResponse response = service.list(initialRequest); | ||
|
||
Iterator<InboundMessage> iterator = response.iterator(); | ||
InboundMessage item = iterator.next(); | ||
Assertions.assertThat(item) | ||
.usingRecursiveComparison() | ||
.isEqualTo( | ||
BinaryMessage.builder() | ||
.setBody("a body") | ||
.setClientReference("a client reference") | ||
.setFrom("+11203494390") | ||
.setId("01FC66621XXXXX119Z8PMV1QPA") | ||
.setOperatorId("35000") | ||
.setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) | ||
.setSentAt(Instant.parse("2019-08-24T14:15:22Z")) | ||
.setTo("11203453453") | ||
.setUdh("foo udh") | ||
.build()); | ||
|
||
item = iterator.next(); | ||
Assertions.assertThat(iterator.hasNext()).isEqualTo(true); | ||
Assertions.assertThat(item) | ||
.usingRecursiveComparison() | ||
.isEqualTo( | ||
TextMessage.builder() | ||
.setBody("a body") | ||
.setClientReference("a client reference") | ||
.setFrom("+11203494390") | ||
.setId("01FC66621XXXXX119Z8PMV1QPA") | ||
.setOperatorId("35000") | ||
.setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) | ||
.setSentAt(Instant.parse("2019-08-24T14:15:22Z")) | ||
.setTo("11203453453") | ||
.build()); | ||
|
||
item = iterator.next(); | ||
Assertions.assertThat(iterator.hasNext()).isEqualTo(false); | ||
Assertions.assertThat(item) | ||
.usingRecursiveComparison() | ||
.isEqualTo( | ||
BinaryMessage.builder() | ||
.setBody("a body") | ||
.setClientReference("a client reference") | ||
.setFrom("+11203494390") | ||
.setId("01FC66621XXXXX119Z8PMV1QPA") | ||
.setOperatorId("35000") | ||
.setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) | ||
.setSentAt(Instant.parse("2019-08-24T14:15:22Z")) | ||
.setTo("11203453453") | ||
.setUdh("foo udh") | ||
.build()); | ||
} | ||
} |
Oops, something went wrong.