|
20 | 20 |
|
21 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 22 |
|
| 23 | +import com.google.gson.Gson; |
23 | 24 | import io.restassured.builder.RequestSpecBuilder; |
24 | 25 | import io.restassured.builder.ResponseSpecBuilder; |
25 | 26 | import io.restassured.http.ContentType; |
|
42 | 43 | import java.util.HashMap; |
43 | 44 | import java.util.List; |
44 | 45 | import java.util.Locale; |
| 46 | +import java.util.Map; |
45 | 47 | import java.util.TimeZone; |
| 48 | +import org.apache.fineract.client.models.GetJournalEntriesTransactionIdResponse; |
46 | 49 | import org.apache.fineract.integrationtests.common.ClientHelper; |
47 | 50 | import org.apache.fineract.integrationtests.common.CollateralManagementHelper; |
48 | 51 | import org.apache.fineract.integrationtests.common.CommonConstants; |
|
68 | 71 | import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper; |
69 | 72 | import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper; |
70 | 73 | import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker; |
| 74 | +import org.apache.fineract.integrationtests.common.shares.ShareAccountHelper; |
| 75 | +import org.apache.fineract.integrationtests.common.shares.ShareAccountTransactionHelper; |
| 76 | +import org.apache.fineract.integrationtests.common.shares.ShareProductHelper; |
| 77 | +import org.apache.fineract.integrationtests.common.shares.ShareProductTransactionHelper; |
71 | 78 | import org.junit.jupiter.api.Assertions; |
72 | 79 | import org.junit.jupiter.api.BeforeEach; |
73 | 80 | import org.junit.jupiter.api.Test; |
@@ -341,7 +348,7 @@ public void checkAccountingWithSavingsFlow() { |
341 | 348 |
|
342 | 349 | this.savingsAccountHelper.addChargesForSavings(savingsID, withdrawalChargeId, false); |
343 | 350 | ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsID); |
344 | | - Assertions.assertEquals(1, chargesPendingState.size()); |
| 351 | + assertEquals(1, chargesPendingState.size()); |
345 | 352 | HashMap savingsChargeForPay = chargesPendingState.get(0); |
346 | 353 | HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsID, (Integer) savingsChargeForPay.get("id")); |
347 | 354 | Float chargeAmount = (Float) paidCharge.get("amount"); |
@@ -1115,4 +1122,71 @@ private LocalDate getDateAsLocalDate(String dateAsString) { |
1115 | 1122 | return LocalDate.parse(dateAsString, Utils.dateFormatter); |
1116 | 1123 | } |
1117 | 1124 |
|
| 1125 | + @Test |
| 1126 | + public void checkAccountingWithSharingFlow() { |
| 1127 | + this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec); |
| 1128 | + |
| 1129 | + final Account assetAccount = this.accountHelper.createAssetAccount(); |
| 1130 | + final Account incomeAccount = this.accountHelper.createIncomeAccount(); |
| 1131 | + final Account equityAccount = this.accountHelper.createEquityAccount(); |
| 1132 | + final Account liabilityAccount = this.accountHelper.createLiabilityAccount(); |
| 1133 | + |
| 1134 | + final Integer shareProductID = createSharesProduct(assetAccount, incomeAccount, equityAccount, liabilityAccount); |
| 1135 | + |
| 1136 | + final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec, DATE_OF_JOINING); |
| 1137 | + Assertions.assertNotNull(clientID); |
| 1138 | + final Integer savingsAccountId = SavingsAccountHelper.openSavingsAccount(requestSpec, responseSpec, clientID, "1000"); |
| 1139 | + Assertions.assertNotNull(savingsAccountId); |
| 1140 | + final Integer shareAccountId = createShareAccount(clientID, shareProductID, savingsAccountId); |
| 1141 | + Assertions.assertNotNull(shareAccountId); |
| 1142 | + final Map<String, Object> shareAccountData = ShareAccountTransactionHelper.retrieveShareAccount(shareAccountId, requestSpec, |
| 1143 | + responseSpec); |
| 1144 | + Assertions.assertNotNull(shareAccountData); |
| 1145 | + // Approve share Account |
| 1146 | + final Map<String, Object> approveMap = new HashMap<>(); |
| 1147 | + approveMap.put("note", "Share Account Approval Note"); |
| 1148 | + approveMap.put("dateFormat", "dd MMMM yyyy"); |
| 1149 | + approveMap.put("approvedDate", "01 Jan 2016"); |
| 1150 | + approveMap.put("locale", "en"); |
| 1151 | + final String approve = new Gson().toJson(approveMap); |
| 1152 | + ShareAccountTransactionHelper.postCommand("approve", shareAccountId, approve, requestSpec, responseSpec); |
| 1153 | + // Activate Share Account |
| 1154 | + final Map<String, Object> activateMap = new HashMap<>(); |
| 1155 | + activateMap.put("dateFormat", "dd MMMM yyyy"); |
| 1156 | + activateMap.put("activatedDate", "01 Jan 2016"); |
| 1157 | + activateMap.put("locale", "en"); |
| 1158 | + final String activateJson = new Gson().toJson(activateMap); |
| 1159 | + ShareAccountTransactionHelper.postCommand("activate", shareAccountId, activateJson, requestSpec, responseSpec); |
| 1160 | + |
| 1161 | + // Checking sharing entries. |
| 1162 | + final JournalEntry[] assetAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.DEBIT) }; |
| 1163 | + final JournalEntry[] liabilityAccountEntry = { new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) }; |
| 1164 | + final JournalEntry[] checkJournalEntryForEquityAccount = { |
| 1165 | + new JournalEntry(Float.parseFloat("200"), JournalEntry.TransactionType.CREDIT) }; |
| 1166 | + this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, "01 Jan 2016", assetAccountEntry); |
| 1167 | + this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, "01 Jan 2016", liabilityAccountEntry); |
| 1168 | + this.journalEntryHelper.checkJournalEntryForEquityAccount(equityAccount, "01 Jan 2016", checkJournalEntryForEquityAccount); |
| 1169 | + |
| 1170 | + final String transactionId = this.journalEntryHelper.getJournalEntryTransactionIdByAccount(assetAccount, "01 Jan 2016", |
| 1171 | + assetAccountEntry); |
| 1172 | + Assertions.assertNotEquals("", transactionId); |
| 1173 | + |
| 1174 | + final GetJournalEntriesTransactionIdResponse journalEntriesTransactionIdResponse = this.journalEntryHelper |
| 1175 | + .getJournalEntries(transactionId); |
| 1176 | + Assertions.assertNotNull(journalEntriesTransactionIdResponse); |
| 1177 | + } |
| 1178 | + |
| 1179 | + public static Integer createSharesProduct(final Account... accounts) { |
| 1180 | + LOG.info("------------------------------CREATING NEW SHARE PRODUCT ---------------------------------------"); |
| 1181 | + final String shareProductJSON = new ShareProductHelper().withCashBasedAccounting(accounts).build(); |
| 1182 | + return ShareProductTransactionHelper.createShareProduct(shareProductJSON, requestSpec, responseSpec); |
| 1183 | + } |
| 1184 | + |
| 1185 | + private Integer createShareAccount(final Integer clientId, final Integer productId, final Integer savingsAccountId) { |
| 1186 | + final String shareAccountJSON = new ShareAccountHelper().withClientId(String.valueOf(clientId)) |
| 1187 | + .withProductId(String.valueOf(productId)).withExternalId("External1").withSavingsAccountId(String.valueOf(savingsAccountId)) |
| 1188 | + .withSubmittedDate("01 Jan 2016").withApplicationDate("01 Jan 2016").withRequestedShares("100").build(); |
| 1189 | + return ShareAccountTransactionHelper.createShareAccount(shareAccountJSON, requestSpec, responseSpec); |
| 1190 | + } |
| 1191 | + |
1118 | 1192 | } |
0 commit comments