15
15
import io .cucumber .core .internal .com .fasterxml .jackson .core .JsonProcessingException ;
16
16
import io .cucumber .core .internal .com .fasterxml .jackson .databind .JsonNode ;
17
17
import io .cucumber .java .en .And ;
18
+ import io .cucumber .java .en .Given ;
18
19
import io .cucumber .java .en .Then ;
19
20
import io .cucumber .java .en .When ;
20
21
import io .restassured .RestAssured ;
31
32
import org .mifos .integrationtest .common .dto .Alias ;
32
33
import org .mifos .integrationtest .common .dto .Bill ;
33
34
import org .mifos .integrationtest .common .dto .BillRTPReqDTO ;
35
+ import org .mifos .integrationtest .common .dto .BillStatusReqDTO ;
34
36
import org .mifos .integrationtest .common .dto .PayerFSPDetail ;
35
37
import org .mifos .integrationtest .common .dto .billpayp2g .BillPaymentsReqDTO ;
36
38
import org .mifos .integrationtest .config .BillPayConnectorConfig ;
@@ -45,15 +47,19 @@ public class BillPayStepDef extends BaseStepDef {
45
47
private BillPayConnectorConfig billPayConnectorConfig ;
46
48
private static String billerId ;
47
49
private static BillRTPReqDTO billRTPReqDTO ;
50
+
51
+ private static BillStatusReqDTO billStatusReqDTO ;
48
52
private static String billId = "12345" ;
49
53
private static String rtpId = "123456" ;
50
54
private static String rtpResponse ;
55
+ private static String statusResponse ;
51
56
52
57
@ Then ("I can create DTO for Biller RTP Request" )
53
58
public void iCanCreateDTOForBillerRTPRequest () {
54
59
Bill bill = new Bill ("Test" , 100.0 );
55
- PayerFSPDetail payerFSPDetail = new PayerFSPDetail ("lion" , "1223455" );
56
- billRTPReqDTO = new BillRTPReqDTO ("123445" , billId , "00" , payerFSPDetail , bill );
60
+ String payeeFsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
61
+ PayerFSPDetail payerFSPDetail = new PayerFSPDetail (payeeFsp , "1223455" );
62
+ billRTPReqDTO = new BillRTPReqDTO ("123445" , scenarioScopeState .billId , "00" , payerFSPDetail , bill );
57
63
58
64
}
59
65
@@ -70,7 +76,8 @@ public void iCallTheGetBillsApiWithBillidWithExpectedStatusOf(int expectedStatus
70
76
71
77
requestSpec .header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId .toString ());
72
78
requestSpec .header ("X-CallbackURL" , billPayConnectorConfig .callbackURL + callbackUrl );
73
- requestSpec .header ("X-PayerFSP-Id" , "lion" );
79
+ String fsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
80
+ requestSpec .header ("X-PayerFSP-Id" , fsp );
74
81
requestSpec .queryParam ("fields" , "inquiry" );
75
82
scenarioScopeState .response = RestAssured .given (requestSpec ).baseUri (billPayConnectorConfig .billPayContactPoint ).expect ()
76
83
.spec (new ResponseSpecBuilder ().expectStatusCode (expectedStatus ).build ()).when ()
@@ -151,7 +158,8 @@ public void iCallThePaymentNotificationApiExpectedStatusOf(int expectedStatus, S
151
158
RequestSpecification requestSpec = Utils .getDefaultSpec (scenarioScopeState .tenant );
152
159
requestSpec .header ("X-Platform-TenantId" , scenarioScopeState .tenant );
153
160
requestSpec .header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId );
154
- requestSpec .header ("X-PayerFSP-Id" , "lion" );
161
+ String fsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
162
+ requestSpec .header ("X-PayerFSP-Id" , fsp );
155
163
requestSpec .queryParam ("fields" , "inquiry" );
156
164
requestSpec .header ("X-CallbackURL" , billPayConnectorConfig .callbackURL + callbackurl );
157
165
scenarioScopeState .response = RestAssured .given (requestSpec ).baseUri (billPayConnectorConfig .billPayContactPoint )
@@ -161,14 +169,22 @@ public void iCallThePaymentNotificationApiExpectedStatusOf(int expectedStatus, S
161
169
162
170
logger .info ("Payment notiifcation response: {}" , scenarioScopeState .response );
163
171
JSONObject jsonObject = new JSONObject (scenarioScopeState .response );
172
+ if (!jsonObject .get ("transactionId" ).toString ().equals ("null" )) {
173
+ scenarioScopeState .transactionId = jsonObject .getString ("transactionId" );
174
+ assertThat (scenarioScopeState .transactionId .equals ("NA" )).isFalse ();
175
+ } else {
176
+ scenarioScopeState .transactionId = jsonObject .getString ("error" );
177
+ assertThat (scenarioScopeState .transactionId .contains ("Invalid Request" )).isTrue ();
178
+ }
164
179
}
165
180
166
181
@ When ("I call the mock get bills api from PBB to Biller with billid with expected status of {int}" )
167
182
public void iCallTheMockGetBillsApiPBBToBillerAggWithBillidWithExpectedStatusOf (int expectedStatus ) {
168
183
RequestSpecification requestSpec = Utils .getDefaultSpec (scenarioScopeState .tenant );
169
184
requestSpec .header ("X-Platform-TenantId" , scenarioScopeState .tenant );
170
185
requestSpec .header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId );
171
- requestSpec .header ("X-PayerFSP-Id" , "lion" );
186
+ String fsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
187
+ requestSpec .header ("X-PayerFSP-Id" , fsp );
172
188
scenarioScopeState .response = RestAssured .given (requestSpec ).baseUri (billPayConnectorConfig .billPayContactPoint ).expect ()
173
189
.spec (new ResponseSpecBuilder ().expectStatusCode (expectedStatus ).build ()).when ()
174
190
.get (billPayConnectorConfig .inquiryEndpoint .replace ("{billId}" , billId )).andReturn ().asString ();
@@ -182,7 +198,8 @@ public void iCallTheMockBillsPaymentApiFromPBBToBillerWithBillidWithExpectedStat
182
198
RequestSpecification requestSpec = Utils .getDefaultSpec (scenarioScopeState .tenant );
183
199
requestSpec .header ("X-Platform-TenantId" , scenarioScopeState .tenant );
184
200
requestSpec .header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId );
185
- requestSpec .header ("X-PayerFSP-Id" , "lion" );
201
+ String fsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
202
+ requestSpec .header ("X-PayerFSP-Id" , fsp );
186
203
requestSpec .header ("X-CallbackURL" , "https://webhook.site/b44174ab-04b4-4b0d-8426-a3c54bc2f794" );
187
204
scenarioScopeState .response = RestAssured .given (requestSpec ).baseUri (billPayConnectorConfig .billPayContactPoint )
188
205
.body (scenarioScopeState .inboundTransferReqP2G ).expect ()
@@ -204,7 +221,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillPay() {
204
221
List <ServeEvent > allServeEvents = getAllServeEvents ();
205
222
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
206
223
ServeEvent request = allServeEvents .get (i );
207
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
224
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty () && request . getRequest (). getUrl (). equals ( "/billInquiry" ) ) {
208
225
JsonNode rootNode = null ;
209
226
flag = true ;
210
227
try {
@@ -244,7 +261,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillNotification()
244
261
List <ServeEvent > allServeEvents = getAllServeEvents ();
245
262
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
246
263
ServeEvent request = allServeEvents .get (i );
247
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
264
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty () && request . getRequest (). getUrl (). equals ( "/billNotification" ) ) {
248
265
JsonNode rootNode = null ;
249
266
flag = true ;
250
267
try {
@@ -283,6 +300,7 @@ public void iCanCallTheBillerRTPRequestAPIWithExpectedStatusOfAndEndpoint(int ex
283
300
ObjectMapper objectMapper = new ObjectMapper ();
284
301
String jsonPayload = objectMapper .writeValueAsString (billRTPReqDTO );
285
302
RequestSpecification requestSpec = Utils .getDefaultSpec ();
303
+ requestSpec .header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId );
286
304
scenarioScopeState .response = RestAssured .given (requestSpec ).header ("Content-Type" , "application/json" )
287
305
.header ("X-Callback-URL" , billPayConnectorConfig .callbackURL + stub ).header ("X-Biller-Id" , billerId )
288
306
.header ("X-Client-Correlation-ID" , scenarioScopeState .clientCorrelationId )
@@ -319,6 +337,7 @@ public void iCanExtractTheCallbackBodyAndAssertTheRtpStatus() {
319
337
String requestId = null ;
320
338
if (rootNode .has ("requestId" )) {
321
339
requestId = rootNode .get ("requestId" ).asText ();
340
+ scenarioScopeState .requestId = requestId ;
322
341
}
323
342
assertThat (requestId ).isNotEmpty ();
324
343
String rtpStatus = null ;
@@ -329,6 +348,7 @@ public void iCanExtractTheCallbackBodyAndAssertTheRtpStatus() {
329
348
String rtpId = null ;
330
349
if (rootNode .has ("rtpId" )) {
331
350
rtpId = rootNode .get ("rtpId" ).asText ();
351
+ scenarioScopeState .rtpId = rtpId ;
332
352
}
333
353
assertThat (rtpId ).isNotEmpty ();
334
354
String billId = null ;
@@ -351,7 +371,8 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillerUnidentified(
351
371
List <ServeEvent > allServeEvents = getAllServeEvents ();
352
372
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
353
373
ServeEvent request = allServeEvents .get (i );
354
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
374
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty ()
375
+ && request .getRequest ().getUrl ().equals ("/billInquiryPrefixInvalid" )) {
355
376
JsonNode rootNode = null ;
356
377
flag = true ;
357
378
try {
@@ -387,7 +408,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillInvalid() {
387
408
List <ServeEvent > allServeEvents = getAllServeEvents ();
388
409
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
389
410
ServeEvent request = allServeEvents .get (i );
390
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
411
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty () && request . getRequest (). getUrl (). equals ( "/invalidbillInquiry" ) ) {
391
412
JsonNode rootNode = null ;
392
413
flag = true ;
393
414
try {
@@ -430,7 +451,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForEmptyBillId() {
430
451
List <ServeEvent > allServeEvents = getAllServeEvents ();
431
452
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
432
453
ServeEvent request = allServeEvents .get (i );
433
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
454
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty () && request . getRequest (). getUrl (). equals ( "/billInquiryEmpty" ) ) {
434
455
JsonNode rootNode = null ;
435
456
flag = true ;
436
457
try {
@@ -488,7 +509,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillAlreadyPaid() {
488
509
List <ServeEvent > allServeEvents = getAllServeEvents ();
489
510
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
490
511
ServeEvent request = allServeEvents .get (i );
491
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
512
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty () && request . getRequest (). getUrl (). equals ( "/billNotificationPaid" ) ) {
492
513
JsonNode rootNode = null ;
493
514
flag = true ;
494
515
try {
@@ -555,7 +576,8 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillPaidAfterTimeou
555
576
List <ServeEvent > allServeEvents = getAllServeEvents ();
556
577
for (int i = allServeEvents .size () - 1 ; i >= 0 ; i --) {
557
578
ServeEvent request = allServeEvents .get (i );
558
- if (!(request .getRequest ().getBodyAsString ()).isEmpty ()) {
579
+ if (!(request .getRequest ().getBodyAsString ()).isEmpty ()
580
+ && request .getRequest ().getUrl ().equals ("/billNotificationsTimeout" )) {
559
581
JsonNode rootNode = null ;
560
582
flag = true ;
561
583
try {
@@ -602,7 +624,8 @@ public void iCanCreateDTOForBillerRTPRequestWithIncorrectRtpType() {
602
624
@ Then ("I can create DTO for Biller RTP Request with incorrect rtp information" )
603
625
public void iCanCreateDTOForBillerRTPRequestWithIncorrectRtpInformation () {
604
626
Bill bill = new Bill ("Test" , 100.0 );
605
- PayerFSPDetail payerFSPDetail = new PayerFSPDetail ("lion" , "1223455" );
627
+ String payeeFsp = payeeFspConfig .getPayerFsp ("payerfsp1" );
628
+ PayerFSPDetail payerFSPDetail = new PayerFSPDetail (payeeFsp , "1223455" );
606
629
billRTPReqDTO = new BillRTPReqDTO ("123445" , billId , "01" , payerFSPDetail , bill );
607
630
}
608
631
@@ -615,15 +638,17 @@ public void iCanCreateDTOForBillerRTPRequestWithIncorrectAliasDetails() {
615
638
@ Then ("I can create DTO for Biller RTP Request to mock payer fi unreachable" )
616
639
public void iCanCreateDTOForBillerRTPRequestToMockPayerFiUnreachable () {
617
640
Bill bill = new Bill ("Test" , 100.0 );
618
- PayerFSPDetail payerFSPDetail = new PayerFSPDetail ("rhino" , "122333" );
641
+ String payerfsp = tenantConfig .getTenant ("paymentbb1" .toLowerCase ());
642
+ PayerFSPDetail payerFSPDetail = new PayerFSPDetail (payerfsp , "122333" );
619
643
billRTPReqDTO = new BillRTPReqDTO ("123445" , billId , "00" , payerFSPDetail , bill );
620
644
}
621
645
622
646
@ Then ("I can create DTO for Biller RTP Request to mock payer fsp failed to debit amount" )
623
647
public void iCanCreateDTOForBillerRTPRequestToMockPayerFspFailedToDebitAmount () {
624
648
Bill bill = new Bill ("Test" , 100.0 );
625
- PayerFSPDetail payerFSPDetail = new PayerFSPDetail ("rhino" , "1223334444" );
626
- billRTPReqDTO = new BillRTPReqDTO ("123445" , billId , "00" , payerFSPDetail , bill );
649
+ String payerfsp = tenantConfig .getTenant ("paymentbb1" .toLowerCase ());
650
+ PayerFSPDetail payerFSPDetail = new PayerFSPDetail (payerfsp , "1223334444" );
651
+ billRTPReqDTO = new BillRTPReqDTO (scenarioScopeState .clientCorrelationId , scenarioScopeState .billId , "00" , payerFSPDetail , bill );
627
652
}
628
653
629
654
@ And ("I can extract the error from response body and assert the error information as {string}" )
@@ -678,4 +703,32 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillNotificationWit
678
703
assertThat (scenarioScopeState .transactionId .equals ("Invalid Request: Bill Id Empty" )).isTrue ();
679
704
});
680
705
}
706
+
707
+ @ Given ("I can create a request for status api" )
708
+ public void iCanCreateARequestForStatusApi () {
709
+ billStatusReqDTO = new BillStatusReqDTO (scenarioScopeState .rtpId , scenarioScopeState .requestId );
710
+
711
+ }
712
+
713
+ @ And ("I can call the biller RTP status API with expected status of {int} until I get the rtpStatus as {string}" )
714
+ public void iCanCallTheBillerRTPStatusAPIWithExpectedStatusOf (int expectedStatus , String status )
715
+ throws com .fasterxml .jackson .core .JsonProcessingException {
716
+ await ().atMost (awaitMost , SECONDS ).pollDelay (pollDelay , SECONDS ).pollInterval (pollInterval , SECONDS ).untilAsserted (() -> {
717
+ ObjectMapper objectMapper = new ObjectMapper ();
718
+ String jsonPayload = objectMapper .writeValueAsString (billStatusReqDTO );
719
+ RequestSpecification requestSpec = Utils .getDefaultSpec (scenarioScopeState .tenant );
720
+ requestSpec .header ("X-CorrelationID" , "123" );
721
+ requestSpec .header ("billId" , scenarioScopeState .billId );
722
+ String endpoint = billPayConnectorConfig .statusEndpoint ;
723
+ endpoint = String .format (endpoint .replace ("{{correlationId}}" , "%s" ), scenarioScopeState .clientCorrelationId );
724
+ scenarioScopeState .response = RestAssured .given (requestSpec ).header ("Content-Type" , "application/json" )
725
+ .header ("X-Biller-Id" , billerId ).header ("X-CorrelationID" , scenarioScopeState .clientCorrelationId )
726
+ .baseUri (billPayConnectorConfig .billPayContactPoint ).body (jsonPayload ).expect ()
727
+ .spec (new ResponseSpecBuilder ().expectStatusCode (expectedStatus ).build ()).when ().get (endpoint ).andReturn ().asString ();
728
+
729
+ statusResponse = scenarioScopeState .response ;
730
+ logger .info ("Status Response: {}" , scenarioScopeState .response );
731
+ assertThat (scenarioScopeState .response .contains (status )).isTrue ();
732
+ });
733
+ }
681
734
}
0 commit comments