Skip to content

Commit a4d699e

Browse files
committed
FINERACT-2554: Modernize PaymentTypeHelper and delete unused PaymentTypeDomain
1 parent 7597eed commit a4d699e

File tree

3 files changed

+32
-135
lines changed

3 files changed

+32
-135
lines changed

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,49 @@ public class PaymentTypeIntegrationTest {
3636

3737
private ResponseSpecification responseSpec;
3838
private RequestSpecification requestSpec;
39-
private PaymentTypeHelper paymentTypeHelper;
4039

4140
@BeforeEach
4241
public void setup() {
4342
Utils.initializeRESTAssured();
4443
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
4544
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
4645
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
47-
this.paymentTypeHelper = new PaymentTypeHelper();
4846
}
4947

50-
@SuppressWarnings({ "rawtypes", "unchecked" })
5148
@Test
5249
public void testPaymentType() {
5350
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
5451
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
5552
Boolean isCashPayment = true;
5653
Long position = 1L;
5754

58-
var paymentTypesResponse = paymentTypeHelper.createPaymentType(
55+
// Create
56+
var paymentTypesResponse = PaymentTypeHelper.createPaymentType(
5957
new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
58+
6059
Long paymentTypeId = paymentTypesResponse.getResourceId();
6160
Assertions.assertNotNull(paymentTypeId);
62-
paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
63-
PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
61+
62+
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
63+
64+
// Retrieve - Yahan PaymentTypeData use karo
65+
PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
6466
Assertions.assertEquals(name, paymentTypeResponse.getName());
65-
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
66-
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
67-
Assertions.assertEquals(position, paymentTypeResponse.getPosition());
6867

69-
// Update Payment Type
68+
// Update
7069
String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5);
71-
String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15);
72-
Boolean isCashPaymentUpdatedValue = false;
73-
Long newPosition = 2L;
70+
PaymentTypeHelper.updatePaymentType(paymentTypeId,
71+
new PaymentTypeUpdateRequest().name(newName).description(description).isCashPayment(isCashPayment).position(position));
7472

75-
paymentTypeHelper.updatePaymentType(paymentTypeId, new PaymentTypeUpdateRequest().name(newName).description(newDescription)
76-
.isCashPayment(isCashPaymentUpdatedValue).position(newPosition));
77-
var paymentTypeUpdatedResponse = paymentTypeHelper.retrieveById(paymentTypeId);
73+
var paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
7874
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
79-
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
80-
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
81-
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
8275

8376
// 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+
var responseDelete = PaymentTypeHelper.deletePaymentType(paymentTypeId);
78+
Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId());
79+
80+
// Final Check
81+
ResponseSpecification errorResponseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
82+
PaymentTypeHelper.retrieveById(requestSpec, errorResponseSpec, paymentTypeId);
8983
}
9084
}

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: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222

23-
import com.google.common.reflect.TypeToken;
24-
import com.google.gson.Gson;
2523
import io.restassured.specification.RequestSpecification;
2624
import io.restassured.specification.ResponseSpecification;
2725
import java.util.List;
@@ -34,60 +32,44 @@
3432
import org.apache.fineract.client.models.PaymentTypeUpdateResponse;
3533
import org.apache.fineract.client.util.Calls;
3634

37-
@SuppressWarnings({ "rawtypes", "unchecked" })
3835
@Slf4j
3936
public final class PaymentTypeHelper {
4037

41-
public PaymentTypeHelper() {
38+
public PaymentTypeHelper() {}
4239

43-
}
44-
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) {
40+
public static List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
4941
log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
5042
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode));
5143
}
5244

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

58-
public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
50+
public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
5951
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
6052
PaymentTypeData response = Calls
6153
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
62-
Long responsePaymentTypeID = response.getId();
63-
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
54+
assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE");
6455
}
6556

66-
public PaymentTypeData retrieveById(final Long paymentTypeId) {
67-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
57+
// Compatibility method (Don't remove)
58+
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
59+
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
6860
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
6961
}
7062

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());
63+
public static PaymentTypeData retrieveById(final Long paymentTypeId) {
64+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
8165
}
8266

83-
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
84-
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
67+
public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
8568
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
86-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
87-
putPaymentTypesPaymentTypeIdRequest));
69+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
8870
}
8971

90-
public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
72+
public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
9173
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
9274
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
9375
}

0 commit comments

Comments
 (0)