PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/org/openmf/mifos/dataimport/populator/SavingsTransactionWorkbookPopulatorTest.java

https://gitlab.com/skylabase/DataImportTool
Java | 105 lines | 86 code | 17 blank | 2 comment | 0 complexity | 4e862b5e58d84d1c4970dc48e3c4efa9 MD5 | raw file
  1. package org.openmf.mifos.dataimport.populator;
  2. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  3. import org.apache.poi.ss.usermodel.Row;
  4. import org.apache.poi.ss.usermodel.Sheet;
  5. import org.apache.poi.ss.usermodel.Workbook;
  6. import org.junit.Assert;
  7. import org.junit.Test;
  8. import org.junit.runner.RunWith;
  9. import org.mockito.Mock;
  10. import org.mockito.Mockito;
  11. import org.mockito.runners.MockitoJUnitRunner;
  12. import org.openmf.mifos.dataimport.handler.Result;
  13. import org.openmf.mifos.dataimport.http.RestClient;
  14. import org.openmf.mifos.dataimport.populator.savings.SavingsTransactionWorkbookPopulator;
  15. @RunWith(MockitoJUnitRunner.class)
  16. public class SavingsTransactionWorkbookPopulatorTest {
  17. @Mock
  18. RestClient restClient;
  19. private static final int LOOKUP_CLIENT_NAME_COL = 15;
  20. private static final int LOOKUP_ACCOUNT_NO_COL = 16;
  21. private static final int LOOKUP_PRODUCT_COL = 17;
  22. private static final int LOOKUP_OPENING_BALANCE_COL = 18;
  23. @Test
  24. public void shouldPopulateLoanRepaymentWorkbook() {
  25. Mockito.when(restClient.get("savingsaccounts?limit=-1")).thenReturn("{\"totalFilteredRecords\": 1,\"pageItems\": [{" +
  26. "\"id\": 6,\"accountNo\": \"000000006\",\"clientId\": 1,\"clientName\": \"Arsene K Wenger\",\"savingsProductId\": 1,\"savingsProductName\": \"SP1\",\"fieldOfficerId\": 1," +
  27. "\"fieldOfficerName\": \"Chatta, Sahil\",\"status\": {\"id\": 300,\"code\": \"savingsAccountStatusType.active\",\"value\": \"Active\",\"submittedAndPendingApproval\": false," +
  28. "\"approved\": false,\"rejected\": false,\"withdrawnByApplicant\": false,\"active\": true,\"closed\": false},\"timeline\": {\"submittedOnDate\": [2013,7,2]," +
  29. "\"approvedOnDate\": [2013,7,3],\"approvedByUsername\": \"mifos\",\"approvedByFirstname\": \"App\",\"approvedByLastname\": \"Administrator\",\"activatedOnDate\": [2013,7,4]}," +
  30. "\"currency\": {\"code\": \"USD\",\"name\": \"US Dollar\",\"decimalPlaces\": 2,\"displaySymbol\": \"$\",\"nameCode\": \"currency.USD\",\"displayLabel\": \"US Dollar ($)\"}," +
  31. "\"nominalAnnualInterestRate\": 8.000000,\"interestCompoundingPeriodType\": {\"id\": 1,\"code\": \"savings.interest.period.savingsCompoundingInterestPeriodType.daily\"," +
  32. "\"value\": \"Daily\"},\"interestPostingPeriodType\": {\"id\": 4,\"code\": \"savings.interest.posting.period.savingsPostingInterestPeriodType.monthly\",\"value\": \"Monthly\"}," +
  33. "\"interestCalculationType\": {\"id\": 1,\"code\": \"savingsInterestCalculationType.dailybalance\",\"value\": \"Daily Balance\"},\"interestCalculationDaysInYearType\": {" +
  34. "\"id\": 365,\"code\": \"savingsInterestCalculationDaysInYearType.days365\",\"value\": \"365 Days\"},\"minRequiredOpeningBalance\": 1200.000000,\"withdrawalFeeForTransfers\": true," +
  35. "\"summary\": {\"currency\": {\"code\": \"USD\",\"name\": \"US Dollar\",\"decimalPlaces\": 2,\"displaySymbol\": \"$\",\"nameCode\": \"currency.USD\",\"displayLabel\": \"US Dollar ($)\"}," +
  36. "\"totalDeposits\": 1300.000000,\"totalWithdrawals\": 200.000000,\"totalInterestEarned\": 19.830000,\"totalInterestPosted\": 15.910000,\"accountBalance\": 1115.910000}}]}");
  37. Mockito.when(restClient.get("clients?limit=-1")).thenReturn("{\"totalFilteredRecords\": 2,\"pageItems\": [{\"id\": 1,\"accountNo\": \"000000001\"," +
  38. "\"status\": {\"id\": 300,\"code\": \"clientStatusType.active\",\"value\": \"Active\"},\"active\": true,\"activationDate\": [2013,7,1]," +
  39. "\"firstname\": \"Arsene\",\"middlename\": \"K\",\"lastname\": \"Wenger\",\"displayName\": \"Arsene K Wenger\",\"officeId\": 1," +
  40. "\"officeName\": \"Head Office\",\"staffId\": 1,\"staffName\": \"Chatta, Sahil\"},{\"id\": 2,\"accountNo\": \"000000002\"," +
  41. "\"status\": {\"id\": 300,\"code\": \"clientStatusType.active\",\"value\": \"Active\"},\"active\": true,\"activationDate\": [2013,7,1]," +
  42. "\"firstname\": \"Billy\",\"middlename\": \"T\",\"lastname\": \"Bob\",\"displayName\": \"Billy T Bob\",\"officeId\": 2,\"officeName\": \"Office1\"," +
  43. "\"staffId\": 2,\"staffName\": \"Dzeko, Edin\"}]}");
  44. Mockito.when(restClient.get("offices?limit=-1")).thenReturn("[{\"id\":1,\"name\":\"Head Office\",\"nameDecorated\":\"Head Office\",\"externalId\": \"1\"," +
  45. "\"openingDate\":[2009,1,1],\"hierarchy\": \".\"},{\"id\": 2,\"name\": \"Office1\",\"nameDecorated\": \"....Office1\",\"openingDate\":[2013,4,1]," +
  46. "\"hierarchy\": \".2.\",\"parentId\": 1,\"parentName\": \"Head Office\"}]");
  47. Mockito.when(restClient.get("funds")).thenReturn("[{\"id\": 1,\"name\": \"Fund1\"}]");
  48. Mockito.when(restClient.get("codes/12/codevalues")).thenReturn("[{\"id\": 10,\"name\": \"Cash\",\"position\": 1},{\"id\": 11,\"name\": \"MPesa\",\"position\": 2}]");
  49. SavingsTransactionWorkbookPopulator savingsTransactionWorkbookPopulator = new SavingsTransactionWorkbookPopulator(restClient,
  50. new OfficeSheetPopulator(restClient), new ClientSheetPopulator(restClient), new ExtrasSheetPopulator(restClient));
  51. savingsTransactionWorkbookPopulator.downloadAndParse();
  52. Workbook savingsTransactionWorkbook = new HSSFWorkbook();
  53. Result result = savingsTransactionWorkbookPopulator.populate(savingsTransactionWorkbook);
  54. Assert.assertTrue(result.isSuccess());
  55. Mockito.verify(restClient, Mockito.atLeastOnce()).get("savingsaccounts?limit=-1");
  56. Mockito.verify(restClient, Mockito.atLeastOnce()).get("clients?limit=-1");
  57. Mockito.verify(restClient, Mockito.atLeastOnce()).get("offices?limit=-1");
  58. Mockito.verify(restClient, Mockito.atLeastOnce()).get("funds");
  59. Mockito.verify(restClient, Mockito.atLeastOnce()).get("codes/12/codevalues");
  60. Sheet savingsTransactionSheet = savingsTransactionWorkbook.getSheet("SavingsTransaction");
  61. Row row = savingsTransactionSheet.getRow(0);
  62. //If test fails, also check if column letters embedded in formulas in setDefault and setRules have changed or not.
  63. Assert.assertEquals("Office Name*", row.getCell(0).getStringCellValue());
  64. Assert.assertEquals("Client Name*", row.getCell(1).getStringCellValue());
  65. Assert.assertEquals("Account No.*", row.getCell(2).getStringCellValue());
  66. Assert.assertEquals("Product Name", row.getCell(3).getStringCellValue());
  67. Assert.assertEquals("Opening Balance", row.getCell(4).getStringCellValue());
  68. Assert.assertEquals("Transaction Type*", row.getCell(5).getStringCellValue());
  69. Assert.assertEquals("Amount*", row.getCell(6).getStringCellValue());
  70. Assert.assertEquals("Date*", row.getCell(7).getStringCellValue());
  71. Assert.assertEquals("Type*", row.getCell(8).getStringCellValue());
  72. Assert.assertEquals("Account No", row.getCell(9).getStringCellValue());
  73. Assert.assertEquals("Check No", row.getCell(10).getStringCellValue());
  74. Assert.assertEquals("Routing Code", row.getCell(11).getStringCellValue());
  75. Assert.assertEquals("Receipt No", row.getCell(12).getStringCellValue());
  76. Assert.assertEquals("Bank No", row.getCell(13).getStringCellValue());
  77. Assert.assertEquals("Lookup Client", row.getCell(LOOKUP_CLIENT_NAME_COL).getStringCellValue());
  78. Assert.assertEquals("Lookup Account", row.getCell(LOOKUP_ACCOUNT_NO_COL).getStringCellValue());
  79. Assert.assertEquals("Lookup Product", row.getCell(LOOKUP_PRODUCT_COL).getStringCellValue());
  80. Assert.assertEquals("Lookup Opening Balance", row.getCell(LOOKUP_OPENING_BALANCE_COL).getStringCellValue());
  81. //Lookup Table test
  82. row = savingsTransactionSheet.getRow(1);
  83. Assert.assertEquals("Arsene K Wenger(1)", row.getCell(LOOKUP_CLIENT_NAME_COL).getStringCellValue());
  84. Assert.assertEquals("6.0", ((Double)row.getCell(LOOKUP_ACCOUNT_NO_COL).getNumericCellValue()).toString());
  85. Assert.assertEquals("SP1", row.getCell(LOOKUP_PRODUCT_COL).getStringCellValue());
  86. Assert.assertEquals("1200.0", ((Double)row.getCell(LOOKUP_OPENING_BALANCE_COL).getNumericCellValue()).toString());
  87. }
  88. }