Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHEE-607] Fix voucher test #234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ public class ScenarioScopeState {
protected int[] initialBalForPayerForBatch;
protected int[] gsmaP2PAmtDebitForBatch;
protected List<String> registeredBeneficiary = new ArrayList<>();
protected String serialNumber;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VoucherInstruction> voucherInstructions = new ArrayList<>();
Expand Down Expand Up @@ -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<VoucherInstruction> voucherInstructions = new ArrayList<>();
Expand Down Expand Up @@ -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();
});
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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<VoucherInstruction> voucherInstructions = new ArrayList<>();
Expand Down Expand Up @@ -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");
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down
35 changes: 18 additions & 17 deletions src/test/java/resources/voucherManagementTest.feature
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down