2929import java .util .ArrayList ;
3030import java .util .HashMap ;
3131import java .util .List ;
32+ import lombok .extern .slf4j .Slf4j ;
3233import org .apache .fineract .integrationtests .common .ClientHelper ;
3334import org .apache .fineract .integrationtests .common .CollateralManagementHelper ;
3435import org .apache .fineract .integrationtests .common .CommonConstants ;
3839import org .apache .fineract .integrationtests .common .loans .LoanStatusChecker ;
3940import org .apache .fineract .integrationtests .common .loans .LoanTestLifecycleExtension ;
4041import org .apache .fineract .integrationtests .common .loans .LoanTransactionHelper ;
42+ import org .apache .fineract .portfolio .loanaccount .domain .transactionprocessor .impl .AdvancedPaymentScheduleTransactionProcessor ;
4143import org .junit .jupiter .api .Assertions ;
4244import org .junit .jupiter .api .BeforeEach ;
4345import org .junit .jupiter .api .Test ;
4446import org .junit .jupiter .api .extension .ExtendWith ;
45- import org .slf4j .Logger ;
46- import org .slf4j .LoggerFactory ;
4747
4848@ SuppressWarnings ("rawtypes" )
4949@ ExtendWith (LoanTestLifecycleExtension .class )
50+ @ Slf4j
5051public class LoanApplicationApprovalTest {
5152
52- private static final Logger LOG = LoggerFactory . getLogger ( LoanApplicationApprovalTest . class ) ;
53+ private static final String DATETIME_PATTERN = "dd MMMM yyyy" ;
5354 private ResponseSpecification responseSpec ;
5455 private ResponseSpecification responseSpecForStatusCode403 ;
5556 private ResponseSpecification responseSpecForStatusCode400 ;
@@ -136,16 +137,41 @@ public void loanApplicationApprovalAndValidationForMultiDisburseLoans() {
136137 createTranches .add (createTrancheDetail ("23 March 2014" , "4000" ));
137138
138139 final Integer clientID = ClientHelper .createClient (this .requestSpec , this .responseSpec , "01 January 2014" );
139- LOG .info ("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}" , clientID );
140+ log .info ("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}" , clientID );
140141
141142 final Integer loanProductID = this .loanTransactionHelper
142143 .getLoanProductId (new LoanProductTestBuilder ().withInterestTypeAsDecliningBalance ().withTranches (true )
143144 .withInterestCalculationPeriodTypeAsRepaymentPeriod (true ).build (null ));
144- LOG .info ("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}" ,
145+ log .info ("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}" ,
145146 loanProductID );
146147
147148 this .trancheLoansApprovedAmountLesserThanProposedAmount (clientID , loanProductID , createTranches );
148149 this .trancheLoansApprovalValidation (clientID , loanProductID , createTranches );
150+ }
151+
152+ @ Test
153+ public void loanApplicationShouldFailIfTransactionProcessingStrategyIsAdvancedPaymentAllocationButItIsNotConfiguredOnProduct () {
154+ final Integer clientId = ClientHelper .createClient (this .requestSpec , this .responseSpec , "01 January 2014" );
155+ log .info ("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}" , clientId );
156+
157+ final Integer loanProductId = this .loanTransactionHelper
158+ .getLoanProductId (new LoanProductTestBuilder ().withInterestTypeAsDecliningBalance ().withTranches (true )
159+ .withInterestCalculationPeriodTypeAsRepaymentPeriod (true ).build (null ));
160+ log .info ("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}" ,
161+ loanProductId );
162+
163+ loanTransactionHelper = new LoanTransactionHelper (this .requestSpec , this .responseSpecForStatusCode400 );
164+ final String loanApplicationJSON = new LoanApplicationTestBuilder ().withPrincipal ("1000" ).withLoanTermFrequency ("1" )
165+ .withLoanTermFrequencyAsMonths ().withNumberOfRepayments ("1" ).withRepaymentEveryAfter ("1" )
166+ .withRepaymentFrequencyTypeAsMonths ().withInterestRatePerPeriod ("0" ).withInterestTypeAsFlatBalance ()
167+ .withAmortizationTypeAsEqualPrincipalPayments ().withInterestCalculationPeriodTypeSameAsRepaymentPeriod ()
168+ .withExpectedDisbursementDate ("01 March 2022" ).withSubmittedOnDate ("01 March 2022" ).withLoanType ("individual" )
169+ .withRepaymentStrategy (AdvancedPaymentScheduleTransactionProcessor .ADVANCED_PAYMENT_ALLOCATION_STRATEGY )
170+ .build (clientId .toString (), loanProductId .toString (), null );
171+ List <HashMap > error = (List <HashMap >) loanTransactionHelper .createLoanAccount (loanApplicationJSON , CommonConstants .RESPONSE_ERROR );
172+ assertEquals (
173+ "validation.msg.loan.transactionProcessingStrategyCode.strategy.cannot.be.advanced.payment.allocation.if.not.configured" ,
174+ error .get (0 ).get (CommonConstants .RESPONSE_ERROR_MESSAGE_CODE ));
149175
150176 }
151177
@@ -160,17 +186,17 @@ private void trancheLoansApprovedAmountLesserThanProposedAmount(Integer clientID
160186 approveTranches .add (createTrancheDetail ("23 March 2014" , "1000" ));
161187
162188 final Integer loanID = applyForLoanApplicationWithTranches (clientID , loanProductID , proposedAmount , createTranches );
163- LOG .info ("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}" , loanID );
189+ log .info ("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}" , loanID );
164190
165191 HashMap loanStatusHashMap = LoanStatusChecker .getStatusOfLoan (this .requestSpec , this .responseSpec , loanID );
166192 LoanStatusChecker .verifyLoanIsPending (loanStatusHashMap );
167193
168- LOG .info ("-----------------------------------APPROVE LOAN-----------------------------------------------------------" );
194+ log .info ("-----------------------------------APPROVE LOAN-----------------------------------------------------------" );
169195 loanStatusHashMap = this .loanTransactionHelper .approveLoanWithApproveAmount (approveDate , expectedDisbursementDate , approvalAmount ,
170196 loanID , approveTranches );
171197 LoanStatusChecker .verifyLoanIsApproved (loanStatusHashMap );
172198 LoanStatusChecker .verifyLoanIsWaitingForDisbursal (loanStatusHashMap );
173- LOG .info ("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------" );
199+ log .info ("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------" );
174200
175201 }
176202
@@ -205,12 +231,12 @@ private void trancheLoansApprovalValidation(Integer clientID, Integer loanProduc
205231 approveTranche4 .add (createTrancheDetail ("24 March 2014" , "100" ));
206232
207233 final Integer loanID = applyForLoanApplicationWithTranches (clientID , loanProductID , proposedAmount , createTranches );
208- LOG .info ("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}" , loanID );
234+ log .info ("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}" , loanID );
209235
210236 HashMap <String , Object > loanStatusHashMap = LoanStatusChecker .getStatusOfLoan (this .requestSpec , this .responseSpec , loanID );
211237 LoanStatusChecker .verifyLoanIsPending (loanStatusHashMap );
212238
213- LOG .info ("-----------------------------------APPROVE LOAN-----------------------------------------------------------" );
239+ log .info ("-----------------------------------APPROVE LOAN-----------------------------------------------------------" );
214240 this .loanTransactionHelper = new LoanTransactionHelper (this .requestSpec , this .responseSpecForStatusCode400 );
215241
216242 /* Tranches with same expected disbursement date */
@@ -278,7 +304,7 @@ private HashMap<String, String> collaterals(Integer collateralId, BigDecimal qua
278304
279305 public Integer applyForLoanApplicationWithTranches (final Integer clientID , final Integer loanProductID , String principal ,
280306 List <HashMap > tranches ) {
281- LOG .info ("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------" );
307+ log .info ("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------" );
282308 List <HashMap > collaterals = new ArrayList <>();
283309 final Integer collateralId = CollateralManagementHelper .createCollateralProduct (this .requestSpec , this .responseSpec );
284310 Assertions .assertNotNull (collateralId );
@@ -304,5 +330,4 @@ public Integer applyForLoanApplicationWithTranches(final Integer clientID, final
304330
305331 return this .loanTransactionHelper .getLoanId (loanApplicationJSON );
306332 }
307-
308333}
0 commit comments