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

Demo TCS with Account Registration in Fineract #9

Open
wants to merge 1 commit into
base: develop
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 @@ -311,7 +311,6 @@ public void callBatchTransactionsEndpoint(int expectedStatus) {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant, scenarioScopeState.clientCorrelationId);
requestSpec.header(HEADER_PURPOSE, "Integartion test");
requestSpec.header(HEADER_FILENAME, scenarioScopeState.filename);
requestSpec.header(HEADER_REGISTERING_INSTITUTE_ID, "SocialWelfare");
requestSpec.queryParam(QUERY_PARAM_TYPE, "CSV");
requestSpec.header(QUERY_PARAM_TYPE, "CSV");
if (scenarioScopeState.signature != null && !scenarioScopeState.signature.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -526,6 +527,22 @@ public void iCreateAIdentityMapperDTOForRegisteringBeneficiary() {
registerBeneficiaryBody = new AccountMapperRequestDTO(requestId, sourceBBID, beneficiaryDTOList);
}

@And("I create a IdentityMapperDTO for registering payee with IAM")
public void iCreateAIdentityMapperDTOForRegisteringPayee() {
List<BeneficiaryDTO> beneficiaryDTOList = new ArrayList<>();
String payeeFsp = "payeefsp3";
String[] financialAddressArray = { "1234", "1235", "1236" };
int fspIndex = 0;
Set<String> payeeIdentifiers = new HashSet<>(scenarioScopeState.payeeIdentifiers);
for (String payeeIdentifier : payeeIdentifiers) {
BeneficiaryDTO beneficiaryDTO = new BeneficiaryDTO(payeeIdentifier, "00", financialAddressArray[fspIndex], payeeFspConfig.getPayeeFsp(payeeFsp));
beneficiaryDTOList.add(beneficiaryDTO);
fspIndex++;
}
requestId = generateUniqueNumber(12);
registerBeneficiaryBody = new AccountMapperRequestDTO(requestId, sourceBBID, beneficiaryDTOList);
}

@And("I should be able to verify that the {string} method to {string} endpoint received a request with successfull registration")
public void iShouldBeAbleToVerifyThatTheMethodToEndpointReceivedARequestWithSuccessfullRegistration(String httpMethod, String stub) {
await().atMost(awaitMost, SECONDS).untilAsserted(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,45 @@ public void addUsersToALS(String client) throws JsonProcessingException {
assertThat(response).isNotNull();
}

@Then("I add {string} with account id {string} to als")
public void addBudgetAccountToALS(String client, String accountId) throws JsonProcessingException {

String clientIdentifierId;
String fspId;
if (client.equals("payer")) {
clientIdentifierId = scenarioScopeState.payerIdentifier;
fspId = mojaloopConfig.payerFspId;
} else {
clientIdentifierId = scenarioScopeState.payeeIdentifier;
fspId = mojaloopConfig.payeeFspId;
}

RequestSpecification requestSpec = Utils.getDefaultSpec();
requestSpec.header("FSPIOP-Source", fspId);
requestSpec.header("Date", getCurrentDateInFormat());
requestSpec.header("Accept", "application/vnd.interoperability.participants+json;version=1");
// requestSpec.header("Content-Type", "application/vnd.interoperability.participants+json;version=1.0");

String endpoint = mojaloopConfig.addUserToAlsEndpoint;
endpoint = endpoint.replaceAll("\\{\\{identifierType\\}\\}", "MSISDN");
endpoint = endpoint.replaceAll("\\{\\{identifier\\}\\}", accountId);

String requestBody = mojaloopDef.setBodyAddAlsUser(fspId);

logger.info(mojaloopConfig.mojaloopBaseurl);
logger.info(requestBody);
logger.info(endpoint);

String response = RestAssured.given(requestSpec).baseUri(mojaloopConfig.mojaloopBaseurl)
.config(RestAssured.config().encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
.body(requestBody).contentType("application/vnd.interoperability.participants+json;version=1.0").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(202).build()).when().post(endpoint).andReturn().asString();

logger.info(response);
assertThat(response).isNotNull();
}


@Given("I am setting up Mojaloop")
public void mojaloopSetup() throws JsonProcessingException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class PayerFundTransferStepDef extends BaseStepDef {

private static String payer_identifier;

private static String savings_account_id;

private static String payee_identifier;

private static String quoteId;
Expand Down Expand Up @@ -176,6 +178,42 @@ public void callCreateInteropIdentifierEndpoint(String client) throws JsonProces
assertThat(fundTransferDef.responseInteropIdentifier).isNotEmpty();
}

@Then("I call the interop identifier endpoint for {string} and accountId {string}")
public void callCreateInteropBudgetIdentifierEndpoint(String client, String accountId) throws JsonProcessingException {
// Setting headers and body
RequestSpecification requestSpec = Utils.getDefaultSpec();
requestSpec = fundTransferDef.setHeaders(requestSpec);
fundTransferDef.interopIdentifierBody = fundTransferDef.setBodyInteropIdentifier();
// Setting account ID in path

String responseSavingsAccount = client.equals("payer") ? fundTransferDef.responseSavingsAccountPayer
: fundTransferDef.responseSavingsAccountPayee;

PostSavingsAccountsResponse savingsAccountResponse = objectMapper.readValue(responseSavingsAccount,
PostSavingsAccountsResponse.class);
savings_account_id = savingsAccountResponse.getSavingsId().toString();

if (client.equals("payer")) {
payer_identifier = accountId;
scenarioScopeState.payerIdentifier = accountId;
} else {
payee_identifier = accountId;
scenarioScopeState.payeeIdentifier = accountId;
}

String endpoint = transferConfig.interopIdentifierEndpoint;
endpoint = endpoint.replaceAll("\\{\\{identifierType\\}\\}", "MSISDN");
endpoint = endpoint.replaceAll("\\{\\{identifier\\}\\}", accountId);

// Calling Interop Identifier endpoint
fundTransferDef.responseInteropIdentifier = RestAssured.given(requestSpec).baseUri(transferConfig.savingsBaseUrl)
.body(fundTransferDef.interopIdentifierBody).expect().spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when()
.post(endpoint).andReturn().asString();

logger.info("Interop Identifier Response: " + fundTransferDef.responseInteropIdentifier);
assertThat(fundTransferDef.responseInteropIdentifier).isNotEmpty();
}

@Then("I approve the deposit with command {string} for {string}")
public void callApproveSavingsEndpoint(String command, String client) throws JsonProcessingException {
// Setting headers and body
Expand All @@ -200,6 +238,31 @@ public void callApproveSavingsEndpoint(String command, String client) throws Jso
assertThat(fundTransferDef.responseSavingsApprove).isNotEmpty();
}

@Then("I approve the deposit for Budget Account with command {string} for {string}")
public void callApproveBudgetAccountEndpoint(String command, String client) throws JsonProcessingException {
// Setting headers and body
RequestSpecification requestSpec = Utils.getDefaultSpec();
requestSpec = fundTransferDef.setHeaders(requestSpec);
requestSpec.queryParam("command", command);
fundTransferDef.savingsApproveBody = fundTransferDef.setBodySavingsApprove();
String endpoint = transferConfig.savingsApproveEndpoint;

if (client.equals("payer")) {
endpoint = endpoint.replaceAll("\\{\\{savingsAccId\\}\\}", savings_account_id);
} else {
endpoint = endpoint.replaceAll("\\{\\{savingsAccId\\}\\}", savings_account_id);
}

// Calling create loan account endpoint
fundTransferDef.responseSavingsApprove = RestAssured.given(requestSpec).baseUri(transferConfig.savingsBaseUrl)
.body(fundTransferDef.savingsApproveBody).expect().spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when()
.post(endpoint).andReturn().asString();

logger.info("Savings Approve Response: " + fundTransferDef.responseSavingsApprove);
assertThat(fundTransferDef.responseSavingsApprove).isNotEmpty();
}


@When("I activate the account with command {string} for {string}")
public void callSavingsActivateEndpoint(String command, String client) throws JsonProcessingException {
// Setting headers and body
Expand All @@ -223,6 +286,30 @@ public void callSavingsActivateEndpoint(String command, String client) throws Js
assertThat(fundTransferDef.responseSavingsActivate).isNotEmpty();
}

@When("I activate the budget account with command {string} for {string}")
public void callBudgetAccountActivateEndpoint(String command, String client) throws JsonProcessingException {
// Setting headers and body
RequestSpecification requestSpec = Utils.getDefaultSpec();
requestSpec = fundTransferDef.setHeaders(requestSpec);
requestSpec.queryParam("command", command);
fundTransferDef.savingsActivateBody = fundTransferDef.setBodySavingsActivate();

String endpoint = transferConfig.savingsActivateEndpoint;
if (client.equals("payer")) {
endpoint = endpoint.replaceAll("\\{\\{savingsAccId\\}\\}", savings_account_id);
} else {
endpoint = endpoint.replaceAll("\\{\\{savingsAccId\\}\\}", savings_account_id);
}
// Calling create loan account endpoint
fundTransferDef.responseSavingsActivate = RestAssured.given(requestSpec).baseUri(transferConfig.savingsBaseUrl)
.body(fundTransferDef.savingsActivateBody).expect().spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when()
.post(endpoint).andReturn().asString();

logger.info("Savings Activate Response: " + fundTransferDef.responseSavingsActivate);
assertThat(fundTransferDef.responseSavingsActivate).isNotEmpty();
}


@Then("I call the deposit account endpoint with command {string} for amount {int} for {string}")
public void callDepositAccountEndpoint(String command, int amount, String client) throws JsonProcessingException {
// Setting headers and body
Expand Down Expand Up @@ -608,4 +695,26 @@ public void consolidatedPayeeCreationStepsForCombinedTestsCases(String client, S
}
}

@Then("I check whether budget account exists with accoundId {string}")
public void budgetAccountExistsWithAccoundId(String accountId) throws JsonProcessingException {
RequestSpecification requestSpec = Utils.getDefaultSpec();
requestSpec = fundTransferDef.setHeaders(requestSpec);
// Setting account ID in path

String endpoint = transferConfig.interopIdentifierEndpoint;
endpoint = endpoint.replaceAll("\\{\\{identifierType\\}\\}", "MSISDN");
endpoint = endpoint.replaceAll("\\{\\{identifier\\}\\}", accountId);
try {
// Calling Interop Identifier endpoint
fundTransferDef.responseInteropIdentifier = RestAssured.given(requestSpec).baseUri(transferConfig.savingsBaseUrl)
.expect().spec(new ResponseSpecBuilder().build()).when()
.delete(endpoint).andReturn().asString();
} catch (Exception e) {
logger.error("Error checking account existence: ", e);
throw new RuntimeException("Failed to check account existence", e);
}
logger.info("Interop Identifier Response: " + fundTransferDef.responseInteropIdentifier);
assertThat(fundTransferDef.responseInteropIdentifier).isNotEmpty();
}

}
4 changes: 2 additions & 2 deletions src/test/java/resources/batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ Feature: Batch Details API test
Scenario: BD-011 Batch test for payerIdentifier resolution using budgetAccount info
Given I have tenant as "paymentBB2"
And I have the demo csv file "payerIdentifier-resolution-using-budgetAccount.csv"
And I have the registeringInstituteId "123"
And I have the programId "SocialWelfare"
And I have the registeringInstituteId "SocialWelfare"
And I have the programId "Education"
And I generate clientCorrelationId
And I have private key
And I generate signature
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/resources/batch_demo_csv/batchTransaction.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,request_id,payment_mode,payer_identifier_type,payer_identifier,payee_identifier_type,payee_identifier,amount,currency,note
0,ed6bf87e-4bda-44dc-be52-004e71438f0f,mojaloop,msisdn,345,msisdn,363,3,USD,Test Payee Payment
1,25ddc445-069a-417b-b62a-f5b952ac313e,mojaloop,msisdn,346,msisdn,363,2,USD,Test Payee Payment
2,0842d2df-0aec-4312-ada4-c3dd2be1ed80,mojaloop,msisdn,347,msisdn,364,1,USD,Test Payee Payment
Loading