Skip to content

Commit 09b2e95

Browse files
authored
[GOV-83New] Tcs for status API (#263)
1 parent 132478e commit 09b2e95

File tree

6 files changed

+159
-22
lines changed

6 files changed

+159
-22
lines changed

src/main/java/org/mifos/integrationtest/config/BillPayConnectorConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class BillPayConnectorConfig {
2121
@Value("${billPay.endpoints.billerRtpRequest}")
2222
public String billerRtpEndpoint;
2323

24+
@Value("${billPay.endpoints.billStatus}")
25+
public String statusEndpoint;
26+
2427
@PostConstruct
2528
private void setup() {
2629
inquiryEndpoint = billPayContactPoint + inquiryEndpoint;

src/main/resources/application.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ billPay:
242242
inquiry: /bills/{billId}
243243
payments: /paymentNotifications
244244
billerRtpRequest: /billTransferRequests
245+
billStatus: /transferRequests/{{correlationId}}
245246

246247
awaitly:
247248
maxWaitTime: 25
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.mifos.integrationtest.common.dto;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class BillStatusReqDTO {
9+
10+
private String rtpId;
11+
private String requestId;
12+
13+
public BillStatusReqDTO(String rtpId, String requestId) {}
14+
}

src/test/java/org/mifos/integrationtest/cucumber/stepdef/BillPayStepDef.java

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.cucumber.core.internal.com.fasterxml.jackson.core.JsonProcessingException;
1616
import io.cucumber.core.internal.com.fasterxml.jackson.databind.JsonNode;
1717
import io.cucumber.java.en.And;
18+
import io.cucumber.java.en.Given;
1819
import io.cucumber.java.en.Then;
1920
import io.cucumber.java.en.When;
2021
import io.restassured.RestAssured;
@@ -31,6 +32,7 @@
3132
import org.mifos.integrationtest.common.dto.Alias;
3233
import org.mifos.integrationtest.common.dto.Bill;
3334
import org.mifos.integrationtest.common.dto.BillRTPReqDTO;
35+
import org.mifos.integrationtest.common.dto.BillStatusReqDTO;
3436
import org.mifos.integrationtest.common.dto.PayerFSPDetail;
3537
import org.mifos.integrationtest.common.dto.billpayp2g.BillPaymentsReqDTO;
3638
import org.mifos.integrationtest.config.BillPayConnectorConfig;
@@ -45,15 +47,19 @@ public class BillPayStepDef extends BaseStepDef {
4547
private BillPayConnectorConfig billPayConnectorConfig;
4648
private static String billerId;
4749
private static BillRTPReqDTO billRTPReqDTO;
50+
51+
private static BillStatusReqDTO billStatusReqDTO;
4852
private static String billId = "12345";
4953
private static String rtpId = "123456";
5054
private static String rtpResponse;
55+
private static String statusResponse;
5156

5257
@Then("I can create DTO for Biller RTP Request")
5358
public void iCanCreateDTOForBillerRTPRequest() {
5459
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);
5763

5864
}
5965

@@ -70,7 +76,8 @@ public void iCallTheGetBillsApiWithBillidWithExpectedStatusOf(int expectedStatus
7076

7177
requestSpec.header("X-CorrelationID", scenarioScopeState.clientCorrelationId.toString());
7278
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);
7481
requestSpec.queryParam("fields", "inquiry");
7582
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(billPayConnectorConfig.billPayContactPoint).expect()
7683
.spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when()
@@ -151,7 +158,8 @@ public void iCallThePaymentNotificationApiExpectedStatusOf(int expectedStatus, S
151158
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
152159
requestSpec.header("X-Platform-TenantId", scenarioScopeState.tenant);
153160
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);
155163
requestSpec.queryParam("fields", "inquiry");
156164
requestSpec.header("X-CallbackURL", billPayConnectorConfig.callbackURL + callbackurl);
157165
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(billPayConnectorConfig.billPayContactPoint)
@@ -161,14 +169,22 @@ public void iCallThePaymentNotificationApiExpectedStatusOf(int expectedStatus, S
161169

162170
logger.info("Payment notiifcation response: {}", scenarioScopeState.response);
163171
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+
}
164179
}
165180

166181
@When("I call the mock get bills api from PBB to Biller with billid with expected status of {int}")
167182
public void iCallTheMockGetBillsApiPBBToBillerAggWithBillidWithExpectedStatusOf(int expectedStatus) {
168183
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
169184
requestSpec.header("X-Platform-TenantId", scenarioScopeState.tenant);
170185
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);
172188
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(billPayConnectorConfig.billPayContactPoint).expect()
173189
.spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when()
174190
.get(billPayConnectorConfig.inquiryEndpoint.replace("{billId}", billId)).andReturn().asString();
@@ -182,7 +198,8 @@ public void iCallTheMockBillsPaymentApiFromPBBToBillerWithBillidWithExpectedStat
182198
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
183199
requestSpec.header("X-Platform-TenantId", scenarioScopeState.tenant);
184200
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);
186203
requestSpec.header("X-CallbackURL", "https://webhook.site/b44174ab-04b4-4b0d-8426-a3c54bc2f794");
187204
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(billPayConnectorConfig.billPayContactPoint)
188205
.body(scenarioScopeState.inboundTransferReqP2G).expect()
@@ -204,7 +221,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillPay() {
204221
List<ServeEvent> allServeEvents = getAllServeEvents();
205222
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
206223
ServeEvent request = allServeEvents.get(i);
207-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
224+
if (!(request.getRequest().getBodyAsString()).isEmpty() && request.getRequest().getUrl().equals("/billInquiry")) {
208225
JsonNode rootNode = null;
209226
flag = true;
210227
try {
@@ -244,7 +261,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillNotification()
244261
List<ServeEvent> allServeEvents = getAllServeEvents();
245262
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
246263
ServeEvent request = allServeEvents.get(i);
247-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
264+
if (!(request.getRequest().getBodyAsString()).isEmpty() && request.getRequest().getUrl().equals("/billNotification")) {
248265
JsonNode rootNode = null;
249266
flag = true;
250267
try {
@@ -283,6 +300,7 @@ public void iCanCallTheBillerRTPRequestAPIWithExpectedStatusOfAndEndpoint(int ex
283300
ObjectMapper objectMapper = new ObjectMapper();
284301
String jsonPayload = objectMapper.writeValueAsString(billRTPReqDTO);
285302
RequestSpecification requestSpec = Utils.getDefaultSpec();
303+
requestSpec.header("X-CorrelationID", scenarioScopeState.clientCorrelationId);
286304
scenarioScopeState.response = RestAssured.given(requestSpec).header("Content-Type", "application/json")
287305
.header("X-Callback-URL", billPayConnectorConfig.callbackURL + stub).header("X-Biller-Id", billerId)
288306
.header("X-Client-Correlation-ID", scenarioScopeState.clientCorrelationId)
@@ -319,6 +337,7 @@ public void iCanExtractTheCallbackBodyAndAssertTheRtpStatus() {
319337
String requestId = null;
320338
if (rootNode.has("requestId")) {
321339
requestId = rootNode.get("requestId").asText();
340+
scenarioScopeState.requestId = requestId;
322341
}
323342
assertThat(requestId).isNotEmpty();
324343
String rtpStatus = null;
@@ -329,6 +348,7 @@ public void iCanExtractTheCallbackBodyAndAssertTheRtpStatus() {
329348
String rtpId = null;
330349
if (rootNode.has("rtpId")) {
331350
rtpId = rootNode.get("rtpId").asText();
351+
scenarioScopeState.rtpId = rtpId;
332352
}
333353
assertThat(rtpId).isNotEmpty();
334354
String billId = null;
@@ -351,7 +371,8 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillerUnidentified(
351371
List<ServeEvent> allServeEvents = getAllServeEvents();
352372
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
353373
ServeEvent request = allServeEvents.get(i);
354-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
374+
if (!(request.getRequest().getBodyAsString()).isEmpty()
375+
&& request.getRequest().getUrl().equals("/billInquiryPrefixInvalid")) {
355376
JsonNode rootNode = null;
356377
flag = true;
357378
try {
@@ -387,7 +408,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillInvalid() {
387408
List<ServeEvent> allServeEvents = getAllServeEvents();
388409
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
389410
ServeEvent request = allServeEvents.get(i);
390-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
411+
if (!(request.getRequest().getBodyAsString()).isEmpty() && request.getRequest().getUrl().equals("/invalidbillInquiry")) {
391412
JsonNode rootNode = null;
392413
flag = true;
393414
try {
@@ -430,7 +451,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForEmptyBillId() {
430451
List<ServeEvent> allServeEvents = getAllServeEvents();
431452
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
432453
ServeEvent request = allServeEvents.get(i);
433-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
454+
if (!(request.getRequest().getBodyAsString()).isEmpty() && request.getRequest().getUrl().equals("/billInquiryEmpty")) {
434455
JsonNode rootNode = null;
435456
flag = true;
436457
try {
@@ -488,7 +509,7 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillAlreadyPaid() {
488509
List<ServeEvent> allServeEvents = getAllServeEvents();
489510
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
490511
ServeEvent request = allServeEvents.get(i);
491-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
512+
if (!(request.getRequest().getBodyAsString()).isEmpty() && request.getRequest().getUrl().equals("/billNotificationPaid")) {
492513
JsonNode rootNode = null;
493514
flag = true;
494515
try {
@@ -555,7 +576,8 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillPaidAfterTimeou
555576
List<ServeEvent> allServeEvents = getAllServeEvents();
556577
for (int i = allServeEvents.size() - 1; i >= 0; i--) {
557578
ServeEvent request = allServeEvents.get(i);
558-
if (!(request.getRequest().getBodyAsString()).isEmpty()) {
579+
if (!(request.getRequest().getBodyAsString()).isEmpty()
580+
&& request.getRequest().getUrl().equals("/billNotificationsTimeout")) {
559581
JsonNode rootNode = null;
560582
flag = true;
561583
try {
@@ -602,7 +624,8 @@ public void iCanCreateDTOForBillerRTPRequestWithIncorrectRtpType() {
602624
@Then("I can create DTO for Biller RTP Request with incorrect rtp information")
603625
public void iCanCreateDTOForBillerRTPRequestWithIncorrectRtpInformation() {
604626
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");
606629
billRTPReqDTO = new BillRTPReqDTO("123445", billId, "01", payerFSPDetail, bill);
607630
}
608631

@@ -615,15 +638,17 @@ public void iCanCreateDTOForBillerRTPRequestWithIncorrectAliasDetails() {
615638
@Then("I can create DTO for Biller RTP Request to mock payer fi unreachable")
616639
public void iCanCreateDTOForBillerRTPRequestToMockPayerFiUnreachable() {
617640
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");
619643
billRTPReqDTO = new BillRTPReqDTO("123445", billId, "00", payerFSPDetail, bill);
620644
}
621645

622646
@Then("I can create DTO for Biller RTP Request to mock payer fsp failed to debit amount")
623647
public void iCanCreateDTOForBillerRTPRequestToMockPayerFspFailedToDebitAmount() {
624648
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);
627652
}
628653

629654
@And("I can extract the error from response body and assert the error information as {string}")
@@ -678,4 +703,32 @@ public void iShouldBeAbleToExtractResponseBodyFromCallbackForBillNotificationWit
678703
assertThat(scenarioScopeState.transactionId.equals("Invalid Request: Bill Id Empty")).isTrue();
679704
});
680705
}
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+
}
681734
}

src/test/java/org/mifos/integrationtest/cucumber/stepdef/ScenarioScopeState.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ public class ScenarioScopeState {
116116
protected String registeringInstitutionId;
117117
protected String agentId;
118118
protected String fetchVoucherResponseBody;
119+
120+
protected String rtpId;
119121
}

0 commit comments

Comments
 (0)