Skip to content

Commit

Permalink
Create test case for airtel-connector.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchit-0 committed Aug 19, 2024
1 parent 773dfdb commit 44483c2
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 22 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/mifos/integrationtest/config/AirtelConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.mifos.integrationtest.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "airtel-connector.mock-airtel")
@Component
public class AirtelConfig {

@Value("${airtel-connector.contactpoint}")
public String airtelConnectorContactPoint;

@Value("${callback_url}")
public String callbackURL;
}
14 changes: 8 additions & 6 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
operations-app:
contactpoint: "https://ops-bk.sandbox.fynarfin.io"
contactpoint: "http://127.0.0.1:5000"
dpgcontactpoint: "https://ops-bk-dpg.sandbox.fynarfin.io"
username: "mifos"
password: "password"
Expand Down Expand Up @@ -34,7 +34,7 @@ bulk-processor:


channel-connector:
contactpoint: "https://channel.sandbox.fynarfin.io"
contactpoint: "http://127.0.0.1:8443"
endpoints:
transfer: "/channel/transfer"
gsma-p2p: "/channel/gsma/transfer"
Expand All @@ -59,7 +59,7 @@ channel:

amsmifos:
mock:
base-url: https://ams-mifos-mock.sandbox.fynarfin.io
base-url: https://127.0.0.1:5013
endpoints:
repayment-endpoint: /fineract/transactions/loanrepayment
deposit-endpoint: /fineract/savingsaccount/transfers
Expand All @@ -71,7 +71,7 @@ ams:
name-endpoint: /ams/accounts/{IdentifierType}/{IdentifierId}/accountname

loan:
base-url: https://fynams.sandbox.fynarfin.io
base-url: https://127.0.0.1:8446
endpoints:
product-endpoint: /fineract-provider/api/v1/loanproducts
account-endpoint: /fineract-provider/api/v1/loans
Expand All @@ -81,7 +81,7 @@ loan:
accountid-endpoint: /fineract-provider/api/v1/loans/{{loanAccId}}

savings:
base-url: https://fynams.sandbox.fynarfin.io
base-url: https://127.0.0.1:8446
endpoints:
client-endpoint: /fineract-provider/api/v1/clients
product-endpoint: /fineract-provider/api/v1/savingsproducts
Expand Down Expand Up @@ -154,6 +154,8 @@ mock-payment-schema:
mock-batch-authorization: "/batches/"
actuator: "/actuator/health"

airtel-connector:
contactpoint: "http://localhost:8080"

netflix-conductor:
server:
Expand Down Expand Up @@ -254,7 +256,7 @@ billPay:
billStatus: /transferRequests/{{correlationId}}

awaitly:
maxWaitTime: 25
maxWaitTime: 45
pollDelaySeconds: 2
pollIntervalSeconds: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setup() {
@Disabled
public void testSendCollectionRequest() throws JSONException {
requestSpec.header(Utils.X_CORRELATIONID, clientCorrelationId);
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "254708374149", "24450523");
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "USD", "254708374149", "24450523");
logger.info(String.valueOf(collectionRequestBody));
String json = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
.body(collectionRequestBody.toString()).expect().spec(statusOkResponseSpec).when().post("/channel/collection").andReturn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setup() {
@Test
@Disabled
public void testSendCollectionRequest() throws JSONException {
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "254708374149", "24450523");
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "USD", "254708374149", "24450523");
log.debug("{}", collectionRequestBody);
String json = RestAssured.given(requestSpec).baseUri("http://localhost:5002").body(collectionRequestBody.toString()).expect()
.spec(statusOkResponseSpec).when().post("/channel/collection").andReturn().asString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ public final class CollectionHelper {

private CollectionHelper() {}

public static JSONObject getCollectionRequestBody(String amount, String msisdn, String accountId) throws JSONException {
public static JSONObject getCollectionRequestBody(String amount, String currency, String msisdn, String accountId)
throws JSONException {
List<Pair<String, String>> payers = new ArrayList<>();
payers.add(new Pair<>("MSISDN", msisdn));
payers.add(new Pair<>("ACCOUNTID", accountId));

JSONObject body = new JSONObject();
body.put("payer", getPayerArray(payers));
body.put("amount", getAmountObject(amount));
body.put("amount", getAmountObject(amount, currency));
body.put("transactionType", getTransactionTypeObject());
body.put("customData", new JSONArray());
body.put("note", "Testing");
return body;
}

Expand All @@ -34,7 +37,7 @@ public static JSONObject getCollectionRequestBody(String key1, String key2) thro

JSONObject body = new JSONObject();
body.put("payer", getPayerArray(payers));
body.put("amount", getAmountObject("1"));
body.put("amount", getAmountObject("1", "USD"));
body.put("transactionType", getTransactionTypeObject());
return body;
}
Expand All @@ -58,16 +61,16 @@ private static JSONObject getPayerObject(String key, String value) throws JSONEx
return payerObject;
}

private static JSONObject getAmountObject(String amount) throws JSONException {
private static JSONObject getAmountObject(String amount, String currency) throws JSONException {
JSONObject amountObject = new JSONObject();
amountObject.put("currency", "USD");
amountObject.put("currency", currency);
amountObject.put("amount", amount);
return amountObject;
}

private static JSONObject getTransactionTypeObject() throws JSONException {
JSONObject txnType = new JSONObject();
txnType.put("scenario", "MPESA");
txnType.put("scenario", "AIRTEL");
txnType.put("subScenario", "BUYGOODS");
txnType.put("initiator", "PAYEE");
txnType.put("initiatorType", "BUSINESS");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/mifos/integrationtest/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ private Utils() {}
public static final String QUERY_PARAM_TYPE = "type";
public static final String HEADER_REGISTERING_INSTITUTE_ID = "X-Registering-Institution-ID";
public static final String HEADER_PROGRAM_ID = "X-Program-ID";
public static final String X_PAYEMENTSCHEMA = "X-Payment-Scheme";
public static final String X_COUNTRY = "X-Country";

public static void initializeRESTAssured() {
RestAssured.baseURI = "https://localhost";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.mifos.integrationtest.cucumber.stepdef;

import static com.google.common.truth.Truth.assertThat;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import org.json.JSONException;
import org.json.JSONObject;
import org.mifos.integrationtest.common.CollectionHelper;
import org.mifos.integrationtest.config.AirtelConfig;
import org.springframework.beans.factory.annotation.Autowired;

public class AirtelStepDef extends BaseStepDef {

@Autowired
AirtelConfig airtelConfig;

@Given("I have MSISDN as {string}")
public void iHaveMSISDNAs(String msisdn) {
scenarioScopeState.msisdn = msisdn;
assertThat(scenarioScopeState.msisdn).isNotEmpty();
}

@Given("I have clientCorrelationId as {string}")
public void iHaveClientCorrelationIdAs(String clientCorrelationId) {
scenarioScopeState.clientCorrelationId = clientCorrelationId;
assertThat(scenarioScopeState.clientCorrelationId).isNotEmpty();
}

@Given("I have accountId as {string}")
public void iHaveAccountId(String accountId) {
scenarioScopeState.accountId = accountId;
assertThat(scenarioScopeState.accountId).isNotEmpty();
}

@And("I have transaction id as {string}")
public void iHaveTransactionIdAs(String transactionId) {
scenarioScopeState.transactionId = transactionId;
assertThat(scenarioScopeState.transactionId).isNotEmpty();
}

@And("I have amount as {string}")
public void iHaveAmountAs(String amount) {
scenarioScopeState.amount = amount;
assertThat(scenarioScopeState.amount).isNotEmpty();
}

@And("I have currency as {string}")
public void iHaveCurrencyAs(String currency) {
scenarioScopeState.currency = currency;
assertThat(scenarioScopeState.currency).isNotEmpty();
}

@And("I have the request body with payer ams identifiers using keys MSISDN and accountId, currency {string}, and amount {string}")
public void iHaveRequestBody(String currency, String amount) throws JSONException {
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody(amount, currency, scenarioScopeState.msisdn,
scenarioScopeState.accountId);
scenarioScopeState.requestBody = collectionRequestBody;
logger.info(String.valueOf(scenarioScopeState.requestBody));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
import io.restassured.RestAssured;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.specification.RequestSpecification;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;
import org.mifos.integrationtest.common.CollectionHelper;
import org.mifos.integrationtest.common.Utils;
import org.mifos.integrationtest.common.dto.CollectionResponse;
import org.mifos.integrationtest.common.dto.operationsapp.GetTransactionRequestResponse;
import org.mifos.integrationtest.config.AirtelConfig;
import org.springframework.beans.factory.annotation.Autowired;

public class ChannelCollectionStepDef extends BaseStepDef {

@Autowired
ScenarioScopeState scenarioScopeState;

@Autowired
AirtelConfig mockAirtelConfig;

@And("I have the request body with payer ams identifier keys as {string} and {string}")
public void iHaveRequestBody(String key1, String key2) throws JSONException {
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody(key1, key2);
Expand All @@ -33,18 +36,31 @@ public void iHaveRequestBody(String key1, String key2) throws JSONException {
@When("I call the channel collection API with client correlation id and expected status of {int}")
public void iCallChannelCollectionAPI(int expectedStatus) {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
requestSpec.header(Utils.X_CORRELATIONID, UUID.randomUUID());
requestSpec.header(Utils.X_CORRELATIONID, "123456");
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
// BaseStepDef.response = RestAssured.given(requestSpec).baseUri("https://localhost:8443")
.body(scenarioScopeState.requestBody.toString()).expect()
.spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when()
.post(channelConnectorConfig.collectionEndpoint).andReturn().asString();
}

@When("I call the channel collection API with client correlation id, country {string}, callback {string}, payment schema {string} and expected status of {int}")
public void iCallChannelCollectionsAPII(String country, String callback, String paymentSchema, int expectedStatus) {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant, scenarioScopeState.clientCorrelationId);
requestSpec.header(Utils.X_PAYEMENTSCHEMA, paymentSchema);
requestSpec.header(Utils.X_COUNTRY, country);
requestSpec.header(Utils.X_CallbackURL, "http://127.0.0.1:53013" + callback);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
.body(scenarioScopeState.requestBody.toString()).expect()
.spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when()
.post(channelConnectorConfig.collectionEndpoint).andReturn().asString();
}

@Then("I should get transaction id in response")
public void iGetTransactionIdInResponse() {
CollectionResponse response = (new Gson()).fromJson(scenarioScopeState.response, CollectionResponse.class);
scenarioScopeState.transactionId = response.getTransactionId();
logger.info("THE TXN ID IS BEING PASSED {}", scenarioScopeState.transactionId);
assertThat(response.getTransactionId()).isNotNull();
}

Expand All @@ -61,7 +77,7 @@ public void iCallTheTxnAPIWithTransactionId() throws InterruptedException {
requestSpec.header("Authorization", "Bearer " + scenarioScopeState.accessToken);
}
requestSpec.queryParam("transactionId", scenarioScopeState.transactionId);

logger.info("the transactionID is {}", scenarioScopeState.transactionId);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(operationsAppConfig.operationAppContactPoint).expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(operationsAppConfig.transactionRequestsEndpoint)
.andReturn().asString();
Expand All @@ -73,9 +89,14 @@ public void iCallTheTxnAPIWithTransactionId() throws InterruptedException {
public void assertValues() {
GetTransactionRequestResponse transactionRequestResponse = (new Gson()).fromJson(scenarioScopeState.response,
GetTransactionRequestResponse.class);

logger.info("The transactionID is {}", scenarioScopeState.transactionId);
logger.info("The transactionId is {}", transactionRequestResponse.getContent().get(0).getState());
logger.info("The transactionId is {}", transactionRequestResponse.getContent().toString());

assertThat(transactionRequestResponse.getContent().size()).isEqualTo(1);
assertThat(transactionRequestResponse.getContent().get(0).getState()).isAnyOf("ACCEPTED", "FAILED");
assertThat(transactionRequestResponse.getContent().get(0).getExternalId()).isNotNull();
assertThat(transactionRequestResponse.getContent().get(0).getExternalId()).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void checkDate() {
public void iCallCollectionApiWithExpectedStatus(int expectedStatus) throws JSONException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
requestSpec.header(Utils.X_CORRELATIONID, clientCorrelationId);
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "254708374149", "24450523");
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "USD", "254708374149", "24450523");
logger.info(String.valueOf(collectionRequestBody));
String json = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
.body(collectionRequestBody.toString()).expect().spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void iCallCollectionApiWithClientCorrelationIdExpectedStatus(int expected
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
requestSpec.header(Utils.X_CORRELATIONID, scenarioScopeState.clientCorrelationId);
logger.info("X-CorrelationId: {}", scenarioScopeState.clientCorrelationId);
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "254708374149", "24450523");
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "USD", "254708374149", "24450523");
String json = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
.body(collectionRequestBody.toString()).expect().spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build())
.when().post(channelConnectorConfig.collectionEndpoint).andReturn().asString();
Expand All @@ -50,7 +50,7 @@ public void iCallCollectionApiWithClientCorrelationIdExpectedStatus(int expected
public void iCallCollectionApiWithClientCorrelationIdErrorExpectedStatus(int expectedStatus) throws JSONException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
requestSpec.header(Utils.X_CORRELATIONID, scenarioScopeState.clientCorrelationId);
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "254708374149", "24450523");
JSONObject collectionRequestBody = CollectionHelper.getCollectionRequestBody("1", "USD", "254708374149", "24450523");
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(channelConnectorConfig.channelConnectorContactPoint)
.body(collectionRequestBody.toString()).expect().spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build())
.when().post(channelConnectorConfig.collectionEndpoint).andReturn().asString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,9 @@ public class ScenarioScopeState {
protected String createTransactionChannelRequestBody;
protected String createGsmaTransferRequestBody;
protected String rtpId;
protected String msisdn;
protected String accountId;
protected String transactionStatusCode;
protected String amount;
protected String currency;
}
38 changes: 38 additions & 0 deletions src/test/java/resources/airtel.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@airtel
Feature: Airtel Test

Scenario: AM-001
Given I can inject MockServer
And I can start mock server
Then I should be able to get instance of mock server
And I can register the stub with "/airtelCallback" endpoint for "POST" request with status of 200
Then I will update the mock server and register stub as done
Given I have tenant as "payerfsp"
And I have clientCorrelationId as "123456"
And I have MSISDN as "1580354289"
And I have accountId as "L000000001"
And I have amount as "100"
And I have currency as "KES"
And I have the request body with payer ams identifiers using keys MSISDN and accountId, currency "KES", and amount "100"
When I call the channel collection API with client correlation id, country "kenya", callback "/airtelCallback", payment schema "airtel" and expected status of 200
Then I should get transaction id in response
Then I should be able to verify that the "POST" method to "/airtelCallback" endpoint received 1 request
When I call the get txn API in ops app with transactionId as parameter
Then I should get transaction state as completed and externalId not null

Scenario: AM-002
Given I can inject MockServer
And I can start mock server
And I can register the stub with "/callback" endpoint for "POST" request with status of 200
Then I will update the mock server and register stub as done
Given I have tenant as "payerfsp"
And I have clientCorrelationId as "123456"
And I have MSISDN as "6729461912"
And I have accountId as "L000000001"
And I have amount as "100"
And I have currency as "KES"
And I have the request body with payer ams identifiers using keys MSISDN and accountId, currency "KES", and amount "100"
When I call the channel collection API with client correlation id, country "kenya", callback "/airtelCallback", payment schema "airtel" and expected status of 200
Then I should get transaction id in response
When I call the get txn API in ops app with transactionId as parameter
Then I should get transaction state as completed and externalId not null
1 change: 0 additions & 1 deletion src/test/java/resources/channelCollection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Feature: Channel Collection API test
| tenant | key1 | key2 |
| gorilla | MSISDN | accountid |


Scenario Outline: Post channel collection API with non-existing BPMN flows
Given I have tenant as "<tenant>"
And I have the request body with payer ams identifier keys as "<key1>" and "<key2>"
Expand Down

0 comments on commit 44483c2

Please sign in to comment.