1616 * specific language governing permissions and limitations
1717 * under the License.
1818 */
19+
1920package org .apache .fineract .integrationtests ;
2021
22+ import static org .junit .jupiter .api .Assertions .assertEquals ;
23+ import static org .junit .jupiter .api .Assertions .assertThrows ;
24+
2125import io .restassured .builder .RequestSpecBuilder ;
2226import io .restassured .builder .ResponseSpecBuilder ;
2327import io .restassured .http .ContentType ;
2630import org .apache .fineract .client .models .PaymentTypeCreateRequest ;
2731import org .apache .fineract .client .models .PaymentTypeData ;
2832import org .apache .fineract .client .models .PaymentTypeUpdateRequest ;
33+ import org .apache .fineract .client .util .CallFailedRuntimeException ;
2934import org .apache .fineract .integrationtests .common .PaymentTypeHelper ;
3035import org .apache .fineract .integrationtests .common .Utils ;
3136import 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}
0 commit comments