all modules populate & import
Project: http://git-wip-us.apache.org/repos/asf/fineract/repo Commit: http://git-wip-us.apache.org/repos/asf/fineract/commit/210647d4 Tree: http://git-wip-us.apache.org/repos/asf/fineract/tree/210647d4 Diff: http://git-wip-us.apache.org/repos/asf/fineract/diff/210647d4 Branch: refs/heads/develop Commit: 210647d4158f8bffe49708a22efebd0ab500244e Parents: d6accae Author: unknown <[email protected]> Authored: Wed Dec 6 18:32:51 2017 +0530 Committer: unknown <[email protected]> Committed: Wed Dec 6 18:32:51 2017 +0530 ---------------------------------------------------------------------- fineract-provider/dependencies.gradle | 2 +- fineract-provider/dev-dependencies.gradle | 2 +- .../client/ClientEntityImportHandlerTest.java | 147 ++++ .../loan/LoanImportHandlerTest.java | 177 +++++ .../office/OfficeImportHandlerTest.java | 102 +++ .../savings/SavingsImportHandlerTest.java | 156 +++++ .../ClientEntityWorkbookPopulatorTest.java | 83 +++ .../loan/LoanWorkbookPopulatorTest.java | 129 ++++ .../office/OfficeWorkBookPopulatorTest.java | 64 ++ .../savings/SavingsWorkbookPopulateTest.java | 112 +++ .../integrationtests/common/ClientHelper.java | 33 + .../integrationtests/common/OfficeHelper.java | 33 + .../fineract/integrationtests/common/Utils.java | 40 +- .../common/loans/LoanTransactionHelper.java | 36 + .../common/savings/SavingsAccountHelper.java | 33 + .../common/savings/SavingsProductHelper.java | 2 +- .../glaccount/api/GLAccountsApiResource.java | 35 +- .../glaccount/data/GLAccountData.java | 50 ++ .../glaccount/domain/GLAccountType.java | 23 + .../GLAccountReadPlatformServiceImpl.java | 12 +- .../api/JournalEntriesApiResource.java | 37 +- .../journalentry/data/CreditDebit.java | 31 + .../journalentry/data/JournalEntryData.java | 87 +++ .../bulkimport/api/BulkImportApiResource.java | 114 ++++ .../bulkimport/constants/CenterConstants.java | 51 ++ .../constants/ChartOfAcountsConstants.java | 38 ++ .../constants/ClientEntityConstants.java | 61 ++ .../constants/ClientPersonConstants.java | 58 ++ .../constants/FixedDepositConstants.java | 55 ++ .../bulkimport/constants/GroupConstants.java | 47 ++ .../constants/GuarantorConstants.java | 45 ++ .../constants/JournalEntryConstants.java | 49 ++ .../bulkimport/constants/LoanConstants.java | 75 +++ .../constants/LoanRepaymentConstants.java | 44 ++ .../bulkimport/constants/OfficeConstants.java | 33 + .../constants/RecurringDepositConstants.java | 60 ++ .../bulkimport/constants/SavingsConstants.java | 57 ++ .../constants/SharedAccountsConstants.java | 45 ++ .../bulkimport/constants/StaffConstants.java | 32 + .../TemplatePopulateImportConstants.java | 143 ++++ .../constants/TransactionConstants.java | 43 ++ .../bulkimport/constants/UserConstants.java | 34 + .../bulkimport/data/BulkImportEvent.java | 71 ++ .../infrastructure/bulkimport/data/Count.java | 45 ++ .../bulkimport/data/GlobalEntityType.java | 118 ++++ .../bulkimport/data/ImportData.java | 80 +++ .../bulkimport/data/ImportFormatType.java | 49 ++ .../bulkimport/domain/ImportDocument.java | 124 ++++ .../domain/ImportDocumentRepository.java | 27 + .../exceptions/ImportTypeNotFoundException.java | 29 + .../bulkimport/importhandler/ImportHandler.java | 27 + .../importhandler/ImportHandlerUtils.java | 355 ++++++++++ .../center/CenterImportHandler.java | 259 +++++++ .../ChartOfAccountsImportHandler.java | 143 ++++ .../client/ClientEntityImportHandler.java | 212 ++++++ .../client/ClientPersonImportHandler.java | 197 ++++++ .../FixedDepositImportHandler.java | 390 +++++++++++ .../FixedDepositTransactionImportHandler.java | 150 +++++ .../importhandler/group/GroupImportHandler.java | 257 +++++++ .../guarantor/GuarantorImportHandler.java | 151 +++++ .../helper/ClientIdSerializer.java | 38 ++ .../helper/CodeValueDataIdSerializer.java | 34 + .../helper/CurrencyDateCodeSerializer.java | 34 + .../importhandler/helper/DateSerializer.java | 41 ++ .../helper/EnumOptionDataIdSerializer.java | 34 + .../helper/EnumOptionDataValueSerializer.java | 34 + .../importhandler/helper/GroupIdSerializer.java | 37 + ...gsAccountTransactionEnumValueSerialiser.java | 35 + .../JournalEntriesImportHandler.java | 226 +++++++ .../importhandler/loan/LoanImportHandler.java | 464 +++++++++++++ .../LoanRepaymentImportHandler.java | 134 ++++ .../office/OfficeImportHandler.java | 123 ++++ .../RecurringDepositImportHandler.java | 372 ++++++++++ ...ecurringDepositTransactionImportHandler.java | 157 +++++ .../savings/SavingsImportHandler.java | 364 ++++++++++ .../SavingsTransactionImportHandler.java | 152 +++++ .../SharedAccountImportHandler.java | 174 +++++ .../importhandler/staff/StaffImportHandler.java | 124 ++++ .../importhandler/users/UserImportHandler.java | 137 ++++ .../populator/AbstractWorkbookPopulator.java | 161 +++++ .../populator/CenterSheetPopulator.java | 123 ++++ .../populator/ClientSheetPopulator.java | 144 ++++ .../populator/ExtrasSheetPopulator.java | 116 ++++ .../FixedDepositProductSheetPopulator.java | 173 +++++ .../populator/GlAccountSheetPopulator.java | 71 ++ .../populator/GroupSheetPopulator.java | 126 ++++ .../populator/LoanProductSheetPopulator.java | 199 ++++++ .../populator/OfficeSheetPopulator.java | 82 +++ .../populator/PersonnelSheetPopulator.java | 131 ++++ .../RecurringDepositProductSheetPopulator.java | 190 ++++++ .../populator/RoleSheetPopulator.java | 67 ++ .../populator/SavingsAccountSheetPopulator.java | 84 +++ .../populator/SavingsProductSheetPopulator.java | 136 ++++ .../populator/SharedProductsSheetPopulator.java | 159 +++++ .../bulkimport/populator/WorkbookPopulator.java | 27 + .../centers/CentersWorkbookPopulator.java | 235 +++++++ .../ChartOfAccountsWorkbook.java | 236 +++++++ .../client/ClientEntityWorkbookPopulator.java | 405 +++++++++++ .../client/ClientPersonWorkbookPopulator.java | 370 ++++++++++ .../LoanComparatorByStatusActive.java | 52 ++ ...ixedDepositTransactionWorkbookPopulator.java | 235 +++++++ .../FixedDepositWorkbookPopulator.java | 349 ++++++++++ .../group/GroupsWorkbookPopulator.java | 254 +++++++ .../guarantor/GuarantorWorkbookPopulator.java | 314 +++++++++ .../JournalEntriesWorkbookPopulator.java | 191 ++++++ .../populator/loan/LoanWorkbookPopulator.java | 565 ++++++++++++++++ .../LoanRepaymentWorkbookPopulator.java | 277 ++++++++ .../office/OfficeWorkbookPopulator.java | 114 ++++ ...ringDepositTransactionWorkbookPopulator.java | 242 +++++++ .../RecurringDepositWorkbookPopulator.java | 404 +++++++++++ .../SavingsTransactionsWorkbookPopulator.java | 240 +++++++ .../savings/SavingsWorkbookPopulator.java | 411 +++++++++++ .../SharedAccountWorkBookPopulator.java | 240 +++++++ .../populator/staff/StaffWorkbookPopulator.java | 120 ++++ .../populator/users/UserWorkbookPopulator.java | 133 ++++ .../service/BulkImportEventListener.java | 174 +++++ .../BulkImportWorkbookPopulatorService.java | 26 + .../BulkImportWorkbookPopulatorServiceImpl.java | 674 +++++++++++++++++++ .../service/BulkImportWorkbookService.java | 40 ++ .../service/BulkImportWorkbookServiceImpl.java | 296 ++++++++ .../codes/data/CodeValueData.java | 9 + .../data/PaginationParametersDataValidator.java | 37 +- .../service/DocumentWritePlatformService.java | 5 + ...ntWritePlatformServiceJpaRepositoryImpl.java | 18 +- .../monetary/data/CurrencyData.java | 14 + .../office/api/OfficesApiResource.java | 34 +- .../organisation/office/data/OfficeData.java | 31 + .../service/OfficeReadPlatformServiceImpl.java | 16 +- .../staff/api/StaffApiResource.java | 36 +- .../organisation/staff/data/StaffData.java | 36 + .../service/StaffReadPlatformServiceImpl.java | 16 +- .../accounts/api/AccountsApiResource.java | 35 +- .../portfolio/address/data/AddressData.java | 32 + .../portfolio/calendar/data/CalendarData.java | 121 +++- .../portfolio/charge/data/ChargeData.java | 12 + .../client/api/ClientApiConstants.java | 1 + .../client/api/ClientsApiResource.java | 33 +- .../portfolio/client/data/ClientData.java | 219 ++++++ .../client/data/ClientNonPersonData.java | 26 + .../service/ClientReadPlatformServiceImpl.java | 41 +- .../fineract/portfolio/fund/data/FundData.java | 8 + .../portfolio/group/api/CentersApiResource.java | 32 +- .../portfolio/group/api/GroupsApiResource.java | 36 +- .../portfolio/group/data/CenterData.java | 54 ++ .../portfolio/group/data/GroupGeneralData.java | 99 +++ .../service/CenterReadPlatformServiceImpl.java | 97 +-- .../service/GroupReadPlatformServiceImpl.java | 108 +-- .../loanaccount/api/LoansApiResource.java | 53 +- .../loanaccount/data/DisbursementData.java | 33 + .../loanaccount/data/LoanAccountData.java | 392 +++++++++++ .../loanaccount/data/LoanApprovalData.java | 22 + .../loanaccount/data/LoanTransactionData.java | 111 +++ .../guarantor/api/GuarantorsApiResource.java | 34 +- .../guarantor/data/GuarantorData.java | 64 ++ .../service/LoanReadPlatformServiceImpl.java | 62 +- .../loanproduct/data/LoanProductData.java | 24 + .../paymenttype/data/PaymentTypeData.java | 8 + .../api/FixedDepositAccountsApiResource.java | 53 +- .../RecurringDepositAccountsApiResource.java | 54 +- .../savings/api/SavingsAccountsApiResource.java | 53 +- .../savings/data/ClosingOfSavingsAccounts.java | 102 +++ .../savings/data/DepositAccountData.java | 53 ++ .../savings/data/DepositProductData.java | 47 +- .../savings/data/FixedDepositAccountData.java | 64 ++ .../savings/data/FixedDepositProductData.java | 48 ++ .../data/RecurringDepositAccountData.java | 77 +++ .../data/RecurringDepositProductData.java | 59 ++ .../SavingsAccountApplicationTimelineData.java | 4 + .../savings/data/SavingsAccountChargeData.java | 25 + .../savings/data/SavingsAccountData.java | 221 +++++- .../data/SavingsAccountTransactionData.java | 68 ++ .../savings/data/SavingsActivation.java | 60 ++ .../portfolio/savings/data/SavingsApproval.java | 67 ++ .../savings/data/SavingsProductData.java | 58 +- .../savings/domain/DepositTermDetail.java | 1 + .../SavingsAccountReadPlatformServiceImpl.java | 52 +- .../data/ShareAccountChargeData.java | 21 + .../shareaccounts/data/ShareAccountData.java | 71 ++ .../api/UsersApiResource.java | 58 +- .../useradministration/data/AppUserData.java | 40 ++ .../useradministration/data/RoleData.java | 8 + .../core_db/V336__m_import_document.sql | 39 ++ 182 files changed, 19653 insertions(+), 253 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/dependencies.gradle ---------------------------------------------------------------------- diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle index 562e767..27a256c 100644 --- a/fineract-provider/dependencies.gradle +++ b/fineract-provider/dependencies.gradle @@ -85,7 +85,7 @@ dependencies { [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'], [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'], [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'], - + [group: 'org.apache.tika', name: 'tika-core', version :'1.9'], // Although fineract (at the time of writing) doesn't have any compile time dep. on this, // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'], http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/dev-dependencies.gradle ---------------------------------------------------------------------- diff --git a/fineract-provider/dev-dependencies.gradle b/fineract-provider/dev-dependencies.gradle index 80c8f49..710314d 100644 --- a/fineract-provider/dev-dependencies.gradle +++ b/fineract-provider/dev-dependencies.gradle @@ -84,7 +84,7 @@ dependencies { [group: 'net.sf.ehcache', name: 'ehcache', version: '2.7.2'], [group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.12'], [group: 'com.jayway.jsonpath', name: 'json-path', version: '0.9.1'], - + [group: 'org.apache.tika', name: 'tika-core', version :'1.9'], // Although fineract (at the time of writing) doesn't have any compile time dep. on this, // it's useful to have this for the Spring Boot TestRestTemplate http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-rest-templates-test-utility [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.5'], http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java new file mode 100644 index 0000000..b2038e8 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/client/ClientEntityImportHandlerTest.java @@ -0,0 +1,147 @@ +/** + * 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.bulkimport.importhandler.client; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.system.CodeHelper; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ClientEntityImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testClientImport() throws InterruptedException, IOException, ParseException { + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper columns in client entity sheet + CodeHelper codeHelper=new CodeHelper(); + //create constitution + codeHelper.retrieveOrCreateCodeValue(24,requestSpec,responseSpec); + //create client classification + codeHelper.retrieveOrCreateCodeValue(17,requestSpec,responseSpec); + //create client types + codeHelper.retrieveOrCreateCodeValue(16,requestSpec,responseSpec); + //create Address types + codeHelper.retrieveOrCreateCodeValue(29,requestSpec,responseSpec); + //create State + codeHelper.retrieveOrCreateCodeValue(27,requestSpec,responseSpec); + //create Country + codeHelper.retrieveOrCreateCodeValue(28,requestSpec,responseSpec); + //create Main business line + codeHelper.retrieveOrCreateCodeValue(25,requestSpec,responseSpec); + + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy"); + + //insert dummy data into client entity sheet + Sheet clientEntitySheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + Row firstClientRow=clientEntitySheet.getRow(1); + firstClientRow.createCell(ClientEntityConstants.NAME_COL).setCellValue(Utils.randomNameGenerator("C_E_",6)); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstClientRow.createCell(ClientEntityConstants.OFFICE_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(0).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.STAFF_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date incoporationDate=simpleDateFormat.parse("14 May 2001"); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_DATE_COL).setCellValue(incoporationDate); + Date validTill=simpleDateFormat.parse("14 May 2019"); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_VALID_TILL_COL).setCellValue(validTill); + firstClientRow.createCell(ClientEntityConstants.MOBILE_NO_COL).setCellValue(Utils.randomNumberGenerator(7)); + firstClientRow.createCell(ClientEntityConstants.CLIENT_TYPE_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_TYPES).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.CLIENT_CLASSIFICATION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.INCOPORATION_NUMBER_COL).setCellValue(Utils.randomNumberGenerator(6)); + firstClientRow.createCell(ClientEntityConstants.MAIN_BUSINESS_LINE).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.CONSTITUTION_COL).setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CONSTITUTION_COL).getStringCellValue()); + firstClientRow.createCell(ClientEntityConstants.ACTIVE_COL).setCellValue("False"); + Date submittedDate=simpleDateFormat.parse("28 September 2017"); + firstClientRow.createCell(ClientEntityConstants.SUBMITTED_ON_COL).setCellValue(submittedDate); + firstClientRow.createCell(ClientEntityConstants.ADDRESS_ENABLED).setCellValue("False"); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\client"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\ClientEntity.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=clientHelper.importClientEntityTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=clientHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook outputWorkbook=new HSSFWorkbook(fileInputStream); + Sheet outputClientEntitySheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME); + Row row= outputClientEntitySheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(ClientEntityConstants.STATUS_COL).getStringCellValue()); + + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java new file mode 100644 index 0000000..72ddeb8 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/loan/LoanImportHandlerTest.java @@ -0,0 +1,177 @@ +/** + * 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.bulkimport.importhandler.loan; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.*; +import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class LoanImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testLoanImport() throws InterruptedException, IOException, ParseException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec); + LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder(); + String jsonLoanProduct=loanProductTestBuilder.build(null); + Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct); + Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion); + + FundsResourceHandler fundsResourceHandler=new FundsResourceHandler(); + String jsonFund="{\n" + + "\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" + + "}"; + Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation); + + PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper(); + String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); + String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); + Boolean isCashPayment = true; + Integer position = 1; + Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position); + Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation); + + Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy"); + + //insert dummy data into loan Sheet + Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME); + Row firstLoanRow=loanSheet.getRow(1); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TYPE_COL).setCellValue("Individual"); + firstLoanRow.createCell(LoanConstants.CLIENT_NAME_COL).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(loanSheet.getRow(1).getCell(LoanConstants.LOOKUP_CLIENT_EXTERNAL_ID).getStringCellValue()); + Sheet loanProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductSheet.getRow(1).getCell(1).getStringCellValue()); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("13 May 2017"); + firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(date); + Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + firstLoanRow.createCell(LoanConstants.DISBURSED_PAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(extrasSheet.getRow(1).getCell(1).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductSheet.getRow(1).getCell(3).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.NO_OF_REPAYMENTS_COL).setCellValue(loanProductSheet.getRow(1).getCell(6).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.REPAID_EVERY_COL).setCellValue(loanProductSheet.getRow(1).getCell(9).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.REPAID_EVERY_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TERM_COL).setCellValue(loanProductSheet.getRow(1).getCell(8).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.LOAN_TERM_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_COL).setCellValue(loanProductSheet.getRow(1).getCell(11).getNumericCellValue()); + firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL).setCellValue(loanProductSheet.getRow(1).getCell(14).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.AMORTIZATION_COL).setCellValue(loanProductSheet.getRow(1).getCell(15).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.INTEREST_METHOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(16).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.INTEREST_CALCULATION_PERIOD_COL).setCellValue(loanProductSheet.getRow(1).getCell(17).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.ARREARS_TOLERANCE_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL).setCellValue(loanProductSheet.getRow(1).getCell(19).getStringCellValue()); + firstLoanRow.createCell(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL).setCellValue(0); + firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.TOTAL_AMOUNT_REPAID_COL).setCellValue(6000); + firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(date); + firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(extrasSheet.getRow(1).getCell(3).getStringCellValue()); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\loan"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Loan.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=loanTransactionHelper.importLoanTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=loanTransactionHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook Outputworkbook=new HSSFWorkbook(fileInputStream); + Sheet outputLoanSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME); + Row row= outputLoanSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(LoanConstants.STATUS_COL).getStringCellValue()); + + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java new file mode 100644 index 0000000..e4dd0aa --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/office/OfficeImportHandlerTest.java @@ -0,0 +1,102 @@ +/** + * 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.bulkimport.importhandler.office; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.populator.AbstractWorkbookPopulator; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.organisation.office.domain.Office; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.*; +import java.lang.reflect.Field; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class OfficeImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testOfficeImport() throws IOException, InterruptedException, NoSuchFieldException, ParseException { + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy"); + + //insert dummy data into excel + Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow= sheet.getRow(1); + firstOfficeRow.createCell(OfficeConstants.OFFICE_NAME_COL).setCellValue(Utils.randomNameGenerator("Test_Off_",6)); + firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_NAME_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue()); + firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_ID_COL).setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("14 May 2001"); + firstOfficeRow.createCell(OfficeConstants.OPENED_ON_COL).setCellValue(date); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\office"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Office.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=officeHelper.importOfficeTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + // Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=officeHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook outputWorkbook=new HSSFWorkbook(fileInputStream); + Sheet officeSheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row row= officeSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(OfficeConstants.STATUS_COL).getStringCellValue()); + + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java new file mode 100644 index 0000000..c26594d --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/importhandler/savings/SavingsImportHandlerTest.java @@ -0,0 +1,156 @@ +/** + * 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.bulkimport.importhandler.savings; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.GroupHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; +import org.apache.fineract.template.domain.Template; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.*; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class SavingsImportHandlerTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testSavingsImport() throws InterruptedException, IOException, ParseException { + + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + SavingsProductHelper savingsProductHelper=new SavingsProductHelper(); + String jsonSavingsProduct=savingsProductHelper.build(); + Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction); + + SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec); + Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy"); + + //insert dummy data into Savings sheet + Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + Row firstSavingsRow=savingsSheet.getRow(1); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.OFFICE_NAME_COL).setCellValue(officeSheet.getRow(1).getCell(1).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.SAVINGS_TYPE_COL).setCellValue("Individual"); + firstSavingsRow.createCell(SavingsConstants.CLIENT_NAME_COL).setCellValue(savingsSheet.getRow(1).getCell(SavingsConstants.LOOKUP_CLIENT_NAME_COL).getStringCellValue()); + Sheet savingsProductSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.PRODUCT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(1).getStringCellValue()); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + firstSavingsRow.createCell(SavingsConstants.FIELD_OFFICER_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue()); + SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd MMMM yyyy"); + Date date=simpleDateFormat.parse("13 May 2017"); + firstSavingsRow.createCell(SavingsConstants.SUBMITTED_ON_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.APPROVED_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.ACTIVATION_DATE_COL).setCellValue(date); + firstSavingsRow.createCell(SavingsConstants.CURRENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(10).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.DECIMAL_PLACES_COL).setCellValue(savingsProductSheet.getRow(1).getCell(11).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.IN_MULTIPLES_OF_COL).setCellValue(savingsProductSheet.getRow(1).getCell(12).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(2).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(3).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_POSTING_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(4).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_COL).setCellValue(savingsProductSheet.getRow(1).getCell(5).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL).setCellValue(savingsProductSheet.getRow(1).getCell(6).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.MIN_OPENING_BALANCE_COL).setCellValue(savingsProductSheet.getRow(1).getCell(7).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_COL).setCellValue(savingsProductSheet.getRow(1).getCell(8).getNumericCellValue()); + firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL).setCellValue(savingsProductSheet.getRow(1).getCell(9).getStringCellValue()); + firstSavingsRow.createCell(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS).setCellValue("False"); + firstSavingsRow.createCell(SavingsConstants.ALLOW_OVER_DRAFT_COL).setCellValue("False"); + firstSavingsRow.createCell(SavingsConstants.OVER_DRAFT_LIMIT_COL).setCellValue(savingsProductSheet.getRow(1).getCell(15).getNumericCellValue()); + + String currentdirectory = new File("").getAbsolutePath(); + File directory=new File(currentdirectory+"\\src\\integrationTest\\" + + "resources\\bulkimport\\importhandler\\savings"); + if (!directory.exists()) + directory.mkdirs(); + File file= new File(directory+"\\Savings.xls"); + OutputStream outputStream=new FileOutputStream(file); + workbook.write(outputStream); + outputStream.close(); + + String importDocumentId=savingsAccountHelper.importSavingsTemplate(file); + file.delete(); + Assert.assertNotNull(importDocumentId); + + //Wait for the creation of output excel + Thread.sleep(3000); + + //check status column of output excel + String location=savingsAccountHelper.getOutputTemplateLocation(importDocumentId); + FileInputStream fileInputStream = new FileInputStream(location); + Workbook Outputworkbook=new HSSFWorkbook(fileInputStream); + Sheet OutputSavingsSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME); + Row row= OutputSavingsSheet.getRow(1); + Assert.assertEquals("Imported",row.getCell(SavingsConstants.STATUS_COL).getStringCellValue()); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java new file mode 100644 index 0000000..27e34b7 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/client/ClientEntityWorkbookPopulatorTest.java @@ -0,0 +1,83 @@ +/** + * 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.bulkimport.populator.client; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class ClientEntityWorkbookPopulatorTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + + + } + + @Test + public void testClientEntityWorkbookPopulate() throws IOException { + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Workbook workbook=clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY,"dd MMMM yyyy"); + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found for given OfficeId ",firstOfficeRow.getCell(1)); + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found for given staffId",firstStaffRow.getCell(1)); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java new file mode 100644 index 0000000..3ba92a6 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/loan/LoanWorkbookPopulatorTest.java @@ -0,0 +1,129 @@ +/** + * 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.bulkimport.populator.loan; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; +import org.apache.fineract.integrationtests.common.*; +import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler; +import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; +import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class LoanWorkbookPopulatorTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + @Test + public void testLoanWorkbookPopulate() throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + LoanTransactionHelper loanTransactionHelper=new LoanTransactionHelper(requestSpec,responseSpec); + LoanProductTestBuilder loanProductTestBuilder=new LoanProductTestBuilder(); + String jsonLoanProduct=loanProductTestBuilder.build(null); + Integer outcome_lp_creaion=loanTransactionHelper.getLoanProductId(jsonLoanProduct); + Assert.assertNotNull("Could not create Loan Product" ,outcome_lp_creaion); + + FundsResourceHandler fundsResourceHandler=new FundsResourceHandler(); + String jsonFund="{\n" + + "\t\"name\": \""+Utils.randomNameGenerator("Fund_Name",9)+"\"\n" + + "}"; + Integer outcome_fund_creation=fundsResourceHandler.createFund(jsonFund,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Fund" ,outcome_fund_creation); + + PaymentTypeHelper paymentTypeHelper=new PaymentTypeHelper(); + String name = PaymentTypeHelper.randomNameGenerator("P_T", 5); + String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15); + Boolean isCashPayment = true; + Integer position = 1; + Integer outcome_payment_creation= paymentTypeHelper.createPaymentType(requestSpec, responseSpec,name,description,isCashPayment,position); + Assert.assertNotNull("Could not create payment type" ,outcome_payment_creation); + + Workbook workbook=loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy"); + + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1)); + + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME); + Row firstClientRow=clientSheet.getRow(1); + Assert.assertNotNull("No clients found ",firstClientRow.getCell(1)); + + Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Row firstGroupRow=groupSheet.getRow(1); + Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1)); + + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1)); + + Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + Row firstProductRow=productSheet.getRow(1); + Assert.assertNotNull("No products found ",firstProductRow.getCell(1)); + + Sheet extrasSheet=workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME); + Row firstExtrasRow=extrasSheet.getRow(1); + Assert.assertNotNull("No Extras found ",firstExtrasRow.getCell(1)); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java new file mode 100644 index 0000000..b878b48 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/office/OfficeWorkBookPopulatorTest.java @@ -0,0 +1,64 @@ +/** + * 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.bulkimport.populator.office; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; + +public class OfficeWorkBookPopulatorTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testOfficeWorkbookPopulate() throws IOException { + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Workbook workbook=officeHelper.getOfficeWorkBook("dd MMMM yyyy"); + Sheet sheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstRow= sheet.getRow(1); + Assert.assertNotNull("No parent offices found",firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue()); + Assert.assertEquals(1,firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue(),0.0); + + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java new file mode 100644 index 0000000..29ea6c4 --- /dev/null +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/bulkimport/populator/savings/SavingsWorkbookPopulateTest.java @@ -0,0 +1,112 @@ +/** + * 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.bulkimport.populator.savings; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants; +import org.apache.fineract.integrationtests.common.ClientHelper; +import org.apache.fineract.integrationtests.common.GroupHelper; +import org.apache.fineract.integrationtests.common.OfficeHelper; +import org.apache.fineract.integrationtests.common.Utils; +import org.apache.fineract.integrationtests.common.organisation.StaffHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper; +import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import java.io.IOException; + +public class SavingsWorkbookPopulateTest { + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + + @Before + public void setup(){ + Utils.initializeRESTAssured(); + this.requestSpec=new RequestSpecBuilder().build(); + this.requestSpec + .header("Authorization", + "Basic " + + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + } + + @Test + public void testSavingsWorkbookPopulate() throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + //in order to populate helper sheets + OfficeHelper officeHelper=new OfficeHelper(requestSpec,responseSpec); + Integer outcome_office_creation=officeHelper.createOffice("02 May 2000"); + Assert.assertNotNull("Could not create office" ,outcome_office_creation); + + //in order to populate helper sheets + ClientHelper clientHelper=new ClientHelper(requestSpec,responseSpec); + Integer outcome_client_creation=clientHelper.createClient(requestSpec,responseSpec); + Assert.assertNotNull("Could not create client" ,outcome_client_creation); + + //in order to populate helper sheets + GroupHelper groupHelper=new GroupHelper(requestSpec,responseSpec); + Integer outcome_group_creation=groupHelper.createGroup(requestSpec,responseSpec,true); + Assert.assertNotNull("Could not create group" ,outcome_group_creation); + + //in order to populate helper sheets + StaffHelper staffHelper=new StaffHelper(); + Integer outcome_staff_creation =staffHelper.createStaff(requestSpec,responseSpec); + Assert.assertNotNull("Could not create staff",outcome_staff_creation); + + SavingsProductHelper savingsProductHelper=new SavingsProductHelper(); + String jsonSavingsProduct=savingsProductHelper.build(); + Integer outcome_sp_creaction=savingsProductHelper.createSavingsProduct(jsonSavingsProduct,requestSpec,responseSpec); + Assert.assertNotNull("Could not create Savings product",outcome_sp_creaction); + + SavingsAccountHelper savingsAccountHelper=new SavingsAccountHelper(requestSpec,responseSpec); + Workbook workbook=savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy"); + + Sheet officeSheet=workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME); + Row firstOfficeRow=officeSheet.getRow(1); + Assert.assertNotNull("No offices found ",firstOfficeRow.getCell(1)); + + Sheet clientSheet=workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME); + Row firstClientRow=clientSheet.getRow(1); + Assert.assertNotNull("No clients found ",firstClientRow.getCell(1)); + + Sheet groupSheet=workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME); + Row firstGroupRow=groupSheet.getRow(1); + Assert.assertNotNull("No groups found ",firstGroupRow.getCell(1)); + + Sheet staffSheet=workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME); + Row firstStaffRow=staffSheet.getRow(1); + Assert.assertNotNull("No staff found ",firstStaffRow.getCell(1)); + + Sheet productSheet=workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME); + Row firstProductRow=productSheet.getRow(1); + Assert.assertNotNull("No products found ",firstProductRow.getCell(1)); + + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java index e79820b..1fb2b4d 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ClientHelper.java @@ -20,15 +20,25 @@ package org.apache.fineract.integrationtests.common; import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; import org.apache.fineract.integrationtests.common.system.CodeHelper; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; public class ClientHelper { @@ -591,4 +601,27 @@ public class ClientHelper { return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "reversed"); } + public Workbook getClientEntityWorkbook(GlobalEntityType clientsEntity, String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte [] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,CLIENT_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&legalFormType="+clientsEntity+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } + + public String importClientEntityTemplate(File file){ + String locale="en"; + String dateFormat="dd MMMM yyyy"; + String legalFormType=GlobalEntityType.CLIENTS_ENTTTY.toString(); + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,CLIENT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + legalFormType,file,locale,dateFormat); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java index 1571735..2940576 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/OfficeHelper.java @@ -18,6 +18,10 @@ */ package org.apache.fineract.integrationtests.common; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import com.google.common.reflect.TypeToken; @@ -25,6 +29,12 @@ import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + public class OfficeHelper { private static final String OFFICE_URL = "/fineract-provider/api/v1/offices"; @@ -77,4 +87,27 @@ public class OfficeHelper { System.out.println("map : " + map); return new Gson().toJson(map); } + + public String importOfficeTemplate(File file){ + String locale="en"; + String dateFormat="dd MMMM yyyy"; + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,OFFICE_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + null,file,locale,dateFormat); + + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } + public Workbook getOfficeWorkBook(final String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,OFFICE_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } } http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java index 3d173c3..5a7c127 100644 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/Utils.java @@ -24,13 +24,11 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import java.io.File; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Locale; -import java.util.Random; -import java.util.TimeZone; +import java.util.*; import org.apache.commons.lang.StringUtils; import org.apache.http.conn.HttpHostConnectException; @@ -41,7 +39,6 @@ import com.jayway.restassured.RestAssured; import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; - /** * Util for RestAssured tests. This class here in src/integrationTest is * copy/pasted to src/test; please keep them in sync. @@ -145,6 +142,16 @@ public class Utils { public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) { return randomStringGenerator(prefix, lenOfRandomSuffix); } + public static Long randomNumberGenerator(final int expectedLength){ + final String source="1234567890"; + final int lengthofSource=source.length(); + final Random random=new Random(); + StringBuilder stringBuilder=new StringBuilder(expectedLength); + for (int i = 0; i < expectedLength; i++) { + stringBuilder.append(source.charAt(random.nextInt(lengthofSource))); + } + return Long.parseLong(stringBuilder.toString()); + } public static String convertDateToURLFormat(final Calendar dateToBeConvert) { DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy"); @@ -165,4 +172,27 @@ public class Utils { return TimeZone.getTimeZone(TENANT_TIME_ZONE); } + public static String performServerTemplatePost(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, + final String postURL,final String legalFormType,final File file,final String locale,final String dateFormat) { + + final String importDocumentId=given().spec(requestSpec) + .queryParam("legalFormType",legalFormType) + .multiPart("file",file) + .formParam("locale",locale) + .formParam("dateFormat",dateFormat) + .expect().spec(responseSpec). + log().ifError().when().post(postURL) + .andReturn().asString(); + return importDocumentId; + } + + public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,final ResponseSpecification responseSpec, + final String getURL,final String importDocumentId){ + final String templateLocation=given().spec(requestSpec). + queryParam("importDocumentId",importDocumentId) + .expect().spec(responseSpec) + .log().ifError().when().get(getURL) + .andReturn().asString(); + return templateLocation.substring(1,templateLocation.length()-1); + } } http://git-wip-us.apache.org/repos/asf/fineract/blob/210647d4/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java index 57fc343..19aa98b 100755 --- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java +++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java @@ -21,18 +21,28 @@ package org.apache.fineract.integrationtests.common.loans; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType; import org.apache.fineract.integrationtests.common.CommonConstants; import org.apache.fineract.integrationtests.common.Utils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; import org.joda.time.LocalDate; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; + @SuppressWarnings({ "rawtypes", "unchecked" }) public class LoanTransactionHelper { @@ -41,6 +51,7 @@ public class LoanTransactionHelper { private static final String CREATE_LOAN_PRODUCT_URL = "/fineract-provider/api/v1/loanproducts?" + Utils.TENANT_IDENTIFIER; private static final String APPLY_LOAN_URL = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER; + private static final String LOAN_ACCOUNT_URL="/fineract-provider/api/v1/loans"; private static final String APPROVE_LOAN_COMMAND = "approve"; private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval"; private static final String DISBURSE_LOAN_COMMAND = "disburse"; @@ -694,4 +705,29 @@ public class LoanTransactionHelper { datatablesListMap.add(datatableMap); return datatablesListMap; } + + public Workbook getLoanWorkbook(String dateFormat) throws IOException { + requestSpec.header(HttpHeaders.CONTENT_TYPE,"application/vnd.ms-excel"); + byte[] byteArray=Utils.performGetBinaryResponse(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/downloadtemplate"+"?"+ + Utils.TENANT_IDENTIFIER+"&dateFormat="+dateFormat); + InputStream inputStream= new ByteArrayInputStream(byteArray); + Workbook workbook=new HSSFWorkbook(inputStream); + return workbook; + } + + public String importLoanTemplate(File file) { + + String locale="en"; + String dateFormat="dd MMMM yyyy"; + String legalFormType= null; + requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA); + return Utils.performServerTemplatePost(requestSpec,responseSpec,LOAN_ACCOUNT_URL+"/uploadtemplate"+"?"+Utils.TENANT_IDENTIFIER, + legalFormType,file,locale,dateFormat); + } + + public String getOutputTemplateLocation(final String importDocumentId){ + requestSpec.header(HttpHeaders.CONTENT_TYPE,MediaType.TEXT_PLAIN); + return Utils.performServerOutputTemplateLocationGet(requestSpec,responseSpec,"/fineract-provider/api/v1/imports/getOutputTemplateLocation"+"?" + +Utils.TENANT_IDENTIFIER,importDocumentId); + } } \ No newline at end of file
