FINERACT-1972 Custom Snapshot Event Triggered by COB
This commit is contained in:
committed by
Peter Bagrij
parent
4cb8946bc1
commit
8b379695d7
+5
-3
@@ -74,6 +74,8 @@ import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleProcessingType;
|
||||
import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanScheduleType;
|
||||
import org.apache.fineract.portfolio.loanproduct.domain.PaymentAllocationType;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@@ -86,7 +88,7 @@ public abstract class BaseLoanIntegrationTest {
|
||||
|
||||
protected static final String DATETIME_PATTERN = "dd MMMM yyyy";
|
||||
|
||||
protected final ResponseSpecification responseSpec = createResponseSpecification(200);
|
||||
protected final ResponseSpecification responseSpec = createResponseSpecification(Matchers.is(200));
|
||||
protected final RequestSpecification requestSpec = createRequestSpecification();
|
||||
|
||||
protected final AccountHelper accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
@@ -261,8 +263,8 @@ public abstract class BaseLoanIntegrationTest {
|
||||
return request;
|
||||
}
|
||||
|
||||
private static ResponseSpecification createResponseSpecification(int statusCode) {
|
||||
return new ResponseSpecBuilder().expectStatusCode(statusCode).build();
|
||||
protected static ResponseSpecification createResponseSpecification(Matcher<Integer> statusCodeMatcher) {
|
||||
return new ResponseSpecBuilder().expectStatusCode(statusCodeMatcher).build();
|
||||
}
|
||||
|
||||
protected void verifyUndoLastDisbursalShallFail(Long loanId, String expectedError) {
|
||||
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
/**
|
||||
* 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.integrationtests;
|
||||
|
||||
import static org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType.BUSINESS_DATE;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.BusinessDateRequest;
|
||||
import org.apache.fineract.client.models.PostLoanProductsRequest;
|
||||
import org.apache.fineract.client.models.PostLoanProductsResponse;
|
||||
import org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
|
||||
import org.apache.fineract.integrationtests.common.BusinessStepHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.externalevents.ExternalEventHelper;
|
||||
import org.apache.fineract.integrationtests.common.externalevents.ExternalEventsExtension;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@Slf4j
|
||||
@ExtendWith({ LoanTestLifecycleExtension.class, ExternalEventsExtension.class })
|
||||
public class CustomSnapshotEventIntegrationTest extends BaseLoanIntegrationTest {
|
||||
|
||||
private SchedulerJobHelper schedulerJobHelper = new SchedulerJobHelper(this.requestSpec);
|
||||
|
||||
@Test
|
||||
public void testSnapshotEventGenerationWhenLoanInstallmentIsNotPayed() {
|
||||
runAt("31 January 2023", () -> {
|
||||
// Enable Business Step
|
||||
enableCOBBusinessStep("APPLY_CHARGE_TO_OVERDUE_LOANS", "LOAN_DELINQUENCY_CLASSIFICATION", "CHECK_LOAN_REPAYMENT_DUE",
|
||||
"CHECK_LOAN_REPAYMENT_OVERDUE", "UPDATE_LOAN_ARREARS_AGING", "ADD_PERIODIC_ACCRUAL_ENTRIES",
|
||||
"EXTERNAL_ASSET_OWNER_TRANSFER", "CHECK_DUE_INSTALLMENTS");
|
||||
|
||||
enableLoanAccountCustomSnapshotBusinessEvent();
|
||||
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
|
||||
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
|
||||
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
|
||||
// Apply and Approve Loan
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4);
|
||||
|
||||
// Disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, false, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
// delete all external events
|
||||
deleteAllExternalEvents();
|
||||
|
||||
// run cob
|
||||
updateBusinessDateAndExecuteCOBJob("01 February 2023");
|
||||
|
||||
// verify external events
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(1, allExternalEvents.size());
|
||||
Assertions.assertEquals("LoanAccountCustomSnapshotBusinessEvent", allExternalEvents.get(0).getType());
|
||||
Assertions.assertEquals(loanId, allExternalEvents.get(0).getAggregateRootId());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSnapshotEventGenerationWhenLoanInstallmentIsPayed() {
|
||||
runAt("31 January 2023", () -> {
|
||||
// Enable Business Step
|
||||
enableCOBBusinessStep("APPLY_CHARGE_TO_OVERDUE_LOANS", "LOAN_DELINQUENCY_CLASSIFICATION", "CHECK_LOAN_REPAYMENT_DUE",
|
||||
"CHECK_LOAN_REPAYMENT_OVERDUE", "UPDATE_LOAN_ARREARS_AGING", "ADD_PERIODIC_ACCRUAL_ENTRIES",
|
||||
"EXTERNAL_ASSET_OWNER_TRANSFER", "CHECK_DUE_INSTALLMENTS");
|
||||
|
||||
enableLoanAccountCustomSnapshotBusinessEvent();
|
||||
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
|
||||
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
|
||||
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
|
||||
// Apply and Approve Loan
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4);
|
||||
|
||||
// Disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, false, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
addRepaymentForLoan(loanId, 313.0, "31 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, true, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
// delete all external events
|
||||
deleteAllExternalEvents();
|
||||
|
||||
// run cob
|
||||
updateBusinessDateAndExecuteCOBJob("01 February 2023");
|
||||
|
||||
// verify external events
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(0, allExternalEvents.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSnapshotEventGenerationWhenWhenCustomSnapshotEventCOBTaskIsNotActive() {
|
||||
runAt("31 January 2023", () -> {
|
||||
// Enable Business Step
|
||||
enableCOBBusinessStep("APPLY_CHARGE_TO_OVERDUE_LOANS", "LOAN_DELINQUENCY_CLASSIFICATION", "CHECK_LOAN_REPAYMENT_DUE",
|
||||
"CHECK_LOAN_REPAYMENT_OVERDUE", "UPDATE_LOAN_ARREARS_AGING", "ADD_PERIODIC_ACCRUAL_ENTRIES",
|
||||
"EXTERNAL_ASSET_OWNER_TRANSFER");
|
||||
|
||||
enableLoanAccountCustomSnapshotBusinessEvent();
|
||||
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
|
||||
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
|
||||
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
|
||||
// Apply and Approve Loan
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4);
|
||||
|
||||
// Disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, false, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
// delete all external events
|
||||
deleteAllExternalEvents();
|
||||
|
||||
// run cob
|
||||
updateBusinessDateAndExecuteCOBJob("01 February 2023");
|
||||
|
||||
// verify external events
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(0, allExternalEvents.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSnapshotEventGenerationWhenCOBDateIsNotMatchingWithInstallmentDueDate() {
|
||||
runAt("30 January 2023", () -> {
|
||||
// Enable Business Step
|
||||
enableCOBBusinessStep("APPLY_CHARGE_TO_OVERDUE_LOANS", "LOAN_DELINQUENCY_CLASSIFICATION", "CHECK_LOAN_REPAYMENT_DUE",
|
||||
"CHECK_LOAN_REPAYMENT_OVERDUE", "UPDATE_LOAN_ARREARS_AGING", "ADD_PERIODIC_ACCRUAL_ENTRIES",
|
||||
"EXTERNAL_ASSET_OWNER_TRANSFER", "CHECK_DUE_INSTALLMENTS");
|
||||
|
||||
enableLoanAccountCustomSnapshotBusinessEvent();
|
||||
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
|
||||
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
|
||||
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
|
||||
// Apply and Approve Loan
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4);
|
||||
|
||||
// Disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, false, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
// delete all external events
|
||||
deleteAllExternalEvents();
|
||||
|
||||
// run cob
|
||||
updateBusinessDateAndExecuteCOBJob("31 January 2023");
|
||||
|
||||
// verify external events
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(0, allExternalEvents.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSnapshotEventGenerationWhenCustomSnapshotEventIsDisabled() {
|
||||
runAt("31 January 2023", () -> {
|
||||
// Enable Business Step
|
||||
enableCOBBusinessStep("APPLY_CHARGE_TO_OVERDUE_LOANS", "LOAN_DELINQUENCY_CLASSIFICATION", "CHECK_LOAN_REPAYMENT_DUE",
|
||||
"CHECK_LOAN_REPAYMENT_OVERDUE", "UPDATE_LOAN_ARREARS_AGING", "ADD_PERIODIC_ACCRUAL_ENTRIES",
|
||||
"EXTERNAL_ASSET_OWNER_TRANSFER", "CHECK_DUE_INSTALLMENTS");
|
||||
|
||||
// Create Client
|
||||
Long clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId();
|
||||
|
||||
// Create Loan Product
|
||||
PostLoanProductsRequest loanProductsRequest = create1InstallmentAmountInMultiplesOf4Period1MonthLongWithInterestAndAmortizationProduct(
|
||||
InterestType.FLAT, AmortizationType.EQUAL_INSTALLMENTS);
|
||||
loanProductsRequest.setEnableInstallmentLevelDelinquency(true);
|
||||
PostLoanProductsResponse loanProductResponse = loanProductHelper.createLoanProduct(loanProductsRequest);
|
||||
|
||||
// Apply and Approve Loan
|
||||
Long loanId = applyAndApproveLoan(clientId, loanProductResponse.getResourceId(), "01 January 2023", 1250.0, 4);
|
||||
|
||||
// Disburse Loan
|
||||
disburseLoan(loanId, BigDecimal.valueOf(1250), "01 January 2023");
|
||||
|
||||
// Verify Repayment Schedule and Due Dates
|
||||
verifyRepaymentSchedule(loanId, //
|
||||
installment(0, null, "01 January 2023"), //
|
||||
installment(313.0, false, "31 January 2023"), //
|
||||
installment(313.0, false, "02 March 2023"), //
|
||||
installment(313.0, false, "01 April 2023"), //
|
||||
installment(311.0, false, "01 May 2023") //
|
||||
);
|
||||
|
||||
// delete all external events
|
||||
deleteAllExternalEvents();
|
||||
|
||||
// run cob
|
||||
updateBusinessDateAndExecuteCOBJob("01 February 2023");
|
||||
|
||||
// verify external events
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(0, allExternalEvents.size());
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteAllExternalEvents() {
|
||||
ExternalEventHelper.deleteAllExternalEvents(requestSpec, createResponseSpecification(Matchers.is(204)));
|
||||
List<ExternalEventDTO> allExternalEvents = ExternalEventHelper.getAllExternalEvents(requestSpec, responseSpec);
|
||||
Assertions.assertEquals(0, allExternalEvents.size());
|
||||
}
|
||||
|
||||
private void enableCOBBusinessStep(String... steps) {
|
||||
new BusinessStepHelper().updateSteps("LOAN_CLOSE_OF_BUSINESS", steps);
|
||||
|
||||
}
|
||||
|
||||
public static String getExternalEventConfigurationsForUpdateJSON() {
|
||||
Map<String, Map<String, Boolean>> configurationsForUpdate = new HashMap<>();
|
||||
Map<String, Boolean> configurations = new HashMap<>();
|
||||
configurations.put("CentersCreateBusinessEvent", true);
|
||||
configurations.put("ClientActivateBusinessEvent", true);
|
||||
configurationsForUpdate.put("externalEventConfigurations", configurations);
|
||||
return new Gson().toJson(configurationsForUpdate);
|
||||
}
|
||||
|
||||
private void enableLoanAccountCustomSnapshotBusinessEvent() {
|
||||
final Map<String, Boolean> updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec,
|
||||
responseSpec, "{\"externalEventConfigurations\":{\"LoanAccountCustomSnapshotBusinessEvent\":true}}\n");
|
||||
Assertions.assertEquals(updatedConfigurations.size(), 1);
|
||||
Assertions.assertTrue(updatedConfigurations.containsKey("LoanAccountCustomSnapshotBusinessEvent"));
|
||||
Assertions.assertTrue(updatedConfigurations.get("LoanAccountCustomSnapshotBusinessEvent"));
|
||||
}
|
||||
|
||||
private void updateBusinessDateAndExecuteCOBJob(String date) {
|
||||
businessDateHelper.updateBusinessDate(
|
||||
new BusinessDateRequest().type(BUSINESS_DATE.getName()).date(date).dateFormat(DATETIME_PATTERN).locale("en"));
|
||||
schedulerJobHelper.executeAndAwaitJob("Loan COB");
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -495,6 +495,11 @@ public class ExternalEventConfigurationHelper {
|
||||
loanAccountDelinquencyPauseChangedBusinessEvent.put("enabled", false);
|
||||
defaults.add(loanAccountDelinquencyPauseChangedBusinessEvent);
|
||||
|
||||
Map<String, Object> loanAccountCustomSnapshotBusinessEvent = new HashMap<>();
|
||||
loanAccountCustomSnapshotBusinessEvent.put("type", "LoanAccountCustomSnapshotBusinessEvent");
|
||||
loanAccountCustomSnapshotBusinessEvent.put("enabled", false);
|
||||
defaults.add(loanAccountCustomSnapshotBusinessEvent);
|
||||
|
||||
return defaults;
|
||||
|
||||
}
|
||||
|
||||
@@ -283,6 +283,9 @@ public final class Utils {
|
||||
final String deleteURL, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().delete(deleteURL).andReturn()
|
||||
.asString();
|
||||
if (jsonAttributeToGetBack == null) {
|
||||
return (T) json;
|
||||
}
|
||||
return (T) JsonPath.from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 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.integrationtests.common.externalevents;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
import org.apache.fineract.infrastructure.event.external.service.validation.ExternalEventDTO;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
@Slf4j
|
||||
public final class ExternalEventHelper {
|
||||
|
||||
private static final Gson GSON = new JSON().getGson();
|
||||
|
||||
private ExternalEventHelper() {}
|
||||
|
||||
@Builder
|
||||
public static class Filter {
|
||||
|
||||
private final String idempotencyKey;
|
||||
private final String type;
|
||||
private final String category;
|
||||
private final Long aggregateRootId;
|
||||
|
||||
public String toQueryParams() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (idempotencyKey != null) {
|
||||
stringBuilder.append("idempotencyKey=").append(idempotencyKey).append("&");
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
stringBuilder.append("type=").append(type).append("&");
|
||||
}
|
||||
|
||||
if (category != null) {
|
||||
stringBuilder.append("category=").append(category).append("&");
|
||||
}
|
||||
|
||||
if (aggregateRootId != null) {
|
||||
stringBuilder.append("aggregateRootId=").append(aggregateRootId).append("&");
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ExternalEventDTO> getAllExternalEvents(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String url = "/fineract-provider/api/v1/internal/externalevents?" + Utils.TENANT_IDENTIFIER;
|
||||
log.info("---------------------------------GETTING ALL EXTERNAL EVENTS---------------------------------------------");
|
||||
String response = Utils.performServerGet(requestSpec, responseSpec, url);
|
||||
return GSON.fromJson(response, new TypeToken<List<ExternalEventDTO>>() {}.getType());
|
||||
}
|
||||
|
||||
public static List<ExternalEventDTO> getAllExternalEvents(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, Filter filter) {
|
||||
final String url = "/fineract-provider/api/v1/internal/externalevents?" + filter.toQueryParams() + Utils.TENANT_IDENTIFIER;
|
||||
log.info("---------------------------------GETTING ALL EXTERNAL EVENTS---------------------------------------------");
|
||||
String response = Utils.performServerGet(requestSpec, responseSpec, url);
|
||||
return GSON.fromJson(response, new TypeToken<List<ExternalEventDTO>>() {}.getType());
|
||||
}
|
||||
|
||||
public static void deleteAllExternalEvents(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String url = "/fineract-provider/api/v1/internal/externalevents?" + Utils.TENANT_IDENTIFIER;
|
||||
log.info("-----------------------------DELETE ALL EXTERNAL EVENTS PARTITIONS----------------------------------------");
|
||||
Utils.performServerDelete(requestSpec, responseSpec, url, null);
|
||||
}
|
||||
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* 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.integrationtests.common.externalevents;
|
||||
|
||||
import static org.apache.fineract.integrationtests.common.Utils.initializeRESTAssured;
|
||||
|
||||
import com.google.common.collect.MapDifference;
|
||||
import com.google.common.collect.Maps;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.integrationtests.common.ExternalEventConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
@Slf4j
|
||||
public class ExternalEventsExtension implements AfterEachCallback, BeforeEachCallback {
|
||||
|
||||
private Map<String, Boolean> original;
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
public ExternalEventsExtension() {
|
||||
initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext context) {
|
||||
ArrayList<Map<String, Object>> allExternalEventConfigurations = ExternalEventConfigurationHelper
|
||||
.getAllExternalEventConfigurations(requestSpec, responseSpec);
|
||||
Map<String, Boolean> collected = allExternalEventConfigurations.stream()
|
||||
.map(map -> Map.entry((String) map.get("type"), (Boolean) map.get("enabled")))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
|
||||
Map<String, MapDifference.ValueDifference<Boolean>> diff = Maps.difference(original, collected).entriesDiffering();
|
||||
diff.keySet().forEach(key -> {
|
||||
MapDifference.ValueDifference<Boolean> valueDifference = diff.get(key);
|
||||
log.debug("External event {} changed from {} to {}. Restoring to its original state.", key, valueDifference.leftValue(),
|
||||
valueDifference.rightValue());
|
||||
restore(key, valueDifference.leftValue());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext context) {
|
||||
ArrayList<Map<String, Object>> allExternalEventConfigurations = ExternalEventConfigurationHelper
|
||||
.getAllExternalEventConfigurations(requestSpec, responseSpec);
|
||||
original = allExternalEventConfigurations.stream().map(map -> Map.entry((String) map.get("type"), (Boolean) map.get("enabled")))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
private void restore(String key, Boolean value) {
|
||||
final Map<String, Boolean> updatedConfigurations = ExternalEventConfigurationHelper.updateExternalEventConfigurations(requestSpec,
|
||||
responseSpec, "{\"externalEventConfigurations\":{\"" + key + "\":" + value + "}}\n");
|
||||
Assertions.assertEquals(updatedConfigurations.size(), 1);
|
||||
Assertions.assertTrue(updatedConfigurations.containsKey(key));
|
||||
Assertions.assertEquals(value, updatedConfigurations.get(key));
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -23,16 +23,17 @@ import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.integrationtests.client.IntegrationTest;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
@Slf4j
|
||||
public class CobHelper extends IntegrationTest {
|
||||
public final class CobHelper {
|
||||
|
||||
private CobHelper() {}
|
||||
|
||||
public static List<Map<String, Object>> getCobPartitions(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, int partitionSize, final String jsonReturn) {
|
||||
final String GET_LOAN_URL = "/fineract-provider/api/v1/internal/cob/partitions/" + partitionSize + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final String url = "/fineract-provider/api/v1/internal/cob/partitions/" + partitionSize + "?" + Utils.TENANT_IDENTIFIER;
|
||||
log.info("---------------------------------GET COB PARTITIONS---------------------------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_LOAN_URL, jsonReturn);
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, jsonReturn);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user