FINERACT-1724: Loan Charge API support for batch APIs and a couple of other batch API enhancements
This commit is contained in:
committed by
Arnold Gálovics
parent
cb39a23467
commit
8ab206aa4a
+87
-4
@@ -25,25 +25,38 @@ import static org.mockito.Mockito.when;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.AdjustChargeByChargeExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.AdjustChargeCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.AdjustTransactionByExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.AdjustTransactionCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.ApproveLoanRescheduleCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CollectChargesByLoanExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateChargeByLoanExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateClientCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateDatatableEntryCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateLoanRescheduleRequestCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateTransactionByLoanExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetChargeByChargeExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetChargeByIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetDatatableEntryByAppTableIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetDatatableEntryByQueryCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetLoanByExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetLoanByIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetTransactionByExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.GetTransactionByIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.LoanStateTransistionsByExternalIdCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.ModifyLoanApplicationCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.UnknownCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.UpdateDatatableEntryOneToManyCommandStrategy;
|
||||
import org.apache.fineract.batch.command.internal.UpdateDatatableEntryOneToOneCommandStrategy;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
@@ -68,12 +81,52 @@ public class CommandStrategyProviderTest {
|
||||
mock(GetLoanByIdCommandStrategy.class)),
|
||||
Arguments.of("loans/123?associations=all&exclude=guarantors", HttpMethod.GET, "getLoanByIdCommandStrategy",
|
||||
mock(GetLoanByIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1", HttpMethod.GET, "getLoanByExternalIdCommandStrategy",
|
||||
mock(GetLoanByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1?associations=all", HttpMethod.GET,
|
||||
"getLoanByExternalIdCommandStrategy", mock(GetLoanByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1?associations=all&exclude=guarantors", HttpMethod.GET,
|
||||
"getLoanByExternalIdCommandStrategy", mock(GetLoanByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("savingsaccounts", HttpMethod.POST, "applySavingsCommandStrategy", mock(ApplySavingsCommandStrategy.class)),
|
||||
Arguments.of("loans/123/charges", HttpMethod.POST, "createChargeCommandStrategy", mock(CreateChargeCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges", HttpMethod.POST,
|
||||
"createChargeByLoanExternalIdCommandStrategy", mock(CreateChargeByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges?command=mycommand", HttpMethod.POST,
|
||||
"createChargeByLoanExternalIdCommandStrategy", mock(CreateChargeByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/123/charges", HttpMethod.GET, "collectChargesCommandStrategy",
|
||||
mock(CollectChargesCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges", HttpMethod.GET,
|
||||
"collectChargesByLoanExternalIdCommandStrategy", mock(CollectChargesByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/123/charges/123", HttpMethod.GET, "getChargeByIdCommandStrategy",
|
||||
mock(GetChargeByIdCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges/external-id/7dfad438-2319-48ce-8520-10a62801e9ab",
|
||||
HttpMethod.GET, "getChargeByChargeExternalIdCommandStrategy",
|
||||
mock(GetChargeByChargeExternalIdCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?fields=id",
|
||||
HttpMethod.GET, "getChargeByChargeExternalIdCommandStrategy",
|
||||
mock(GetChargeByChargeExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/123/charges/123?command=adjustment", HttpMethod.POST, "adjustChargeCommandStrategy",
|
||||
mock(AdjustChargeCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?command=adjustment",
|
||||
HttpMethod.POST, "adjustChargeByChargeExternalIdCommandStrategy",
|
||||
mock(AdjustChargeByChargeExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=repayment", HttpMethod.POST,
|
||||
"createTransactionByLoanExternalIdCommandStrategy", mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=creditBalanceRefund",
|
||||
HttpMethod.POST, "createTransactionByLoanExternalIdCommandStrategy",
|
||||
mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=goodwillCredit", HttpMethod.POST,
|
||||
"createTransactionByLoanExternalIdCommandStrategy", mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=merchantIssuedRefund",
|
||||
HttpMethod.POST, "createTransactionByLoanExternalIdCommandStrategy",
|
||||
mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=payoutRefund", HttpMethod.POST,
|
||||
"createTransactionByLoanExternalIdCommandStrategy", mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions?command=chargeRefund", HttpMethod.POST,
|
||||
"createTransactionByLoanExternalIdCommandStrategy", mock(CreateTransactionByLoanExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions?command=repayment", HttpMethod.POST, "createTransactionLoanCommandStrategy",
|
||||
mock(CreateTransactionLoanCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions?command=creditBalanceRefund", HttpMethod.POST, "createTransactionLoanCommandStrategy",
|
||||
@@ -90,18 +143,33 @@ public class CommandStrategyProviderTest {
|
||||
mock(AdjustTransactionCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions/123?command=chargeback", HttpMethod.POST, "adjustTransactionCommandStrategy",
|
||||
mock(AdjustTransactionCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab",
|
||||
HttpMethod.POST, "adjustTransactionByExternalIdCommandStrategy",
|
||||
mock(AdjustTransactionByExternalIdCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?command=chargeback",
|
||||
HttpMethod.POST, "adjustTransactionByExternalIdCommandStrategy",
|
||||
mock(AdjustTransactionByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("clients/456?command=activate", HttpMethod.POST, "activateClientCommandStrategy",
|
||||
mock(ActivateClientCommandStrategy.class)),
|
||||
Arguments.of("loans/123?command=approve", HttpMethod.POST, "approveLoanCommandStrategy",
|
||||
mock(ApproveLoanCommandStrategy.class)),
|
||||
Arguments.of("loans/123?command=disburse", HttpMethod.POST, "disburseLoanCommandStrategy",
|
||||
mock(DisburseLoanCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1?command=approve", HttpMethod.POST,
|
||||
"loanStateTransistionsByExternalIdCommandStrategy", mock(LoanStateTransistionsByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1?command=disburse", HttpMethod.POST,
|
||||
"loanStateTransistionsByExternalIdCommandStrategy", mock(LoanStateTransistionsByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("rescheduleloans", HttpMethod.POST, "createLoanRescheduleRequestCommandStrategy",
|
||||
mock(CreateLoanRescheduleRequestCommandStrategy.class)),
|
||||
Arguments.of("rescheduleloans/123?command=approve", HttpMethod.POST, "approveLoanRescheduleCommandStrategy",
|
||||
mock(ApproveLoanRescheduleCommandStrategy.class)),
|
||||
Arguments.of("loans/123/transactions/123", HttpMethod.GET, "getTransactionByIdCommandStrategy",
|
||||
mock(GetTransactionByIdCommandStrategy.class)),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions/external-id/7dfad438-2319-48ce-8520-10a62801e9ab?fields=id",
|
||||
HttpMethod.GET, "getTransactionByExternalIdCommandStrategy", mock(GetTransactionByExternalIdCommandStrategy.class)),
|
||||
Arguments.of("datatables/test_dt_table/123", HttpMethod.GET, "getDatatableEntryByAppTableIdCommandStrategy",
|
||||
mock(GetDatatableEntryByAppTableIdCommandStrategy.class)),
|
||||
Arguments.of("datatables/test_dt_table/123?genericResultSet=true", HttpMethod.GET,
|
||||
@@ -109,7 +177,15 @@ public class CommandStrategyProviderTest {
|
||||
Arguments.of("datatables/test_dt_table/123", HttpMethod.POST, "createDatatableEntryCommandStrategy",
|
||||
mock(CreateDatatableEntryCommandStrategy.class)),
|
||||
Arguments.of("datatables/test_dt_table/123/1", HttpMethod.PUT, "updateDatatableEntryOneToManyCommandStrategy",
|
||||
mock(UpdateDatatableEntryOneToManyCommandStrategy.class)));
|
||||
mock(UpdateDatatableEntryOneToManyCommandStrategy.class)),
|
||||
Arguments.of("datatables/test_dt_table/123", HttpMethod.PUT, "updateDatatableEntryOneToOneCommandStrategy",
|
||||
mock(UpdateDatatableEntryOneToOneCommandStrategy.class)),
|
||||
Arguments.of("loans/123?command=markAsFraud", HttpMethod.PUT, "modifyLoanApplicationCommandStrategy",
|
||||
mock(ModifyLoanApplicationCommandStrategy.class)),
|
||||
Arguments.of("loans/123", HttpMethod.PUT, "modifyLoanApplicationCommandStrategy",
|
||||
mock(ModifyLoanApplicationCommandStrategy.class)),
|
||||
Arguments.of("datatables/test_dt_table/query?columnFilter=id&valueFilter=12&resultColumns=id", HttpMethod.GET,
|
||||
"getDatatableEntryByQueryCommandStrategy", mock(GetDatatableEntryByQueryCommandStrategy.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,15 +212,22 @@ public class CommandStrategyProviderTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Command strategy provider for error scenarioss.
|
||||
* Command strategy provider for error scenarios.
|
||||
*
|
||||
* @return the test data stream
|
||||
*/
|
||||
private static Stream<Arguments> provideCommandStrategyResourceDetailsForErrors() {
|
||||
return Stream.of(Arguments.of("loans/123?command=reject", HttpMethod.POST),
|
||||
Arguments.of("loans/glimAccount/746?command=approve", HttpMethod.POST), Arguments.of("loans/123", HttpMethod.PUT),
|
||||
Arguments.of("loans/glimAccount/746?command=approve", HttpMethod.POST),
|
||||
Arguments.of("datatables/test_dt_table", HttpMethod.GET), Arguments.of("datatables", HttpMethod.GET),
|
||||
Arguments.of("loans//charges/123", HttpMethod.GET), Arguments.of("loans/123/charges/", HttpMethod.GET));
|
||||
Arguments.of("loans//charges/123", HttpMethod.GET), Arguments.of("loans/123/charges/", HttpMethod.GET),
|
||||
Arguments.of("loans/123/charges/123", HttpMethod.POST),
|
||||
Arguments.of(
|
||||
"loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/charges/external-id/7dfad438-2319-48ce-8520-10a62801e9ab",
|
||||
HttpMethod.POST),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/transactions", HttpMethod.POST),
|
||||
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1", HttpMethod.POST),
|
||||
Arguments.of("datatables/test_dt_table/query", HttpMethod.GET));
|
||||
|
||||
}
|
||||
|
||||
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link AdjustChargeByChargeExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class AdjustChargeByChargeExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link AdjustChargeByChargeExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteAdjustChargeByExternalIdWithCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String loanChargeExternalId = UUID.randomUUID().toString();
|
||||
final String command = "adjustment";
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, loanChargeExternalId, command);
|
||||
final String responseBody = "{\"loanId\":13,\"resourceId\":16,\"subResourceId\":26,\"changes\":{\"amount\":10.0,"
|
||||
+ "\"transactionDate\":[2022,12,7],\"locale\":\"de_DE\"}}";
|
||||
|
||||
given(testContext.loanChargesApiResource.executeLoanCharge(eq(loanExternalId), eq(loanChargeExternalId), eq(command),
|
||||
eq(request.getBody()))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanChargesApiResource).executeLoanCharge(eq(loanExternalId), eq(loanChargeExternalId), eq(command),
|
||||
eq(request.getBody()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link AdjustChargeByChargeExternalIdCommandStrategy#execute} error scenario.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteAdjustChargeByExternalIdWithoutCommandErrorScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String loanChargeExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, loanChargeExternalId, null);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals("Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist",
|
||||
response.getBody());
|
||||
verifyNoInteractions(testContext.loanChargesApiResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id and charge external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param chargeExternalId
|
||||
* the charge external id
|
||||
* @param chargeCommand
|
||||
* the charge command
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String chargeExternalId, final String chargeCommand) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = String.format("loans/external-id/%s/charges/external-id/%s", loanExternalId, chargeExternalId);
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
if (StringUtils.isNotBlank(chargeCommand)) {
|
||||
br.setRelativeUrl(br.getRelativeUrl() + String.format("?command=%s", chargeCommand));
|
||||
}
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{\"amount\":7.00,\"locale\":\"en\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanChargesApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanChargesApiResource loanChargesApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final AdjustChargeByChargeExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new AdjustChargeByChargeExternalIdCommandStrategy(loanChargesApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link AdjustChargeCommandStrategy}.
|
||||
*/
|
||||
public class AdjustChargeCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link AdjustChargeCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithAdjustmentCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long loanChargeId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final String command = "adjustment";
|
||||
final BatchRequest request = getBatchRequest(loanId, loanChargeId, command);
|
||||
final String responseBody = "{\"loanId\":13,\"resourceId\":16,\"subResourceId\":26,\"changes\":{\"amount\":10.0,"
|
||||
+ "\"transactionDate\":[2022,12,7],\"locale\":\"de_DE\"}}";
|
||||
|
||||
given(testContext.loanChargesApiResource.executeLoanCharge(eq(loanId), eq(loanChargeId), eq(command), eq(request.getBody())))
|
||||
.willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanChargesApiResource).executeLoanCharge(eq(loanId), eq(loanChargeId), eq(command), eq(request.getBody()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link AdjustChargeCommandStrategy#execute} error scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithoutCommandErrorScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final Long loanChargeId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, loanChargeId, null);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals("Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist",
|
||||
response.getBody());
|
||||
verifyNoInteractions(testContext.loanChargesApiResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and transaction id.
|
||||
*
|
||||
* @param loanId
|
||||
* the loan id
|
||||
* @param transactionId
|
||||
* the transaction id
|
||||
* @param chargeCommand
|
||||
* the charge command
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final Long loanId, final Long transactionId, final String chargeCommand) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = String.format("loans/%s/charges/%s", loanId, transactionId);
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
if (StringUtils.isNotBlank(chargeCommand)) {
|
||||
br.setRelativeUrl(br.getRelativeUrl() + String.format("?command=%s", chargeCommand));
|
||||
}
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{\"amount\":7.00,\"locale\":\"en\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanChargesApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanChargesApiResource loanChargesApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final AdjustChargeCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new AdjustChargeCommandStrategy(loanChargesApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link AdjustTransactionByExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class AdjustTransactionByExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link AdjustTransactionByExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithoutCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String transactionExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, transactionExternalId, null);
|
||||
final String responseBody = "{\"officeId\":1,\"clientId\":107,\"loanId\":71,\"resourceId\":193,\"changes\""
|
||||
+ ":{\"transactionDate\":\"03 October 2022\",\"transactionAmount\":\"500\",\"locale\":\"en\",\"dateFormat\":"
|
||||
+ "\"dd MMMM yyyy\",\"paymentTypeId\":\"\"}}";
|
||||
|
||||
given(testContext.loanTransactionsApiResource.adjustLoanTransaction(eq(loanExternalId), eq(transactionExternalId),
|
||||
eq(request.getBody()), eq(null))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanTransactionsApiResource).adjustLoanTransaction(eq(loanExternalId), eq(transactionExternalId),
|
||||
eq(request.getBody()), isNull());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link AdjustTransactionByExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteWithCommandSuccessScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String transactionExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, transactionExternalId, "chargeback");
|
||||
final String responseBody = "{\"officeId\":1,\"clientId\":107,\"loanId\":71,\"resourceId\":193,\"changes\""
|
||||
+ ":{\"transactionDate\":\"03 October 2022\",\"transactionAmount\":\"500\",\"locale\":\"en\",\"dateFormat\":"
|
||||
+ "\"dd MMMM yyyy\",\"paymentTypeId\":\"\"}}";
|
||||
|
||||
given(testContext.loanTransactionsApiResource.adjustLoanTransaction(eq(loanExternalId), eq(transactionExternalId),
|
||||
eq(request.getBody()), eq("chargeback"))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanTransactionsApiResource).adjustLoanTransaction(eq(loanExternalId), eq(transactionExternalId),
|
||||
eq(request.getBody()), eq("chargeback"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and transaction id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan id
|
||||
* @param transactionExternalId
|
||||
* the transaction id
|
||||
* @param transactionCommand
|
||||
* the optional transaction command
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String transactionExternalId, final String transactionCommand) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = String.format("loans/external-id/%s/transactions/external-id/%s", loanExternalId, transactionExternalId);
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
if (StringUtils.isNotBlank(transactionCommand)) {
|
||||
br.setRelativeUrl(br.getRelativeUrl() + String.format("?command=%s", transactionCommand));
|
||||
}
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{\"locale\":\"en\",\"dateFormat\":\"dd MMMM yyyy\",\"transactionDate\":\"03 October 2022\",\"transactionAmount\":500}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanTransactionsApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanTransactionsApiResource loanTransactionsApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final AdjustTransactionByExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new AdjustTransactionByExternalIdCommandStrategy(loanTransactionsApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-9
@@ -21,6 +21,7 @@ package org.apache.fineract.batch.command.internal;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
@@ -30,10 +31,13 @@ import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link AdjustTransactionCommandStrategy}.
|
||||
*/
|
||||
public class AdjustTransactionCommandStrategyTest {
|
||||
|
||||
/**
|
||||
@@ -58,10 +62,12 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
|
||||
assertEquals(response.getRequestId(), request.getRequestId());
|
||||
assertEquals(response.getHeaders(), request.getHeaders());
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanTransactionsApiResource).adjustLoanTransaction(eq(loanId), eq(transactionId), eq(request.getBody()),
|
||||
eq(null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,10 +92,12 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
|
||||
assertEquals(response.getRequestId(), request.getRequestId());
|
||||
assertEquals(response.getHeaders(), request.getHeaders());
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loanTransactionsApiResource).adjustLoanTransaction(eq(loanId), eq(transactionId), eq(request.getBody()),
|
||||
eq("chargeback"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,14 +133,26 @@ public class AdjustTransactionCommandStrategyTest {
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanTransactionsApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanTransactionsApiResource loanTransactionsApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final AdjustTransactionCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new AdjustTransactionCommandStrategy(loanTransactionsApiResource);
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* The {@link CollectChargesByLoanExternalIdCommandStrategy} test class.
|
||||
*/
|
||||
public class CollectChargesByLoanExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Query parameter provider.
|
||||
*
|
||||
* @return the test data stream
|
||||
*/
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of(null, 0), Arguments.of("fields=name,amountOrPercentage", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link CollectChargesByLoanExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testExecuteSuccessScenario(final String queryParameter, final int numberOfQueryParams) {
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, queryParameter);
|
||||
final String responseBody = "someResponseBody";
|
||||
|
||||
given(testContext.loanChargesApiResource.retrieveAllLoanCharges(eq(loanExternalId), any(UriInfo.class))).willReturn(responseBody);
|
||||
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
assertThat(response.getRequestId()).isEqualTo(request.getRequestId());
|
||||
assertThat(response.getHeaders()).isEqualTo(request.getHeaders());
|
||||
assertThat(response.getBody()).isEqualTo(responseBody);
|
||||
|
||||
verify(testContext.loanChargesApiResource).retrieveAllLoanCharges(eq(loanExternalId), testContext.uriInfoCaptor.capture());
|
||||
MutableUriInfo mutableUriInfo = testContext.uriInfoCaptor.getValue();
|
||||
assertThat(mutableUriInfo.getAdditionalQueryParameters()).hasSize(numberOfQueryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param queryParameter
|
||||
* the query parameter
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String queryParameter) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId + "/charges";
|
||||
|
||||
if (queryParameter != null) {
|
||||
relativeUrl = relativeUrl + "?" + queryParameter;
|
||||
}
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.GET);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The subject to test
|
||||
*/
|
||||
private final CollectChargesByLoanExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* The mock uri info
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The mock {@link LoanChargesApiResource} object.
|
||||
*/
|
||||
@Mock
|
||||
private LoanChargesApiResource loanChargesApiResource;
|
||||
|
||||
/**
|
||||
* The uri info captor
|
||||
*/
|
||||
@Captor
|
||||
private ArgumentCaptor<MutableUriInfo> uriInfoCaptor;
|
||||
|
||||
/**
|
||||
* Test Context constructor
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new CollectChargesByLoanExternalIdCommandStrategy(loanChargesApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for {@link CreateChargeByLoanExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class CreateChargeByLoanExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Command arguments provider.
|
||||
*
|
||||
* @return command argument
|
||||
*/
|
||||
private static Stream<Arguments> provideCommandParameters() {
|
||||
return Stream.of(Arguments.of(null, 0), Arguments.of("adjustment", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link CreateChargeByLoanExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*
|
||||
* @param command
|
||||
* the command to pass
|
||||
* @param noOfArguments
|
||||
* the number of arguments
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideCommandParameters")
|
||||
public void testExecuteSuccessScenario(final String command, final int noOfArguments) {
|
||||
final TestContext testContext = new TestContext();
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest batchRequest = getBatchRequest(loanExternalId, command);
|
||||
final String responseBody = "myResponseBody";
|
||||
|
||||
when(testContext.loanChargesApiResource.executeLoanCharge(loanExternalId, command, batchRequest.getBody()))
|
||||
.thenReturn(responseBody);
|
||||
|
||||
BatchResponse batchResponse = testContext.subjectToTest.execute(batchRequest, testContext.uriInfo);
|
||||
|
||||
assertEquals(HttpStatus.SC_OK, batchResponse.getStatusCode());
|
||||
assertSame(responseBody, batchResponse.getBody());
|
||||
assertEquals(batchRequest.getRequestId(), batchResponse.getRequestId());
|
||||
assertEquals(batchRequest.getHeaders(), batchResponse.getHeaders());
|
||||
|
||||
verify(testContext.loanChargesApiResource).executeLoanCharge(loanExternalId, command, batchRequest.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and command value.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param command
|
||||
* the transaction id
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String command) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId + "/charges";
|
||||
if (StringUtils.isNotBlank(command)) {
|
||||
relativeUrl = relativeUrl + String.format("?command=%s", command);
|
||||
}
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* Mock URI info.
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* Mock loan charges API resource.
|
||||
*/
|
||||
@Mock
|
||||
private LoanChargesApiResource loanChargesApiResource;
|
||||
|
||||
/**
|
||||
* The {@link CreateChargeByLoanExternalIdCommandStrategy} under test.
|
||||
*/
|
||||
private final CreateChargeByLoanExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new CreateChargeByLoanExternalIdCommandStrategy(loanChargesApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-5
@@ -29,10 +29,13 @@ import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.dataqueries.api.DatatablesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link CreateDatatableEntryCommandStrategy}.
|
||||
*/
|
||||
public class CreateDatatableEntryCommandStrategyTest {
|
||||
|
||||
/**
|
||||
@@ -55,10 +58,10 @@ public class CreateDatatableEntryCommandStrategyTest {
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
|
||||
assertEquals(response.getRequestId(), request.getRequestId());
|
||||
assertEquals(response.getHeaders(), request.getHeaders());
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,14 +91,27 @@ public class CreateDatatableEntryCommandStrategyTest {
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link DatatablesApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private DatatablesApiResource datatablesApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final CreateDatatableEntryCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new CreateDatatableEntryCommandStrategy(datatablesApiResource);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class fpr {@link CreateLoanRescheduleRequestCommandStrategy}.
|
||||
* Test class for {@link CreateLoanRescheduleRequestCommandStrategy}.
|
||||
*/
|
||||
public class CreateLoanRescheduleRequestCommandStrategyTest {
|
||||
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link CreateTransactionByLoanExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class CreateTransactionByLoanExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link CreateTransactionByLoanExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccessScenario() {
|
||||
final TestContext testContext = new TestContext();
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String command = "myCommand";
|
||||
final BatchRequest batchRequest = getBatchRequest(loanExternalId, command);
|
||||
final String responseBody = "myResponseBody";
|
||||
|
||||
when(testContext.loanTransactionsApiResource.executeLoanTransaction(loanExternalId, command, batchRequest.getBody()))
|
||||
.thenReturn(responseBody);
|
||||
|
||||
BatchResponse batchResponse = testContext.subjectToTest.execute(batchRequest, testContext.uriInfo);
|
||||
|
||||
assertEquals(HttpStatus.SC_OK, batchResponse.getStatusCode());
|
||||
assertSame(responseBody, batchResponse.getBody());
|
||||
assertEquals(batchRequest.getRequestId(), batchResponse.getRequestId());
|
||||
assertEquals(batchRequest.getHeaders(), batchResponse.getHeaders());
|
||||
|
||||
verify(testContext.loanTransactionsApiResource).executeLoanTransaction(loanExternalId, command, batchRequest.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id and command value.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param command
|
||||
* the transaction id
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String command) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId + "/transactions?command=" + command;
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* Mock URI info.
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* Mock loan transactions API resource.
|
||||
*/
|
||||
@Mock
|
||||
private LoanTransactionsApiResource loanTransactionsApiResource;
|
||||
|
||||
/**
|
||||
* The {@link CreateTransactionByLoanExternalIdCommandStrategy} under test.
|
||||
*/
|
||||
private final CreateTransactionByLoanExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new CreateTransactionByLoanExternalIdCommandStrategy(loanTransactionsApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -35,7 +35,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class fpr {@link CreateTransactionLoanCommandStrategy}.
|
||||
* Test class for {@link CreateTransactionLoanCommandStrategy}.
|
||||
*/
|
||||
public class CreateTransactionLoanCommandStrategyTest {
|
||||
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanChargesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* The {@link GetChargeByChargeExternalIdCommandStrategy} test class.
|
||||
*/
|
||||
public class GetChargeByChargeExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Query parameter provider.
|
||||
*
|
||||
* @return the test data stream
|
||||
*/
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of(null, 0), Arguments.of("fields=name,amountOrPercentage", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link GetChargeByChargeExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testExecuteSuccessScenario(final String queryParameter, final int numberOfQueryParams) {
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String chargeExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, chargeExternalId, queryParameter);
|
||||
final String responseBody = "someResponseBody";
|
||||
|
||||
given(testContext.loanChargesApiResource.retrieveLoanCharge(eq(loanExternalId), eq(chargeExternalId), any(UriInfo.class)))
|
||||
.willReturn(responseBody);
|
||||
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
assertThat(response.getRequestId()).isEqualTo(request.getRequestId());
|
||||
assertThat(response.getHeaders()).isEqualTo(request.getHeaders());
|
||||
assertThat(response.getBody()).isEqualTo(responseBody);
|
||||
|
||||
verify(testContext.loanChargesApiResource).retrieveLoanCharge(eq(loanExternalId), eq(chargeExternalId),
|
||||
testContext.uriInfoCaptor.capture());
|
||||
MutableUriInfo mutableUriInfo = testContext.uriInfoCaptor.getValue();
|
||||
assertThat(mutableUriInfo.getAdditionalQueryParameters()).hasSize(numberOfQueryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id and charge external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param chargeExternalId
|
||||
* the charge external id
|
||||
* @param queryParameter
|
||||
* the query parameter
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String chargeExternalId, final String queryParameter) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId + "/charges/external-id/" + chargeExternalId;
|
||||
|
||||
if (queryParameter != null) {
|
||||
relativeUrl = relativeUrl + "?" + queryParameter;
|
||||
}
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.GET);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The subject to test
|
||||
*/
|
||||
private final GetChargeByChargeExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* The mock uri info
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The mock {@link LoanChargesApiResource} object.
|
||||
*/
|
||||
@Mock
|
||||
private LoanChargesApiResource loanChargesApiResource;
|
||||
|
||||
/**
|
||||
* The uri info captor
|
||||
*/
|
||||
@Captor
|
||||
private ArgumentCaptor<MutableUriInfo> uriInfoCaptor;
|
||||
|
||||
/**
|
||||
* Test Context constructor
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new GetChargeByChargeExternalIdCommandStrategy(loanChargesApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
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.verify;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.core.api.MutableUriInfo;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link GetLoanByExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class GetLoanByExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* The query parameter provider.
|
||||
*
|
||||
* @return Arguments.
|
||||
*/
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of(null, null, null, null, 0), Arguments.of("all", null, null, null, 1),
|
||||
Arguments.of("repaymentSchedule,transactions", null, "guarantors,futureSchedule", "true", 3),
|
||||
Arguments.of("repaymentSchedule,transactions", "id,principal,annualInterestRate", null, "false", 3),
|
||||
Arguments.of("repaymentSchedule,transactions", "id,principal,annualInterestRate", "guarantors,futureSchedule", "false", 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link GetLoanByExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testExecuteSuccessScenario(final String associations, final String fields, final String exclude,
|
||||
final String staffInSelectedOfficeOnlyFlag, final int noOfQueryParams) {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, associations, exclude, fields, staffInSelectedOfficeOnlyFlag);
|
||||
final Boolean staffInSelectedOfficeOnlyBooleanFlag = BooleanUtils.toBoolean(staffInSelectedOfficeOnlyFlag);
|
||||
final String responseBody = "{\\\"id\\\":2,\\\"accountNo\\\":\\\"000000002\\\"}";
|
||||
|
||||
given(testContext.loansApiResource.retrieveLoan(eq(loanExternalId), eq(staffInSelectedOfficeOnlyBooleanFlag), eq(associations),
|
||||
eq(exclude), eq(fields), any(UriInfo.class))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.underTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
|
||||
verify(testContext.loansApiResource).retrieveLoan(eq(loanExternalId), eq(staffInSelectedOfficeOnlyBooleanFlag), eq(associations),
|
||||
eq(exclude), eq(fields), testContext.uriInfoCaptor.capture());
|
||||
final MutableUriInfo mutableUriInfo = testContext.uriInfoCaptor.getValue();
|
||||
assertEquals(noOfQueryParams, mutableUriInfo.getAdditionalQueryParameters().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param associations
|
||||
* the associations query param
|
||||
* @param exclude
|
||||
* exclude query param
|
||||
* @param fields
|
||||
* fields query param
|
||||
* @param staffInSelectedOfficeOnlyFlag
|
||||
* staff in selected office only query param
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String associations, final String exclude, final String fields,
|
||||
final String staffInSelectedOfficeOnlyFlag) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId;
|
||||
|
||||
Set<String> queryParams = new HashSet<>();
|
||||
if (associations != null) {
|
||||
queryParams.add("associations=" + associations);
|
||||
}
|
||||
if (exclude != null) {
|
||||
queryParams.add("exclude=" + exclude);
|
||||
}
|
||||
if (fields != null) {
|
||||
queryParams.add("fields=" + fields);
|
||||
}
|
||||
if (staffInSelectedOfficeOnlyFlag != null) {
|
||||
queryParams.add("staffInSelectedOfficeOnly=" + staffInSelectedOfficeOnlyFlag);
|
||||
}
|
||||
if (!queryParams.isEmpty()) {
|
||||
relativeUrl = relativeUrl + "?" + String.join("&", queryParams);
|
||||
}
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.GET);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoansApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoansApiResource loansApiResource;
|
||||
|
||||
/**
|
||||
* The Captor for UriInfo
|
||||
*/
|
||||
@Captor
|
||||
private ArgumentCaptor<MutableUriInfo> uriInfoCaptor;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final GetLoanByExternalIdCommandStrategy underTest;
|
||||
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
underTest = new GetLoanByExternalIdCommandStrategy(loansApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -43,6 +43,9 @@ import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link GetLoanByIdCommandStrategy}.
|
||||
*/
|
||||
public class GetLoanByIdCommandStrategyTest {
|
||||
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoanTransactionsApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for {@link GetTransactionByExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class GetTransactionByExternalIdCommandStrategyTest {
|
||||
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of(null, 0), Arguments.of("id,date,amount", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link GetTransactionByExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testExecuteSuccessScenario(final String fields, final int noOfQueryParams) {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final String transactionExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, transactionExternalId, 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,"
|
||||
+ "\"recoveryRepayment\":false,\"initiateTransfer\":false,\"approveTransfer\":false,\"withdrawTransfer\":false,"
|
||||
+ "\"rejectTransfer\":false,\"chargePayment\":false,\"refund\":false,\"refundForActiveLoans\":false},\"date\":[2022,3,29],"
|
||||
+ "\"currency\":{\"code\":\"EUR\",\"name\":\"Euro\",\"decimalPlaces\":2,\"inMultiplesOf\":0,\"displaySymbol\":\"€\","
|
||||
+ "\"nameCode\":\"currency.EUR\",\"displayLabel\":\"Euro (€)\"},\"amount\":0.000000,\"netDisbursalAmount\":200.000000,"
|
||||
+ "\"principalPortion\":0,\"interestPortion\":0.000000,\"feeChargesPortion\":0,\"penaltyChargesPortion\":0,\"overpaymentPortion\":0,"
|
||||
+ "\"unrecognizedIncomePortion\":0,\"outstandingLoanBalance\":0,\"submittedOnDate\":[2022,3,29],\"manuallyReversed\":false,"
|
||||
+ "\"loanChargePaidByList\":[],\"numberOfRepayments\":0}";
|
||||
|
||||
given(testContext.loanTransactionsApiResource.retrieveTransactionByLoanExternalIdAndTransactionExternalId(eq(loanExternalId),
|
||||
eq(transactionExternalId), eq(fields), any(UriInfo.class))).willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SC_OK);
|
||||
assertThat(response.getRequestId()).isEqualTo(request.getRequestId());
|
||||
assertThat(response.getHeaders()).isEqualTo(request.getHeaders());
|
||||
assertThat(response.getBody()).isEqualTo(responseBody);
|
||||
verify(testContext.loanTransactionsApiResource).retrieveTransactionByLoanExternalIdAndTransactionExternalId(eq(loanExternalId),
|
||||
eq(transactionExternalId), eq(fields), any(UriInfo.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id and transaction external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param transactionExternalId
|
||||
* the transaction external id
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String transactionExternalId, final String fields) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = "loans/external-id/" + loanExternalId + "/transactions/external-id/" + transactionExternalId;
|
||||
if (fields != null) {
|
||||
relativeUrl = relativeUrl + "?fields=" + fields;
|
||||
}
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
br.setMethod(HttpMethod.GET);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanTransactionsApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanTransactionsApiResource loanTransactionsApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final GetTransactionByExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new GetTransactionByExternalIdCommandStrategy(loanTransactionsApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -37,6 +37,9 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link GetTransactionByIdCommandStrategy}.
|
||||
*/
|
||||
public class GetTransactionByIdCommandStrategyTest {
|
||||
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
@@ -110,14 +113,27 @@ public class GetTransactionByIdCommandStrategyTest {
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoanTransactionsApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoanTransactionsApiResource loanTransactionsApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final GetTransactionByIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new GetTransactionByIdCommandStrategy(loanTransactionsApiResource);
|
||||
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for {@link LoanStateTransistionsByExternalIdCommandStrategy}.
|
||||
*/
|
||||
public class LoanStateTransistionsByExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link LoanStateTransistionsByExternalIdCommandStrategy#execute} happy path scenario.
|
||||
*
|
||||
* @param command
|
||||
* the command
|
||||
* @param noOfArguments
|
||||
* the no. of arguments
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideQueryParameters")
|
||||
public void testLoanStateTransistionsByExternalIdWithCommandSuccessScenario(final String command, final int noOfArguments) {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, command);
|
||||
final String responseBody = "{\"loanId\":13,\"resourceId\":16,\"subResourceId\":26,\"changes\":{\"amount\":10.0,"
|
||||
+ "\"transactionDate\":[2022,12,7],\"locale\":\"de_DE\"}}";
|
||||
|
||||
given(testContext.loansApiResource.stateTransitions(eq(loanExternalId), eq(command), eq(request.getBody())))
|
||||
.willReturn(responseBody);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loansApiResource).stateTransitions(eq(loanExternalId), eq(command), eq(request.getBody()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query parameter provider.
|
||||
*
|
||||
* @return the test data stream
|
||||
*/
|
||||
private static Stream<Arguments> provideQueryParameters() {
|
||||
return Stream.of(Arguments.of("approve", 1), Arguments.of("disburse", 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link LoanStateTransistionsByExternalIdCommandStrategy#execute} error scenario.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testLoanStateTransistionsByExternalIdWithoutCommandErrorScenario() {
|
||||
// given
|
||||
final TestContext testContext = new TestContext();
|
||||
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, null);
|
||||
|
||||
// when
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals("Resource with method " + request.getMethod() + " and relativeUrl " + request.getRelativeUrl() + " doesn't exist",
|
||||
response.getBody());
|
||||
verifyNoInteractions(testContext.loansApiResource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param chargeCommand
|
||||
* the charge command
|
||||
* @return BatchRequest
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String chargeCommand) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
String relativeUrl = String.format("loans/external-id/%s", loanExternalId);
|
||||
|
||||
br.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setRelativeUrl(relativeUrl);
|
||||
if (StringUtils.isNotBlank(chargeCommand)) {
|
||||
br.setRelativeUrl(br.getRelativeUrl() + String.format("?command=%s", chargeCommand));
|
||||
}
|
||||
br.setMethod(HttpMethod.POST);
|
||||
br.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
br.setBody("{\"amount\":7.00,\"locale\":\"en\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* The Mock UriInfo
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* The Mock {@link LoansApiResource}
|
||||
*/
|
||||
@Mock
|
||||
private LoansApiResource loansApiResource;
|
||||
|
||||
/**
|
||||
* The class under test.
|
||||
*/
|
||||
private final LoanStateTransistionsByExternalIdCommandStrategy subjectToTest;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
subjectToTest = new LoanStateTransistionsByExternalIdCommandStrategy(loansApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for {@link ModifyLoanApplicationByExternalIdCommandStrategy}
|
||||
*/
|
||||
public class ModifyLoanApplicationByExternalIdCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link ModifyLoanApplicationByExternalIdCommandStrategy#execute(BatchRequest, UriInfo)} happy path scenario.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("commandParamDataProvider")
|
||||
public void testExecuteSuccessScenario(final String command, final String responseBody) {
|
||||
final TestContext testContext = new TestContext();
|
||||
final String loanExternalId = UUID.randomUUID().toString();
|
||||
final BatchRequest request = getBatchRequest(loanExternalId, command);
|
||||
|
||||
given(testContext.loansApiResource.modifyLoanApplication(eq(loanExternalId), eq(command), eq(request.getBody())))
|
||||
.willReturn(responseBody);
|
||||
|
||||
final BatchResponse response = testContext.testSubject.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loansApiResource).modifyLoanApplication(eq(loanExternalId), eq(command), eq(request.getBody()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Command Param data provider
|
||||
*
|
||||
* @return test data stream
|
||||
*/
|
||||
private static Stream<Arguments> commandParamDataProvider() {
|
||||
return Stream.of(
|
||||
Arguments.of("markAsFraud", "{\"officeId\":1,\"clientId\":2,\"loanId\":2,\"resourceId\":2,\"changes\":{\"fraud\":true}}"),
|
||||
Arguments.of(null, "body"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan external id.
|
||||
*
|
||||
* @param loanExternalId
|
||||
* the loan external id
|
||||
* @param queryParameter
|
||||
* the command query param
|
||||
* @return {@link BatchRequest}
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final String loanExternalId, final String queryParameter) {
|
||||
final BatchRequest batchRequest = new BatchRequest();
|
||||
|
||||
String relativeUrl = String.format("loans/external-id/%s", loanExternalId);
|
||||
|
||||
if (StringUtils.isNotBlank(queryParameter)) {
|
||||
relativeUrl = relativeUrl + "?command=" + queryParameter;
|
||||
}
|
||||
|
||||
batchRequest.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
batchRequest.setRelativeUrl(relativeUrl);
|
||||
batchRequest.setMethod(HttpMethod.PUT);
|
||||
batchRequest.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
batchRequest.setBody("{\"fraud\": \"true\"}");
|
||||
return batchRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* Mock URI info
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* Mock loans api resource
|
||||
*/
|
||||
@Mock
|
||||
private LoansApiResource loansApiResource;
|
||||
|
||||
/**
|
||||
* {@link ModifyLoanApplicationByExternalIdCommandStrategy} under test
|
||||
*/
|
||||
private final ModifyLoanApplicationByExternalIdCommandStrategy testSubject;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
testSubject = new ModifyLoanApplicationByExternalIdCommandStrategy(loansApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.batch.command.internal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.portfolio.loanaccount.api.LoansApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for {@link ModifyLoanApplicationCommandStrategy}
|
||||
*/
|
||||
public class ModifyLoanApplicationCommandStrategyTest {
|
||||
|
||||
/**
|
||||
* Test {@link ModifyLoanApplicationCommandStrategy#execute(BatchRequest, UriInfo)} happy path scenario.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("commandParamDataProvider")
|
||||
public void testExecuteSuccessScenario(final String command, final String responseBody) {
|
||||
final TestContext testContext = new TestContext();
|
||||
final Long loanId = Long.valueOf(RandomStringUtils.randomNumeric(4));
|
||||
final BatchRequest request = getBatchRequest(loanId, command);
|
||||
|
||||
given(testContext.loansApiResource.modifyLoanApplication(eq(loanId), eq(command), eq(request.getBody()))).willReturn(responseBody);
|
||||
|
||||
final BatchResponse response = testContext.testSubject.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
verify(testContext.loansApiResource).modifyLoanApplication(eq(loanId), eq(command), eq(request.getBody()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Command Param data provider
|
||||
*
|
||||
* @return test data stream
|
||||
*/
|
||||
private static Stream<Arguments> commandParamDataProvider() {
|
||||
return Stream.of(
|
||||
Arguments.of("markAsFraud", "{\"officeId\":1,\"clientId\":2,\"loanId\":2,\"resourceId\":2,\"changes\":{\"fraud\":true}}"),
|
||||
Arguments.of(null, "body"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a request with the given loan id.
|
||||
*
|
||||
* @param loanId
|
||||
* the loan id
|
||||
* @param queryParameter
|
||||
* the command query param
|
||||
* @return {@link BatchRequest}
|
||||
*/
|
||||
private BatchRequest getBatchRequest(final Long loanId, final String queryParameter) {
|
||||
final BatchRequest batchRequest = new BatchRequest();
|
||||
|
||||
String relativeUrl = String.format("loans/%s", loanId);
|
||||
|
||||
if (StringUtils.isNotBlank(queryParameter)) {
|
||||
relativeUrl = relativeUrl + "?command=" + queryParameter;
|
||||
}
|
||||
|
||||
batchRequest.setRequestId(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
batchRequest.setRelativeUrl(relativeUrl);
|
||||
batchRequest.setMethod(HttpMethod.PUT);
|
||||
batchRequest.setReference(Long.valueOf(RandomStringUtils.randomNumeric(5)));
|
||||
batchRequest.setBody("{\"fraud\": \"true\"}");
|
||||
return batchRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private test context class used since testng runs in parallel to avoid state between tests
|
||||
*/
|
||||
private static class TestContext {
|
||||
|
||||
/**
|
||||
* Mock URI info
|
||||
*/
|
||||
@Mock
|
||||
private UriInfo uriInfo;
|
||||
|
||||
/**
|
||||
* Mock loans api resource
|
||||
*/
|
||||
@Mock
|
||||
private LoansApiResource loansApiResource;
|
||||
|
||||
/**
|
||||
* {@link ModifyLoanApplicationCommandStrategy} under test
|
||||
*/
|
||||
private final ModifyLoanApplicationCommandStrategy testSubject;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
TestContext() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
testSubject = new ModifyLoanApplicationCommandStrategy(loansApiResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -29,10 +29,13 @@ import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.dataqueries.api.DatatablesApiResource;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Test class for {@link UpdateDatatableEntryOneToManyCommandStrategy}.
|
||||
*/
|
||||
public class UpdateDatatableEntryOneToManyCommandStrategyTest {
|
||||
|
||||
/**
|
||||
@@ -56,10 +59,10 @@ public class UpdateDatatableEntryOneToManyCommandStrategyTest {
|
||||
final BatchResponse response = testContext.subjectToTest.execute(request, testContext.uriInfo);
|
||||
|
||||
// then
|
||||
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
|
||||
assertEquals(response.getRequestId(), request.getRequestId());
|
||||
assertEquals(response.getHeaders(), request.getHeaders());
|
||||
assertEquals(response.getBody(), responseBody);
|
||||
assertEquals(HttpStatus.SC_OK, response.getStatusCode());
|
||||
assertEquals(request.getRequestId(), response.getRequestId());
|
||||
assertEquals(request.getHeaders(), response.getHeaders());
|
||||
assertEquals(responseBody, response.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user