Avtansh88 commented on code in PR #5692:
URL: https://github.com/apache/fineract/pull/5692#discussion_r3041546167
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/PaymentTypeIntegrationTest.java:
##########
@@ -36,55 +37,55 @@ public class PaymentTypeIntegrationTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
- private PaymentTypeHelper paymentTypeHelper;
@BeforeEach
public void setup() {
Utils.initializeRESTAssured();
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());
+ Assertions.assertNotNull(paymentTypeId, "Payment Type Resource ID
should not be null");
+
+ // 3. Verify Creation
+ PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(paymentTypeId);
- // Update Payment Type
+ // 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(description).isCashPayment(isCashPayment).position(position));
+
+ // 6. Verify Update
+ var paymentTypeUpdatedResponse =
PaymentTypeHelper.retrieveById(paymentTypeId);
+ Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName(),
"Name mismatch after update");
- 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());
+ // 7. Delete Payment Type
+ var responseDelete =
PaymentTypeHelper.deletePaymentType(paymentTypeId);
+ Assertions.assertEquals(paymentTypeId, responseDelete.getResourceId(),
"Deleted Resource ID mismatch");
- // 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);
+ ResponseSpecification errorResponseSpec = new
ResponseSpecBuilder().expectStatusCode(404).build();
+ try {
+ PaymentTypeHelper.retrieveById(requestSpec, errorResponseSpec,
paymentTypeId);
+ } catch (Exception e) {
+ // Expected for 404
+ }
Review Comment:
Done. I have refactored the exception handling logic using assertThrows as
suggested. Please take a look
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]