|
36 | 36 | import java.util.List; |
37 | 37 | import java.util.Locale; |
38 | 38 | import java.util.Map; |
| 39 | +import java.util.Objects; |
39 | 40 | import java.util.Optional; |
40 | 41 | import org.apache.fineract.infrastructure.core.api.JsonCommand; |
41 | 42 | import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; |
@@ -136,6 +137,21 @@ public void testNewPauseEndIsOverlappingWithExistingPause() throws JsonProcessin |
136 | 137 | () -> underTest.validateAndParseUpdate(command, loan, existing, localDate("09 September 2022"))); |
137 | 138 | } |
138 | 139 |
|
| 140 | + @Test |
| 141 | + public void testNewPauseIsOverlappingWithExistingPauseBecauseSameDates() throws JsonProcessingException { |
| 142 | + Loan loan = Mockito.mock(Loan.class); |
| 143 | + Mockito.when(loan.getStatus()).thenReturn(LoanStatus.ACTIVE); |
| 144 | + |
| 145 | + List<LoanDelinquencyAction> existing = List.of(loanDelinquencyAction(PAUSE, "15 September 2022", "22 September 2022")); |
| 146 | + JsonCommand command = delinquencyAction("pause", "15 September 2022", "22 September 2022"); |
| 147 | + List<LoanDelinquencyActionData> effectiveList = List.of(loanDelinquencyActionData(existing.get(0))); |
| 148 | + Mockito.when(delinquencyEffectivePauseHelper.calculateEffectiveDelinquencyList(existing)).thenReturn(effectiveList); |
| 149 | + |
| 150 | + assertPlatformValidationException("Delinquency pause period cannot overlap with another pause period", |
| 151 | + "loan-delinquency-action-overlapping", |
| 152 | + () -> underTest.validateAndParseUpdate(command, loan, existing, localDate("09 September 2022"))); |
| 153 | + } |
| 154 | + |
139 | 155 | @Test |
140 | 156 | public void testNewPauseIsNotOverlappingBecauseThereWasAResume() throws JsonProcessingException { |
141 | 157 | Loan loan = Mockito.mock(Loan.class); |
@@ -214,6 +230,32 @@ public void testValidationErrorResumeInvalidStartDate() throws JsonProcessingExc |
214 | 230 | () -> underTest.validateAndParseUpdate(command, loan, List.of(), localDate("10 September 2022"))); |
215 | 231 | } |
216 | 232 |
|
| 233 | + @Test |
| 234 | + public void testValidationErrorResumeOnExistingResumeDate() throws JsonProcessingException { |
| 235 | + Loan loan = Mockito.mock(Loan.class); |
| 236 | + Mockito.when(loan.getStatus()).thenReturn(LoanStatus.ACTIVE); |
| 237 | + |
| 238 | + JsonCommand command = delinquencyAction("resume", "09 September 2022", null); |
| 239 | + List<LoanDelinquencyAction> existing = List.of(loanDelinquencyAction(PAUSE, "05 September 2022", "15 September 2022")); |
| 240 | + List<LoanDelinquencyActionData> effectiveList = List.of(loanDelinquencyActionData(existing.get(0))); |
| 241 | + Mockito.when(delinquencyEffectivePauseHelper.calculateEffectiveDelinquencyList(existing)).thenReturn(effectiveList); |
| 242 | + |
| 243 | + LoanDelinquencyAction parsedDelinquencyAction = underTest.validateAndParseUpdate(command, loan, existing, |
| 244 | + localDate("09 September 2022")); |
| 245 | + Assertions.assertEquals(RESUME, parsedDelinquencyAction.getAction()); |
| 246 | + Assertions.assertEquals(localDate("09 September 2022"), parsedDelinquencyAction.getStartDate()); |
| 247 | + Assertions.assertNull(parsedDelinquencyAction.getEndDate()); |
| 248 | + |
| 249 | + List<LoanDelinquencyAction> existing2 = List.of(loanDelinquencyAction(PAUSE, "05 September 2022", "15 September 2022"), |
| 250 | + loanDelinquencyAction(RESUME, "09 September 2022", null)); |
| 251 | + |
| 252 | + JsonCommand command2 = delinquencyAction("resume", "09 September 2022", null); |
| 253 | + |
| 254 | + assertPlatformValidationException("There is an existing Resume Delinquency Action on this date", |
| 255 | + "loan-delinquency-action-resume-should-be-unique", |
| 256 | + () -> underTest.validateAndParseUpdate(command2, loan, existing2, localDate("09 September 2022"))); |
| 257 | + } |
| 258 | + |
217 | 259 | @Test |
218 | 260 | public void testValidationErrorPausePeriodShouldBeAtLeastOneDay() throws JsonProcessingException { |
219 | 261 | Loan loan = Mockito.mock(Loan.class); |
@@ -348,7 +390,7 @@ private void assertPlatformException(String expectedMessage, String expectedCode |
348 | 390 | } |
349 | 391 |
|
350 | 392 | private LoanDelinquencyAction loanDelinquencyAction(DelinquencyAction action, String startTime, String endTime) { |
351 | | - return new LoanDelinquencyAction(null, action, localDate(startTime), localDate(endTime)); |
| 393 | + return new LoanDelinquencyAction(null, action, localDate(startTime), Objects.isNull(endTime) ? null : localDate(endTime)); |
352 | 394 | } |
353 | 395 |
|
354 | 396 | private LoanDelinquencyActionData loanDelinquencyActionData(LoanDelinquencyAction loanDelinquencyAction) { |
|
0 commit comments