Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hw 66759 v4 webhooks notifications java #84

Merged
merged 5 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,6 +72,7 @@ public String toString() {
private String type;
private Date createdOn;
private Object object;
private List<HyperwalletLink> links;

public String getToken() {
return token;
Expand Down Expand Up @@ -103,4 +105,17 @@ public Object getObject() {
public void setObject(Object object) {
this.object = object;
}

public List<HyperwalletLink> getLinks() {
return links;
}

public void setLinks(List<HyperwalletLink> links) {
this.links = links;
}

public HyperwalletWebhookNotification links(List<HyperwalletLink> links) {
setLinks(links);
return this;
}
}
108 changes: 104 additions & 4 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<HyperwalletLink> 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<String, String> mapParams = new HashMap<>();
mapParams.put("rel", "self");
hyperwalletLink.setParams(mapParams);
hyperwalletLinks.add(hyperwalletLink);
HashMap<String, String> 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<HyperwalletWebhookNotification> returnValue;
try {
returnValue = client.listWebhookEvents();
} catch (Exception e) {
mockServer.verify(parseRequest(functionality));
throw e;
}
List<HyperwalletLink> hyperwalletLinks = new ArrayList<>();
HyperwalletLink hyperwalletLink = new HyperwalletLink();
hyperwalletLink.setHref("https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications?limit=5");
Map<String, String> 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<String, String> 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());

}

//
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/integration/getWebhookEvent-request.txt
Original file line number Diff line number Diff line change
@@ -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" \
31 changes: 31 additions & 0 deletions src/test/resources/integration/getWebhookEvent-response.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
3 changes: 3 additions & 0 deletions src/test/resources/integration/listWebhookEvent-request.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -X "GET" "https://api.sandbox.hyperwallet.com/rest/v4/webhook-notifications" \
-u testuser@12345678:myAccPassw0rd \
-H "Accept: application/json" \
46 changes: 46 additions & 0 deletions src/test/resources/integration/listWebhookEvent-response.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}