Search in sources :

Example 6 with HyperwalletApiClient

use of com.hyperwallet.clientsdk.util.HyperwalletApiClient in project java-sdk by hyperwallet.

the class HyperwalletTest method testListPayments_noParameters.

@Test
public void testListPayments_noParameters() throws Exception {
    HyperwalletList<HyperwalletPayment> response = new HyperwalletList<HyperwalletPayment>();
    Hyperwallet client = new Hyperwallet("test-username", "test-password");
    HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);
    Mockito.when(mockApiClient.get(ArgumentMatchers.anyString(), ArgumentMatchers.any(TypeReference.class))).thenReturn(response);
    HyperwalletList<HyperwalletPayment> resp = client.listPayments();
    assertThat(resp, is(equalTo(response)));
    Mockito.verify(mockApiClient).get(ArgumentMatchers.eq("https://api.sandbox.hyperwallet.com/rest/v4/payments"), ArgumentMatchers.any(TypeReference.class));
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.testng.annotations.Test)

Example 7 with HyperwalletApiClient

use of com.hyperwallet.clientsdk.util.HyperwalletApiClient in project java-sdk by hyperwallet.

the class HyperwalletTest method testGetProgram_successful.

@Test
public void testGetProgram_successful() throws Exception {
    HyperwalletProgram programResponse = new HyperwalletProgram();
    Hyperwallet client = new Hyperwallet("test-username", "test-password");
    HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);
    Mockito.when(mockApiClient.get(ArgumentMatchers.anyString(), ArgumentMatchers.any(Class.class))).thenReturn(programResponse);
    HyperwalletProgram resp = client.getProgram("test-program-token");
    assertThat(resp, is(equalTo(programResponse)));
    Mockito.verify(mockApiClient).get("https://api.sandbox.hyperwallet.com/rest/v4/programs/test-program-token", programResponse.getClass());
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) Test(org.testng.annotations.Test)

Example 8 with HyperwalletApiClient

use of com.hyperwallet.clientsdk.util.HyperwalletApiClient in project java-sdk by hyperwallet.

the class HyperwalletTest method testCreatePrepaidCard_withType.

@Test
public void testCreatePrepaidCard_withType() throws Exception {
    HyperwalletPrepaidCard prepaidCard = new HyperwalletPrepaidCard();
    prepaidCard.setUserToken("test-user-token");
    prepaidCard.setType(HyperwalletPrepaidCard.Type.PREPAID_CARD);
    prepaidCard.setStatus(HyperwalletPrepaidCard.Status.ACTIVATED);
    prepaidCard.setCreatedOn(new Date());
    prepaidCard.setCardType(HyperwalletPrepaidCard.CardType.VIRTUAL);
    prepaidCard.setTransferMethodCountry("test-transfer-method-country");
    prepaidCard.setTransferMethodCurrency("test-transfer-method-currency");
    prepaidCard.setCardNumber("test-card-number");
    prepaidCard.setCardBrand(HyperwalletPrepaidCard.Brand.VISA);
    prepaidCard.setDateOfExpiry(new Date());
    prepaidCard.setCardPackage("test-card-package");
    HyperwalletPrepaidCard prepaidCardResponse = new HyperwalletPrepaidCard();
    Hyperwallet client = new Hyperwallet("test-username", "test-password");
    HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);
    Mockito.when(mockApiClient.post(ArgumentMatchers.anyString(), ArgumentMatchers.anyObject(), ArgumentMatchers.any(Class.class))).thenReturn(prepaidCardResponse);
    HyperwalletPrepaidCard resp = client.createOrReplacePrepaidCard(prepaidCard);
    assertThat(resp, is(equalTo(prepaidCardResponse)));
    ArgumentCaptor<HyperwalletPrepaidCard> argument = ArgumentCaptor.forClass(HyperwalletPrepaidCard.class);
    Mockito.verify(mockApiClient).post(ArgumentMatchers.eq("https://api.sandbox.hyperwallet.com/rest/v4/users/test-user-token/prepaid-cards"), argument.capture(), ArgumentMatchers.eq(prepaidCard.getClass()));
    HyperwalletPrepaidCard apiClientPrepaidCard = argument.getValue();
    assertThat(apiClientPrepaidCard, is(notNullValue()));
    assertThat(apiClientPrepaidCard.getType(), is(equalTo(HyperwalletPrepaidCard.Type.PREPAID_CARD)));
    assertThat(apiClientPrepaidCard.getCardPackage(), is(equalTo("test-card-package")));
    assertThat(apiClientPrepaidCard.getStatus(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getCreatedOn(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getCardType(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getCardBrand(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getTransferMethodCountry(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getTransferMethodCurrency(), is(nullValue()));
    assertThat(apiClientPrepaidCard.getDateOfExpiry(), is(nullValue()));
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) Test(org.testng.annotations.Test)

Example 9 with HyperwalletApiClient

use of com.hyperwallet.clientsdk.util.HyperwalletApiClient in project java-sdk by hyperwallet.

the class HyperwalletTest method createAndInjectHyperwalletApiClientMock.

// --------------------------------------
// Internal utils
// --------------------------------------
private HyperwalletApiClient createAndInjectHyperwalletApiClientMock(Hyperwallet client) throws Exception {
    HyperwalletApiClient mock = Mockito.mock(HyperwalletApiClient.class);
    Field apiClientField = client.getClass().getDeclaredField("apiClient");
    apiClientField.setAccessible(true);
    apiClientField.set(client, mock);
    return mock;
}
Also used : Field(java.lang.reflect.Field) HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient)

Example 10 with HyperwalletApiClient

use of com.hyperwallet.clientsdk.util.HyperwalletApiClient in project java-sdk by hyperwallet.

the class HyperwalletTest method testListBankAccounts_withSomeParameters.

@Test
public void testListBankAccounts_withSomeParameters() throws Exception {
    HyperwalletList<HyperwalletBankAccount> response = new HyperwalletList<HyperwalletBankAccount>();
    Hyperwallet client = new Hyperwallet("test-username", "test-password");
    HyperwalletApiClient mockApiClient = createAndInjectHyperwalletApiClientMock(client);
    HyperwalletBankAccountsListPaginationOptions options = new HyperwalletBankAccountsListPaginationOptions();
    options.status(HyperwalletBankAccount.Status.ACTIVATED).sortBy("test-sort-by").createdBefore(convertStringToDate("2019-06-29T17:58:26Z"));
    Mockito.when(mockApiClient.get(ArgumentMatchers.anyString(), ArgumentMatchers.any(TypeReference.class))).thenReturn(response);
    HyperwalletList<HyperwalletBankAccount> resp = client.listBankAccounts("test-user-token", options);
    assertThat(resp, is(equalTo(response)));
    Mockito.verify(mockApiClient).get(ArgumentMatchers.eq("https://api.sandbox.hyperwallet.com/rest/v4/users/test-user-token/bank-accounts?createdBefore=2019-06-29T17:58:26Z" + "&sortBy=test-sort-by&status=ACTIVATED"), ArgumentMatchers.any(TypeReference.class));
}
Also used : HyperwalletApiClient(com.hyperwallet.clientsdk.util.HyperwalletApiClient) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.testng.annotations.Test)

Aggregations

HyperwalletApiClient (com.hyperwallet.clientsdk.util.HyperwalletApiClient)170 Test (org.testng.annotations.Test)168 TypeReference (com.fasterxml.jackson.core.type.TypeReference)85 HyperwalletUser (com.hyperwallet.clientsdk.model.HyperwalletUser)11 ForeignExchange (com.hyperwallet.clientsdk.model.HyperwalletTransfer.ForeignExchange)3 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)1 JSONObject (net.minidev.json.JSONObject)1