Skip to content

Commit

Permalink
Merge pull request #63 from hyperwallet/HW-56015_ChangePagination
Browse files Browse the repository at this point in the history
Hw 56015 change pagination
  • Loading branch information
akalichety-hw committed Sep 2, 2020
2 parents 743412d + 92929d0 commit dcaa0cf
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 39 deletions.
35 changes: 35 additions & 0 deletions src/main/java/com/hyperwallet/clientsdk/model/HyperwalletLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hyperwallet.clientsdk.model;

import java.util.List;
import java.util.Map;

/**
* @author amylavarapu
* HyperwalletLink represents HATEOAS links
*/

public class HyperwalletLink {

public Map<String, String> params;
public String href;

public HyperwalletLink() {
}

public Map<String, String> getParams() {
return params;
}

public void setParams(Map<String, String> params) {
this.params = params;
}

public String getHref() {
return href;
}

public void setHref(String href) {
this.href = href;
}
}

34 changes: 23 additions & 11 deletions src/main/java/com/hyperwallet/clientsdk/model/HyperwalletList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@

public class HyperwalletList<T> {

private int count;
private int offset;
private boolean hasNextPage;
private boolean hasPreviousPage;
private int limit;
private List<T> data;
private List<HyperwalletLink> links = new ArrayList<HyperwalletLink>();

private List<T> data = new ArrayList<T>();
public HyperwalletList() {
}

public int getCount() {
return count;
public boolean hasNextPage() {
return hasNextPage;
}

public void setCount(int count) {
this.count = count;
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}

public int getOffset() {
return offset;
public boolean hasPreviousPage() {
return hasPreviousPage;
}

public void setOffset(int offset) {
this.offset = offset;
public void setHasPreviousPage(boolean hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}

public int getLimit() {
Expand All @@ -42,4 +45,13 @@ public List<T> getData() {
public void setData(List<T> data) {
this.data = data;
}

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

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

}
28 changes: 18 additions & 10 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void testListUserStatusTransitions() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("sts-1f7f58a9-22e8-4fef-8d6e-a17e2c71db33")));
assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2017-11-16T01:55:34 UTC"))));
assertThat(returnValue.getData().get(0).getTransition(), is(equalTo(DE_ACTIVATED)));
Expand Down Expand Up @@ -262,7 +263,8 @@ public void testListBankCard() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(2)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("trm-7e915660-8c97-47bf-8a4f-0c1bc890d46f")));
assertThat(returnValue.getData().get(0).getType(), is(equalTo(HyperwalletTransferMethod.Type.BANK_CARD)));
assertThat(returnValue.getData().get(0).getStatus(), is(equalTo(HyperwalletTransferMethod.Status.ACTIVATED)));
Expand Down Expand Up @@ -313,7 +315,8 @@ public void testListBankCardStatusTransitions() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("sts-1825afa2-61f1-4860-aa69-a65b9d14f556")));
assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2017-11-16T00:55:57 UTC"))));
assertThat(returnValue.getData().get(0).getTransition(), is(equalTo(DE_ACTIVATED)));
Expand Down Expand Up @@ -501,7 +504,8 @@ public void testListPaperCheck() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("trm-59f67c62-fd06-497e-a9ea-99d6eb38b12b")));
assertThat(returnValue.getData().get(0).getType(), is(equalTo(HyperwalletTransferMethod.Type.PAPER_CHECK)));
assertThat(returnValue.getData().get(0).getStatus(), is(equalTo(HyperwalletTransferMethod.Status.ACTIVATED)));
Expand Down Expand Up @@ -558,7 +562,8 @@ public void testListPaperCheckStatusTransitions() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("sts-ed2207f0-39cc-493f-9cd0-24998de0c0f7")));
assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-30T19:50:49 UTC"))));
assertThat(returnValue.getData().get(0).getTransition(), is(equalTo(DE_ACTIVATED)));
Expand Down Expand Up @@ -713,7 +718,8 @@ public void testListTransfer() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("trm-59f67c62-fd06-497e-a9ea-99d6eb38b12b")));
assertThat(returnValue.getData().get(0).getStatus(), is(equalTo(HyperwalletTransfer.Status.QUOTED)));
assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2017-10-31T22:32:57 UTC"))));
Expand Down Expand Up @@ -829,7 +835,8 @@ public void testListPayPalAccount() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("trm-54b0db9c-5565-47f7-aee6-685e713595f3")));
assertThat(returnValue.getData().get(0).getStatus(), is(equalTo(HyperwalletTransferMethod.Status.ACTIVATED)));
assertThat(returnValue.getData().get(0).getType(), is(equalTo(HyperwalletTransferMethod.Type.PAYPAL_ACCOUNT)));
Expand Down Expand Up @@ -876,8 +883,8 @@ public void testListPayPalAccountStatusTransitions() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(1)));
assertThat(returnValue.getOffset(), is(equalTo(0)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getLimit(), is(equalTo(10)));
assertThat(returnValue.getData().get(0).getToken(), is(equalTo("sts-70ddc78a-0c14-4a72-8390-75d49ff376f2")));
assertThat(returnValue.getData().get(0).getCreatedOn(), is(equalTo(dateFormat.parse("2018-10-30T18:50:20 UTC"))));
Expand Down Expand Up @@ -954,7 +961,8 @@ public void testListPaymentStatusTransitions() throws Exception {
throw e;
}

assertThat(returnValue.getCount(), is(equalTo(2)));
assertThat(returnValue.hasNextPage(), is(equalTo(false)));
assertThat(returnValue.hasPreviousPage(), is(equalTo(false)));
assertThat(returnValue.getData().get(1).getToken(), is(equalTo("sts-1f7f58a9-22e8-4fef-8d6e-a17e2c71db33")));
assertThat(returnValue.getData().get(1).getCreatedOn(), is(equalTo(dateFormat.parse("2017-11-16T02:04:17 UTC"))));
assertThat(returnValue.getData().get(1).getTransition(), is(equalTo(RECALLED)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;

/**
* @author fkrauthan
Expand All @@ -18,22 +19,72 @@ public class HyperwalletListTest {
@Test
public void testHyperwalletList() {
HyperwalletList<String> list = new HyperwalletList<String>();
assertThat(list.getCount(), is(equalTo(0)));
assertThat(list.hasNextPage(), is(equalTo(false)));
assertThat(list.hasPreviousPage(), is(equalTo(false)));
assertThat(list.getLimit(), is(equalTo(0)));
assertThat(list.getOffset(), is(equalTo(0)));
assertThat(list.getData(), is(Matchers.<String>empty()));
assertThat(list.getData(), is(nullValue()));
assertThat(list.getLinks(), is(not(nullValue())));

list.setCount(1);
assertThat(list.hasNextPage(), is(equalTo(false)));
assertThat(list.hasPreviousPage(), is(equalTo(false)));
list.setLimit(2);
list.setOffset(3);
List<String> strList = new ArrayList<String>();
strList.add("test");
list.setData(strList);
List<String> dataList = new ArrayList<String>();
dataList.add("test");
list.setData(dataList);

assertThat(list.getCount(), is(equalTo(1)));
assertThat(list.hasNextPage(), is(equalTo(false)));
assertThat(list.hasPreviousPage(), is(equalTo(false)));
assertThat(list.getLimit(), is(equalTo(2)));
assertThat(list.getOffset(), is(equalTo(3)));
assertThat(list.getData(), is(equalTo(strList)));
}
assertThat(list.getData(), is(equalTo(dataList)));
assertThat(list.getData(), Matchers.<String>hasSize(1));

assertThat(list.hasNextPage(), is(equalTo(false)));
assertThat(list.hasPreviousPage(), is(equalTo(false)));
assertThat(list.getLimit(), is(equalTo(2)));
assertThat(list.getData(), is(equalTo(dataList)));

list.setLimit(10);
for(int i=1; i < list.getLimit(); i++) {

dataList.add("test" + i);
}
list.setData(dataList);
list.setHasNextPage(true);
HyperwalletLink link = new HyperwalletLink();
link.setHref("https://localhost:8181/users?limit=10");
Map<String, String> params = new HashMap<String, String>();
params.put("rel", "self");
link.setParams(params);
list.getLinks().add(link);
List<HyperwalletLink> hateoasLinks = new ArrayList<HyperwalletLink>();
hateoasLinks.add(link);

assertThat(list.hasNextPage(), is(equalTo(true)));
assertThat(list.hasPreviousPage(), is(equalTo(false)));
assertThat(list.getLimit(), is(equalTo(10)));
assertThat(list.getData(), is(equalTo(dataList)));
assertThat(list.getData(), Matchers.<String>hasSize(10));
assertThat(list.getLinks().get(0).getHref(), is(equalTo(link.getHref())));
assertThat(list.getLinks().get(0).getParams().get("rel"), is(equalTo("self")));

for(int i=0; i < list.getLimit(); i++) {
dataList.add("test" + i);
}
list.setData(dataList);
list.setHasNextPage(false);
list.setHasPreviousPage(true);
link = new HyperwalletLink();
link.setHref("https://localhost:8181/users?after=trf-w234-2342-234&limit=10");
params = new HashMap<String, String>();
params.put("rel", "next");
link.setParams(params);

hateoasLinks.add(link);
list.setLinks(hateoasLinks);
assertThat(list.hasNextPage(), is(equalTo(false)));
assertThat(list.hasPreviousPage(), is(equalTo(true)));
assertThat(list.getLimit(), is(equalTo(10)));
assertThat(list.getData(), is(equalTo(dataList)));
assertThat(list.getData(), Matchers.<String>hasSize(20));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public void testInvalidJsonResponse() throws Exception {
" \"params\" : {\n" +
" \"rel\" : \"self\"\n" +
" },\n" +
" \"href\" : \"https://maelle.paylution.com/rest/v3/payments/pmt-81aad61a-03ff-4995-a2fc-6a6e2d8911af\"\n" +
" \"href\" : \"https://maelle.paylution.com/rest/v4/payments/pmt-81aad61a-03ff-4995-a2fc-6a6e2d8911af\"\n" +
" } ]\n" +
" } {\n" +
" \"token\" : \"pmt-81aad61a-03ff-4995-a2fc-6a6e2d8911af\",\n" +
Expand All @@ -883,7 +883,7 @@ public void testInvalidJsonResponse() throws Exception {
" \"params\" : {\n" +
" \"rel\" : \"self\"\n" +
" },\n" +
" \"href\" : \"https://maelle.paylution.com/rest/v3/payments/pmt-81aad61a-03ff-4995-a2fc-6a6e2d8911af\"\n" +
" \"href\" : \"https://maelle.paylution.com/rest/v4/payments/pmt-81aad61a-03ff-4995-a2fc-6a6e2d8911af\"\n" +
" } ]\n" +
" }")
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/integration/listBankCards-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"params": {
"rel": "self"
},
"href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards/trm-7742f31d-452c-4bf7-8645-c003fa1511d5"
"href": "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards/trm-7742f31d-452c-4bf7-8645-c003fa1511d5"
}
]
}
Expand All @@ -49,7 +49,7 @@
"params": {
"rel": "self"
},
"href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards?offset=0&limit=10"
"href": "https://api.sandbox.hyperwallet.com/rest/v4/users/usr-c4292f1a-866f-4310-a289-b916853939de/bank-cards?offset=0&limit=10"
}
]
}

0 comments on commit dcaa0cf

Please sign in to comment.