diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/Constants.java b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/Constants.java index a483f3a0..3fd08087 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/Constants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/Constants.java @@ -3,15 +3,10 @@ public final class Constants { private Constants() {} - public static final String PUBLIC ="PUBLIC"; - public static final String YUKON ="YUKON"; - public static final String STANDARD ="STANDARD"; public static final String NINETY = "90"; public static final String NINETYNINE = "99"; - public static final String NINETYSIX = "96"; public static final String NINETYFIVE = "95"; public static final String NINETYFOUR = "94"; - public static final String NINETYSEVEN = "97"; public static final String LOWERBOUND = "000"; public static final String TWENTYFIVE = "25"; public static final String UPPERBOUND = "999"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityCategoryLookup.java b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityCategoryLookup.java index e4c02970..fe7024bd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityCategoryLookup.java +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityCategoryLookup.java @@ -4,17 +4,18 @@ public enum FacilityCategoryLookup { - ENTRY1(new String[] {"DIST_LEARN", "DISTONLINE", "ALT_PROGS"}, new String[]{Constants.PUBLIC, Constants.YUKON, "INDEPEND"}), - ENTRY2(new String[] {Constants.STANDARD}, new String[]{Constants.PUBLIC, Constants.YUKON}), - ENTRY3(new String[] {Constants.STANDARD}, new String[]{"OFFSHORE", "INDEPEND"}), - ENTRY4(new String[] {Constants.STANDARD}, new String[]{"INDP_FNS", "FED_BAND"}), - ENTRY5(new String[] {"CONT_ED"}, new String[]{Constants.PUBLIC}), - ENTRY6(new String[] {"STRONG_CEN", "STRONG_OUT", "JUSTB4PRO"}, new String[]{"EAR_LEARN"}), - ENTRY7(new String[] {"SHORT_PRP", "LONG_PRP" }, new String[]{Constants.PUBLIC}), - ENTRY8(new String[] {"SUMMER"}, new String[]{Constants.PUBLIC, Constants.YUKON}), - ENTRY9(new String[] {"YOUTH"}, new String[]{Constants.PUBLIC}), - ENTRY10(new String[] {"POST_SEC"}, new String[]{"POST_SEC"}) - ; + ENTRY1(new String[] {FacilityTypeCodes.DIST_LEARN.getCode(), FacilityTypeCodes.DISTONLINE.getCode(), FacilityTypeCodes.ALT_PROGS.getCode()}, + new String[]{SchoolCategoryCodes.PUBLIC.getCode(), SchoolCategoryCodes.YUKON.getCode()}), + ENTRY2(new String[] {FacilityTypeCodes.STANDARD.getCode()}, new String[]{SchoolCategoryCodes.PUBLIC.getCode(), SchoolCategoryCodes.YUKON.getCode()}), + ENTRY3(new String[] {FacilityTypeCodes.DIST_LEARN.getCode(), FacilityTypeCodes.STANDARD.getCode()}, new String[]{SchoolCategoryCodes.OFFSHORE.getCode(), SchoolCategoryCodes.INDEPEND.getCode()}), + ENTRY4(new String[] {FacilityTypeCodes.STANDARD.getCode()}, new String[]{SchoolCategoryCodes.INDP_FNS.getCode(), SchoolCategoryCodes.FED_BAND.getCode()}), + ENTRY5(new String[] {FacilityTypeCodes.CONT_ED.getCode()}, new String[]{SchoolCategoryCodes.PUBLIC.getCode()}), + ENTRY6(new String[] {FacilityTypeCodes.STRONG_CEN.getCode(), FacilityTypeCodes.STRONG_OUT.getCode(), FacilityTypeCodes.JUSTB4PRO.getCode()}, + new String[]{SchoolCategoryCodes.EAR_LEARN.getCode()}), + ENTRY7(new String[] {FacilityTypeCodes.SHORT_PRP.getCode(), FacilityTypeCodes.LONG_PRP.getCode() }, new String[]{SchoolCategoryCodes.PUBLIC.getCode()}), + ENTRY8(new String[] {FacilityTypeCodes.SUMMER.getCode()}, new String[]{SchoolCategoryCodes.PUBLIC.getCode(), SchoolCategoryCodes.YUKON.getCode()}), + ENTRY9(new String[] {FacilityTypeCodes.YOUTH.getCode()}, new String[]{SchoolCategoryCodes.PUBLIC.getCode()}), + ENTRY10(new String[] {FacilityTypeCodes.POST_SEC.getCode()}, new String[]{SchoolCategoryCodes.POST_SEC.getCode()}); private final String[] facilityCodes; private final String[] mappedCategories; diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityTypeCodes.java b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityTypeCodes.java new file mode 100644 index 00000000..7b4d8190 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/FacilityTypeCodes.java @@ -0,0 +1,29 @@ +package ca.bc.gov.educ.api.institute.constants.v1; + +import lombok.Getter; + +/** + * The enum for school's facility type codes + */ +@Getter +public enum FacilityTypeCodes { + PROVINCIAL("PROVINCIAL"), + DIST_CONT("DIST_CONT"), + ELEC_DELIV("ELEC_DELIV"), + STANDARD("STANDARD"), + CONT_ED("CONT_ED"), + DIST_LEARN("DIST_LEARN"), + ALT_PROGS("ALT_PROGS"), + STRONG_CEN("STRONG_CEN"), + STRONG_OUT("STRONG_OUT"), + SHORT_PRP("SHORT_PRP"), + LONG_PRP("LONG_PRP"), + SUMMER("SUMMER"), + YOUTH("YOUTH"), + DISTONLINE("DISTONLINE"), + POST_SEC("POST_SEC"), + JUSTB4PRO("JUSTB4PRO"); + + private final String code; + FacilityTypeCodes(String code) { this.code = code; } +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/SchoolCategoryCodes.java b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/SchoolCategoryCodes.java new file mode 100644 index 00000000..67f89c78 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/institute/constants/v1/SchoolCategoryCodes.java @@ -0,0 +1,24 @@ +package ca.bc.gov.educ.api.institute.constants.v1; + +import lombok.Getter; + +/** + * The enum for school category codes + */ +@Getter +public enum SchoolCategoryCodes { + IMM_DATA("IMM_DATA"), + CHILD_CARE("CHILD_CARE"), + MISC("MISC"), + PUBLIC("PUBLIC"), + INDEPEND("INDEPEND"), + FED_BAND("FED_BAND"), + OFFSHORE("OFFSHORE"), + EAR_LEARN("EAR_LEARN"), + YUKON("YUKON"), + POST_SEC("POST_SEC"), + INDP_FNS("INDP_FNS"); + + private final String code; + SchoolCategoryCodes(String code) { this.code = code; } +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/service/EventHandlerServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/service/EventHandlerServiceTest.java index c5ce6faf..8c8a2c74 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/institute/service/EventHandlerServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/service/EventHandlerServiceTest.java @@ -1,30 +1,12 @@ package ca.bc.gov.educ.api.institute.service; -import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.AUTHORITY_FOUND; -import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.AUTHORITY_NOT_FOUND; -import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.SCHOOL_CREATED; -import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.SCHOOL_MOVED; -import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.SCHOOL_UPDATED; -import static ca.bc.gov.educ.api.institute.constants.v1.EventStatus.MESSAGE_PUBLISHED; -import static ca.bc.gov.educ.api.institute.constants.v1.EventType.*; -import static org.assertj.core.api.Assertions.assertThat; - import ca.bc.gov.educ.api.institute.constants.v1.Topics; -import ca.bc.gov.educ.api.institute.exception.ConflictFoundException; import ca.bc.gov.educ.api.institute.exception.EntityNotFoundException; import ca.bc.gov.educ.api.institute.filter.FilterOperation; import ca.bc.gov.educ.api.institute.mapper.v1.IndependentAuthorityMapper; import ca.bc.gov.educ.api.institute.mapper.v1.SchoolMapper; -import ca.bc.gov.educ.api.institute.model.v1.DistrictTombstoneEntity; -import ca.bc.gov.educ.api.institute.model.v1.IndependentAuthorityEntity; -import ca.bc.gov.educ.api.institute.model.v1.InstituteEvent; -import ca.bc.gov.educ.api.institute.model.v1.SchoolAddressEntity; -import ca.bc.gov.educ.api.institute.model.v1.SchoolEntity; -import ca.bc.gov.educ.api.institute.repository.v1.DistrictTombstoneRepository; -import ca.bc.gov.educ.api.institute.repository.v1.IndependentAuthorityRepository; -import ca.bc.gov.educ.api.institute.repository.v1.InstituteEventRepository; -import ca.bc.gov.educ.api.institute.repository.v1.SchoolMoveRepository; -import ca.bc.gov.educ.api.institute.repository.v1.SchoolRepository; +import ca.bc.gov.educ.api.institute.model.v1.*; +import ca.bc.gov.educ.api.institute.repository.v1.*; import ca.bc.gov.educ.api.institute.service.v1.EventHandlerService; import ca.bc.gov.educ.api.institute.struct.v1.*; import ca.bc.gov.educ.api.institute.util.JsonUtil; @@ -33,18 +15,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import java.io.IOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ExecutionException; import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Before; @@ -57,6 +27,19 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.ExecutionException; + +import static ca.bc.gov.educ.api.institute.constants.v1.EventOutcome.*; +import static ca.bc.gov.educ.api.institute.constants.v1.EventStatus.MESSAGE_PUBLISHED; +import static ca.bc.gov.educ.api.institute.constants.v1.EventType.*; +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @ActiveProfiles("test") @SpringBootTest @@ -81,7 +64,6 @@ public class EventHandlerServiceTest { @Autowired private EventHandlerService eventHandlerServiceUnderTest; private static final IndependentAuthorityMapper independentAuthorityMapper = IndependentAuthorityMapper.mapper; - private static final SchoolMapper schoolMapper = SchoolMapper.mapper; private final boolean isSynchronous = false; @Before public void setUp() { @@ -97,7 +79,7 @@ public void tearDown() { } @Test - public void testHandleEvent_givenEventTypeGET_AUTHORITY__whenNoStudentExist_shouldHaveEventOutcomeAUTHORITY_NOT_FOUND() throws JsonProcessingException, IOException { + public void testHandleEvent_givenEventTypeGET_AUTHORITY__whenNoStudentExist_shouldHaveEventOutcomeAUTHORITY_NOT_FOUND() throws IOException { var sagaId = UUID.randomUUID(); final Event event = Event.builder().eventType(GET_AUTHORITY).sagaId(sagaId).replyTo(INSTITUTE_API_TOPIC).eventPayload(JsonUtil.getJsonStringFromObject(UUID.randomUUID().toString())).build(); byte[] response = eventHandlerServiceUnderTest.handleGetAuthorityEvent(event, isSynchronous); @@ -144,7 +126,7 @@ public void testHandleEvent_givenEventTypeGET_AUTHORITY__whenAuthorityDoesNotExi @Test public void testHandleEvent_givenEventTypeGET_PAGINATED_SCHOOLS_BY_CRITERIA__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { - var schoolEntity = this.createNewSchoolData(null, "PUBLIC", "DISTONLINE");; + var schoolEntity = this.createNewSchoolData(null, "PUBLIC", "DISTONLINE"); schoolRepository.save(schoolEntity); SearchCriteria criteriaSchoolNumber = SearchCriteria.builder().key("schoolNumber").operation(FilterOperation.EQUAL).value(schoolEntity.getSchoolNumber()).valueType(ValueType.STRING).build(); @@ -189,7 +171,7 @@ public void testHandleEvent_givenEventTypeGET_PAGINATED_AUTHORITIES_BY_CRITERIA_ } @Test - public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_NEW_SCHOOL_NUMBER__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_NEW_SCHOOL_NUMBER__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); var schoolEntity = this.createNewSchoolData(null, "PUBLIC", "DISTONLINE"); @@ -219,8 +201,8 @@ public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_NEW_SCHOOL_NUMBER__ } @Test(expected = EntityNotFoundException.class) - public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WithNoDistrict__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { - final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); + public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WithNoDistrict__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException { + this.districtTombstoneRepository.save(this.createDistrictData()); var schoolEntity = this.createNewSchoolData(null, "PUBLIC", "DISTONLINE"); @@ -249,7 +231,7 @@ public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WithNoDistrict__DoesExis } @Test - public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_EXISTING_SCHOOL_NUMBER__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_EXISTING_SCHOOL_NUMBER__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); var schoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); @@ -277,7 +259,7 @@ public void testHandleEvent_givenEventTypeCREATE_SCHOOL_WITH_EXISTING_SCHOOL_NUM assertThat(schoolCreatedEvent.get().getEventOutcome()).isEqualTo(SCHOOL_CREATED.toString()); } @Test - public void testHandleEvent_givenEventTypeUPDATE_SCHOOL__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeUPDATE_SCHOOL__DoesExistAndSynchronousNatsMessage_shouldRespondWithData() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); var schoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); schoolEntity.setDistrictEntity(dist); @@ -301,7 +283,7 @@ public void testHandleEvent_givenEventTypeUPDATE_SCHOOL__DoesExistAndSynchronous } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); @@ -364,7 +346,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL__DoesExistAndSynchronousNa } @Test(expected = EntityNotFoundException.class) - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_DistrictNotFound__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_DistrictNotFound__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); @@ -401,7 +383,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_DistrictNotFound__DoesExis } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_whereSchoolNumberInNewDistrictIsAvailable__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_whereSchoolNumberInNewDistrictIsAvailable__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("99100", "PUBLIC", "DISTONLINE"); @@ -461,7 +443,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_whereSchoolNumberInNewDist } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNewSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNewSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "EAR_LEARN", "STRONG_CEN"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("99100", "PUBLIC", "DISTONLINE"); @@ -522,7 +504,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNewSchoolCategory__Doe } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("96100", "INDEPEND", "STANDARD"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("96100", "INDEPEND", "STANDARD"); @@ -583,7 +565,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCateg } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNonIndependentSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNonIndependentSchoolCategory__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("97100", "FED_BAND", "STANDARD"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("97100", "FED_BAND", "STANDARD"); @@ -644,7 +626,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withNonIndependentSchoolCa } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCategoryChange__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCategoryChange__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("97100", "FED_BAND", "STANDARD"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("96100", "OFFSHORE", "STANDARD"); @@ -705,9 +687,9 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolCateg } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolFacilityChange__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolFacilityChange__DoesExistAndSynchronousNatsMessage_shouldRespondWithDataAndCreateMoveHistory() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); - SchoolEntity toSchoolEntity = this.createNewSchoolData("97100", "INDEPEND", "DISTONLINE"); + SchoolEntity toSchoolEntity = this.createNewSchoolData("97100", "INDEPEND", "DIST_LEARN"); SchoolEntity fromSchoolEntity = this.createNewSchoolData("96100", "INDEPEND", "STANDARD"); LocalDateTime moveDate = LocalDateTime.now().plusDays(1).truncatedTo(ChronoUnit.MILLIS); @@ -744,8 +726,8 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolFacil //check that data in event payload is updated MoveSchoolData moveSchoolEventData = JsonUtil.getJsonObjectFromString(MoveSchoolData.class, event.getEventPayload()); assertThat(moveSchoolEventData.getToSchool().getSchoolId()).isNotNull(); - assertThat(moveSchoolEventData.getToSchool().getSchoolNumber()).isEqualTo("99000"); //new school number since school number already exists in district - assertThat(moveSchoolEventData.getToSchool().getSchoolNumber()).startsWith("99"); + assertThat(moveSchoolEventData.getToSchool().getSchoolNumber()).isEqualTo("96000"); //new school number since school number already exists in district + assertThat(moveSchoolEventData.getToSchool().getSchoolNumber()).startsWith("96"); //2 schools = 1 that was created + 1 that was closed for the move. assertThat(schoolRepository.findAll()).hasSize(2); @@ -766,7 +748,7 @@ public void testHandleEvent_givenEventTypeMOVE_SCHOOL_withIndependentSchoolFacil } @Test - public void testHandleEvent_givenEventTypeMOVE_SCHOOL__ToSchoolIdDoesNotExist_shouldThrowEntitynotFoundException() throws IOException, ExecutionException, InterruptedException { + public void testHandleEvent_givenEventTypeMOVE_SCHOOL__ToSchoolIdDoesNotExist_shouldThrowEntitynotFoundException() throws IOException { final DistrictTombstoneEntity dist = this.districtTombstoneRepository.save(this.createDistrictData()); SchoolEntity toSchoolEntity = this.createNewSchoolData("99000", "PUBLIC", "DISTONLINE"); LocalDateTime moveDate = LocalDateTime.now().plusDays(1).truncatedTo(ChronoUnit.MILLIS); @@ -836,8 +818,6 @@ private SchoolAddress createSchoolAddress() { } private MoveSchoolData createMoveSchoolData(School toSchool, UUID fromSchoolId, LocalDateTime moveDate) { - MoveSchoolData moveSchoolData = MoveSchoolData.builder().toSchool(toSchool).fromSchoolId(fromSchoolId.toString()).moveDate(moveDate.toString()).build(); - - return moveSchoolData; + return MoveSchoolData.builder().toSchool(toSchool).fromSchoolId(fromSchoolId.toString()).moveDate(moveDate.toString()).build(); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/institute/service/SchoolNumberGenerationServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/institute/service/SchoolNumberGenerationServiceTest.java index 8ad7fca4..57298116 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/institute/service/SchoolNumberGenerationServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/institute/service/SchoolNumberGenerationServiceTest.java @@ -1,15 +1,16 @@ package ca.bc.gov.educ.api.institute.service; -import ca.bc.gov.educ.api.institute.InstituteApiResourceApplication; import ca.bc.gov.educ.api.institute.exception.InvalidParameterException; import ca.bc.gov.educ.api.institute.exception.PreConditionFailedException; import ca.bc.gov.educ.api.institute.model.v1.DistrictTombstoneEntity; import ca.bc.gov.educ.api.institute.model.v1.FacilityTypeCodeEntity; import ca.bc.gov.educ.api.institute.model.v1.SchoolCategoryCodeEntity; import ca.bc.gov.educ.api.institute.model.v1.SchoolEntity; -import ca.bc.gov.educ.api.institute.repository.v1.*; +import ca.bc.gov.educ.api.institute.repository.v1.DistrictTombstoneRepository; +import ca.bc.gov.educ.api.institute.repository.v1.FacilityTypeCodeRepository; +import ca.bc.gov.educ.api.institute.repository.v1.SchoolCategoryCodeRepository; +import ca.bc.gov.educ.api.institute.repository.v1.SchoolRepository; import ca.bc.gov.educ.api.institute.service.v1.SchoolNumberGenerationService; - import lombok.extern.slf4j.Slf4j; import org.junit.After; import org.junit.Before; @@ -109,11 +110,11 @@ public void testCreateSchool_givenSchoolCodeYUKON_givenFacilityCodeDISTONLINE_sh @Test public void testCreateSchool_givenSchoolCodeINDEPEND_givenFacilityCodeALT_PROGS_shouldCreateValidSchoolNumber() { SchoolCategoryCodeEntity schoolCategoryCodeEntity = schoolCategoryCodeRepository.save(createSchoolCategoryCodeData("INDEPEND")); - FacilityTypeCodeEntity facilityTypeCodeEntity = facilityTypeCodeRepository.save(createFacilityTypeCodeData("ALT_PROGS")); + FacilityTypeCodeEntity facilityTypeCodeEntity = facilityTypeCodeRepository.save(createFacilityTypeCodeData("DIST_LEARN")); String schoolNumber = schoolNumberGenerationService.generateSchoolNumber("003", facilityTypeCodeEntity.getFacilityTypeCode(), schoolCategoryCodeEntity.getSchoolCategoryCode(), null); assertThat(schoolNumber) .isNotEmpty() - .isEqualTo("99000"); + .isEqualTo("96000"); } @Test @@ -368,7 +369,7 @@ public void testCreateSchool_givenSchoolCodePOST_SEC_givenFacilityCodePOST_shoul var schoolEntity = this.createSchoolDataWithSchoolNumber("99999","POST_SEC", "POST_SEC"); schoolEntity.setDistrictEntity(dist); this.schoolRepository.save(schoolEntity); - String schoolNumber = schoolNumberGenerationService.generateSchoolNumber("003", facilityTypeCodeEntity.getFacilityTypeCode(), schoolCategoryCodeEntity.getSchoolCategoryCode(), null); + schoolNumberGenerationService.generateSchoolNumber("003", facilityTypeCodeEntity.getFacilityTypeCode(), schoolCategoryCodeEntity.getSchoolCategoryCode(), null); } @Test public void testCreateSchool_givenSchoolCodePOST_SEC_givenFacilityCodePOST_shouldGetNextSchoolNumber() {