FINERACT-1724 swagger fix

This commit is contained in:
Peter Kovacs
2023-07-17 11:25:07 +02:00
committed by Adam Saghy
parent be935cd55b
commit 948af9ab2b
13 changed files with 125 additions and 114 deletions
@@ -36,12 +36,12 @@ public class PaymentTypeData implements Serializable {
private String name; private String name;
private String description; private String description;
private Boolean isCashPayment; private Boolean isCashPayment;
private Long position; private Integer position;
private String codeName; private String codeName;
private Boolean isSystemDefined; private Boolean isSystemDefined;
public static PaymentTypeData instance(final Long id, final String name, final String description, final Boolean isCashPayment, public static PaymentTypeData instance(final Long id, final String name, final String description, final Boolean isCashPayment,
final Long position) { final Integer position) {
String codeName = null; String codeName = null;
Boolean isSystemDefined = false; Boolean isSystemDefined = false;
return new PaymentTypeData(id, name, description, isCashPayment, position, codeName, isSystemDefined); return new PaymentTypeData(id, name, description, isCashPayment, position, codeName, isSystemDefined);
@@ -50,7 +50,7 @@ public class PaymentTypeData implements Serializable {
public static PaymentTypeData instance(final Long id, final String name) { public static PaymentTypeData instance(final Long id, final String name) {
String description = null; String description = null;
Boolean isCashPayment = null; Boolean isCashPayment = null;
Long position = null; Integer position = null;
String codeName = null; String codeName = null;
Boolean isSystemDefined = false; Boolean isSystemDefined = false;
return new PaymentTypeData(id, name, description, isCashPayment, position, codeName, isSystemDefined); return new PaymentTypeData(id, name, description, isCashPayment, position, codeName, isSystemDefined);
@@ -33,7 +33,7 @@ public final class PaymentTypeApiResourceSwagger {
private GetPaymentTypesResponse() {} private GetPaymentTypesResponse() {}
@Schema(example = "24") @Schema(example = "24")
public Integer id; public Long id;
@Schema(example = "PTC") @Schema(example = "PTC")
public String name; public String name;
@Schema(example = "Cash") @Schema(example = "Cash")
@@ -54,7 +54,7 @@ public final class PaymentTypeApiResourceSwagger {
private GetPaymentTypesPaymentTypeIdResponse() {} private GetPaymentTypesPaymentTypeIdResponse() {}
@Schema(example = "13") @Schema(example = "13")
public Integer id; public Long id;
@Schema(example = "cash") @Schema(example = "cash")
public String name; public String name;
@Schema(example = "cash Payment") @Schema(example = "cash Payment")
@@ -94,7 +94,7 @@ public final class PaymentTypeApiResourceSwagger {
private PostPaymentTypesResponse() {} private PostPaymentTypesResponse() {}
@Schema(example = "1") @Schema(example = "1")
public Integer resourceId; public Long resourceId;
} }
@Schema(description = "PutPaymentTypesPaymentTypeIdRequest") @Schema(description = "PutPaymentTypesPaymentTypeIdRequest")
@@ -122,7 +122,7 @@ public final class PaymentTypeApiResourceSwagger {
private PutPaymentTypesPaymentTypeIdResponse() {} private PutPaymentTypesPaymentTypeIdResponse() {}
@Schema(example = "13") @Schema(example = "13")
public Integer resourceId; public Long resourceId;
} }
@Schema(description = "DeletePaymentTypesPaymentTypeIdResponse") @Schema(description = "DeletePaymentTypesPaymentTypeIdResponse")
@@ -131,6 +131,6 @@ public final class PaymentTypeApiResourceSwagger {
private DeletePaymentTypesPaymentTypeIdResponse() {} private DeletePaymentTypesPaymentTypeIdResponse() {}
@Schema(example = "13") @Schema(example = "13")
public Integer resourceId; public Long resourceId;
} }
} }
@@ -39,6 +39,8 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper; import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
@@ -80,6 +82,7 @@ public class ClientSavingsIntegrationTest {
private SavingsAccountHelper savingsAccountHelper; private SavingsAccountHelper savingsAccountHelper;
private SavingsProductHelper savingsProductHelper; private SavingsProductHelper savingsProductHelper;
private SchedulerJobHelper scheduleJobHelper; private SchedulerJobHelper scheduleJobHelper;
private PaymentTypeHelper paymentTypeHelper;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
@@ -88,6 +91,7 @@ public class ClientSavingsIntegrationTest {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.requestSpec.header("Fineract-Platform-TenantId", "default"); this.requestSpec.header("Fineract-Platform-TenantId", "default");
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@Test @Test
@@ -2639,8 +2643,9 @@ public class ClientSavingsIntegrationTest {
Boolean isCashPayment = false; Boolean isCashPayment = false;
Integer position = 1; Integer position = 1;
Integer paymentTypeIdOne = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
position); new PostPaymentTypesRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeIdOne = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeIdOne); Assertions.assertNotNull(paymentTypeIdOne);
final Integer chargeIdOne = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, final Integer chargeIdOne = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
@@ -2661,8 +2666,9 @@ public class ClientSavingsIntegrationTest {
String paymentTypeNameTwo = PaymentTypeHelper.randomNameGenerator("P_T", 5); String paymentTypeNameTwo = PaymentTypeHelper.randomNameGenerator("P_T", 5);
Integer paymentTypeIdTwo = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeNameTwo, description, PostPaymentTypesResponse paymentTypesResponseTwo = paymentTypeHelper.createPaymentType(new PostPaymentTypesRequest()
isCashPayment, position); .name(paymentTypeNameTwo).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeIdTwo = paymentTypesResponseTwo.getResourceId();
Assertions.assertNotNull(paymentTypeIdTwo); Assertions.assertNotNull(paymentTypeIdTwo);
final Integer chargeIdTwo = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, final Integer chargeIdTwo = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
@@ -35,6 +35,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.GroupHelper; import org.apache.fineract.integrationtests.common.GroupHelper;
@@ -65,6 +67,7 @@ public class GroupSavingsIntegrationTest {
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private SavingsAccountHelper savingsAccountHelper; private SavingsAccountHelper savingsAccountHelper;
private PaymentTypeHelper paymentTypeHelper;
private static final Logger LOG = LoggerFactory.getLogger(GroupSavingsIntegrationTest.class); private static final Logger LOG = LoggerFactory.getLogger(GroupSavingsIntegrationTest.class);
@BeforeEach @BeforeEach
@@ -74,6 +77,7 @@ public class GroupSavingsIntegrationTest {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.requestSpec.header("Fineract-Platform-TenantId", "default"); this.requestSpec.header("Fineract-Platform-TenantId", "default");
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@Test @Test
@@ -313,7 +317,9 @@ public class GroupSavingsIntegrationTest {
Boolean isCashPayment = true; Boolean isCashPayment = true;
Integer position = 1; Integer position = 1;
Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position); PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
new PostPaymentTypesRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeId = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeId); Assertions.assertNotNull(paymentTypeId);
List<Map<String, Object>> savingsArray = new ArrayList<>(); List<Map<String, Object>> savingsArray = new ArrayList<>();
@@ -804,7 +810,7 @@ public class GroupSavingsIntegrationTest {
return map; return map;
} }
private Map<String, Object> savingsArray(final Integer paymentId, final Integer savingsId, final Integer transactionAmount, private Map<String, Object> savingsArray(final Long paymentId, final Integer savingsId, final Integer transactionAmount,
final String transactionDate) { final String transactionDate) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("transactionDate", transactionDate); map.put("transactionDate", transactionDate);
@@ -47,6 +47,8 @@ import org.apache.fineract.client.models.PostLoanProductsRequest;
import org.apache.fineract.client.models.PostLoanProductsResponse; import org.apache.fineract.client.models.PostLoanProductsResponse;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest;
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse; import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.PaymentTypeHelper; import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
@@ -79,6 +81,7 @@ public class LoanPostChargeOffScenariosTest {
private JournalEntryHelper journalEntryHelper; private JournalEntryHelper journalEntryHelper;
private AccountHelper accountHelper; private AccountHelper accountHelper;
private LoanProductHelper loanProductHelper; private LoanProductHelper loanProductHelper;
private PaymentTypeHelper paymentTypeHelper;
// asset // asset
private Account loansReceivable; private Account loansReceivable;
private Account interestFeeReceivable; private Account interestFeeReceivable;
@@ -108,6 +111,7 @@ public class LoanPostChargeOffScenariosTest {
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec); this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
this.loanProductHelper = new LoanProductHelper(); this.loanProductHelper = new LoanProductHelper();
this.paymentTypeHelper = new PaymentTypeHelper();
// Asset // Asset
this.loansReceivable = this.accountHelper.createAssetAccount(); this.loansReceivable = this.accountHelper.createAssetAccount();
@@ -1127,8 +1131,9 @@ public class LoanPostChargeOffScenariosTest {
Boolean isCashPayment = false; Boolean isCashPayment = false;
Integer position = 1; Integer position = 1;
Integer paymentTypeIdOne = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeName, description, PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(new PostPaymentTypesRequest()
isCashPayment, position); .name(paymentTypeName).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeIdOne = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeIdOne); Assertions.assertNotNull(paymentTypeIdOne);
List<GetLoanPaymentChannelToFundSourceMappings> paymentChannelToFundSourceMappings = new ArrayList<>(); List<GetLoanPaymentChannelToFundSourceMappings> paymentChannelToFundSourceMappings = new ArrayList<>();
@@ -23,8 +23,11 @@ import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification; import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification; import io.restassured.specification.ResponseSpecification;
import java.util.HashMap; import org.apache.fineract.client.models.DeletePaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.integrationtests.common.PaymentTypeDomain; import org.apache.fineract.client.models.GetPaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.client.models.PutPaymentTypesPaymentTypeIdRequest;
import org.apache.fineract.integrationtests.common.PaymentTypeHelper; import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@@ -35,6 +38,7 @@ public class PaymentTypeIntegrationTest {
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private PaymentTypeHelper paymentTypeHelper;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
@@ -42,7 +46,7 @@ public class PaymentTypeIntegrationTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@@ -53,10 +57,12 @@ public class PaymentTypeIntegrationTest {
Boolean isCashPayment = true; Boolean isCashPayment = true;
Integer position = 1; Integer position = 1;
Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position); PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
new PostPaymentTypesRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeId = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeId); Assertions.assertNotNull(paymentTypeId);
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId); paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId); GetPaymentTypesPaymentTypeIdResponse paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(name, paymentTypeResponse.getName()); Assertions.assertEquals(name, paymentTypeResponse.getName());
Assertions.assertEquals(description, paymentTypeResponse.getDescription()); Assertions.assertEquals(description, paymentTypeResponse.getDescription());
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment()); Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
@@ -68,24 +74,19 @@ public class PaymentTypeIntegrationTest {
Boolean isCashPaymentUpdatedValue = false; Boolean isCashPaymentUpdatedValue = false;
Integer newPosition = 2; Integer newPosition = 2;
HashMap request = new HashMap(); paymentTypeHelper.updatePaymentType(paymentTypeId, new PutPaymentTypesPaymentTypeIdRequest().name(newName)
request.put("name", newName); .description(newDescription).isCashPayment(isCashPaymentUpdatedValue).position(newPosition));
request.put("description", newDescription); GetPaymentTypesPaymentTypeIdResponse paymentTypeUpdatedResponse = paymentTypeHelper.retrieveById(paymentTypeId);
request.put("isCashPayment", isCashPaymentUpdatedValue);
request.put("position", newPosition);
PaymentTypeHelper.updatePaymentType(paymentTypeId, request, requestSpec, responseSpec);
PaymentTypeDomain paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName()); Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription()); Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment()); Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition()); Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
// Delete // Delete
Integer deletedPaymentTypeId = PaymentTypeHelper.deletePaymentType(paymentTypeId, requestSpec, responseSpec); DeletePaymentTypesPaymentTypeIdResponse responseDelete = paymentTypeHelper.deletePaymentType(paymentTypeId);
Long deletedPaymentTypeId = responseDelete.getResourceId();
Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId); Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId);
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build(); ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build();
PaymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId); paymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
} }
} }
@@ -34,9 +34,11 @@ import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.fineract.client.models.GetPaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper; import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
import org.apache.fineract.integrationtests.common.PaymentTypeDomain;
import org.apache.fineract.integrationtests.common.PaymentTypeHelper; import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
import org.apache.fineract.integrationtests.common.Utils; import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder; import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
@@ -56,6 +58,7 @@ public class RepaymentWithPostDatedChecksTest {
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private final SimpleDateFormat dateFormatterStandard = new SimpleDateFormat("dd MMMM yyyy", Locale.US); private final SimpleDateFormat dateFormatterStandard = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
private LoanTransactionHelper loanTransactionHelper; private LoanTransactionHelper loanTransactionHelper;
private PaymentTypeHelper paymentTypeHelper;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
@@ -63,6 +66,7 @@ public class RepaymentWithPostDatedChecksTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@Test @Test
@@ -136,10 +140,12 @@ public class RepaymentWithPostDatedChecksTest {
Boolean isCashPayment = false; Boolean isCashPayment = false;
Integer position = 1; Integer position = 1;
Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position); PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
new PostPaymentTypesRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
Long paymentTypeId = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(paymentTypeId); Assertions.assertNotNull(paymentTypeId);
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId); paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId); GetPaymentTypesPaymentTypeIdResponse paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
Assertions.assertEquals(name, paymentTypeResponse.getName()); Assertions.assertEquals(name, paymentTypeResponse.getName());
// Repay for the installment 1 using post dated check // Repay for the installment 1 using post dated check
@@ -41,6 +41,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.CollateralManagementHelper; import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
@@ -75,6 +77,7 @@ public class LoanImportHandlerTest {
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private PaymentTypeHelper paymentTypeHelper;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
@@ -82,6 +85,7 @@ public class LoanImportHandlerTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@Test @Test
@@ -162,8 +166,11 @@ public class LoanImportHandlerTest {
String paymentTypeName = PaymentTypeHelper.randomNameGenerator("P_T", 5); String paymentTypeName = PaymentTypeHelper.randomNameGenerator("P_T", 5);
String paymentTypeDescription = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); String paymentTypeDescription = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Integer outcome_payment_creation = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeName,
paymentTypeDescription, true, 1); PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
new PostPaymentTypesRequest().name(paymentTypeName).description(paymentTypeDescription).isCashPayment(true).position(1));
Long outcome_payment_creation = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type"); Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type");
LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec); LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
@@ -26,6 +26,8 @@ import io.restassured.specification.ResponseSpecification;
import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.MediaType;
import java.io.IOException; import java.io.IOException;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
import org.apache.fineract.integrationtests.common.ClientHelper; import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.GroupHelper; import org.apache.fineract.integrationtests.common.GroupHelper;
@@ -47,6 +49,7 @@ public class LoanWorkbookPopulatorTest {
private ResponseSpecification responseSpec; private ResponseSpecification responseSpec;
private RequestSpecification requestSpec; private RequestSpecification requestSpec;
private PaymentTypeHelper paymentTypeHelper;
@BeforeEach @BeforeEach
public void setup() { public void setup() {
@@ -54,6 +57,7 @@ public class LoanWorkbookPopulatorTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.paymentTypeHelper = new PaymentTypeHelper();
} }
@Test @Test
@@ -90,8 +94,9 @@ public class LoanWorkbookPopulatorTest {
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
Boolean isCashPayment = true; Boolean isCashPayment = true;
Integer position = 1; Integer position = 1;
Integer outcome_payment_creation = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, PostPaymentTypesResponse paymentTypesResponse = paymentTypeHelper.createPaymentType(
position); new PostPaymentTypesRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
Long outcome_payment_creation = paymentTypesResponse.getResourceId();
Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type"); Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type");
Workbook workbook = loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy"); Workbook workbook = loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
@@ -20,13 +20,13 @@ package org.apache.fineract.integrationtests.common;
public final class PaymentTypeDomain { public final class PaymentTypeDomain {
private Integer id; private Long id;
private String name; private String name;
private String description; private String description;
private Boolean isCashPayment; private Boolean isCashPayment;
private Integer position; private Integer position;
public PaymentTypeDomain(final Integer id, final String name, final String description, final Boolean isCashPayment, public PaymentTypeDomain(final Long id, final String name, final String description, final Boolean isCashPayment,
final Integer position) { final Integer position) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@@ -36,11 +36,11 @@ public final class PaymentTypeDomain {
} }
public Integer getId() { public Long getId() {
return this.id; return this.id;
} }
public void setId(Integer id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
@@ -24,97 +24,70 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.restassured.specification.RequestSpecification; import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification; import io.restassured.specification.ResponseSpecification;
import java.lang.reflect.Type; import java.util.List;
import java.util.ArrayList; import lombok.extern.slf4j.Slf4j;
import java.util.HashMap; import org.apache.fineract.client.models.DeletePaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.client.models.GetPaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.client.models.GetPaymentTypesResponse; import org.apache.fineract.client.models.GetPaymentTypesResponse;
import org.apache.fineract.client.models.PostPaymentTypesRequest;
import org.apache.fineract.client.models.PostPaymentTypesResponse;
import org.apache.fineract.client.models.PutPaymentTypesPaymentTypeIdRequest;
import org.apache.fineract.client.models.PutPaymentTypesPaymentTypeIdResponse;
import org.apache.fineract.integrationtests.client.IntegrationTest;
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
public final class PaymentTypeHelper { @Slf4j
public final class PaymentTypeHelper extends IntegrationTest {
private PaymentTypeHelper() { public PaymentTypeHelper() {
} }
private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes"; private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes";
private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER; private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER;
public static ArrayList<GetPaymentTypesResponse> getSystemPaymentType(final RequestSpecification requestSpec, public List<GetPaymentTypesResponse> getAllPaymentTypes(final Boolean onlyWithCode) {
final ResponseSpecification responseSpec) { log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
String response = Utils.performServerGet(requestSpec, responseSpec, return ok(fineract().paymentTypes.getAllPaymentTypes(onlyWithCode));
PAYMENTTYPE_URL + "?onlyWithCode=true&" + Utils.TENANT_IDENTIFIER);
Type paymentTypeList = new TypeToken<ArrayList<GetPaymentTypesResponse>>() {}.getType();
return new Gson().fromJson(response, paymentTypeList);
} }
public static Integer createPaymentType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public PostPaymentTypesResponse createPaymentType(final PostPaymentTypesRequest postPaymentTypesRequest) {
final String name, final String description, final Boolean isCashPayment, final Integer position) { log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
// system.out.println("---------------------------------CREATING A return ok(fineract().paymentTypes.createPaymentType(postPaymentTypesRequest));
// PAYMENT
// TYPE---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_PAYMENTTYPE_URL,
getJsonToCreatePaymentType(name, description, isCashPayment, position), "resourceId");
} }
public static String getJsonToCreatePaymentType(final String name, final String description, final Boolean isCashPayment, public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
final Integer position) { log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
HashMap hm = new HashMap(); GetPaymentTypesPaymentTypeIdResponse response = ok(fineract().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
hm.put("name", name); Long responsePaymentTypeID = response.getId();
if (description != null) {
hm.put("description", description);
}
hm.put("isCashPayment", isCashPayment);
if (position != null) {
hm.put("position", position);
}
// system.out.println("------------------------CREATING PAYMENT
// TYPE-------------------------" + hm);
return new Gson().toJson(hm);
}
public static void verifyPaymentTypeCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
final Integer generatedPaymentTypeID) {
// system.out.println("------------------------------CHECK PAYMENT
// DETAILS------------------------------------\n");
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + generatedPaymentTypeID + "?" + Utils.TENANT_IDENTIFIER;
final Integer responsePaymentTypeID = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "id");
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE"); assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
} }
public static PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, public GetPaymentTypesPaymentTypeIdResponse retrieveById(final Long paymentTypeId) {
final Integer paymentTypeId) { log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
return ok(fineract().paymentTypes.retrieveOnePaymentType(paymentTypeId));
}
public PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER; final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
// system.out.println("---------------------------------GET PAYMENT log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
// TYPE---------------------------------------------");
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, ""); Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "");
final String jsonData = new Gson().toJson(get); final String jsonData = new Gson().toJson(get);
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType()); return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
} }
public static HashMap<String, String> updatePaymentType(final int id, HashMap request, final RequestSpecification requestSpec, public PutPaymentTypesPaymentTypeIdResponse updatePaymentType(final Long paymentTypeId,
final ResponseSpecification responseSpec) { PutPaymentTypesPaymentTypeIdRequest putPaymentTypesPaymentTypeIdRequest) {
final String UPDATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
// system.out.println("---------------------------------UPDATE PAYMENT return ok(fineract().paymentTypes.updatePaymentType(paymentTypeId, putPaymentTypesPaymentTypeIdRequest));
// TYPE " +
// id + "---------------------------------------------");
HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_PAYMENTTYPE_URL, new Gson().toJson(request),
"changes");
return hash;
} }
public static Integer deletePaymentType(final int id, final RequestSpecification requestSpec, public DeletePaymentTypesPaymentTypeIdResponse deletePaymentType(final Long paymentTypeId) {
final ResponseSpecification responseSpec) { log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
final String DELETE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER; return ok(fineract().paymentTypes.deleteCode1(paymentTypeId));
// system.out.println("---------------------------------DELETING PAYMENT
// TYPE "
// + id + "--------------------------------------------");
return Utils.performServerDelete(requestSpec, responseSpec, DELETE_PAYMENTTYPE_URL, "resourceId");
} }
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix); return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
} }
} }
@@ -194,11 +194,11 @@ public final class ChargesHelper extends IntegrationTest {
return chargesCreateJson; return chargesCreateJson;
} }
public static String paymentTypeCharge(Integer amount, final boolean enablePaymentType, final Integer paymentTypeId) { public static String paymentTypeCharge(Integer amount, final boolean enablePaymentType, final Long paymentTypeId) {
return paymentTypeChargeJSON(amount, enablePaymentType, paymentTypeId); return paymentTypeChargeJSON(amount, enablePaymentType, paymentTypeId);
} }
public static String paymentTypeChargeJSON(Integer amount, final boolean enablePaymentType, final Integer paymentTypeId) { public static String paymentTypeChargeJSON(Integer amount, final boolean enablePaymentType, final Long paymentTypeId) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("active", ChargesHelper.ACTIVE); map.put("active", ChargesHelper.ACTIVE);
map.put("amount", amount); map.put("amount", amount);
@@ -112,10 +112,12 @@ public class LoanTransactionHelper extends IntegrationTest {
private static final Gson GSON = new JSON().getGson(); private static final Gson GSON = new JSON().getGson();
private final RequestSpecification requestSpec; private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec; private final ResponseSpecification responseSpec;
private PaymentTypeHelper paymentTypeHelper;
public LoanTransactionHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { public LoanTransactionHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
this.requestSpec = requestSpec; this.requestSpec = requestSpec;
this.responseSpec = responseSpec; this.responseSpec = responseSpec;
this.paymentTypeHelper = new PaymentTypeHelper();
} }
public GetLoanProductsProductIdResponse getLoanProduct(final Integer loanProductId) { public GetLoanProductsProductIdResponse getLoanProduct(final Integer loanProductId) {
@@ -745,7 +747,7 @@ public class LoanTransactionHelper extends IntegrationTest {
return ok(fineract().loanTransactions.adjustLoanTransaction(loanId, transactionId, request, "undo")); return ok(fineract().loanTransactions.adjustLoanTransaction(loanId, transactionId, request, "undo"));
} }
public HashMap makeRepaymentWithPDC(final String date, final Float amountToBePaid, final Integer loanID, final Integer paymentType) { public HashMap makeRepaymentWithPDC(final String date, final Float amountToBePaid, final Integer loanID, final Long paymentType) {
return (HashMap) performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID), return (HashMap) performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
getRepaymentWithPDCBodyAsJSON(date, amountToBePaid, paymentType), ""); getRepaymentWithPDCBodyAsJSON(date, amountToBePaid, paymentType), "");
} }
@@ -1123,7 +1125,7 @@ public class LoanTransactionHelper extends IntegrationTest {
return new Gson().toJson(map); return new Gson().toJson(map);
} }
private String getRepaymentWithPDCBodyAsJSON(final String transactionDate, final Float transactionAmount, final Integer paymentTypeId) { private String getRepaymentWithPDCBodyAsJSON(final String transactionDate, final Float transactionAmount, final Long paymentTypeId) {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("locale", "en"); map.put("locale", "en");
map.put("paymentTypeId", paymentTypeId.toString()); map.put("paymentTypeId", paymentTypeId.toString());
@@ -1692,7 +1694,7 @@ public class LoanTransactionHelper extends IntegrationTest {
public Long applyChargebackTransaction(final Integer loanId, final Long transactionId, final String amount, public Long applyChargebackTransaction(final Integer loanId, final Long transactionId, final String amount,
final Integer paymentTypeIdx, ResponseSpecification responseSpec) { final Integer paymentTypeIdx, ResponseSpecification responseSpec) {
List<GetPaymentTypesResponse> paymentTypeList = PaymentTypeHelper.getSystemPaymentType(this.requestSpec, this.responseSpec); List<GetPaymentTypesResponse> paymentTypeList = paymentTypeHelper.getAllPaymentTypes(false);
assertTrue(!paymentTypeList.isEmpty()); assertTrue(!paymentTypeList.isEmpty());
final String payload = createChargebackPayload(amount, paymentTypeList.get(paymentTypeIdx).getId()); final String payload = createChargebackPayload(amount, paymentTypeList.get(paymentTypeIdx).getId());
@@ -1722,7 +1724,7 @@ public class LoanTransactionHelper extends IntegrationTest {
} }
} }
private String createChargebackPayload(final String transactionAmount, final Integer paymentTypeId) { private String createChargebackPayload(final String transactionAmount, final Long paymentTypeId) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("transactionAmount", transactionAmount); map.put("transactionAmount", transactionAmount);
map.put("paymentTypeId", paymentTypeId); map.put("paymentTypeId", paymentTypeId);