Skip to content

Commit

Permalink
Rearranged test code. (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Dec 31, 2017
1 parent f02ae69 commit 8b99c24
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 75 deletions.
50 changes: 25 additions & 25 deletions src/test/java/com/bunq/sdk/http/PaginationScenarioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ public class PaginationScenarioTest extends BunqSdkTestBase {
*/
private static Gson gson = BunqGsonBuilder.buildDefault().create();

@Test
public void apiScenarioPaymentListingWithPaginationTest() {
EnsureEnoughPayments();
ArrayList paymentsExpected = new ArrayList<>(GetPaymentsRequired());
Pagination paginationCountOnly = new Pagination();
paginationCountOnly.setCount(PAYMENT_LISTING_PAGE_SIZE);

BunqResponse<List<Payment>> responseLatest =
ListPayments(paginationCountOnly.getUrlParamsCountOnly());
Pagination paginationLatest = responseLatest.getPagination();
BunqResponse<List<Payment>> responsePrevious =
ListPayments(paginationLatest.getUrlParamsPreviousPage());
Pagination paginationPrevious = responsePrevious.getPagination();
BunqResponse<List<Payment>> responsePreviousNext =
ListPayments(paginationPrevious.getUrlParamsNextPage());

ArrayList<Payment> paymentsActual = new ArrayList<>();
paymentsActual.addAll(responsePreviousNext.getValue());
paymentsActual.addAll(responsePrevious.getValue());
String paymentsExpectedSerialized = gson.toJson(paymentsExpected);
String paymentsActualSerialized = gson.toJson(paymentsActual);

Assert.assertEquals(paymentsExpectedSerialized, paymentsActualSerialized);
}

private static void EnsureEnoughPayments() {
for (int i = NUMBER_ZERO; i < GetPaymentsMissingCount(); ++i) {
CreatePayment();
Expand Down Expand Up @@ -104,4 +79,29 @@ private static void CreatePayment() {

Payment.create(apiContext, requestMap, userId, monetaryAccountId);
}

@Test
public void apiScenarioPaymentListingWithPaginationTest() {
EnsureEnoughPayments();
ArrayList paymentsExpected = new ArrayList<>(GetPaymentsRequired());
Pagination paginationCountOnly = new Pagination();
paginationCountOnly.setCount(PAYMENT_LISTING_PAGE_SIZE);

BunqResponse<List<Payment>> responseLatest =
ListPayments(paginationCountOnly.getUrlParamsCountOnly());
Pagination paginationLatest = responseLatest.getPagination();
BunqResponse<List<Payment>> responsePrevious =
ListPayments(paginationLatest.getUrlParamsPreviousPage());
Pagination paginationPrevious = responsePrevious.getPagination();
BunqResponse<List<Payment>> responsePreviousNext =
ListPayments(paginationPrevious.getUrlParamsNextPage());

ArrayList<Payment> paymentsActual = new ArrayList<>();
paymentsActual.addAll(responsePreviousNext.getValue());
paymentsActual.addAll(responsePrevious.getValue());
String paymentsExpectedSerialized = gson.toJson(paymentsExpected);
String paymentsActualSerialized = gson.toJson(paymentsActual);

Assert.assertEquals(paymentsExpectedSerialized, paymentsActualSerialized);
}
}
20 changes: 10 additions & 10 deletions src/test/java/com/bunq/sdk/http/PaginationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ public class PaginationTest {
@Rule
public final ExpectedException exception = ExpectedException.none();

@Test
public void getUrlParamsCountOnlyTest() {
Pagination pagination = createPaginationWithAllPropertiesSet();
Map<String, String> urlParamsCountOnlyExpected = new HashMap<>();
urlParamsCountOnlyExpected.put(Pagination.PARAM_COUNT,
Integer.toString(PAGINATION_COUNT_CUSTOM));

Assert.assertEquals(urlParamsCountOnlyExpected, pagination.getUrlParamsCountOnly());
}

private static Pagination createPaginationWithAllPropertiesSet() {
Pagination pagination = new Pagination();
pagination.setOlderId(PAGINATION_OLDER_ID_CUSTOM);
Expand All @@ -46,6 +36,16 @@ private static Pagination createPaginationWithAllPropertiesSet() {
return pagination;
}

@Test
public void getUrlParamsCountOnlyTest() {
Pagination pagination = createPaginationWithAllPropertiesSet();
Map<String, String> urlParamsCountOnlyExpected = new HashMap<>();
urlParamsCountOnlyExpected.put(Pagination.PARAM_COUNT,
Integer.toString(PAGINATION_COUNT_CUSTOM));

Assert.assertEquals(urlParamsCountOnlyExpected, pagination.getUrlParamsCountOnly());
}

@Test
public void getUrlParamsPreviousPageTest() {
Pagination pagination = createPaginationWithAllPropertiesSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,23 @@ public class MonetaryAccountBankTest extends BunqSdkTestBase {
*/
private static Integer monetaryAccountIdToClose;

@AfterClass
public static void tearDown() throws Exception {
if (monetaryAccountIdToClose != null) {
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(MonetaryAccountBank.FIELD_STATUS, CANCELLED_STATUS);
requestMap.put(MonetaryAccountBank.FIELD_SUB_STATUS, SUB_STATUS);
requestMap.put(MonetaryAccountBank.FIELD_REASON, REASON);
requestMap.put(MonetaryAccountBank.FIELD_REASON_DESCRIPTION, REASON_DESCRIPTION);

MonetaryAccountBank.update(apiContext, requestMap, userId, monetaryAccountIdToClose);
}
}

/**
* Tests the creation of a new monetary account. This account will be deleted after test exited
* with code 0
*
* <p>
* This test has no assertion as of its testing to see if the code runs without errors
*/
@Test
Expand All @@ -49,17 +62,4 @@ public void createNewMonetaryAccountTest() throws Exception {
.getValue();
}

@AfterClass
public static void tearDown() throws Exception {
if (monetaryAccountIdToClose != null) {
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(MonetaryAccountBank.FIELD_STATUS, CANCELLED_STATUS);
requestMap.put(MonetaryAccountBank.FIELD_SUB_STATUS, SUB_STATUS);
requestMap.put(MonetaryAccountBank.FIELD_REASON, REASON);
requestMap.put(MonetaryAccountBank.FIELD_REASON_DESCRIPTION, REASON_DESCRIPTION);

MonetaryAccountBank.update(apiContext, requestMap, userId, monetaryAccountIdToClose);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public class PaymentTest extends BunqSdkTestBase {

private static final ApiContext apiContext = getApiContext();

private static final String AMOUNT_EUR = "00.01";
private static final String AMOUNT_EUR = "0.01";
private static final String CURRENCY = "EUR";
private static final String PAYMENT_DESCRIPTION = "Java test Payment";

/**
* Tests making a payment to another sandbox user
*
* <p>
* This test has no assertion as of its testing to see if the code runs without errors
*/
@Test
Expand All @@ -51,7 +51,7 @@ public void makePaymentToOtherUser() throws Exception {

/**
* Tests making a payment to another monetary account of the same user
*
* <p>
* This test has no assertion as of its testing to see if the code runs without errors
*/
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,32 @@
*/
public class RequestInquiryTest extends BunqSdkTestBase {

private static final String ACCEPTED_STATUS = "ACCEPTED";
private static final String AMOUNT_EUR = "0.01";
private static final String CURRENCY = "EUR";
private static final String REQUEST_DESCRIPTION = "Java Test Payment";
private static final int INDEX_FIRST = 0;
/**
* Config values.
*/
private static int userId = Config.getUserId();
private static int monetaryAccountId = Config.getMonetaryAccountId();
private static int monetaryAccountId2 = Config.getMonetaryAccountId2();
private static Pointer counterPartyAliasSelf = Config.getCounterPartyAliasSelf();
private static ApiContext apiContext = getApiContext();

private static final String ACCEPTED_STATUS = "ACCEPTED";
private static final String AMOUNT_EUR = "0.01";
private static final String CURRENCY = "EUR";
private static final String REQUEST_DESCRIPTION = "Java Test Payment";
private static final int INDEX_FIRST = 0;
private static String acceptRequest() {
List<RequestResponse> responses = RequestResponse.list(apiContext, userId,
monetaryAccountId2).getValue();

private static ApiContext apiContext = getApiContext();
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(RequestResponse.FIELD_STATUS, ACCEPTED_STATUS);

RequestResponse acceptRequest = RequestResponse.update(apiContext, requestMap, userId,
monetaryAccountId2, responses.get(INDEX_FIRST).getId()).getValue();

return acceptRequest.getStatus();
}

/**
* Tests sending a request from monetary account 1 to monetary account 2 and accepting this
Expand All @@ -51,17 +62,4 @@ public void createRequestInquiryTest() throws Exception {
assertEquals(ACCEPTED_STATUS, acceptRequest());
}

private static String acceptRequest() {
List<RequestResponse> responses = RequestResponse.list(apiContext, userId,
monetaryAccountId2).getValue();

HashMap<String, Object> requestMap = new HashMap<>();
requestMap.put(RequestResponse.FIELD_STATUS, ACCEPTED_STATUS);

RequestResponse acceptRequest = RequestResponse.update(apiContext, requestMap, userId,
monetaryAccountId2, responses.get(INDEX_FIRST).getId()).getValue();

return acceptRequest.getStatus();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public class SessionTest extends BunqSdkTestBase {
*/
private static final int SESSION_ID_DUMMY = 0;
private static final int SECONDS_TO_SLEEP = 2;

private static String apiConfigPath = Config.getApiConfigPath();

private static final ApiContext apiContext = getApiContext();
private static String apiConfigPath = Config.getApiConfigPath();

/**
* Tests deletion of the current session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public class NotificationUrlTest extends BunqSdkTestBase {
private static final String JSON_PATH_SHARE_INVITE_BANK_RESPONSE_MODEL = BASE_PATH_JSON_MODEL +
"/ShareInviteBankResponse.json";

private static final Type TYPE_NOTIFICATION_URL = new TypeToken<NotificationUrl>() {}.getType();
private static final Type TYPE_NOTIFICATION_URL = new TypeToken<NotificationUrl>() {
}.getType();

private void executeNotificationUrlTest(
String expectedJsonFileName,
Expand Down

0 comments on commit 8b99c24

Please sign in to comment.