Skip to content

Commit 82f38b5

Browse files
committed
FINERACT-2554: Modernize PaymentTypeHelper and Integration Test
1 parent 5956214 commit 82f38b5

2 files changed

Lines changed: 34 additions & 53 deletions

File tree

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

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

2122
import io.restassured.builder.RequestSpecBuilder;
@@ -36,55 +37,49 @@ public class PaymentTypeIntegrationTest {
3637

3738
private ResponseSpecification responseSpec;
3839
private RequestSpecification requestSpec;
39-
private PaymentTypeHelper paymentTypeHelper;
4040

4141
@BeforeEach
4242
public void setup() {
4343
Utils.initializeRESTAssured();
4444
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
4545
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
4646
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
47-
this.paymentTypeHelper = new PaymentTypeHelper();
4847
}
4948

50-
@SuppressWarnings({ "rawtypes", "unchecked" })
5149
@Test
5250
public void testPaymentType() {
5351
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
5452
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
5553
Boolean isCashPayment = true;
5654
Long position = 1L;
5755

58-
var paymentTypesResponse = paymentTypeHelper.createPaymentType(
56+
// Create
57+
var paymentTypesResponse = PaymentTypeHelper.createPaymentType(
5958
new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
59+
6060
Long paymentTypeId = paymentTypesResponse.getResourceId();
6161
Assertions.assertNotNull(paymentTypeId);
62-
paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
63-
PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
62+
63+
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
64+
65+
// Retrieve - Yahan PaymentTypeData use karo
66+
PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
6467
Assertions.assertEquals(name, paymentTypeResponse.getName());
65-
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
66-
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
67-
Assertions.assertEquals(position, paymentTypeResponse.getPosition());
6868

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

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

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

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

Lines changed: 15 additions & 29 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,47 @@
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

4140
public PaymentTypeHelper() {
4241

4342
}
4443

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) {
44+
public static List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
4945
log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
5046
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode));
5147
}
5248

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

58-
public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
54+
public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
5955
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
6056
PaymentTypeData response = Calls
6157
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
62-
Long responsePaymentTypeID = response.getId();
63-
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
58+
assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE");
6459
}
6560

66-
public PaymentTypeData retrieveById(final Long paymentTypeId) {
67-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
61+
// Compatibility method (Don't remove)
62+
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
63+
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
6864
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
6965
}
7066

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());
67+
public static PaymentTypeData retrieveById(final Long paymentTypeId) {
68+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
8169
}
8270

83-
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
84-
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
71+
public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
8572
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
86-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
87-
putPaymentTypesPaymentTypeIdRequest));
73+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
8874
}
8975

90-
public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
76+
public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
9177
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
9278
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
9379
}

0 commit comments

Comments
 (0)