|
2 | 2 |
|
3 | 3 | import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SdcDistrictCollectionStatus;
|
4 | 4 | import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SdcSchoolCollectionStatus;
|
| 5 | +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SdcSchoolStudentStatus; |
5 | 6 | import ca.bc.gov.educ.studentdatacollection.api.exception.EntityNotFoundException;
|
6 | 7 | import ca.bc.gov.educ.studentdatacollection.api.exception.InvalidPayloadException;
|
7 | 8 | import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcDistrictCollectionEntity;
|
8 | 9 | import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity;
|
9 | 10 | import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionHistoryEntity;
|
10 | 11 | import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity;
|
11 | 12 | import ca.bc.gov.educ.studentdatacollection.api.repository.v1.*;
|
| 13 | +import ca.bc.gov.educ.studentdatacollection.api.struct.ReprocessSdcSchoolCollection; |
12 | 14 | import ca.bc.gov.educ.studentdatacollection.api.struct.v1.ReportZeroEnrollmentSdcSchoolCollection;
|
13 | 15 | import ca.bc.gov.educ.studentdatacollection.api.struct.v1.UnsubmitSdcSchoolCollection;
|
14 | 16 | import ca.bc.gov.educ.studentdatacollection.api.struct.v1.ValidationIssueTypeCode;
|
|
18 | 20 | import org.mockito.Mock;
|
19 | 21 | import org.mockito.junit.jupiter.MockitoExtension;
|
20 | 22 |
|
| 23 | +import java.math.BigDecimal; |
21 | 24 | import java.util.*;
|
22 | 25 |
|
23 | 26 | import static org.junit.jupiter.api.Assertions.*;
|
@@ -51,6 +54,9 @@ class SdcSchoolCollectionServiceTest {
|
51 | 54 | @Mock
|
52 | 55 | SdcDuplicateRepository sdcDuplicateRepository;
|
53 | 56 |
|
| 57 | + @Mock |
| 58 | + SdcSchoolCollectionStudentStorageService sdcSchoolCollectionStudentStorageService; |
| 59 | + |
54 | 60 | @InjectMocks
|
55 | 61 | private SdcSchoolCollectionService sdcSchoolCollectionService;
|
56 | 62 |
|
@@ -195,9 +201,7 @@ void testReportZeroEnrollment_NonExistentSchoolCollection() {
|
195 | 201 | .updateUser("USER")
|
196 | 202 | .build();
|
197 | 203 |
|
198 |
| - assertThrows(EntityNotFoundException.class, () -> { |
199 |
| - sdcSchoolCollectionService.reportZeroEnrollment(input); |
200 |
| - }); |
| 204 | + assertThrows(EntityNotFoundException.class, () -> sdcSchoolCollectionService.reportZeroEnrollment(input)); |
201 | 205 | }
|
202 | 206 |
|
203 | 207 | @Test
|
@@ -315,4 +319,233 @@ void testGetStudentValidationIssueCodes_withEmptyList() {
|
315 | 319 |
|
316 | 320 | assertEquals(0, result.size());
|
317 | 321 | }
|
| 322 | + |
| 323 | + @Test |
| 324 | + void testReprocessSchoolCollection_sdcSchoolCollectionNotFound() { |
| 325 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 326 | + |
| 327 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.empty()); |
| 328 | + |
| 329 | + ReprocessSdcSchoolCollection sdcSchoolCollectionReprocess = ReprocessSdcSchoolCollection.builder().sdcSchoolCollectionID(sdcSchoolCollectionID).updateUser("USER").build(); |
| 330 | + |
| 331 | + assertThrows(EntityNotFoundException.class, () -> sdcSchoolCollectionService.reprocessSchoolCollection(sdcSchoolCollectionReprocess)); |
| 332 | + |
| 333 | + verify(sdcSchoolCollectionRepository, times(1)).findById(sdcSchoolCollectionID); |
| 334 | + verifyNoMoreInteractions(sdcSchoolCollectionRepository, sdcDistrictCollectionRepository, sdcDistrictCollectionService); |
| 335 | + } |
| 336 | + |
| 337 | + @Test |
| 338 | + void testReprocessSchoolCollection_indySchool() { |
| 339 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 340 | + |
| 341 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 342 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 343 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.SUBMITTED.getCode()); |
| 344 | + sdcSchoolCollectionEntity.setSdcSchoolStudentEntities(new HashSet<>()); |
| 345 | + |
| 346 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 347 | + |
| 348 | + SdcSchoolCollectionEntity result = sdcSchoolCollectionService.reprocessSchoolCollection(ReprocessSdcSchoolCollection.builder().sdcSchoolCollectionID(sdcSchoolCollectionID).updateUser("USER").build()); |
| 349 | + |
| 350 | + assertEquals(sdcSchoolCollectionID, result.getSdcSchoolCollectionID()); |
| 351 | + |
| 352 | + verify(sdcSchoolCollectionRepository, times(1)).findById(sdcSchoolCollectionID); |
| 353 | + verify(sdcDistrictCollectionRepository, times(0)).findById(any()); |
| 354 | + verify(sdcSchoolCollectionStudentStorageService, times(1)).saveAllSDCStudentsWithHistory(any()); |
| 355 | + } |
| 356 | + |
| 357 | + @Test |
| 358 | + void testReprocessSchoolCollection_withStudents_ShouldProcessNonDeletedStudents() { |
| 359 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 360 | + String updateUser = "TEST_USER"; |
| 361 | + |
| 362 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 363 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 364 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.NEW.getCode()); |
| 365 | + |
| 366 | + SdcSchoolCollectionStudentEntity loadedStudent = new SdcSchoolCollectionStudentEntity(); |
| 367 | + loadedStudent.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 368 | + loadedStudent.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.LOADED.getCode()); |
| 369 | + |
| 370 | + SdcSchoolCollectionStudentEntity errorStudent = new SdcSchoolCollectionStudentEntity(); |
| 371 | + errorStudent.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 372 | + errorStudent.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.ERROR.getCode()); |
| 373 | + |
| 374 | + SdcSchoolCollectionStudentEntity deletedStudent = new SdcSchoolCollectionStudentEntity(); |
| 375 | + deletedStudent.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 376 | + deletedStudent.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.DELETED.getCode()); |
| 377 | + |
| 378 | + Set<SdcSchoolCollectionStudentEntity> students = new HashSet<>(); |
| 379 | + students.add(loadedStudent); |
| 380 | + students.add(errorStudent); |
| 381 | + students.add(deletedStudent); |
| 382 | + sdcSchoolCollectionEntity.setSdcSchoolStudentEntities(students); |
| 383 | + |
| 384 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 385 | + |
| 386 | + sdcSchoolCollectionService.reprocessSchoolCollection( |
| 387 | + ReprocessSdcSchoolCollection.builder() |
| 388 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 389 | + .updateUser(updateUser) |
| 390 | + .build() |
| 391 | + ); |
| 392 | + |
| 393 | + assertEquals(SdcSchoolStudentStatus.LOADED.getCode(), loadedStudent.getSdcSchoolCollectionStudentStatusCode()); |
| 394 | + assertEquals(SdcSchoolStudentStatus.LOADED.getCode(), errorStudent.getSdcSchoolCollectionStudentStatusCode()); |
| 395 | + assertEquals(updateUser, loadedStudent.getUpdateUser()); |
| 396 | + assertEquals(updateUser, errorStudent.getUpdateUser()); |
| 397 | + |
| 398 | + assertEquals(SdcSchoolStudentStatus.DELETED.getCode(), deletedStudent.getSdcSchoolCollectionStudentStatusCode()); |
| 399 | + assertNotEquals(updateUser, deletedStudent.getUpdateUser()); |
| 400 | + |
| 401 | + verify(sdcSchoolCollectionStudentStorageService, times(1)).saveAllSDCStudentsWithHistory(any()); |
| 402 | + } |
| 403 | + |
| 404 | + @Test |
| 405 | + void testReprocessSchoolCollection_withOnlyDeletedStudents_ShouldNotProcessAnyStudents() { |
| 406 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 407 | + String updateUser = "TEST_USER"; |
| 408 | + |
| 409 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 410 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 411 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.NEW.getCode()); |
| 412 | + |
| 413 | + SdcSchoolCollectionStudentEntity deletedStudent1 = new SdcSchoolCollectionStudentEntity(); |
| 414 | + deletedStudent1.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 415 | + deletedStudent1.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.DELETED.getCode()); |
| 416 | + |
| 417 | + SdcSchoolCollectionStudentEntity deletedStudent2 = new SdcSchoolCollectionStudentEntity(); |
| 418 | + deletedStudent2.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 419 | + deletedStudent2.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.DELETED.getCode()); |
| 420 | + |
| 421 | + Set<SdcSchoolCollectionStudentEntity> students = new HashSet<>(); |
| 422 | + students.add(deletedStudent1); |
| 423 | + students.add(deletedStudent2); |
| 424 | + sdcSchoolCollectionEntity.setSdcSchoolStudentEntities(students); |
| 425 | + |
| 426 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 427 | + |
| 428 | + sdcSchoolCollectionService.reprocessSchoolCollection( |
| 429 | + ReprocessSdcSchoolCollection.builder() |
| 430 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 431 | + .updateUser(updateUser) |
| 432 | + .build() |
| 433 | + ); |
| 434 | + |
| 435 | + assertEquals(SdcSchoolStudentStatus.DELETED.getCode(), deletedStudent1.getSdcSchoolCollectionStudentStatusCode()); |
| 436 | + assertEquals(SdcSchoolStudentStatus.DELETED.getCode(), deletedStudent2.getSdcSchoolCollectionStudentStatusCode()); |
| 437 | + assertNotEquals(updateUser, deletedStudent1.getUpdateUser()); |
| 438 | + assertNotEquals(updateUser, deletedStudent2.getUpdateUser()); |
| 439 | + |
| 440 | + verify(sdcSchoolCollectionStudentStorageService, times(1)).saveAllSDCStudentsWithHistory(any()); |
| 441 | + } |
| 442 | + |
| 443 | + @Test |
| 444 | + void testReprocessSchoolCollection_GivenProvincialDuplicatesStatus_ShouldThrowException() { |
| 445 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 446 | + |
| 447 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 448 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 449 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.P_DUP_POST.getCode()); |
| 450 | + |
| 451 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 452 | + |
| 453 | + ReprocessSdcSchoolCollection sdcSchoolCollectionReprocess = ReprocessSdcSchoolCollection.builder() |
| 454 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 455 | + .updateUser("USER") |
| 456 | + .build(); |
| 457 | + |
| 458 | + assertThrows(InvalidPayloadException.class, () -> sdcSchoolCollectionService.reprocessSchoolCollection(sdcSchoolCollectionReprocess)); |
| 459 | + |
| 460 | + verify(sdcSchoolCollectionRepository, times(1)).findById(sdcSchoolCollectionID); |
| 461 | + verifyNoMoreInteractions(sdcSchoolCollectionRepository, sdcDistrictCollectionRepository, sdcDistrictCollectionService); |
| 462 | + } |
| 463 | + |
| 464 | + @Test |
| 465 | + void testReprocessSchoolCollection_GivenProvincialDuplicatesVerifiedStatus_ShouldThrowException() { |
| 466 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 467 | + |
| 468 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 469 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 470 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.P_DUP_VRFD.getCode()); |
| 471 | + |
| 472 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 473 | + |
| 474 | + ReprocessSdcSchoolCollection sdcSchoolCollectionReprocess = ReprocessSdcSchoolCollection.builder() |
| 475 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 476 | + .updateUser("USER") |
| 477 | + .build(); |
| 478 | + |
| 479 | + assertThrows(InvalidPayloadException.class, () -> sdcSchoolCollectionService.reprocessSchoolCollection(sdcSchoolCollectionReprocess)); |
| 480 | + |
| 481 | + verify(sdcSchoolCollectionRepository, times(1)).findById(sdcSchoolCollectionID); |
| 482 | + verifyNoMoreInteractions(sdcSchoolCollectionRepository, sdcDistrictCollectionRepository, sdcDistrictCollectionService); |
| 483 | + } |
| 484 | + |
| 485 | + @Test |
| 486 | + void testReprocessSchoolCollection_ShouldClearCalculatedFields() { |
| 487 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 488 | + String updateUser = "TEST_USER"; |
| 489 | + |
| 490 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 491 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 492 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.NEW.getCode()); |
| 493 | + |
| 494 | + SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); |
| 495 | + student.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 496 | + student.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.VERIFIED.getCode()); |
| 497 | + student.setFte(BigDecimal.ONE); |
| 498 | + student.setFteZeroReasonCode("REASON"); |
| 499 | + |
| 500 | + Set<SdcSchoolCollectionStudentEntity> students = new HashSet<>(); |
| 501 | + students.add(student); |
| 502 | + sdcSchoolCollectionEntity.setSdcSchoolStudentEntities(students); |
| 503 | + |
| 504 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 505 | + |
| 506 | + sdcSchoolCollectionService.reprocessSchoolCollection( |
| 507 | + ReprocessSdcSchoolCollection.builder() |
| 508 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 509 | + .updateUser(updateUser) |
| 510 | + .build() |
| 511 | + ); |
| 512 | + |
| 513 | + assertEquals(SdcSchoolStudentStatus.LOADED.getCode(), student.getSdcSchoolCollectionStudentStatusCode()); |
| 514 | + assertEquals(updateUser, student.getUpdateUser()); |
| 515 | + |
| 516 | + verify(sdcSchoolCollectionStudentStorageService, times(1)).saveAllSDCStudentsWithHistory(any()); |
| 517 | + } |
| 518 | + |
| 519 | + @Test |
| 520 | + void testReprocessSchoolCollection_ShouldUpdateTimestamps() { |
| 521 | + UUID sdcSchoolCollectionID = UUID.randomUUID(); |
| 522 | + String updateUser = "TEST_USER"; |
| 523 | + |
| 524 | + SdcSchoolCollectionEntity sdcSchoolCollectionEntity = new SdcSchoolCollectionEntity(); |
| 525 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionID(sdcSchoolCollectionID); |
| 526 | + sdcSchoolCollectionEntity.setSdcSchoolCollectionStatusCode(SdcSchoolCollectionStatus.NEW.getCode()); |
| 527 | + |
| 528 | + SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); |
| 529 | + student.setSdcSchoolCollectionStudentID(UUID.randomUUID()); |
| 530 | + student.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.ERROR.getCode()); |
| 531 | + |
| 532 | + Set<SdcSchoolCollectionStudentEntity> students = new HashSet<>(); |
| 533 | + students.add(student); |
| 534 | + sdcSchoolCollectionEntity.setSdcSchoolStudentEntities(students); |
| 535 | + |
| 536 | + when(sdcSchoolCollectionRepository.findById(sdcSchoolCollectionID)).thenReturn(Optional.of(sdcSchoolCollectionEntity)); |
| 537 | + |
| 538 | + SdcSchoolCollectionEntity result = sdcSchoolCollectionService.reprocessSchoolCollection( |
| 539 | + ReprocessSdcSchoolCollection.builder() |
| 540 | + .sdcSchoolCollectionID(sdcSchoolCollectionID) |
| 541 | + .updateUser(updateUser) |
| 542 | + .build() |
| 543 | + ); |
| 544 | + |
| 545 | + assertEquals(updateUser, result.getUpdateUser()); |
| 546 | + assertEquals(updateUser, student.getUpdateUser()); |
| 547 | + assertNotNull(student.getUpdateDate()); |
| 548 | + |
| 549 | + verify(sdcSchoolCollectionStudentStorageService, times(1)).saveAllSDCStudentsWithHistory(any()); |
| 550 | + } |
318 | 551 | }
|
0 commit comments