diff --git a/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletWebhookNotification.java b/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletWebhookNotification.java index cda8202b7..0fc4b485f 100644 --- a/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletWebhookNotification.java +++ b/src/main/java/com/hyperwallet/clientsdk/model/HyperwalletWebhookNotification.java @@ -5,6 +5,7 @@ import javax.xml.bind.annotation.XmlRootElement; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; @XmlRootElement @@ -71,6 +72,7 @@ public String toString() { private String type; private Date createdOn; private Object object; + private List links; public String getToken() { return token; @@ -103,4 +105,17 @@ public Object getObject() { public void setObject(Object object) { this.object = object; } + + public List getLinks() { + return links; + } + + public void setLinks(List links) { + this.links = links; + } + + public HyperwalletWebhookNotification links(List links) { + setLinks(links); + return this; + } } diff --git a/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java b/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java index 1805f06a4..d4dae07db 100644 --- a/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java +++ b/src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java @@ -1375,10 +1375,110 @@ public void testGetProgramAccount() throws Exception { assertThat(returnValue.getType(), is(equalTo(HyperwalletAccount.EType.FUNDING))); assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-04T21:19:24 UTC")))); assertThat(returnValue.getEmail(), is(equalTo("8715201615-fundingaccount@hyperwallet.com"))); - HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0); - HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0); - assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref()))); - assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams()); + HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0); + HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0); + assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref()))); + assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams()); + } + + // + // Webhook Notification + // + @Test + public void testGetWebhookEvent() throws Exception { + String functionality = "getWebhookEvent"; + initMockServer(functionality); + + HyperwalletWebhookNotification returnValue; + try { + returnValue = client.getWebhookEvent("wbh-53010937-fbe4-4040-9a87-9fa0065f79bb"); + } catch (Exception e) { + mockServer.verify(parseRequest(functionality)); + throw e; + } + List hyperwalletLinks = new ArrayList<>(); + HyperwalletLink hyperwalletLink = new HyperwalletLink(); + hyperwalletLink.setHref("https://uat-api.paylution.com/rest/v4/webhook-notifications/wbh-53010937-fbe4-4040-9a87-9fa0065f79bb"); + Map mapParams = new HashMap<>(); + mapParams.put("rel", "self"); + hyperwalletLink.setParams(mapParams); + hyperwalletLinks.add(hyperwalletLink); + HashMap map = (HashMap) returnValue.getObject(); + assertThat(returnValue.getToken(), is(equalTo("wbh-53010937-fbe4-4040-9a87-9fa0065f79bb"))); + assertThat(returnValue.getType(), is(equalTo(HyperwalletWebhookNotification.Type.USER_CREATED.toString()))); + assertThat(returnValue.getCreatedOn(), is(equalTo(dateFormat.parse("2019-12-21T11:35:43 UTC")))); + assertThat(returnValue.getObject(), is(instanceOf(HashMap.class))); + assertThat(map.get("token"), is("usr-23e4d66a-879d-419b-950b-3f8d344c9cc7")); + assertThat(map.get("status"), is("PRE_ACTIVATED")); + assertThat(map.get("createdOn"), is("2019-12-21T11:35:43")); + assertThat(map.get("clientUserId"), is("webhook-cleint")); + assertThat(map.get("profileType"), is("INDIVIDUAL")); + assertThat(map.get("firstName"), is("John")); + assertThat(map.get("lastName"), is("Smith")); + assertThat(map.get("dateOfBirth"), is("1991-01-01")); + assertThat(map.get("email"), is("XKOSdXRs@hyperwallet.com")); + assertThat(map.get("addressLine1"), is("123 Main Street")); + assertThat(map.get("city"), is("New York")); + assertThat(map.get("stateProvince"), is("NY")); + assertThat(map.get("country"), is("US")); + assertThat(map.get("postalCode"), is("10016")); + assertThat(map.get("language"), is("en")); + assertThat(map.get("programToken"), is("prg-31507b29-95df-4b37-95ca-ecba6c06f995")); + HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0); + HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0); + assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref()))); + assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams()); + + } + + @Test + public void testListWebhookEvents() throws Exception { + String functionality = "listWebhookEvent"; + initMockServer(functionality); + + HyperwalletList returnValue; + try { + returnValue = client.listWebhookEvents(); + } catch (Exception e) { + mockServer.verify(parseRequest(functionality)); + throw e; + } + List hyperwalletLinks = new ArrayList<>(); + HyperwalletLink hyperwalletLink = new HyperwalletLink(); + hyperwalletLink.setHref("https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications?limit=5"); + Map mapParams = new HashMap<>(); + mapParams.put("rel", "self"); + hyperwalletLink.setParams(mapParams); + hyperwalletLinks.add(hyperwalletLink); + assertThat(returnValue.hasNextPage(), is(equalTo(true))); + assertThat(returnValue.hasPreviousPage(), is(equalTo(true))); + assertThat(returnValue.getLimit(), is(equalTo(5))); + assertThat(returnValue.getData().get(0).getToken(), is(equalTo("wbh-946472ab-4e17-4224-9abe-e91f9e1d4031"))); + assertThat(returnValue.getData().get(0).getType(), is(equalTo(HyperwalletWebhookNotification.Type.USER_CREATED.toString()))); + assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-10T21:51:00 UTC")))); + HashMap map = (HashMap) returnValue.getData().get(0).getObject(); + assertThat(returnValue.getData().get(0).getObject(), is(instanceOf(HashMap.class))); + assertThat(map.get("token"), is("usr-23e4d66a-879d-419b-950b-3f8d344c9cc7")); + assertThat(map.get("status"), is("PRE_ACTIVATED")); + assertThat(map.get("createdOn"), is("2019-12-21T11:35:43")); + assertThat(map.get("clientUserId"), is("webhook-cleint")); + assertThat(map.get("profileType"), is("INDIVIDUAL")); + assertThat(map.get("firstName"), is("John")); + assertThat(map.get("lastName"), is("Smith")); + assertThat(map.get("dateOfBirth"), is("1991-01-01")); + assertThat(map.get("email"), is("XKOSdXRs@hyperwallet.com")); + assertThat(map.get("addressLine1"), is("123 Main Street")); + assertThat(map.get("city"), is("New York")); + assertThat(map.get("stateProvince"), is("NY")); + assertThat(map.get("country"), is("US")); + assertThat(map.get("postalCode"), is("10016")); + assertThat(map.get("language"), is("en")); + assertThat(map.get("programToken"), is("prg-31507b29-95df-4b37-95ca-ecba6c06f995")); + HyperwalletLink actualHyperwalletLink = returnValue.getLinks().get(0); + HyperwalletLink expectedHyperwalletLink = hyperwalletLinks.get(0); + assertThat(actualHyperwalletLink.getHref(), is(equalTo(expectedHyperwalletLink.getHref()))); + assertEquals(actualHyperwalletLink.getParams(), expectedHyperwalletLink.getParams()); + } // diff --git a/src/test/resources/integration/getWebhookEvent-request.txt b/src/test/resources/integration/getWebhookEvent-request.txt new file mode 100644 index 000000000..10b0cdc48 --- /dev/null +++ b/src/test/resources/integration/getWebhookEvent-request.txt @@ -0,0 +1,3 @@ +curl -X "GET" "https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications/wbh-53010937-fbe4-4040-9a87-9fa0065f79bb" \ +-u testuser@12345678:myAccPassw0rd \ +-H "Accept: application/json" \ diff --git a/src/test/resources/integration/getWebhookEvent-response.json b/src/test/resources/integration/getWebhookEvent-response.json new file mode 100644 index 000000000..692b149d5 --- /dev/null +++ b/src/test/resources/integration/getWebhookEvent-response.json @@ -0,0 +1,31 @@ +{ + "token": "wbh-53010937-fbe4-4040-9a87-9fa0065f79bb", + "type": "USERS.CREATED", + "createdOn": "2019-12-21T11:35:43", + "object": { + "token": "usr-23e4d66a-879d-419b-950b-3f8d344c9cc7", + "status": "PRE_ACTIVATED", + "createdOn": "2019-12-21T11:35:43", + "clientUserId": "webhook-cleint", + "profileType": "INDIVIDUAL", + "firstName": "John", + "lastName": "Smith", + "dateOfBirth": "1991-01-01", + "email": "XKOSdXRs@hyperwallet.com", + "addressLine1": "123 Main Street", + "city": "New York", + "stateProvince": "NY", + "country": "US", + "postalCode": "10016", + "language": "en", + "programToken": "prg-31507b29-95df-4b37-95ca-ecba6c06f995" + }, + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://uat-api.paylution.com/rest/v4/webhook-notifications/wbh-53010937-fbe4-4040-9a87-9fa0065f79bb" + } + ] +} diff --git a/src/test/resources/integration/listWebhookEvent-request.txt b/src/test/resources/integration/listWebhookEvent-request.txt new file mode 100644 index 000000000..3264823c9 --- /dev/null +++ b/src/test/resources/integration/listWebhookEvent-request.txt @@ -0,0 +1,3 @@ +curl -X "GET" "https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications" \ +-u testuser@12345678:myAccPassw0rd \ +-H "Accept: application/json" \ diff --git a/src/test/resources/integration/listWebhookEvent-response.json b/src/test/resources/integration/listWebhookEvent-response.json new file mode 100644 index 000000000..bdaf5a0c1 --- /dev/null +++ b/src/test/resources/integration/listWebhookEvent-response.json @@ -0,0 +1,46 @@ +{ + "hasNextPage": true, + "hasPreviousPage": true, + "limit": 5, + "data": [ + { + "token": "wbh-946472ab-4e17-4224-9abe-e91f9e1d4031", + "type": "USERS.CREATED", + "createdOn": "2017-10-10T21:51:00", + "object": { + "token": "usr-23e4d66a-879d-419b-950b-3f8d344c9cc7", + "status": "PRE_ACTIVATED", + "createdOn": "2019-12-21T11:35:43", + "clientUserId": "webhook-cleint", + "profileType": "INDIVIDUAL", + "firstName": "John", + "lastName": "Smith", + "dateOfBirth": "1991-01-01", + "email": "XKOSdXRs@hyperwallet.com", + "addressLine1": "123 Main Street", + "city": "New York", + "stateProvince": "NY", + "country": "US", + "postalCode": "10016", + "language": "en", + "programToken": "prg-31507b29-95df-4b37-95ca-ecba6c06f995" + }, + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications/wbh-946472ab-4e17-4224-9abe-e91f9e1d4031" + } + ] + } + ], + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications?limit=5" + } + ] +}