http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java new file mode 100644 index 0000000..25a4644 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java @@ -0,0 +1,425 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.fineract.batch.domain.BatchRequest; +import org.apache.fineract.batch.domain.BatchResponse; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.integrationtests.common.BatchHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Test class for + * {@link org.apache.fineract.batch.command.CommandStrategyProvider}. This tests + * the response provided by commandStrategy by injecting it with a + * {@code BatchRequest}. + * + * @author RishabhShukla + * + * @see org.apache.fineract.integrationtests.common.BatchHelper + * @see org.apache.fineract.batch.domain.BatchRequest + */ +public class BatchApiTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + public BatchApiTest() { + super(); + } + + /** + * Sets up the essential settings for the TEST like contentType, + * expectedStatusCode. It uses the '@Before' annotation provided by jUnit. + */ + @Before + public void setup() { + + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + /** + * Tests for the unimplemented command Strategies by returning 501 status + * code. For a unknownRequest a statusCode 501 is returned back with + * response. + * + * @see org.apache.fineract.batch.command.internal.UnknownCommandStrategy + */ + @Test + public void shouldReturnStatusNotImplementedUnknownCommand() { + + final BatchRequest br = new BatchRequest(); + br.setRequestId(4711L); + br.setRelativeUrl("/nirvana"); + br.setMethod("POST"); + + final List<BatchResponse> response = BatchHelper.postWithSingleRequest(this.requestSpec, this.responseSpec, br); + + // Verify that only 501 is returned as the status code + for (BatchResponse resp : response) { + Assert.assertEquals("Verify Status code 501", (long) 501, (long) resp.getStatusCode()); + } + } + + /** + * Tests for the successful response for a createClient request from + * createClientCommand. A successful response with statusCode '200' is + * returned back. + * + * @see org.apache.fineract.batch.command.internal.CreateClientCommandStrategy + */ + @Test + public void shouldReturnOkStatusForCreateClientCommand() { + + final BatchRequest br = BatchHelper.createClientRequest(4712L, ""); + + final List<BatchResponse> response = BatchHelper.postWithSingleRequest(this.requestSpec, this.responseSpec, br); + + // Verify that a 200 response is returned as the status code + for (BatchResponse resp : response) { + Assert.assertEquals("Verify Status code 200", (long) 200, (long) resp.getStatusCode()); + } + } + + /** + * Tests for an erroneous response with statusCode '501' if transaction + * fails. If Query Parameter 'enclosingTransaction' is set to 'true' and if + * one of the request in BatchRequest fails then all transactions are rolled + * back. + * + * @see org.apache.fineract.batch.command.internal.CreateClientCommandStrategy + * @see org.apache.fineract.batch.api.BatchApiResource + * @see org.apache.fineract.batch.service.BatchApiService + */ + @Test + public void shouldRollBackAllTransactionsOnFailure() { + + // Create first client request + final BatchRequest br1 = BatchHelper.createClientRequest(4713L, "TestExtId11"); + + // Create second client request + final BatchRequest br2 = BatchHelper.createClientRequest(4714L, "TestExtId12"); + + // Create third client request, having same externalID as second client, + // hence cause of error + final BatchRequest br3 = BatchHelper.createClientRequest(4715L, "TestExtId11"); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + batchRequests.add(br3); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + // Verifies that none of the client in BatchRequest is created on the + // server + BatchHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, "TestExtId11"); + BatchHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, "TestExtId12"); + + // Asserts that all the transactions have been successfully rolled back + Assert.assertEquals(response.size(), 1); + Assert.assertEquals("Verify Status code 400", (long) 400, (long) response.get(0).getStatusCode()); + } + + /** + * Tests that a client information was successfully updated through + * updateClientCommand. A 'changes' parameter is returned in the response + * after successful update of client information. + * + * @see org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy + */ + @Test + public void shouldReflectChangesOnClientUpdate() { + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4716L, ""); + + // Create a clientUpdate Request + final BatchRequest br2 = BatchHelper.updateClientRequest(4717L, 4716L); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + // Get the changes parameter from updateClient Response + final JsonObject changes = new FromJsonHelper().parse(response.get(1).getBody()).getAsJsonObject().get("changes").getAsJsonObject(); + + // Asserts the client information is successfully updated + Assert.assertEquals("Verify Firstname", "TestFirstName", changes.get("firstname").getAsString()); + Assert.assertEquals("Verify Lastname", "TestLastName", changes.get("lastname").getAsString()); + } + + /** + * Tests that a ApplyLoanCommand was successfully executed and returned a + * 200(OK) status. It creates a new client and apply a loan to that client. + * This also verifies the successful resolution of dependencies among two + * requests. + * + * @see org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy + */ + @Test + public void shouldReturnOkStatusForApplyLoanCommand() { + + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("10000000.00") // + .withNumberOfRepayments("24") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("2") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualPrincipalPayment() // + .withInterestTypeAsDecliningBalance() // + .currencyDetails("0", "100").build(null); + + final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON); + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4718L, ""); + + // Create a activateClient Request + final BatchRequest br2 = BatchHelper.activateClientRequest(4719L, 4718L); + + // Create a ApplyLoan Request + final BatchRequest br3 = BatchHelper.applyLoanRequest(4720L, 4719L, productId); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + batchRequests.add(br3); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + // Get the clientId parameter from createClient Response + final JsonElement clientId = new FromJsonHelper().parse(response.get(0).getBody()).getAsJsonObject().get("clientId"); + + Assert.assertEquals("Verify Status Code 200" + clientId.getAsString(), 200L, (long) response.get(1).getStatusCode()); + } + + /** + * Tests that a new savings accounts was applied to an existing client and a + * 200(OK) status was returned. It first creates a new client and a savings + * product, then uses the cliendId and ProductId to apply a savings account. + * + * @see org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy + */ + @Test + public void shouldReturnOkStatusForApplySavingsCommand() { + + final SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); + final String savingsProductJSON = savingsProductHelper // + .withInterestCompoundingPeriodTypeAsDaily() // + .withInterestPostingPeriodTypeAsMonthly() // + .withInterestCalculationPeriodTypeAsDailyBalance() // + .withMinimumOpenningBalance("5000").build(); + + final Integer productId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec); + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4720L, ""); + + // Create a activateClient Request + final BatchRequest br2 = BatchHelper.activateClientRequest(4721L, 4720L); + + // Create a applySavings Request + final BatchRequest br3 = BatchHelper.applySavingsRequest(4722L, 4721L, productId); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + batchRequests.add(br3); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + Assert.assertEquals("Verify Status Code 200", 200L, (long) response.get(1).getStatusCode()); + } + + /** + * Tests that a new charge was added to a newly created loan and charges are + * Collected properly 200(OK) status was returned for successful responses. + * It first creates a new client and apply a loan, then creates a new charge + * for the create loan and then fetches all the applied charges + * + * @see org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy + * @see org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy + */ + @Test + public void shouldReturnOkStatusForCollectChargesCommand() { + + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("10000000.00") // + .withNumberOfRepayments("24") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("2") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualPrincipalPayment() // + .withInterestTypeAsDecliningBalance() // + .currencyDetails("0", "100").build(null); + + final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON); + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4722L, ""); + + // Create a activateClient Request + final BatchRequest br2 = BatchHelper.activateClientRequest(4723L, 4722L); + + // Create a ApplyLoan Request + final BatchRequest br3 = BatchHelper.applyLoanRequest(4724L, 4723L, productId); + + // Create a Collect Charges Request + final BatchRequest br4 = BatchHelper.collectChargesRequest(4725L, 4724L); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + batchRequests.add(br3); + batchRequests.add(br4); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + Assert.assertEquals("Verify Status Code 200 for Create Loan Charge", 200L, (long) response.get(3).getStatusCode()); + } + + /** + * Test for the successful activation of a pending client using + * 'ActivateClientCommandStrategy'. A '200' status code is expected on + * successful activation. + * + * @see org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy + */ + @Test + public void shouldReturnOkStatusOnSuccessfulClientActivation() { + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4726L, ""); + + // Create a activateClient Request + final BatchRequest br2 = BatchHelper.activateClientRequest(4727L, 4726L); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + Assert.assertEquals("Verify Status Code 200 for Create Client", 200L, (long) response.get(0).getStatusCode()); + Assert.assertEquals("Verify Status Code 200 for Activate Client", 200L, (long) response.get(1).getStatusCode()); + } + + /** + * Test for the successful approval and disbursal of a loan using + * 'ApproveLoanCommandStrategy' and 'DisburseLoanCommandStrategy'. A '200' + * status code is expected on successful activation. + * + * @see org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy + * @see org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy + */ + @Test + public void shouldReturnOkStatusOnSuccessfulLoanApprovalAndDisburse() { + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal("10000000.00") // + .withNumberOfRepayments("24") // + .withRepaymentAfterEvery("1") // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod("2") // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualPrincipalPayment() // + .withInterestTypeAsDecliningBalance() // + .currencyDetails("0", "100").build(null); + + final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON); + + // Create a createClient Request + final BatchRequest br1 = BatchHelper.createClientRequest(4730L, ""); + + // Create a activateClient Request + final BatchRequest br2 = BatchHelper.activateClientRequest(4731L, 4730L); + + // Create a ApplyLoan Request + final BatchRequest br3 = BatchHelper.applyLoanRequest(4732L, 4731L, productId); + + // Create a approveLoan Request + final BatchRequest br4 = BatchHelper.approveLoanRequest(4733L, 4732L); + + // Create a disburseLoan Request + final BatchRequest br5 = BatchHelper.disburseLoanRequest(4734L, 4733L); + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + batchRequests.add(br1); + batchRequests.add(br2); + batchRequests.add(br3); + batchRequests.add(br4); + batchRequests.add(br5); + + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + Assert.assertEquals("Verify Status Code 200 for Approve Loan", 200L, (long) response.get(3).getStatusCode()); + Assert.assertEquals("Verify Status Code 200 for Disburse Loan", 200L, (long) response.get(4).getStatusCode()); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchRequestsIntegrationTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchRequestsIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchRequestsIntegrationTest.java new file mode 100644 index 0000000..ad1f61b --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchRequestsIntegrationTest.java @@ -0,0 +1,140 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.fineract.batch.domain.BatchRequest; +import org.apache.fineract.batch.domain.BatchResponse; +import org.apache.fineract.integrationtests.common.BatchHelper; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.GroupHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +/** + * Test class for testing the integration of Batch API with custom batch + * requests and various user defined workflow. Like in the case of mifos + * community-app + * + * @author Rishabh Shukla + */ +public class BatchRequestsIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + public BatchRequestsIntegrationTest() { + super(); + } + + /** + * Sets up the essential settings for the TEST like contentType, + * expectedStatusCode. It uses the '@Before' annotation provided by jUnit. + */ + @Before + public void setup() { + + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + /** + * Tests that a loan is successfully applied to client members of a group. + * Firstly, it'll create a few new clients and then will add those clients + * to the group. Then a few loans will be created and one of those loans + * will be chosen at random and similarily a few of the created clients will + * be chosen on random. Now, the selected loan will be applied to these + * clients through Batch - API ApplyLoanCommandStrategy. + */ + public void shouldReturnOkStatusForLoansAppliedToSelectedClients() { + + // Generate a random count of number of clients to be created + final Integer clientsCount = (int) Math.ceil(Math.random() * 7) + 3; + final Integer[] clientIDs = new Integer[clientsCount]; + + // Create a new group and get its groupId + Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true); + + // Create new clients and add those to this group + for (Integer i = 0; i < clientsCount; i++) { + clientIDs[i] = ClientHelper.createClient(this.requestSpec, this.responseSpec); + groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientIDs[i].toString()); + System.out.println("client " + clientIDs[i] + " has been added to the group " + groupID); + } + + // Generate a random count of number of new loan products to be created + final Integer loansCount = (int) Math.ceil(Math.random() * 4) + 1; + final Integer[] loanProducts = new Integer[loansCount]; + + // Create new loan Products + for (Integer i = 0; i < loansCount; i++) { + final String loanProductJSON = new LoanProductTestBuilder() // + .withPrincipal(String.valueOf(10000.00 + Math.ceil(Math.random() * 1000000.00))) // + .withNumberOfRepayments(String.valueOf(2 + (int) Math.ceil(Math.random() * 36))) // + .withRepaymentAfterEvery(String.valueOf(1 + (int) Math.ceil(Math.random() * 3))) // + .withRepaymentTypeAsMonth() // + .withinterestRatePerPeriod(String.valueOf(1 + (int) Math.ceil(Math.random() * 4))) // + .withInterestRateFrequencyTypeAsMonths() // + .withAmortizationTypeAsEqualPrincipalPayment() // + .withInterestTypeAsDecliningBalance() // + .currencyDetails("0", "100").build(null); + + loanProducts[i] = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON); + } + + // Select anyone of the loan products at random + final Integer loanProductID = loanProducts[(int) Math.floor(Math.random() * (loansCount - 1))]; + + final List<BatchRequest> batchRequests = new ArrayList<>(); + + // Select a few clients from created group at random + Integer selClientsCount = (int) Math.ceil(Math.random() * clientsCount) + 2; + for (int i = 0; i < selClientsCount; i++) { + BatchRequest br = BatchHelper.applyLoanRequest((long) selClientsCount, null, loanProductID); + br.setBody(br.getBody().replace("$.clientId", String.valueOf(clientIDs[(int) Math.floor(Math.random() * (clientsCount - 1))]))); + batchRequests.add(br); + } + + // Send the request to Batch - API + final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests); + + final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, + jsonifiedRequest); + + // Verify that each loan has been applied successfully + for (BatchResponse res : response) { + Assert.assertEquals("Verify Status Code 200", 200L, (long) res.getStatusCode()); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java new file mode 100644 index 0000000..d923ee5 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/CenterIntegrationTest.java @@ -0,0 +1,261 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.CenterDomain; +import org.apache.fineract.integrationtests.common.CenterHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.google.gson.Gson; +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class CenterIntegrationTest { + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void testBasicCenterCreation() { + int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007"); + + String name = "TestBasicCreation" + new Timestamp(new java.util.Date().getTime()); + int resourceId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec); + CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec); + + Assert.assertNotNull(center); + Assert.assertTrue(center.getName().equals(name)); + Assert.assertTrue(center.getOfficeId() == officeId); + Assert.assertTrue(center.isActive() == false); + + // Test retrieval by listing all centers + int id = CenterHelper.listCenters(requestSpec, responseSpec).get(0).getId(); + Assert.assertTrue(id > 0); + + CenterDomain retrievedCenter = CenterHelper.retrieveByID(id, requestSpec, responseSpec); + Assert.assertNotNull(retrievedCenter); + Assert.assertNotNull(retrievedCenter.getName()); + Assert.assertNotNull(retrievedCenter.getHierarchy()); + Assert.assertNotNull(retrievedCenter.getOfficeName()); + + } + + @Test + public void testFullCenterCreation() { + + int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007"); + String name = "TestFullCreation" + new Timestamp(new java.util.Date().getTime()); + String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int staffId = StaffHelper.createStaff(requestSpec, responseSpec); + int[] groupMembers = generateGroupMembers(3, officeId); + int resourceId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, requestSpec, responseSpec); + CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec); + + Assert.assertNotNull(center); + Assert.assertTrue(center.getName().equals(name)); + Assert.assertTrue(center.getOfficeId() == officeId); + Assert.assertTrue(center.getExternalId().equals(externalId)); + Assert.assertTrue(center.getStaffId() == staffId); + Assert.assertTrue(center.isActive() == false); + Assert.assertArrayEquals(center.getGroupMembers(), groupMembers); + } + + @Test + public void testListCenters() { + ArrayList<CenterDomain> paginatedList = CenterHelper.paginatedListCenters(requestSpec, responseSpec); + ArrayList<CenterDomain> list = CenterHelper.listCenters(requestSpec, responseSpec); + + Assert.assertNotNull(paginatedList); + Assert.assertNotNull(list); + Assert.assertTrue(Arrays.equals(paginatedList.toArray(new CenterDomain[paginatedList.size()]), + list.toArray(new CenterDomain[list.size()]))); + } + + @Test + public void testVoidCenterRetrieval() { + ArrayList<CenterDomain> arr = CenterHelper.listCenters(requestSpec, responseSpec); + int id = arr.get(arr.size() - 1).getId() + 1; + ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build(); + CenterDomain center = CenterHelper.retrieveByID(id, requestSpec, responseSpec); + Assert.assertNotNull(center); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void testCenterUpdate() { + int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007"); + String name = "TestFullCreation" + new Timestamp(new java.util.Date().getTime()); + String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int staffId = StaffHelper.createStaff(requestSpec, responseSpec); + int[] groupMembers = generateGroupMembers(3, officeId); + int resourceId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, requestSpec, responseSpec); + + String newName = "TestCenterUpdateNew" + new Timestamp(new java.util.Date().getTime()); + String newExternalId = Utils.randomStringGenerator("newID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + int newStaffId = StaffHelper.createStaff(requestSpec, responseSpec); + int[] associateGroupMembers = generateGroupMembers(2, officeId); + + int[] associateResponse = CenterHelper.associateGroups(resourceId, associateGroupMembers, requestSpec, responseSpec); + Arrays.sort(associateResponse); + Arrays.sort(associateGroupMembers); + Assert.assertArrayEquals(associateResponse, associateGroupMembers); + + int[] newGroupMembers = new int[5]; + for (int i = 0; i < 5; i++) { + if (i < 3) { + newGroupMembers[i] = groupMembers[i]; + } else { + newGroupMembers[i] = associateGroupMembers[i % 3]; + } + } + + HashMap request = new HashMap(); + request.put("name", newName); + request.put("externalId", newExternalId); + request.put("staffId", newStaffId); + HashMap response = CenterHelper.updateCenter(resourceId, request, requestSpec, responseSpec); + Assert.assertNotNull(response); + Assert.assertEquals(newName, response.get("name")); + Assert.assertEquals(newExternalId, response.get("externalId")); + Assert.assertEquals(newStaffId, response.get("staffId")); + + CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec); + Assert.assertNotNull(center); + Assert.assertEquals(newName, center.getName()); + Assert.assertEquals(newExternalId, center.getExternalId()); + Assert.assertEquals((Integer)newStaffId, center.getStaffId()); + Assert.assertArrayEquals(newGroupMembers, center.getGroupMembers()); + } + + @Test + public void testCenterDeletion() { + int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007"); + String name = "TestBasicCreation" + new Timestamp(new java.util.Date().getTime()); + int resourceId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec); + + CenterHelper.deleteCenter(resourceId, requestSpec, responseSpec); + ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build(); + CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec); + Assert.assertNotNull(center); + } + + private int[] generateGroupMembers(int size, int officeId) { + int[] groupMembers = new int[size]; + for (int i = 0; i < groupMembers.length; i++) { + final HashMap<String, String> map = new HashMap<>(); + map.put("officeId", "" + officeId); + map.put("name", Utils.randomStringGenerator("Group_Name_", 5)); + map.put("externalId", Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", "04 March 2011"); + + groupMembers[i] = Utils.performServerPost(requestSpec, responseSpec, "/fineract-provider/api/v1/groups?" + + Utils.TENANT_IDENTIFIER, new Gson().toJson(map), "groupId"); + } + return groupMembers; + } + + @Test + public void testStaffAssignmentDuringCenterCreation() { + + Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec); + System.out.println("--------------creating first staff with id-------------" + staffId); + Assert.assertNotNull(staffId); + + int centerWithStaffId = CenterHelper.createCenterWithStaffId(this.requestSpec, this.responseSpec, staffId); + CenterDomain center = CenterHelper.retrieveByID(centerWithStaffId, requestSpec, responseSpec); + Assert.assertNotNull(center); + Assert.assertTrue(center.getId() == centerWithStaffId); + Assert.assertTrue(center.getStaffId() == staffId); + Assert.assertTrue(center.isActive() == true); + } + + @Test + public void testAssignStaffToCenter() { + Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec); + System.out.println("--------------creating first staff with id-------------" + staffId); + Assert.assertNotNull(staffId); + + Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec); + CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID); + + HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(), + staffId.longValue()); + assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId); + + CenterDomain center = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec); + Assert.assertNotNull(center); + Assert.assertTrue(center.getId() == groupID); + Assert.assertTrue(center.getStaffId() == staffId); + + } + + @Test + public void testUnassignStaffToCenter() { + Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec); + System.out.println("--------------creating first staff with id-------------" + staffId); + Assert.assertNotNull(staffId); + + Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec); + CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID); + + HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(), + staffId.longValue()); + assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId); + CenterDomain centerWithStaffAssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec); + Assert.assertNotNull(centerWithStaffAssigned); + Assert.assertTrue(centerWithStaffAssigned.getId() == groupID); + Assert.assertTrue(centerWithStaffAssigned.getStaffId() == staffId); + + HashMap unassignStaffToCenterResponseMap = (HashMap) CenterHelper.unassignStaff(this.requestSpec, this.responseSpec, groupID.toString(), + staffId.longValue()); + assertEquals("Verify staffId is null after unassigning ", unassignStaffToCenterResponseMap.get("staffId"), null); + CenterDomain centerWithStaffUnssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec); + Assert.assertNotNull(centerWithStaffUnssigned); + Assert.assertTrue(centerWithStaffUnssigned.getId() == groupID); + Assert.assertTrue(centerWithStaffUnssigned.getStaffId() == null); + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/4b1ec9ef/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ChargesTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ChargesTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ChargesTest.java new file mode 100644 index 0000000..d441401 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/ChargesTest.java @@ -0,0 +1,326 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.integrationtests; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.charges.ChargesHelper; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +@SuppressWarnings({ "rawtypes" }) +public class ChargesTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } + + @Test + public void testChargesForLoans() { + + // Retrieving all Charges + ArrayList<HashMap> allChargesData = ChargesHelper.getCharges(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allChargesData); + + // Testing Creation, Updation and Deletion of Disbursement Charge + final Integer disbursementChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanDisbursementJSON()); + Assert.assertNotNull(disbursementChargeId); + + // Updating Charge Amount + HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId, + ChargesHelper.getModifyChargeJSON()); + + HashMap chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId, + ChargesHelper.getModifyChargeAsPecentageAmountJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId); + + HashMap chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode")); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId, + ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId, + ChargesHelper.getModifyChargeAsPercentageInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, disbursementChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", disbursementChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Specified due date Charge + final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanSpecifiedDueDateJSON()); + Assert.assertNotNull(specifiedDueDateChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId, + ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId, + ChargesHelper.getModifyChargeAsPecentageAmountJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode")); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId, + ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId, + ChargesHelper.getModifyChargeAsPercentageInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Installment Fee Charge + final Integer installmentFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanInstallmentFeeJSON()); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId, + ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId, + ChargesHelper.getModifyChargeAsPecentageAmountJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode")); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId, + ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId, + ChargesHelper.getModifyChargeAsPercentageInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, installmentFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", installmentFeeChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Overdue Installment Fee + // Charge + final Integer overdueFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getLoanOverdueFeeJSON()); + Assert.assertNotNull(overdueFeeChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, + ChargesHelper.getModifyChargeAsPecentageAmountJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode")); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, + ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, + ChargesHelper.getModifyChargeAsPercentageInterestJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, + ChargesHelper.getModifyChargeFeeFrequencyAsYearsJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId); + + chargeChangedData = (HashMap) chargeDataAfterChanges.get("feeFrequency"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("feeFrequency")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdueFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", overdueFeeChargeId, chargeIdAfterDeletion); + } + + @Test + public void testChargesForSavings() { + + // Testing Creation, Updation and Deletion of Specified due date Charge + final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsSpecifiedDueDateJSON()); + Assert.assertNotNull(specifiedDueDateChargeId); + + // Updating Charge Amount + HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId, + ChargesHelper.getModifyChargeJSON()); + + HashMap chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Savings Activation Charge + final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsActivationFeeJSON()); + Assert.assertNotNull(savingsActivationChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, savingsActivationChargeId, + ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, savingsActivationChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, savingsActivationChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", savingsActivationChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Charge for Withdrawal Fee + final Integer withdrawalFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsWithdrawalFeeJSON()); + Assert.assertNotNull(withdrawalFeeChargeId); + + // Updating Charge-Calculation-Type to Withdrawal-Fee + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, withdrawalFeeChargeId, + ChargesHelper.getModifyWithdrawalFeeSavingsChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, withdrawalFeeChargeId); + + HashMap chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType"); + Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, withdrawalFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", withdrawalFeeChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Charge for Annual Fee + final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsAnnualFeeJSON()); + Assert.assertNotNull(annualFeeChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, annualFeeChargeId, ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, annualFeeChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, annualFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", annualFeeChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Charge for Monthly Fee + final Integer monthlyFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsMonthlyFeeJSON()); + Assert.assertNotNull(monthlyFeeChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, monthlyFeeChargeId, ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, monthlyFeeChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, monthlyFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", monthlyFeeChargeId, chargeIdAfterDeletion); + + // Testing Creation, Updation and Deletion of Charge for Overdraft Fee + final Integer overdraftFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsOverdraftFeeJSON()); + Assert.assertNotNull(overdraftFeeChargeId); + + // Updating Charge Amount + changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdraftFeeChargeId, + ChargesHelper.getModifyChargeJSON()); + + chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdraftFeeChargeId); + Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount")); + + chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdraftFeeChargeId); + Assert.assertEquals("Verifying Charge ID after deletion", overdraftFeeChargeId, chargeIdAfterDeletion); + } +}
