From 03fd2e5fe1194919632c8fc4fb18e51d46c1dddb Mon Sep 17 00:00:00 2001 From: Apurb Rajdhan <103931815+apurbraj@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:32:18 +0530 Subject: [PATCH 1/2] Fix voucher test --- .../cucumber/stepdef/ScenarioScopeState.java | 1 + .../stepdef/VoucherManagementStepDef.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ScenarioScopeState.java b/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ScenarioScopeState.java index bec7bc394..f3562099f 100644 --- a/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ScenarioScopeState.java +++ b/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ScenarioScopeState.java @@ -103,5 +103,6 @@ public class ScenarioScopeState { protected int[] initialBalForPayerForBatch; protected int[] gsmaP2PAmtDebitForBatch; protected List registeredBeneficiary = new ArrayList<>(); + protected String serialNumber; } diff --git a/src/test/java/org/mifos/integrationtest/cucumber/stepdef/VoucherManagementStepDef.java b/src/test/java/org/mifos/integrationtest/cucumber/stepdef/VoucherManagementStepDef.java index 7c13b625e..daca5b411 100644 --- a/src/test/java/org/mifos/integrationtest/cucumber/stepdef/VoucherManagementStepDef.java +++ b/src/test/java/org/mifos/integrationtest/cucumber/stepdef/VoucherManagementStepDef.java @@ -45,7 +45,6 @@ public class VoucherManagementStepDef extends BaseStepDef { private static String redeemVoucherBody; private static String redeemVoucherResponseBody; private static String callbackBody; - private static String serialNumber; private static String voucherNumber; private static String cancelVoucherBody; private static String suspendVoucherBody; @@ -115,7 +114,7 @@ public void iCanCreateAnVoucherRequestDTOForVoucherActivation() { scenarioScopeState.batchId = generateUniqueNumber(10); VoucherInstruction voucherInstruction = new VoucherInstruction(); - voucherInstruction.setSerialNumber(serialNumber); + voucherInstruction.setSerialNumber(scenarioScopeState.serialNumber); voucherInstruction.setStatus("02"); ArrayList voucherInstructions = new ArrayList<>(); @@ -148,7 +147,7 @@ public void iCanCreateAnVoucherRequestDTOForVoucherCancellation() { requestId = generateUniqueNumber(12); VoucherInstruction voucherInstruction = new VoucherInstruction(); - voucherInstruction.setSerialNumber(serialNumber); + voucherInstruction.setSerialNumber(scenarioScopeState.serialNumber); voucherInstruction.setStatus("03"); ArrayList voucherInstructions = new ArrayList<>(); @@ -229,14 +228,14 @@ public void iShouldBeAbleToExtractResponseBodyFromCallback() { JsonNode voucherInstructionsNode = rootNode.get("voucherInstructions"); if (voucherInstructionsNode.isArray()) { for (JsonNode voucherNode : voucherInstructionsNode) { - serialNumber = voucherNode.get("serialNumber").asText(); + scenarioScopeState.serialNumber = voucherNode.get("serialNumber").asText(); voucherNumber = voucherNode.get("voucherNumber").asText(); } } } catch (Exception e) { logger.debug(e.getMessage()); } - assertThat(serialNumber).isNotEmpty(); + assertThat(scenarioScopeState.serialNumber).isNotEmpty(); }); } @@ -245,7 +244,7 @@ public void iCanCreateAnRedeemVoucherRequestDTOForVoucherRedemption() { requestId = generateUniqueNumber(12); agentId = generateUniqueNumber(10); - RedeemVoucherRequestDTO requestDTO = new RedeemVoucherRequestDTO(requestId, agentId, serialNumber, voucherNumber); + RedeemVoucherRequestDTO requestDTO = new RedeemVoucherRequestDTO(requestId, agentId, scenarioScopeState.serialNumber, voucherNumber); ObjectMapper objectMapper = new ObjectMapper(); try { @@ -341,7 +340,7 @@ public void iCanCreateAnVoucherRequestDTOForVoucherSuspension() { scenarioScopeState.batchId = generateUniqueNumber(10); VoucherInstruction voucherInstruction = new VoucherInstruction(); - voucherInstruction.setSerialNumber(serialNumber); + voucherInstruction.setSerialNumber(scenarioScopeState.serialNumber); voucherInstruction.setStatus("06"); ArrayList voucherInstructions = new ArrayList<>(); @@ -382,7 +381,7 @@ public void iCanCreateAnVoucherRequestDTOForVoucherReactivation() { // variable sb.append(" \"voucherInstructions\": [\n"); sb.append(" {\n"); - sb.append(" \"serialNumber\": \"").append(serialNumber).append("\",\n"); + sb.append(" \"serialNumber\": \"").append(scenarioScopeState.serialNumber).append("\",\n"); sb.append(" \"status\": \"02\"\n"); sb.append(" }\n"); sb.append(" ]\n"); @@ -395,7 +394,7 @@ public void iCanCreateAnVoucherRequestDTOForVoucherReactivation() { public void iCallTheValidityCheckAPIWithExpectedStatusOfAndStub(int responseCode, String stub) { RequestSpecification requestSpec = Utils.getDefaultSpec(); scenarioScopeState.response = RestAssured.given(requestSpec).header("Content-Type", "application/json") - .queryParam("serialNumber", serialNumber).queryParam("isValid", "true") + .queryParam("serialNumber", scenarioScopeState.serialNumber).queryParam("isValid", "true") .header("X-CallbackURL", identityMapperConfig.callbackURL + stub) .header("X-Registering-Institution-ID", registeringInstitutionId) .baseUri(voucherManagementConfig.voucherManagementContactPoint).expect() @@ -468,7 +467,7 @@ public void iWillCallTheFetchVoucherAPIWithExpectedStatusOf(int responseCode) { .header("X-Registering-Institution-ID", registeringInstitutionId) .baseUri(voucherManagementConfig.voucherManagementContactPoint).expect() .spec(new ResponseSpecBuilder().expectStatusCode(responseCode).build()).when() - .get(voucherManagementConfig.fetchVoucherEndpoint + "/" + serialNumber).andReturn().asString(); + .get(voucherManagementConfig.fetchVoucherEndpoint + "/" + scenarioScopeState.serialNumber).andReturn().asString(); fetchVoucherResponseBody = scenarioScopeState.response; logger.info("Voucher Response: {}", scenarioScopeState.response); @@ -482,7 +481,7 @@ public void iWillAssertTheFieldsFromFetchVoucherResponse() { String serialNumberResponse = rootNode.get("serialNumber").asText(); String registeringInstitutionIdResponse = rootNode.get("registeringInstitutionId").asText(); - assertThat(serialNumberResponse).isEqualTo(serialNumber); + assertThat(serialNumberResponse).isEqualTo(scenarioScopeState.serialNumber); assertThat(registeringInstitutionIdResponse).isEqualTo(registeringInstitutionId); } catch (Exception e) { logger.debug(e.getMessage()); From fa3d11ba80bbfabd805e2b5ea5b15d13c51daa71 Mon Sep 17 00:00:00 2001 From: Apurb Rajdhan <103931815+apurbraj@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:34:37 +0530 Subject: [PATCH 2/2] reorder test --- .../resources/voucherManagementTest.feature | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/test/java/resources/voucherManagementTest.feature b/src/test/java/resources/voucherManagementTest.feature index d7bff051c..d2f77cdd6 100644 --- a/src/test/java/resources/voucherManagementTest.feature +++ b/src/test/java/resources/voucherManagementTest.feature @@ -1,7 +1,24 @@ @gov Feature: Voucher Management Api Test - Scenario: Create Voucher Api Test + @createAndActivateVoucher @redeemVoucherSuccess + Scenario: Reactivate Voucher Api Test + Given I can create an VoucherRequestDTO for voucher suspension + And I can register the stub with "/suspendVoucher" endpoint for "PUT" request with status of 200 + When I call the suspend voucher API with expected status of 202 and stub "/suspendVoucher" + And I can create an VoucherRequestDTO for voucher reactivation + And I can register the stub with "/reactivateVoucher" endpoint for "PUT" request with status of 200 + When I call the activate voucher API with expected status of 202 and stub "/reactivateVoucher" +# Then I will sleep for 2000 millisecond + + @createAndActivateVoucher + Scenario: Validity Check Voucher Api Test + When I can register the stub with "/validity" endpoint for "PUT" request with status of 200 + And I call the validity check API with expected status of 202 and stub "/validity" +# And I will sleep for 3000 millisecond + Then I can extract result from validation callback and assert if validation is successful on "/validity" + + Scenario: Create Voucher Api Test When I can inject MockServer Then I can start mock server And I can register the stub with "/createVoucher" endpoint for "PUT" request with status of 200 @@ -38,22 +55,6 @@ Feature: Voucher Management Api Test When I call the suspend voucher API with expected status of 202 and stub "/suspendVoucher" # Then I will sleep for 2000 millisecond - @createAndActivateVoucher @redeemVoucherSuccess - Scenario: Reactivate Voucher Api Test - Given I can create an VoucherRequestDTO for voucher suspension - And I can register the stub with "/suspendVoucher" endpoint for "PUT" request with status of 200 - When I call the suspend voucher API with expected status of 202 and stub "/suspendVoucher" - And I can create an VoucherRequestDTO for voucher reactivation - And I can register the stub with "/reactivateVoucher" endpoint for "PUT" request with status of 200 - When I call the activate voucher API with expected status of 202 and stub "/reactivateVoucher" -# Then I will sleep for 2000 millisecond - - @createAndActivateVoucher - Scenario: Validity Check Voucher Api Test - When I can register the stub with "/validity" endpoint for "PUT" request with status of 200 - And I call the validity check API with expected status of 202 and stub "/validity" -# And I will sleep for 3000 millisecond - Then I can extract result from validation callback and assert if validation is successful on "/validity" @createAndActivateVoucher Scenario: Fetch Voucher Api Test