From fa4a739136f87a2efa88a875bf09fef6e049d050 Mon Sep 17 00:00:00 2001 From: Apurb Rajdhan <103931815+apurbraj@users.noreply.github.com> Date: Wed, 14 Aug 2024 12:20:04 +0530 Subject: [PATCH 1/3] [setup]Delete config file of service (#5) * Delete config file of service Fix config file path address build issue * Fix * remove ci chart --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bff323f6c..5a24ef857 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2323,5 +2323,5 @@ workflows: - slack - Ngrok requires: - - build-g2p-sandbox-ci-chart + - build-and-host-g2p-sandbox From f4d34b803494e9165b4d10f6652eeaf29356e76c Mon Sep 17 00:00:00 2001 From: dhruvsonagara Date: Mon, 2 Sep 2024 14:53:08 +0530 Subject: [PATCH 2/3] [PHEE-685] Ops-app get transfers test page and size path param TC --- .../cucumber/stepdef/ChannelClientIdDef.java | 267 ++++++++++++++++++ .../test/java/resources/getTransfer.feature | 61 +++- 2 files changed, 325 insertions(+), 3 deletions(-) diff --git a/ph-ee-integration-test/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ChannelClientIdDef.java b/ph-ee-integration-test/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ChannelClientIdDef.java index c17c8f22f..130bafeb7 100644 --- a/ph-ee-integration-test/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ChannelClientIdDef.java +++ b/ph-ee-integration-test/src/test/java/org/mifos/integrationtest/cucumber/stepdef/ChannelClientIdDef.java @@ -2,6 +2,9 @@ import static com.google.common.truth.Truth.assertThat; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import io.cucumber.java.en.And; import io.cucumber.java.en.When; import io.restassured.RestAssured; @@ -12,6 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + public class ChannelClientIdDef extends BaseStepDef { @Value("${operations-app.auth.enabled}") @@ -61,4 +67,265 @@ public void iCallTheTxnStateWithClientCorrelationIdAsExpectedStatusOf(String XCl logger.info("Txn Req response: {}", scenarioScopeState.response); } + + @When("I call the transfer API with size {int} and page {int} expecting expected status of {int}") + public void iCallTheTransferAPIWithSizeAndPageExpectingExpectedStatusOf(float size, float page, int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + if (authEnabled) { + requestSpec.header("Authorization", "Bearer " + scenarioScopeState.accessToken); + } + + String endpoint = String.format("%s?size=%f&page=%f", operationsAppConfig.transfersEndpoint, size, page); + logger.info("Calling endpoint with size and page: {}", endpoint); + + scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(operationsAppConfig.operationAppContactPoint).expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when().get(endpoint).andReturn().asString(); + + logger.info("Inbound transfer with size and page Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with end date is before the start date expecting expected status of {int}") + public void iCallTheTransferAPIWithEndDateBeforeStartDateExpectingExpectedStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + LocalDate startDate = LocalDate.now(); + LocalDate endDate = startDate.minusDays(5); + DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE; + + // Set the dates with endDate before startDate + String startfrom = startDate.format(formatter); + String startto = endDate.format(formatter); + + String endpoint = String.format("%s?startfrom=%s&startto=%s", operationsAppConfig.transfersEndpoint, startfrom, startto); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(operationsAppConfig.operationAppContactPoint).expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when().get(endpoint).andReturn().asString(); + + logger.info("Inbound transfer with date range Response: {}", scenarioScopeState.response); + } + + @And("I should have page and size in response") + public void iShouldHavePageAndSizeInResponse() throws JsonProcessingException { + String response = scenarioScopeState.response; + + // Parse the JSON response + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(response); + + // Check that 'size' and 'number' are present + assertThat(jsonNode.has("size")).isTrue(); + assertThat(jsonNode.has("number")).isTrue(); + + // Check the exact values + int expectedSize = 4; + int expectedNumber = 2; + assertThat(jsonNode.get("size").asInt()).isEqualTo(expectedSize); + assertThat(jsonNode.get("number").asInt()).isEqualTo(expectedNumber); + } + + @When("I call the transfer API with currency {string} and amount {int} expecting expected status of {int}") + public void iCallTheTransferAPIWithCurrencyAndAmountExpectingExpectedStatusOf(String currency, float amount, int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + if (authEnabled) { + requestSpec.header("Authorization", "Bearer " + scenarioScopeState.accessToken); + } + + String endpoint = String.format("%s?currency=%s&amount=%f", operationsAppConfig.transfersEndpoint, currency, amount); + logger.info("Calling get transfer endpoint: {}", endpoint); + + scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(operationsAppConfig.operationAppContactPoint).expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when().get(endpoint).andReturn().asString(); + + logger.info("Inbound transfer with currency and amount Response: {}", scenarioScopeState.response); + } + + @And("I should have currency and amount in response") + public void iShouldHaveCurrencyAndAmountInResponse() throws JsonProcessingException { + String response = scenarioScopeState.response; + + // Parse the JSON response + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(response); + + assertThat(jsonNode.has("content")).isTrue(); + assertThat(jsonNode.get("content").isArray()).isTrue(); + assertThat(jsonNode.get("content").size()).isGreaterThan(0); + + // Extract the first object in the 'content' array + JsonNode firstContentItem = jsonNode.get("content").get(0); + + // Check that 'currency' and 'amount' are present in the first content item + assertThat(firstContentItem.has("currency")).isTrue(); + assertThat(firstContentItem.has("amount")).isTrue(); + + // Retrieve and validate the currency + JsonNode currencyNode = firstContentItem.get("currency"); + assertThat(currencyNode).isNotNull(); + String currency = currencyNode.asText(); + String expectedCurrency = "USD"; + assertThat(currency).isEqualTo(expectedCurrency); + + // Retrieve and validate the amount + JsonNode amountNode = firstContentItem.get("amount"); + assertThat(amountNode).isNotNull(); + String amountAsString = amountNode.asText(); + int amount = Integer.parseInt(amountAsString); + int expectedAmount = 1; + assertThat(amount).isEqualTo(expectedAmount); + } + + @When("I call the transfer API with invalid sorting order") + public void iCallTheTransferAPIWithInvalidSortingOrder() { + + } + + @When("I call the transfer API with invalid sorting order with expected status of {int}") + public void iCallTheTransferAPIWithInvalidSortingOrderWithExpectedStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Add sorted order param to endpoint + String endpoint = String.format("%s?sortedOrder=reverse", operationsAppConfig.transfersEndpoint); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling transfer endpoint with invalid sorting order: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Inbound transfer with invalid sorting order Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with invalid date format expecting expected status of {int}") + public void iCallTheTransferAPIWithInvalidDateFormatExpectingExpectedStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Set an invalid date format for start from + String invalidStartDate = "invalid-date-format"; + + // Construct the endpoint with the invalid start from parameter + String endpoint = String.format("%s?startfrom=%s", operationsAppConfig.transfersEndpoint, invalidStartDate); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint with invalid date format: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Inbound transfer with invalid start date Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with an empty start date expecting expected status of {int}") + public void iCallTheTransferAPIWithEmptyStartDateExpectingExpectedStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Set an empty value for start from + String emptyStartDate = ""; + + // the endpoint with the empty start from parameter + String endpoint = String.format("%s?startfrom=%s", operationsAppConfig.transfersEndpoint, emptyStartDate); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint with empty date: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Inbound transfer with empty start date Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with status set to PROCESSING expecting expected status of {int}") + public void iCallTheTransferAPIWithStatusSetToPROCESSINGExpectingExpectedStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Set the status value to PROCESSING + String status = "PROCESSING"; + + // Construct the endpoint with the status parameter + String endpoint = String.format("%s?status=%s", operationsAppConfig.transfersEndpoint, status); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint with invalid status param: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Get transfer with status 'PROCESSING' Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with clientCorrelationId of exceeding max length with status of {int}") + public void iCallTheTransferAPIWithClientCorrelationIdOfExceedingMaxLengthWithStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Set the clientCorrelationId value to an alphanumeric string longer than 12 characters + String clientCorrelationId = "abc1234567890"; // Example alphanumeric string with 13 characters + + // Construct the endpoint with the clientCorrelationId parameter + String endpoint = String.format("%s?clientCorrelationId=%s", operationsAppConfig.transfersEndpoint, clientCorrelationId); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint with exceeding max length: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Get transfer with clientCorrelationId longer than 12 characters Response: {}", scenarioScopeState.response); + } + + @When("I call the transfer API with invalid transactionId with status of {int}") + public void iCallTheTransferAPIWithInvalidTransactionIdWithStatusOf(int expectedStatus) { + RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant); + + // Set the transactionId value to a random invalid value + String transactionId = "abcdefgh"; + + // Construct the endpoint with the clientCorrelationId parameter + String endpoint = String.format("%s?transactionId=%s", operationsAppConfig.transfersEndpoint, transactionId); + String fullUrl = operationsAppConfig.operationAppContactPoint + endpoint; + + logger.info("Calling endpoint with invalid transactionId: {}", fullUrl); + + scenarioScopeState.response = RestAssured.given(requestSpec) + .baseUri(operationsAppConfig.operationAppContactPoint) + .expect() + .spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()) + .when() + .get(endpoint) + .andReturn() + .asString(); + + logger.info("Get transfer with transactionId Response: {}", scenarioScopeState.response); + + } } diff --git a/ph-ee-integration-test/src/test/java/resources/getTransfer.feature b/ph-ee-integration-test/src/test/java/resources/getTransfer.feature index 6932586fe..b8259fca6 100644 --- a/ph-ee-integration-test/src/test/java/resources/getTransfer.feature +++ b/ph-ee-integration-test/src/test/java/resources/getTransfer.feature @@ -1,8 +1,7 @@ -@common @gov -@cucumberCli Feature: Get Transfers API test - + @common @gov + @cucumberCli Scenario: GT-001 Get Transfers API With Auth Given I have tenant as "paymentBB2" When I call the operations-app auth endpoint with username: "mifos" and password: "password" @@ -10,3 +9,59 @@ Feature: Get Transfers API test When I call the transfer API with expected status of 200 Then I should get non empty response And I should have clientCorrelationId in response + + Scenario: GT-012 Get Transfers API With Page retrieval and size + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with size -4 and page -2 expecting expected status of 400 + Then I should get non empty response + And I should have page and size in response + + Scenario: GT-006 Get Transfers API with end date is before the start date + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with end date is before the start date expecting expected status of 400 + Then I should get non empty response + + Scenario: GT-002 Get Transfers API with invalid date format + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with invalid date format expecting expected status of 400 + Then I should get non empty response + + Scenario: GT-004 Get Transfers API with empty date query parameter value + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with an empty start date expecting expected status of 400 + Then I should get non empty response + + Scenario: GT-007,008 Get Transfers API With invalid amount and currency + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with currency "RUPEES" and amount -1 expecting expected status of 400 + Then I should get non empty response + And I should have currency and amount in response + + Scenario: GT-010 Get Transfer API with invalid sorting order + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with invalid sorting order with expected status of 400 + Then I should get non empty response + + Scenario: GT-005 Get Transfers API with invalid status format + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with status set to PROCESSING expecting expected status of 400 + Then I should get non empty response + + Scenario: GT-009,017 Get Transfers API with invalid clientCorrelationId length + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with clientCorrelationId of exceeding max length with status of 400 + Then I should get non empty response + + Scenario: GT-001 Get Transfers API with invalid txnID + Given I have tenant as "paymentBB2" + Then I should get a valid token + When I call the transfer API with invalid transactionId with status of 400 + Then I should get non empty response From 840d200ed3109de64fa939da9ba069cd28fccba6 Mon Sep 17 00:00:00 2001 From: dhruvsonagara Date: Mon, 2 Sep 2024 14:54:52 +0530 Subject: [PATCH 3/3] reverted unnescessary changes --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5a24ef857..bff323f6c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2323,5 +2323,5 @@ workflows: - slack - Ngrok requires: - - build-and-host-g2p-sandbox + - build-g2p-sandbox-ci-chart