Skip to content

Commit

Permalink
Test network_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Oct 15, 2024
1 parent d6960de commit 558e17d
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

# [8.12.0] - 2024-10-??
- Added `network_apis` capability to Application API
- Added `@JsonCreator` annotation to webhook classes' `fromJson(String)` method

# [8.11.0] - 2024-09-25
- Added custom user agent property setting to `HttpConfig`
- Added RCS channel to Messages API
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vonage/client/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ public Verify getVerify() {
* Network APIs capability.
*
* @return The Network APIs capability, or {@code null} if absent.
* @since 8.9.0
* @since 8.12.0
*/
@JsonProperty("network_apis")
public NetworkApis networkApis() {
public NetworkApis getNetworkApis() {
return networkApis;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public enum Type {
/**
* Network APIs
*
* @since 8.9.0
* @since 8.12.0
*/
NETWORK
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Network APIs capability configuration settings.
*
* @since 8.9.0
* @since 8.12.0
*/
public final class NetworkApis extends Capability {
private URI redirectUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public List<Content> getContent() {
* @return The deserialized webhook response object.
* @throws com.vonage.client.VonageResponseParseException If the response could not be deserialized.
*/
@JsonCreator
public static InboundMessage fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public String getWhatsappConversationId() {
*
* @return An instance of this class with the fields populated, if present.
*/
@JsonCreator
public static MessageStatus fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/sms/MessageEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.sms;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -198,6 +199,7 @@ public Integer getConcatPart() {
*
* @return An instance of this class with the fields populated, if present.
*/
@JsonCreator
public static MessageEvent fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.verify2;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -176,6 +177,7 @@ public URI getSilentAuthUrl() {
* @return The deserialized webhook response object.
* @throws VonageResponseParseException If the response could not be deserialized.
*/
@JsonCreator
public static VerificationCallback fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/voice/AnswerWebhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
Expand Down Expand Up @@ -107,6 +108,7 @@ public URI getRegionUrl() {
*
* @return A new instance of this class.
*/
@JsonCreator
public static AnswerWebhook fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/vonage/client/voice/EventWebhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vonage.client.voice;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
Expand Down Expand Up @@ -292,6 +293,7 @@ public String getReason() {
*
* @return A new instance of this class.
*/
@JsonCreator
public static EventWebhook fromJson(String json) {
return Jsonable.fromJson(json);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.function.Executable;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,6 +74,10 @@ public class ApplicationClientTest extends AbstractClientTest<ApplicationClient>
" }\n" +
" }\n" +
" },\n" +
" \"network_apis\": {\n" +
" \"network_application_id\": \"2bzfIFqRG128IcjSj1YhZNtw6LADG\",\n" +
" \"redirect_uri\": \"https://my-redirect-uri.example.com\"\n" +
" },\n" +
" \"rtc\": {\n" +
" \"webhooks\": {\n" +
" \"event_url\": {\n" +
Expand Down Expand Up @@ -133,6 +138,11 @@ static void assertEqualsSampleApplication(Application response) {
assertEquals("https://example.com/webhooks/status", message.getWebhooks().get(Webhook.Type.STATUS).getAddress());
assertEquals(HttpMethod.POST, message.getWebhooks().get(Webhook.Type.STATUS).getMethod());

NetworkApis networkApis = capabilities.getNetworkApis();
assertEquals(Capability.Type.NETWORK, networkApis.getType());
assertEquals("2bzfIFqRG128IcjSj1YhZNtw6LADG", networkApis.getNetworkApplicationId());
assertEquals(URI.create("https://my-redirect-uri.example.com"), networkApis.getRedirectUri());

Rtc rtc = capabilities.getRtc();
assertEquals(Capability.Type.RTC, rtc.getType());
assertEquals("https://example.com/webhooks/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress());
Expand Down
31 changes: 25 additions & 6 deletions src/test/java/com/vonage/client/application/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,36 @@ public void testAddVerifyCapabilityWithStatusWebhooks() {
@Test
public void testAddMessagesCapabilityWithInboundWebhook() {
String json = "{\"capabilities\":{\"messages\":{\"webhooks\":{\"inbound_url\":{\"address\":\"https://example.com/inbound\",\"http_method\":\"POST\"}}}}}";
Application application = Application.builder()
.addCapability(
Messages.builder()
.addWebhook(Webhook.Type.INBOUND, new Webhook("https://example.com/inbound", HttpMethod.POST))
.build())
.build();
Application application = Application.builder().addCapability(
Messages.builder()
.addWebhook(Webhook.Type.INBOUND, new Webhook("https://example.com/inbound", HttpMethod.POST))
.build()
)
.build();

assertEquals(json, application.toJson());
testJsonableBaseObject(application);
}

@Test
public void testAddNetworkApisCapabilityWithRedirectUriAndId() {
String redirectUri = "http://localhost:8080/camara/redirect",
networkApplicationId = "my-network-application-id",
expectedJson = "{\"capabilities\":{\"network_apis\":{\"redirect_uri\":\"" +
redirectUri + "\",\"network_application_id\":\""+networkApplicationId+"\"}}}";

Application application = Application.builder().addCapability(
NetworkApis.builder()
.redirectUri(redirectUri)
.networkApplicationId(networkApplicationId)
.build()
)
.build();

testJsonableBaseObject(application);
assertEquals(expectedJson, application.toJson());
}

@Test
public void testUpdatingApplication() {
String json = "{\"name\":\"updated\"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void testFromJson() {
" }\n" +
"}");

TestUtils.testJsonableBaseObject(response);
assertEquals(InsightStatus.LOOKUP_NOT_RETURNED, response.getStatus());
assertEquals(43, response.getStatus().getInsightStatus());
assertEquals("Lookup not returned", response.getStatusMessage());
Expand Down

0 comments on commit 558e17d

Please sign in to comment.