-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,36 @@ public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_NEW_SCHOOL_NUMBER__ | |
assertThat(schoolCreatedEvent.get().getEventOutcome()).isEqualTo(SCHOOL_CREATED.toString()); | ||
} | ||
|
||
@Test(expected = EntityNotFoundException.class) | ||
public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WithNoDistrict__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { | ||
final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); | ||
|
||
var schoolEntity = this.createNewSchoolData(null, "PUBLIC", "DISTONLINE"); | ||
|
||
SchoolMapper map = SchoolMapper.mapper; | ||
|
||
School mappedSchool = map.toStructure(schoolEntity); | ||
|
||
mappedSchool.setDistrictId(UUID.randomUUID().toString()); | ||
mappedSchool.setCreateDate(null); | ||
mappedSchool.setUpdateDate(null); | ||
mappedSchool.setSchoolNumber(null); | ||
mappedSchool.setGrades(List.of(createSchoolGrade())); | ||
mappedSchool.setNeighborhoodLearning(List.of(createNeighborhoodLearning())); | ||
mappedSchool.setAddresses(List.of(createSchoolAddress())); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()).configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | ||
|
||
var sagaId = UUID.randomUUID(); | ||
final Event event = Event.builder().eventType(CREATE_SCHOOL).sagaId(sagaId).eventPayload(objectMapper.writeValueAsString(mappedSchool)).build(); | ||
eventHandlerServiceUnderTest.handleCreateSchoolEvent(event).getLeft(); | ||
var schoolCreatedEvent = instituteEventRepository.findBySagaIdAndEventType(sagaId, CREATE_SCHOOL.toString()); | ||
assertThat(schoolCreatedEvent).isPresent(); | ||
assertThat(schoolCreatedEvent.get().getEventStatus()).isEqualTo(MESSAGE_PUBLISHED.toString()); | ||
assertThat(schoolCreatedEvent.get().getEventOutcome()).isEqualTo(SCHOOL_CREATED.toString()); | ||
} | ||
|
||
@Test | ||
public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_EXISTING_SCHOOL_NUMBER__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { | ||
final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); | ||
|
@@ -333,6 +363,43 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL__DoesExistAndSynchronousNa | |
assertThat(toSchoolEntityComplete.getSchoolMoveFrom().stream().toList().get(0).getFromSchoolId()).isEqualTo(fromSchoolEntityComplete.getSchoolId()); | ||
} | ||
|
||
@Test(expected = EntityNotFoundException.class) | ||
public void testHandleEvent_givenEventTypeMOVE_SCHOOL_DistrictNotFound__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { | ||
final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); | ||
SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); | ||
SchoolEntity fromSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); | ||
LocalDateTime moveDate = LocalDateTime.now().plusDays(1).truncatedTo(ChronoUnit.MILLIS); | ||
|
||
Set<SchoolAddressEntity> schoolAddressSet = new HashSet<>(); | ||
SchoolAddressEntity fromSchoolAddressEntity = SchoolAddressEntity.builder() | ||
.addressTypeCode("MAILING").addressLine1("123 This Street").city("Victoria") | ||
.provinceCode("BC").countryCode("CA").postal("V1V2V3").schoolEntity(fromSchoolEntity).build(); | ||
schoolAddressSet.add(fromSchoolAddressEntity); | ||
|
||
fromSchoolEntity.setDistrictEntity(dist); | ||
fromSchoolEntity.setAddresses(schoolAddressSet); | ||
schoolRepository.save(fromSchoolEntity); | ||
|
||
School toSchool = new School(); | ||
toSchool.setGrades(List.of(createSchoolGrade())); | ||
toSchool.setNeighborhoodLearning(List.of(createNeighborhoodLearning())); | ||
toSchool.setAddresses(List.of(createSchoolAddress())); | ||
SchoolMapper map = SchoolMapper.mapper; | ||
|
||
BeanUtils.copyProperties(map.toStructure(toSchoolEntity), toSchool); | ||
toSchool.setDistrictId(UUID.randomUUID().toString()); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()).configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | ||
|
||
MoveSchoolData moveSchoolData = createMoveSchoolData(toSchool, fromSchoolEntity.getSchoolId(), moveDate); | ||
|
||
UUID sagaId = UUID.randomUUID(); | ||
final Event event = Event.builder().eventType(MOVE_SCHOOL).sagaId(sagaId).eventPayload(objectMapper.writeValueAsString(moveSchoolData)).build(); | ||
|
||
eventHandlerServiceUnderTest.handleMoveSchoolEvent(event).getLeft(); | ||
} | ||
|
||
@Test | ||
public void testHandleEvent_givenEventTypeMOVE_SCHOOL_whereSchoolNumberInNewDistrictIsAvailable__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { | ||
final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); | ||
|
@@ -680,6 +747,7 @@ private DistrictTombstoneEntity createDistrictData() { | |
return DistrictTombstoneEntity.builder().districtNumber("003").displayName("District Name").districtStatusCode("OPEN").districtRegionCode("KOOTENAYS") | ||
.website("[email protected]").createDate(LocalDateTime.now()).updateDate(LocalDateTime.now()).createUser("TEST").updateUser("TEST").build(); | ||
} | ||
|
||
private SchoolGrade createSchoolGrade() { | ||
SchoolGrade schoolGrade = new SchoolGrade(); | ||
schoolGrade.setSchoolGradeCode("01"); | ||
|