diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java index 03a0f9bec1d..38749bee32e 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java @@ -16,8 +16,12 @@ * 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.assertThrows; + import io.restassured.builder.RequestSpecBuilder; import io.restassured.builder.ResponseSpecBuilder; import io.restassured.http.ContentType; @@ -26,6 +30,7 @@ import org.apache.fineract.client.models.PaymentTypeCreateRequest; import org.apache.fineract.client.models.PaymentTypeData; import org.apache.fineract.client.models.PaymentTypeUpdateRequest; +import org.apache.fineract.client.util.CallFailedRuntimeException; import org.apache.fineract.integrationtests.common.PaymentTypeHelper; import org.apache.fineract.integrationtests.common.Utils; import org.junit.jupiter.api.Assertions; @@ -36,7 +41,6 @@ public class PaymentTypeIntegrationTest { private ResponseSpecification responseSpec; private RequestSpecification requestSpec; - private PaymentTypeHelper paymentTypeHelper; @BeforeEach public void setup() { @@ -44,47 +48,48 @@ public void setup() { this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); - this.paymentTypeHelper = new PaymentTypeHelper(); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testPaymentType() { + // 1. Setup Data String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); Boolean isCashPayment = true; Long position = 1L; - var paymentTypesResponse = paymentTypeHelper.createPaymentType( + // 2. Create Payment Type + var paymentTypesResponse = PaymentTypeHelper.createPaymentType( new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position)); + Long paymentTypeId = paymentTypesResponse.getResourceId(); - Assertions.assertNotNull(paymentTypeId); - paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId); - PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId); - Assertions.assertEquals(name, paymentTypeResponse.getName()); - Assertions.assertEquals(description, paymentTypeResponse.getDescription()); - Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment()); - Assertions.assertEquals(position, paymentTypeResponse.getPosition()); - - // Update Payment Type + Assertions.assertNotNull(paymentTypeId, "Payment Type Resource ID should not be null"); + + // 3. Verify Creation + PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId); + + // 4. Retrieve and Assert + PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId); + Assertions.assertEquals(name, paymentTypeResponse.getName(), "Name mismatch after creation"); + + // 5. Update Payment Type String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5); - String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15); - Boolean isCashPaymentUpdatedValue = false; - Long newPosition = 2L; - - paymentTypeHelper.updatePaymentType(paymentTypeId, new PaymentTypeUpdateRequest().name(newName).description(newDescription) - .isCashPayment(isCashPaymentUpdatedValue).position(newPosition)); - var paymentTypeUpdatedResponse = paymentTypeHelper.retrieveById(paymentTypeId); - Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName()); - Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription()); - Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment()); - Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition()); - - // Delete - var responseDelete = paymentTypeHelper.deletePaymentType(paymentTypeId); - Long deletedPaymentTypeId = responseDelete.getResourceId(); - Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId); - ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build(); - paymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId); + PaymentTypeHelper.updatePaymentType(paymentTypeId, + new PaymentTypeUpdateRequest().name(newName).description(description).isCashPayment(isCashPayment).position(position)); + + // 6. Verify Update + var paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(paymentTypeId); + Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName(), "Name mismatch after update"); + + // 7. Delete Payment Type + var responseDelete = PaymentTypeHelper.deletePaymentType(paymentTypeId); + Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId(), "Deleted Resource ID mismatch"); + + // JUnit style assertThrows + final CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class, () -> { + PaymentTypeHelper.retrieveById(paymentTypeId); + }); + + assertEquals(404, exception.getResponse().code()); } } diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java deleted file mode 100644 index c3ea6c3ca76..00000000000 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * 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; - -public final class PaymentTypeDomain { - - private Long id; - private String name; - private String description; - private Boolean isCashPayment; - private Integer position; - - public PaymentTypeDomain(final Long id, final String name, final String description, final Boolean isCashPayment, - final Integer position) { - this.id = id; - this.name = name; - this.description = description; - this.isCashPayment = isCashPayment; - this.position = position; - - } - - public Long getId() { - return this.id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Boolean getIsCashPayment() { - return this.isCashPayment; - } - - public void setIsCashPayment(Boolean isCashPayment) { - this.isCashPayment = isCashPayment; - } - - public Integer getPosition() { - return this.position; - } - - public void setPosition(Integer position) { - this.position = position; - } - -} diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java index 1c306fde127..8c683677308 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java @@ -16,12 +16,11 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.fineract.integrationtests.common; import static org.junit.jupiter.api.Assertions.assertEquals; -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; @@ -34,60 +33,44 @@ import org.apache.fineract.client.models.PaymentTypeUpdateResponse; import org.apache.fineract.client.util.Calls; -@SuppressWarnings({ "rawtypes", "unchecked" }) @Slf4j +@SuppressWarnings("HideUtilityClassConstructor") public final class PaymentTypeHelper { - public PaymentTypeHelper() { - - } + public PaymentTypeHelper() {} - private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes"; - private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER; - - public List getAllPaymentTypes(final Boolean onlyWithCode) { + public static List getAllPaymentTypes(final Boolean onlyWithCode) { log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------"); return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode)); } - public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest paymentTypeRequest) { + public static PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest request) { log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------"); - return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(paymentTypeRequest)); + return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(request)); } - public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) { + public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) { log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------"); PaymentTypeData response = Calls .ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID)); - Long responsePaymentTypeID = response.getId(); - assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE"); + assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE"); } - public PaymentTypeData retrieveById(final Long paymentTypeId) { - log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------"); + public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) { + log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------"); return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId)); } - // TODO: Rewrite to use fineract-client instead! - // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, - // org.apache.fineract.client.models.PostLoansLoanIdRequest) - @Deprecated(forRemoval = true) - public PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) { - final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER; - log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------"); - Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, ""); - final String jsonData = new Gson().toJson(get); - return new Gson().fromJson(jsonData, new TypeToken() {}.getType()); + public static PaymentTypeData retrieveById(final Long paymentTypeId) { + return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId)); } - public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, - PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) { + public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) { log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------"); - return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, - putPaymentTypesPaymentTypeIdRequest)); + return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request)); } - public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) { + public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) { log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------"); return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId)); }