[FINERACT-1678] API for job business step configuration

This commit is contained in:
taskain7
2022-08-22 13:36:38 +02:00
committed by Arnold Gálovics
parent 7a2af51e6c
commit 675dda2b42
22 changed files with 1020 additions and 0 deletions
@@ -0,0 +1,112 @@
/**
* 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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.List;
import org.apache.fineract.cob.data.BusinessStep;
import org.apache.fineract.cob.data.JobBusinessStepConfigData;
import org.apache.fineract.cob.data.JobBusinessStepDetail;
import org.apache.fineract.integrationtests.common.BusinessStepConfigurationHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class BusinessConfigurationApiTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private static final String LOAN_JOB_NAME = "LOAN_CLOSE_OF_BUSINESS";
private static final String LOAN_CATEGORY_NAME = "loan";
private static final String APPLY_CHARGE_TO_OVERDUE_LOANS = "APPLY_CHARGE_TO_OVERDUE_LOANS";
@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
}
@Test
public void shouldReturnApplyChargeToOverdueLoanStepConfig() {
JobBusinessStepConfigData response = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec, responseSpec,
LOAN_JOB_NAME);
Assertions.assertNotNull(response);
assertEquals(LOAN_JOB_NAME, response.getJobName());
assertTrue(response.getBusinessSteps().size() > 0);
assertTrue(response.getBusinessSteps().stream()
.anyMatch(businessStep -> APPLY_CHARGE_TO_OVERDUE_LOANS.equals(businessStep.getStepName())));
}
@Test
public void shouldReturnApplyChargeToOverdueLoanStepConfigByJobCategory() {
JobBusinessStepDetail response = BusinessStepConfigurationHelper.getAvailableBusinessStepsByJobName(requestSpec, responseSpec,
LOAN_CATEGORY_NAME);
Assertions.assertNotNull(response);
assertEquals(LOAN_CATEGORY_NAME, response.getJobName());
assertTrue(response.getAvailableBusinessSteps().size() > 0);
assertTrue(response.getAvailableBusinessSteps().stream()
.anyMatch(businessStep -> APPLY_CHARGE_TO_OVERDUE_LOANS.equals(businessStep.getStepName())));
}
@Test
public void shouldUpdateStepOrder() {
JobBusinessStepConfigData originalStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec,
responseSpec, LOAN_JOB_NAME);
Long originalOrder = originalStepConfig.getBusinessSteps().stream() //
.filter(businessStep -> APPLY_CHARGE_TO_OVERDUE_LOANS.equals(businessStep.getStepName())) //
.findFirst().get().getOrder();
List<BusinessStep> requestBody = getBusinessSteps(originalOrder + 1);
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
BusinessStepConfigurationHelper.toJsonString(requestBody));
JobBusinessStepConfigData newStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec,
responseSpec, LOAN_JOB_NAME);
Long newOrder = newStepConfig.getBusinessSteps().stream() //
.filter(businessStep -> APPLY_CHARGE_TO_OVERDUE_LOANS.equals(businessStep.getStepName())) //
.findFirst().get().getOrder();
assertEquals(originalOrder + 1, newOrder);
List<BusinessStep> originalBusinessSteps = getBusinessSteps(originalOrder);
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
BusinessStepConfigurationHelper.toJsonString(originalBusinessSteps));
}
private List<BusinessStep> getBusinessSteps(Long order) {
List<BusinessStep> businessSteps = new ArrayList<>();
BusinessStep businessStep = new BusinessStep();
businessStep.setStepName(APPLY_CHARGE_TO_OVERDUE_LOANS);
businessStep.setOrder(order);
businessSteps.add(businessStep);
return businessSteps;
}
}
@@ -0,0 +1,85 @@
/**
* 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;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.cob.data.BusinessStep;
import org.apache.fineract.cob.data.JobBusinessStepConfigData;
import org.apache.fineract.cob.data.JobBusinessStepDetail;
@Slf4j
public final class BusinessStepConfigurationHelper {
private static final String BUSINESS_STEPS_API_URL_START = "/fineract-provider/api/v1/jobs/";
private static final String BUSINESS_STEPS_API_URL_END = "/steps?" + Utils.TENANT_IDENTIFIER;
private static final String GET_AVAILABLE_BUSINESS_STEPS_API_URL_END = "/available-steps?" + Utils.TENANT_IDENTIFIER;
private BusinessStepConfigurationHelper() {
}
public static String toJsonString(final List<BusinessStep> batchRequests) {
return new Gson().toJson(new BusinessStepWrapper(batchRequests));
}
private static JobBusinessStepConfigData configuredBusinessStepFromJsonString(final String json) {
return new Gson().fromJson(json, new TypeToken<JobBusinessStepConfigData>() {}.getType());
}
private static JobBusinessStepDetail availableBusinessStepFromJsonString(final String json) {
return new Gson().fromJson(json, new TypeToken<JobBusinessStepDetail>() {}.getType());
}
public static JobBusinessStepConfigData getConfiguredBusinessStepsByJobName(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, String jobName) {
final String response = Utils.performServerGet(requestSpec, responseSpec,
BUSINESS_STEPS_API_URL_START + jobName + BUSINESS_STEPS_API_URL_END);
log.info("BusinessStepConfigurationHelper Response: {}", response);
return BusinessStepConfigurationHelper.configuredBusinessStepFromJsonString(response);
}
public static JobBusinessStepDetail getAvailableBusinessStepsByJobName(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, String jobName) {
final String response = Utils.performServerGet(requestSpec, responseSpec,
BUSINESS_STEPS_API_URL_START + jobName + GET_AVAILABLE_BUSINESS_STEPS_API_URL_END);
log.info("BusinessStepConfigurationHelper Response: {}", response);
return BusinessStepConfigurationHelper.availableBusinessStepFromJsonString(response);
}
public static void updateBusinessStepOrder(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
String jobName, String jsonBodyToSend) {
String response = Utils.performServerPut(requestSpec, responseSpec,
BUSINESS_STEPS_API_URL_START + jobName + BUSINESS_STEPS_API_URL_END, jsonBodyToSend);
log.info("BusinessStepConfigurationHelper Response: {}", response);
}
private static final class BusinessStepWrapper {
private List<BusinessStep> businessSteps;
private BusinessStepWrapper(List<BusinessStep> businessSteps) {
this.businessSteps = businessSteps;
}
}
}