From b8668af49cc77c4ec09a891076b4ab5417296f12 Mon Sep 17 00:00:00 2001 From: Vishwa1311 Date: Thu, 3 Apr 2014 19:59:26 +0530 Subject: [PATCH] [MIFOSX-1047] Latest updated Scheduler Job test cases --- .../GlobalConfigurationTest.java | 24 ++- .../integrationtests/SchedulerJobsTest.java | 13 +- .../SchedulerJobsTestResults.java | 188 ++++++++++++++++++ .../common/savings/SavingsAccountHelper.java | 3 +- 4 files changed, 213 insertions(+), 15 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java index 72723009a..2774a25c9 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GlobalConfigurationTest.java @@ -83,20 +83,26 @@ public class GlobalConfigurationTest { public void testGlobalConfigurationIsCacheEnabled() { this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec); - for (Integer cacheType = 1; cacheType <= 2; cacheType++) { - // Retrieving Is Cache Enabled Global Configuration details - final ArrayList isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled( + // Retrieving Is Cache Enabled Global Configuration details + ArrayList isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled( + this.requestSpec, this.responseSpec); + Assert.assertNotNull(isCacheGlobalConfig); + + for (Integer cacheType = 0; cacheType <= ((isCacheGlobalConfig.size()) - 1); cacheType++) { + + // Retrieving Is Cache Enabled Global Configuration details + isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled( this.requestSpec, this.responseSpec); Assert.assertNotNull(isCacheGlobalConfig); - HashMap cacheTypeAsHashMap = (HashMap) isCacheGlobalConfig.get(cacheType - 1).get("cacheType"); - String cacheTypeCode = (String) cacheTypeAsHashMap.get("value"); - Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType - 1).get("enabled"); - + + HashMap cacheTypeAsHashMap = (HashMap) isCacheGlobalConfig.get(cacheType).get("cacheType"); Integer cacheTypeId = (Integer) cacheTypeAsHashMap.get("id"); + String cacheTypeValue = (String) cacheTypeAsHashMap.get("value"); + Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType).get("enabled"); - if (cacheTypeCode.compareTo("No cache") == 0 && enabled == true) { + if (cacheTypeValue.compareTo("No cache") == 0 && enabled == true) { cacheTypeId += 1; - } else if (cacheTypeCode.compareTo("Single node") == 0 && enabled == true) { + } else if (cacheTypeValue.compareTo("Single node") == 0 && enabled == true) { cacheTypeId -= 1; } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java index 4d586c6b5..d43d5da62 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTest.java @@ -37,10 +37,6 @@ public class SchedulerJobsTest { public void testSchedulerJobs() { this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec); - // Retrieving All Scheduler Jobs - ArrayList allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec); - Assert.assertNotNull(allSchedulerJobsData); - // Retrieving Status of Scheduler HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec); Boolean status = (Boolean) schedulerStatus.get("active"); @@ -56,7 +52,13 @@ public class SchedulerJobsTest { Assert.assertEquals("Verifying Scheduler Job Status", true, schedulerStatus.get("active")); } - for (Integer jobId = 1; jobId <= 9; jobId++) { + // Retrieving All Scheduler Jobs + ArrayList allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allSchedulerJobsData); + + for (Integer jobIndex = 0; jobIndex <= ((allSchedulerJobsData.size()) - 1); jobIndex++) { + + Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId"); // Retrieving Scheduler Job by ID HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); @@ -86,4 +88,5 @@ public class SchedulerJobsTest { } } + } \ No newline at end of file diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java new file mode 100644 index 000000000..fc0d0758b --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/SchedulerJobsTestResults.java @@ -0,0 +1,188 @@ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.ClientHelper; +import org.mifosplatform.integrationtests.common.CommonConstants; +import org.mifosplatform.integrationtests.common.SchedulerJobHelper; +import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.charges.ChargesHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper; +import org.mifosplatform.integrationtests.common.savings.SavingsStatusChecker; + +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({ "unused", "unchecked", "rawtypes", "static-access", "cast" }) +public class SchedulerJobsTestResults { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private ResponseSpecification responseSpecForSchedulerJob; + private SchedulerJobHelper schedulerJobHelper; + private SavingsAccountHelper savingsAccountHelper; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.requestSpec.header("X-Mifos-Platform-TenantId", "default"); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build(); + } + + @Test + public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, + ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, + ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL); + Assert.assertNotNull(savingsProductID); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, + ChargesHelper.getSavingsAnnualFeeJSON()); + Assert.assertNotNull(annualFeeChargeId); + + this.savingsAccountHelper.addChargesForSavings(savingsId, annualFeeChargeId); + ArrayList chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId); + Assert.assertEquals(1, chargesPendingState.size()); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + ArrayList allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allSchedulerJobsData); + + Integer jobId = (Integer) allSchedulerJobsData.get(3).get("jobId"); + + HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId); + + // Executing Scheduler Job + this.schedulerJobHelper.runSchedulerJob(this.requestSpec, this.responseSpecForSchedulerJob, jobId.toString()); + ArrayList jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec, + jobId.toString()); + + // Retrieving Scheduler Job by ID + HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + + // Waiting for Job to Complete + while ((Boolean) schedulerJob.get("currentlyRunning") == true) { + Thread.sleep(120000); + schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + System.out.println("Job is Still Running"); + } + + // Verifying the Status of the Recently executed Scheduler Job + Assert.assertEquals("Verifying Last Scheduler Job Status", "success", + jobHistoryData.get(((jobHistoryData.size()) - 1)).get("status")); + final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, annualFeeChargeId); + + Float chargeAmount = (Float) chargeData.get("amount"); + + final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId); + Assert.assertEquals("Verifying Annual Fee after Running Scheduler Job for Apply Anual Fee", chargeAmount, + (Float) summaryAfter.get("totalAnnualFees")); + + } + + @Test + public void testInterestPostingForSavingsJobOutcome() throws InterruptedException { + this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); + this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec); + + final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); + Assert.assertNotNull(clientID); + + final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, + ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE); + Assert.assertNotNull(savingsProductID); + + final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, + ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL); + Assert.assertNotNull(savingsProductID); + + HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId); + SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId); + SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap); + + savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId); + SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap); + + ArrayList allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec); + Assert.assertNotNull(allSchedulerJobsData); + + Integer jobId = (Integer) allSchedulerJobsData.get(5).get("jobId"); + + final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId); + + // Executing Scheduler Job + this.schedulerJobHelper.runSchedulerJob(this.requestSpec, this.responseSpecForSchedulerJob, jobId.toString()); + ArrayList jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec, + jobId.toString()); + + // Retrieving Scheduler Job by ID + HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + + // Waiting for Job to complete + while ((Boolean) schedulerJob.get("currentlyRunning") == true) { + Thread.sleep(120000); + schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString()); + Assert.assertNotNull(schedulerJob); + System.out.println("Job is Still Running"); + } + + // Verifying the Status of the Recently executed Scheduler Job + Assert.assertEquals("Verifying Last Scheduler Job Status", "success", + jobHistoryData.get(((jobHistoryData.size()) - 1)).get("status")); + + final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId); + + Assert.assertNotSame("Verifying the Balance after running Post Interest for Savings Job", summaryBefore.get("accountBalance"), + summaryAfter.get("accountBalance")); + } + + private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String minOpenningBalance) { + System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); + SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); + final String savingsProductJSON = savingsProductHelper // + .withInterestCompoundingPeriodTypeAsDaily() // + .withInterestPostingPeriodTypeAsMonthly() // + .withInterestCalculationPeriodTypeAsDailyBalance() // + .withMinimumOpenningBalance(minOpenningBalance).build(); + return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec); + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java index e722f75ee..b98892714 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java @@ -353,7 +353,8 @@ public class SavingsAccountHelper { map.put("feeOnMonthDay", "15 January"); map.put("locale", CommonConstants.locale); map.put("monthDayFormat", "dd MMMM"); - + map.put("dateFormat", "dd MMMM yyy"); + map.put("dueDate", "10 January 2013"); String json = new Gson().toJson(map); return json; }