Skip to content

Commit

Permalink
Added account balances endpoint sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Olamit committed Aug 2, 2016
1 parent 97924f0 commit 5e2f310
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/main/java/com/hyperwallet/clientsdk/Hyperwallet.java
Expand Up @@ -549,6 +549,43 @@ public HyperwalletList<HyperwalletBalance> listBalancesForUser(String userToken,
});
}

/**
* List all Program account balances
*
* @param accountToken Account token assigned
* @param programToken Program token assigned
* @return HyperwalletList of HyperwalletBalance
*/
public HyperwalletList<HyperwalletBalance> listBalancesForAccount(String programToken, String accountToken) {
return listBalancesForAccount(programToken, accountToken, null);
}

/**
* List all Program account balances
*
* @param accountToken Account token assigned
* @param programToken Program token assigned
* @param options List filter option
* @return HyperwalletList list of HyperwalletBalance
*/
public HyperwalletList<HyperwalletBalance> listBalancesForAccount(String programToken, String accountToken, HyperwalletBalanceListOptions options) {
if (StringUtils.isEmpty(programToken)) {
throw new HyperwalletException("Program token is required");
}
if (StringUtils.isEmpty(accountToken)) {
throw new HyperwalletException("Account token is required");
}
String url = this.url + "/programs/" + programToken + "/accounts/" + accountToken + "/balances";
if (options != null) {
url = addParameter(url, "currency", options.getCurrency());
url = addParameter(url, "sortBy", options.getSortBy());
url = addParameter(url, "offset", options.getOffset());
url = addParameter(url, "limit", options.getLimit());
}
return apiClient.get(url, new TypeReference<HyperwalletList<HyperwalletBalance>>() {
});
}

/**
* List all User's Prepaid Card Balances
*
Expand Down
118 changes: 118 additions & 0 deletions src/test/java/com/hyperwallet/clientsdk/HyperwalletTest.java
Expand Up @@ -1580,6 +1580,124 @@ public void testListBalancesForUser_withSomeParameters() throws Exception {
Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/users/test-user-token/balances?sortBy=test-sort-by&offset=5"), Mockito.any(TypeReference.class));
}


@Test
public void testListBalancesForProgramAccount_noParameters_noProgramToken() throws Exception {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.listBalancesForAccount(null, null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Program token is required")));
assertThat(e.getMessage(), is(equalTo("Program token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
}
}

@Test
public void testListBalancesForProgramAccount_noParameters_noAccountToken() throws Exception {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.listBalancesForAccount("prg-token", null);
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Account token is required")));
assertThat(e.getMessage(), is(equalTo("Account token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
}
}

@Test
public void testListBalancesForProgramAccount_noParameters() throws Exception {
HyperwalletList<HyperwalletBalance> response = new HyperwalletList<HyperwalletBalance>();

Hyperwallet client = new Hyperwallet("test-username", "test-password");
HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);

Mockito.when(mockApiClient.get(Mockito.anyString(), Mockito.any(TypeReference.class))).thenReturn(response);

HyperwalletList<HyperwalletBalance> resp = client.listBalancesForAccount("test-prg-token", "test-acct-token");
assertThat(resp, is(equalTo(response)));

Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/programs/test-prg-token/accounts/test-acct-token/balances"), Mockito.any(TypeReference.class));
}

@Test
public void testListBalancesForProgramAccount_withParameters_noProgramToken() throws Exception {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.listBalancesForAccount(null, null, new HyperwalletBalanceListOptions());
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Program token is required")));
assertThat(e.getMessage(), is(equalTo("Program token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
}
}

@Test
public void testListBalancesForProgramAccount_withParameters_noAccountToken() throws Exception {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
try {
client.listBalancesForAccount("prg-token", null, new HyperwalletBalanceListOptions());
fail("Expect HyperwalletException");
} catch (HyperwalletException e) {
assertThat(e.getErrorCode(), is(nullValue()));
assertThat(e.getResponse(), is(nullValue()));
assertThat(e.getErrorMessage(), is(equalTo("Account token is required")));
assertThat(e.getMessage(), is(equalTo("Account token is required")));
assertThat(e.getHyperwalletErrors(), is(nullValue()));
}
}

@Test
public void testListBalancesForProgramAccount_withParameters() throws Exception {
HyperwalletList<HyperwalletBalance> response = new HyperwalletList<HyperwalletBalance>();

Hyperwallet client = new Hyperwallet("test-username", "test-password");
HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);

HyperwalletBalanceListOptions options = new HyperwalletBalanceListOptions();
options
.sortBy("test-sort-by")
.offset(5)
.limit(10)
.currency("test-currency");

Mockito.when(mockApiClient.get(Mockito.anyString(), Mockito.any(TypeReference.class))).thenReturn(response);

HyperwalletList<HyperwalletBalance> resp = client.listBalancesForAccount("test-prg-token", "test-acct-token", options);
assertThat(resp, is(equalTo(response)));

Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/programs/test-prg-token/accounts/test-acct-token/balances?currency=test-currency&sortBy=test-sort-by&offset=5&limit=10"), Mockito.any(TypeReference.class));
}

@Test
public void testListBalancesForProgramAccount_withSomeParameters() throws Exception {
HyperwalletList<HyperwalletBalance> response = new HyperwalletList<HyperwalletBalance>();

Hyperwallet client = new Hyperwallet("test-username", "test-password");
HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);

HyperwalletBalanceListOptions options = new HyperwalletBalanceListOptions();
options
.sortBy("test-sort-by")
.offset(5);

Mockito.when(mockApiClient.get(Mockito.anyString(), Mockito.any(TypeReference.class))).thenReturn(response);

HyperwalletList<HyperwalletBalance> resp = client.listBalancesForAccount("test-prg-token", "test-acct-token", options);
assertThat(resp, is(equalTo(response)));

Mockito.verify(mockApiClient).get(Mockito.eq("https://api.sandbox.hyperwallet.com/rest/v3/programs/test-prg-token/accounts/test-acct-token/balances?sortBy=test-sort-by&offset=5"), Mockito.any(TypeReference.class));
}

@Test
public void testListBalancesForPrepaidCard_noParameters_noUserToken() throws Exception {
Hyperwallet client = new Hyperwallet("test-username", "test-password");
Expand Down

0 comments on commit 5e2f310

Please sign in to comment.