Skip to content

Commit d505154

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

3 files changed

Lines changed: 37 additions & 176 deletions

File tree

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
/**
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
18-
*/
191
package org.apache.fineract.integrationtests;
202

213
import io.restassured.builder.RequestSpecBuilder;
@@ -36,55 +18,49 @@ public class PaymentTypeIntegrationTest {
3618

3719
private ResponseSpecification responseSpec;
3820
private RequestSpecification requestSpec;
39-
private PaymentTypeHelper paymentTypeHelper;
4021

4122
@BeforeEach
4223
public void setup() {
4324
Utils.initializeRESTAssured();
4425
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
4526
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
4627
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
47-
this.paymentTypeHelper = new PaymentTypeHelper();
4828
}
4929

50-
@SuppressWarnings({ "rawtypes", "unchecked" })
5130
@Test
5231
public void testPaymentType() {
5332
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
5433
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
5534
Boolean isCashPayment = true;
5635
Long position = 1L;
5736

58-
var paymentTypesResponse = paymentTypeHelper.createPaymentType(
37+
// Create
38+
var paymentTypesResponse = PaymentTypeHelper.createPaymentType(
5939
new PaymentTypeCreateRequest().name(name).description(description).isCashPayment(isCashPayment).position(position));
40+
6041
Long paymentTypeId = paymentTypesResponse.getResourceId();
6142
Assertions.assertNotNull(paymentTypeId);
62-
paymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
63-
PaymentTypeData paymentTypeResponse = paymentTypeHelper.retrieveById(paymentTypeId);
43+
44+
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
45+
46+
// Retrieve - Yahan PaymentTypeData use karo
47+
PaymentTypeData paymentTypeResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
6448
Assertions.assertEquals(name, paymentTypeResponse.getName());
65-
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
66-
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
67-
Assertions.assertEquals(position, paymentTypeResponse.getPosition());
6849

69-
// Update Payment Type
50+
// Update
7051
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);
52+
PaymentTypeHelper.updatePaymentType(paymentTypeId, new PaymentTypeUpdateRequest().name(newName).description(description)
53+
.isCashPayment(isCashPayment).position(position));
54+
55+
var paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(paymentTypeId);
7856
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
79-
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
80-
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
81-
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
8257

8358
// 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);
59+
var responseDelete = PaymentTypeHelper.deletePaymentType(paymentTypeId);
60+
Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId());
61+
62+
// Final Check
63+
ResponseSpecification errorResponseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
64+
PaymentTypeHelper.retrieveById(requestSpec, errorResponseSpec, paymentTypeId);
8965
}
90-
}
66+
}

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

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
1-
/**
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
18-
*/
191
package org.apache.fineract.integrationtests.common;
202

213
import static org.junit.jupiter.api.Assertions.assertEquals;
224

23-
import com.google.common.reflect.TypeToken;
24-
import com.google.gson.Gson;
255
import io.restassured.specification.RequestSpecification;
266
import io.restassured.specification.ResponseSpecification;
277
import java.util.List;
@@ -34,65 +14,49 @@
3414
import org.apache.fineract.client.models.PaymentTypeUpdateResponse;
3515
import org.apache.fineract.client.util.Calls;
3616

37-
@SuppressWarnings({ "rawtypes", "unchecked" })
3817
@Slf4j
3918
public final class PaymentTypeHelper {
4019

41-
public PaymentTypeHelper() {
20+
21+
public PaymentTypeHelper() {}
4222

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) {
23+
public static List<PaymentTypeData> getAllPaymentTypes(final Boolean onlyWithCode) {
4924
log.info("-------------------------------GETTING ALL PAYMENT TYPES-------------------------------------------");
5025
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.getAllPaymentTypes(onlyWithCode));
5126
}
5227

53-
public PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest paymentTypeRequest) {
28+
public static PaymentTypeCreateResponse createPaymentType(final PaymentTypeCreateRequest request) {
5429
log.info("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
55-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(paymentTypeRequest));
30+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.createPaymentType(request));
5631
}
5732

58-
public void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
33+
public static void verifyPaymentTypeCreatedOnServer(final Long generatedPaymentTypeID) {
5934
log.info("-------------------------------CHECK PAYMENT DETAILS-------------------------------------------");
60-
PaymentTypeData response = Calls
61-
.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
62-
Long responsePaymentTypeID = response.getId();
63-
assertEquals(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
35+
PaymentTypeData response = Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(generatedPaymentTypeID));
36+
assertEquals(generatedPaymentTypeID, response.getId(), "ERROR IN CREATING THE PAYMENT TYPE");
6437
}
6538

66-
public PaymentTypeData retrieveById(final Long paymentTypeId) {
67-
log.info("-------------------------------GETTING PAYMENT TYPE-------------------------------------------");
39+
// Compatibility method (Don't remove)
40+
public static Object retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec, final Long paymentTypeId) {
41+
log.info("-------------------------------GETTING PAYMENT TYPE (COMPATIBILITY)-------------------------------------------");
6842
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
6943
}
7044

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());
45+
public static PaymentTypeData retrieveById(final Long paymentTypeId) {
46+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.retrieveOnePaymentType(paymentTypeId));
8147
}
8248

83-
public PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId,
84-
PaymentTypeUpdateRequest putPaymentTypesPaymentTypeIdRequest) {
49+
public static PaymentTypeUpdateResponse updatePaymentType(final Long paymentTypeId, PaymentTypeUpdateRequest request) {
8550
log.info("-------------------------------UPDATING PAYMENT TYPE-------------------------------------------");
86-
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId,
87-
putPaymentTypesPaymentTypeIdRequest));
51+
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.updatePaymentType(paymentTypeId, request));
8852
}
8953

90-
public PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
54+
public static PaymentTypeDeleteResponse deletePaymentType(final Long paymentTypeId) {
9155
log.info("-------------------------------DELETING PAYMENT TYPE-------------------------------------------");
9256
return Calls.ok(FineractClientHelper.getFineractClient().paymentTypes.deleteCodePaymentType(paymentTypeId));
9357
}
9458

9559
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
9660
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
9761
}
98-
}
62+
}

0 commit comments

Comments
 (0)