Skip to content

Commit 5a946fc

Browse files
committed
FINERACT-2554: Modernize PaymentTypeHelper and Integration Tests
1 parent 516be50 commit 5a946fc

File tree

3 files changed

+51
-142
lines changed

3 files changed

+51
-142
lines changed

integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.apache.fineract.integrationtests;
2021

22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
24+
2125
import io.restassured.builder.RequestSpecBuilder;
2226
import io.restassured.builder.ResponseSpecBuilder;
2327
import io.restassured.http.ContentType;
@@ -26,6 +30,7 @@
2630
import org.apache.fineract.client.models.PaymentTypeCreateRequest;
2731
import org.apache.fineract.client.models.PaymentTypeData;
2832
import org.apache.fineract.client.models.PaymentTypeUpdateRequest;
33+
import org.apache.fineract.client.util.CallFailedRuntimeException;
2934
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
3035
import org.apache.fineract.integrationtests.common.Utils;
3136
import org.junit.jupiter.api.Assertions;
@@ -36,55 +41,55 @@ public class PaymentTypeIntegrationTest {
3641

3742
private ResponseSpecification responseSpec;
3843
private RequestSpecification requestSpec;
39-
private PaymentTypeHelper paymentTypeHelper;
4044

4145
@BeforeEach
4246
public void setup() {
4347
Utils.initializeRESTAssured();
4448
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
4549
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
4650
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
47-
this.paymentTypeHelper = new PaymentTypeHelper();
4851
}
4952

50-
@SuppressWarnings({ "rawtypes", "unchecked" })
5153
@Test
5254
public void testPaymentType() {
55+
// 1. Setup Data
5356
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
5457
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
5558
Boolean isCashPayment = true;
5659
Long position = 1L;
5760

58-
var paymentTypesResponse = paymentTypeHelper.createPaymentType(
61+
// 2. Create Payment Type
62+
var paymentTypesResponse = PaymentTypeHelper.createPaymentType(
5963
new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
64+
6065
Long paymentTypeId = paymentTypesResponse.getResourceId();
61-
Assertions.assertNotNull(paymentTypeId);
62-
paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
63-
PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
64-
Assertions.assertEquals(name, paymentTypeResponse.getName());
65-
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
66-
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
67-
Assertions.assertEquals(position, paymentTypeResponse.getPosition());
68-
69-
// Update Payment Type
66+
Assertions.assertNotNull(paymentTypeId, "Payment Type Resource ID should not be null");
67+
68+
// 3. Verify Creation
69+
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
70+
71+
// 4. Retrieve and Assert
72+
PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
73+
Assertions.assertEquals(name, paymentTypeResponse.getName(), "Name mismatch after creation");
74+
75+
// 5. Update Payment Type
7076
String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5);
71-
String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15);
72-
Boolean isCashPaymentUpdatedValue = false;
73-
Long newPosition = 2L;
74-
75-
paymentTypeHelper.updatePaymentType(paymentTypeId, new PaymentTypeUpdateRequest().name(newName).description(newDescription)
76-
.isCashPayment(isCashPaymentUpdatedValue).position(newPosition));
77-
var paymentTypeUpdatedResponse = paymentTypeHelper.retrieveById(paymentTypeId);
78-
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
79-
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
80-
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
81-
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
82-
83-
// Delete
84-
var responseDelete = paymentTypeHelper.deletePaymentType(paymentTypeId);
85-
Long deletedPaymentTypeId = responseDelete.getResourceId();
86-
Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId);
87-
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build();
88-
paymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
77+
PaymentTypeHelper.updatePaymentType(paymentTypeId,
78+
new PaymentTypeUpdateRequest().name(newName).description(description).isCashPayment(isCashPayment).position(position));
79+
80+
// 6. Verify Update
81+
var paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
82+
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName(), "Name mismatch after update");
83+
84+
// 7. Delete Payment Type
85+
var responseDelete = PaymentTypeHelper.deletePaymentType(paymentTypeId);
86+
Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId(), "Deleted Resource ID mismatch");
87+
88+
// JUnit style assertThrows
89+
final CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class, () -> {
90+
PaymentTypeHelper.retrieveById(paymentTypeId);
91+
});
92+
93+
assertEquals(404, exception.getResponse().code());
8994
}
9095
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeDomain.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/PaymentTypeHelper.java

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.apache.fineract.integrationtests.common;
2021

2122
import static org.junit.jupiter.api.Assertions.assertEquals;
2223

23-
import com.google.common.reflect.TypeToken;
24-
import com.google.gson.Gson;
2524
import io.restassured.specification.RequestSpecification;
2625
import io.restassured.specification.ResponseSpecification;
2726
import java.util.List;
@@ -34,60 +33,44 @@
3433
import org.apache.fineract.client.models.PaymentTypeUpdateResponse;
3534
import org.apache.fineract.client.util.Calls;
3635

37-
@SuppressWarnings({ "rawtypes", "unchecked" })
3836
@Slf4j
37+
@SuppressWarnings("HideUtilityClassConstructor")
3938
public final class PaymentTypeHelper {
4039

41-
public PaymentTypeHelper() {
42-
43-
}
40+
public PaymentTypeHelper() {}
4441

45-
private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes";
46-
private static final String CREATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "?" + Utils.TENANT_IDENTIFIER;
47-
48-
public List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
42+
public static List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
4943
log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
5044
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode));
5145
}
5246

53-
public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest paymentTypeRequest) {
47+
public static PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest request) {
5448
log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
55-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(paymentTypeRequest));
49+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(request));
5650
}
5751

58-
public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
52+
public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
5953
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
6054
PaymentTypeData response = Calls
6155
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
62-
Long responsePaymentTypeID = response.getId();
63-
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
56+
assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE");
6457
}
6558

66-
public PaymentTypeData retrieveById(final Long paymentTypeId) {
67-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
59+
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
60+
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
6861
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
6962
}
7063

71-
// TODO: Rewrite to use fineract-client instead!
72-
// Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long,
73-
// org.apache.fineract.client.models.PostLoansLoanIdRequest)
74-
@Deprecated(forRemoval = true)
75-
public PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
76-
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
77-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
78-
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "");
79-
final String jsonData = new Gson().toJson(get);
80-
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
64+
public static PaymentTypeData retrieveById(final Long paymentTypeId) {
65+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
8166
}
8267

83-
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
84-
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
68+
public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
8569
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
86-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
87-
putPaymentTypesPaymentTypeIdRequest));
70+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
8871
}
8972

90-
public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
73+
public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
9174
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
9275
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
9376
}

0 commit comments

Comments
 (0)