Specify query parameters for LoanTransactionsApi retrieveTransaction
This commit is contained in:
committed by
Arnold Gálovics
parent
fb0556c20e
commit
470ff9a745
+25
-11
@@ -20,9 +20,12 @@ package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
@@ -33,22 +36,30 @@ import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException
|
||||
import org.apache.fineract.portfolio.loanaccount.exception.LoanTransactionNotFoundException;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class GetTransactionByIdCommandStrategyTest {
|
||||
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of(null, 0), Arguments.of("id,date,amount", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link GetTransactionByIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccessScenario() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testExecuteSuccessScenario(final String fields, final int noOfQueryParams) {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId);
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, fields);
|
||||
final String responseBody = "{\"id\":12,\"officeId\":1,\"officeName\":\"Head Office\",\"type\":{\"id\":10,\"code\":"
|
||||
+ "\"loanTransactionType.accrual\",\"value\":\"Accrual\",\"disbursement\":false,\"repaymentAtDisbursement\":false,"
|
||||
+ "\"repayment\":false,\"contra\":false,\"waiveInterest\":false,\"waiveCharges\":false,\"accrual\":true,\"writeOff\":false,"
|
||||
@@ -60,7 +71,7 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
+ "\"unrecognizedIncomePortion\":0,\"outstandingLoanBalance\":0,\"submittedOnDate\":[2022,3,29],\"manuallyReversed\":false,"
|
||||
+ "\"loanChargePaidByList\":[],\"numberOfRepayments\":0}";
|
||||
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, testContext.uriInfo))
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(eq(loanId), eq(transactionId), eq(fields), any(UriInfo.class)))
|
||||
.willReturn(responseBody);
|
||||
|
||||
// when
|
||||
@@ -82,9 +93,9 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
final TestContext testContext = new TestContext();
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId);
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, null);
|
||||
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, testContext.uriInfo))
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, null, testContext.uriInfo))
|
||||
.willThrow(new RuntimeException("Some error"));
|
||||
|
||||
// when
|
||||
@@ -106,9 +117,9 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
final TestContext testContext = new TestContext();
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId);
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, null);
|
||||
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, testContext.uriInfo))
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, null, testContext.uriInfo))
|
||||
.willThrow(new LoanNotFoundException(loanId));
|
||||
|
||||
// when
|
||||
@@ -129,9 +140,9 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
final TestContext testContext = new TestContext();
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long transactionId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId);
|
||||
final BatchRequest request = getBatchRequest(loanId, transactionId, null);
|
||||
|
||||
when(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, testContext.uriInfo))
|
||||
when(testContext.loanTransactionsApiResource.retrieveTransaction(loanId, transactionId, null, testContext.uriInfo))
|
||||
.thenThrow(new LoanTransactionNotFoundException(transactionId));
|
||||
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
@@ -151,10 +162,13 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
* the transaction id
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final Long loanId, final Long transactionId) {
|
||||
private BatchRequest getBatchRequest(final Long loanId, final Long transactionId, final String fields) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/" + loanId + "/transactions/" + transactionId;
|
||||
if (fields != null) {
|
||||
relativeUrl = relativeUrl + "?fields=" + fields;
|
||||
}
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
|
||||
Reference in New Issue
Block a user