Skip to content
54 changes: 26 additions & 28 deletions MIGRATION-GUIDE.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.sinch.sdk.domains.voice.api.v1;

import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.domains.voice.models.v1.sinchevents.VoiceSinchEvent;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.webhooks.VoiceWebhookEvent;
import java.util.Map;

/**
* Webhooks service
* Sinch Events service
*
* @see <a
* href="https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks">https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/</a>
* @since 1.4
* @since 2.0
*/
public interface WebHooksService {
public interface SinchEventsService {

/**
* The Sinch Platform can initiate callback requests to a URL you define (Callback URL) on request
Expand All @@ -26,10 +26,10 @@ public interface WebHooksService {
* @param path The path to you backend endpoint used for callback
* @param headers Received headers
* @param jsonPayload Received payload
* @return Is authentication is validated (true) or not (false)
* @return Is authentication validated (true) or not (false)
* <p>see <a
* href="https://developers.sinch.com/docs/voice/api-reference/authentication/callback-signed-request">https://developers.sinch.com/docs/voice/api-reference/authentication/callback-signed-request/</a>
* @since 1.4
* @since 2.0
*/
boolean validateAuthenticationHeader(
String method, String path, Map<String, String> headers, String jsonPayload);
Expand All @@ -42,9 +42,9 @@ boolean validateAuthenticationHeader(
* @return The Voice event instance class
* <p>see <a
* href="https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/">https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/</a>
* @since 1.4
* @since 2.0
*/
VoiceWebhookEvent parseEvent(String jsonPayload) throws ApiMappingException;
VoiceSinchEvent parseEvent(String jsonPayload) throws ApiMappingException;

/**
* This function can be called to serialize a Voice response to be sent as JSON
Expand All @@ -53,7 +53,7 @@ boolean validateAuthenticationHeader(
* @return The JSON string to be sent
* <p>see <a
* href="https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/">https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callbacks/</a>
* @since 1.4
* @since 2.0
*/
String serializeResponse(SvamlControl response) throws ApiMappingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public interface VoiceService {
ApplicationsService applications();

/**
* Webhooks helpers instance
* Sinch Events helpers instance
*
* @return instance service related to webhooks helpers
* @since 1.4
* @return service instance for project
* @since 2.0
*/
WebHooksService webhooks();
SinchEventsService sinchEvents();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
import com.sinch.sdk.core.utils.MapUtils;
import com.sinch.sdk.core.utils.StringUtil;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.voice.models.v1.sinchevents.VoiceSinchEvent;
import com.sinch.sdk.domains.voice.models.v1.sinchevents.internal.SinchEventInternalImpl;
import com.sinch.sdk.domains.voice.models.v1.svaml.SvamlControl;
import com.sinch.sdk.domains.voice.models.v1.webhooks.VoiceWebhookEvent;
import com.sinch.sdk.domains.voice.models.v1.webhooks.internal.WebhooksEventInternalImpl;
import java.util.Map;
import java.util.logging.Logger;

public class WebHooksService implements com.sinch.sdk.domains.voice.api.v1.WebHooksService {
private static final Logger LOGGER = Logger.getLogger(WebHooksService.class.getName());
public class SinchEventsService implements com.sinch.sdk.domains.voice.api.v1.SinchEventsService {
private static final Logger LOGGER = Logger.getLogger(SinchEventsService.class.getName());

private final Map<String, AuthManager> authManagers;

public WebHooksService(Map<String, AuthManager> authManagers) {
public SinchEventsService(Map<String, AuthManager> authManagers) {
this.authManagers = authManagers;
}

Expand Down Expand Up @@ -47,11 +47,11 @@ public boolean validateAuthenticationHeader(
}

@Override
public VoiceWebhookEvent parseEvent(String jsonPayload) throws ApiMappingException {
public VoiceSinchEvent parseEvent(String jsonPayload) throws ApiMappingException {
try {
WebhooksEventInternalImpl o =
Mapper.getInstance().readValue(jsonPayload, WebhooksEventInternalImpl.class);
return (VoiceWebhookEvent) o.getActualInstance();
SinchEventInternalImpl o =
Mapper.getInstance().readValue(jsonPayload, SinchEventInternalImpl.class);
return (VoiceSinchEvent) o.getActualInstance();
} catch (JsonProcessingException e) {
throw new ApiMappingException(jsonPayload, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class VoiceService implements com.sinch.sdk.domains.voice.api.v1.VoiceSer
private volatile ConferencesService conferences;
private volatile CallsService calls;
private volatile ApplicationsService applications;
private volatile WebHooksService webhooks;
private volatile SinchEventsService sinchEvents;

private volatile Map<String, AuthManager> clientAuthManagers;
private volatile Map<String, AuthManager> webhooksAuthManagers;
Expand Down Expand Up @@ -126,12 +126,12 @@ public ApplicationsService applications() {
return this.applications;
}

public WebHooksService webhooks() {
if (null == this.webhooks) {
public SinchEventsService sinchEvents() {
if (null == this.sinchEvents) {
instanceLazyInit();
this.webhooks = new WebHooksService(webhooksAuthManagers);
this.sinchEvents = new SinchEventsService(webhooksAuthManagers);
}
return this.webhooks;
return this.sinchEvents;
}

private void instanceLazyInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import com.sinch.sdk.core.models.pagination.Page;
import com.sinch.sdk.domains.voice.adapters.VoiceBaseTest;
import com.sinch.sdk.domains.voice.api.v1.ApplicationsService;
import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks;
import com.sinch.sdk.domains.voice.models.v1.applications.EventDestinations;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequestTest;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateCallbackUrlsRequestTest;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateEventDestinationsRequestTest;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequestTest;
import com.sinch.sdk.domains.voice.models.v1.applications.response.GetCallbackUrlsResponseTest;
import com.sinch.sdk.domains.voice.models.v1.applications.response.GetEventDestinationsResponseTest;
import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation;
import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersListResponse;
import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumbersResponseTest;
Expand All @@ -45,11 +45,12 @@ public class ApplicationsServiceTest extends VoiceBaseTest {
@GivenTextResource("/domains/voice/v1/applications/response/OwnedNumbersResponseDto.json")
String ownedNumbersResponseDto;

@GivenTextResource("/domains/voice/v1/applications/response/GetCallbackUrlsResponseDto.json")
String getCallbackUrlsResponseDto;
@GivenTextResource("/domains/voice/v1/applications/response/GetEventDestinationsResponseDto.json")
String getEventDestinationsResponseDto;

@GivenTextResource("/domains/voice/v1/applications/request/UpdateCallbackUrlsRequestDto.json")
String updateCallbackUrlsRequestDto;
@GivenTextResource(
"/domains/voice/v1/applications/request/UpdateEventDestinationsRequestDto.json")
String updateEventDestinationsRequestDto;

@GivenTextResource("/domains/voice/v1/applications/request/UpdateNumbersRequestDto.json")
String updateNumbersRequestDto;
Expand Down Expand Up @@ -111,7 +112,7 @@ void getNumbers() throws ApiException {
}

@Test
void getCallbackUrls() throws ApiException {
void getEventDestinations() throws ApiException {

HttpRequest httpRequest =
new HttpRequest(
Expand All @@ -124,28 +125,29 @@ void getCallbackUrls() throws ApiException {
Collections.emptyList(),
AUTH_NAMES);
HttpResponse httpResponse =
new HttpResponse(200, null, Collections.emptyMap(), getCallbackUrlsResponseDto.getBytes());
new HttpResponse(
200, null, Collections.emptyMap(), getEventDestinationsResponseDto.getBytes());

when(httpClient.invokeAPI(
eq(serverConfiguration),
eq(authManagers),
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

Callbacks response = service.getCallbackUrls("app/id");
EventDestinations response = service.getEventDestinations("app/id");

TestHelpers.recursiveEquals(response, GetCallbackUrlsResponseTest.expected);
TestHelpers.recursiveEquals(response, GetEventDestinationsResponseTest.expected);
}

@Test
void updateCallbackUrls() {
void updateEventDestinations() {

HttpRequest httpRequest =
new HttpRequest(
"/v1/configuration/callbacks/applications/" + URLPathUtils.encodePathSegment("app/key"),
HttpMethod.POST,
Collections.emptyList(),
updateCallbackUrlsRequestDto,
updateEventDestinationsRequestDto,
Collections.emptyMap(),
Collections.emptyList(),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Expand All @@ -158,7 +160,7 @@ void updateCallbackUrls() {
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

service.updateCallbackUrls("app/key", UpdateCallbackUrlsRequestTest.expected);
service.updateEventDestinations("app/key", UpdateEventDestinationsRequestTest.expected);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ void checkCredentialsVoiceConferences() {

@Test
void checkCredentialsVoiceWebhooks() {
CredentialsValidationHelper.checkCredentials(() -> httpClient, VoiceService::webhooks);
CredentialsValidationHelper.checkCredentials(() -> httpClient, VoiceService::sinchEvents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.sinch.sdk.core.TestHelpers;
import com.sinch.sdk.domains.voice.api.v1.ApplicationsService;
import com.sinch.sdk.domains.voice.models.v1.applications.Callbacks;
import com.sinch.sdk.domains.voice.models.v1.applications.CallbacksUrl;
import com.sinch.sdk.domains.voice.models.v1.applications.Capability;
import com.sinch.sdk.domains.voice.models.v1.applications.EventDestinationTarget;
import com.sinch.sdk.domains.voice.models.v1.applications.EventDestinations;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UnAssignNumberRequest;
import com.sinch.sdk.domains.voice.models.v1.applications.request.UpdateNumbersRequest;
import com.sinch.sdk.domains.voice.models.v1.applications.response.OwnedNumberInformation;
Expand All @@ -27,8 +27,8 @@ public class ApplicationsSteps {
Boolean assignNumbersPassed;
Boolean unassignNumberPassed;

Callbacks getCallbackUrlsResult;
Boolean updateCallbackUrlsPassed;
EventDestinations getEventDestinationsResult;
Boolean updateEventDestinationsPassed;

@Given("^the Voice service \"Applications\" is available")
public void serviceAvailable() {
Expand Down Expand Up @@ -65,22 +65,23 @@ public void unassignNumber() {
}

@When("^I send a request to get the callback URLs associated to an application$")
public void getCallbackUrls() {
public void getEventDestinations() {

getCallbackUrlsResult = service.getCallbackUrls("f00dcafe-abba-c0de-1dea-dabb1ed4caf3");
getEventDestinationsResult =
service.getEventDestinations("f00dcafe-abba-c0de-1dea-dabb1ed4caf3");
}

@When("^I send a request to update the callback URLs associated to an application$")
public void updateCallbackUrls() {
Callbacks request =
Callbacks.builder()
.setUrl(
CallbacksUrl.builder()
public void updateEventDestinations() {
EventDestinations request =
EventDestinations.builder()
.setTarget(
EventDestinationTarget.builder()
.setPrimary("https://my-new.callback-server.com/voice")
.build())
.build();
service.updateCallbackUrls("f00dcafe-abba-c0de-1dea-dabb1ed4caf3", request);
updateCallbackUrlsPassed = true;
service.updateEventDestinations("f00dcafe-abba-c0de-1dea-dabb1ed4caf3", request);
updateEventDestinationsPassed = true;
}

@Then("the response contains details about the numbers that I own")
Expand Down Expand Up @@ -121,20 +122,20 @@ public void unassignNumberResult() {
}

@Then("the response contains callback URLs details")
public void getCallbackUrlsResult() {
Callbacks expected =
Callbacks.builder()
.setUrl(
CallbacksUrl.builder()
public void getEventDestinationsResult() {
EventDestinations expected =
EventDestinations.builder()
.setTarget(
EventDestinationTarget.builder()
.setPrimary("https://my.callback-server.com/voice")
.setFallback("https://my.fallback-server.com/voice")
.build())
.build();
TestHelpers.recursiveEquals(getCallbackUrlsResult, expected);
TestHelpers.recursiveEquals(getEventDestinationsResult, expected);
}

@Then("the update callback URLs response contains no data")
public void updateCallbackUrlsResult() {
Assertions.assertTrue(updateCallbackUrlsPassed);
public void updateEventDestinationsResult() {
Assertions.assertTrue(updateEventDestinationsPassed);
}
}
Loading
Loading