Skip to content

Commit

Permalink
Finalizing unit testing and move school.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris.ditcher authored and chris.ditcher committed Aug 2, 2024
1 parent 7247845 commit d53e67b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ca.bc.gov.educ.api.trax.model.dto.GradStatusEventPayloadDTO;
import ca.bc.gov.educ.api.trax.model.dto.SchoolContact;
import ca.bc.gov.educ.api.trax.model.dto.institute.District;
import ca.bc.gov.educ.api.trax.model.dto.institute.MoveSchoolData;
import ca.bc.gov.educ.api.trax.model.dto.institute.School;
import ca.bc.gov.educ.api.trax.model.entity.EventEntity;
import ca.bc.gov.educ.api.trax.repository.EventRepository;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void handleEvent(@NonNull final EventEntity eventEntity) {
this.eventServiceMap.get(CREATE_SCHOOL.toString()).processEvent(schoolCreated, eventEntity);
}
case MOVE_SCHOOL -> {
val schoolMoved = JsonUtil.getJsonObjectFromString(School.class, eventEntity.getEventPayload());
val schoolMoved = JsonUtil.getJsonObjectFromString(MoveSchoolData.class, eventEntity.getEventPayload());
this.eventServiceMap.get(MOVE_SCHOOL.toString()).processEvent(schoolMoved, eventEntity);
}
case UPDATE_DISTRICT -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import ca.bc.gov.educ.api.trax.model.dto.BaseModel;
import ca.bc.gov.educ.api.trax.model.dto.SchoolContact;
import ca.bc.gov.educ.api.trax.model.entity.institute.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.index.Indexed;
import org.springframework.stereotype.Component;

import java.util.List;
Expand Down Expand Up @@ -35,10 +32,6 @@ public class SchoolDetail extends BaseModel {
private String closedDate;
private boolean canIssueTranscripts;
private boolean canIssueCertificates;
private String createUser;
private String updateUser;
private String createDate;
private String updateDate;
List<SchoolContact> contacts;
List<SchoolAddress> addresses;
List<Note> notes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
import ca.bc.gov.educ.api.trax.model.dto.DistrictContact;
import ca.bc.gov.educ.api.trax.model.entity.EventEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ca.bc.gov.educ.api.trax.service.institute.DistrictService;

@Service
@Slf4j
public class DistrictContactUpdatedService extends EventBaseService<DistrictContact> {

private final DistrictService districtService;

@Autowired
public DistrictContactUpdatedService(DistrictService districtService) {
super();
this.districtService = districtService;
}

@Override
public void processEvent(final DistrictContact districtContact, EventEntity eventEntity) {
log.debug("Processing District Contact Deleted");
// process the eventEntity here as per https://eccbc.atlassian.net/browse/GRAD2-2648
this.updateEvent(eventEntity);
districtService.updateDistrictCache(districtContact.getDistrictId());
this.updateEventWithHistory(eventEntity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

import ca.bc.gov.educ.api.trax.constant.EventType;
import ca.bc.gov.educ.api.trax.exception.ServiceException;
import ca.bc.gov.educ.api.trax.model.dto.institute.School;
import ca.bc.gov.educ.api.trax.model.dto.institute.MoveSchoolData;
import ca.bc.gov.educ.api.trax.model.entity.EventEntity;
import ca.bc.gov.educ.api.trax.service.institute.SchoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
@Slf4j
public class SchoolMovedService extends EventBaseService<School> {
public class SchoolMovedService extends EventBaseService<MoveSchoolData> {

SchoolService schoolService;

Expand All @@ -21,10 +23,10 @@ public SchoolMovedService(SchoolService schoolService) {
}

@Override
public void processEvent(final School school, EventEntity eventEntity) {
public void processEvent(final MoveSchoolData moveSchoolData, EventEntity eventEntity) {
log.debug("Processing School Moved");
try{
schoolService.updateSchoolCache(school.getSchoolId());
schoolService.updateSchoolCache(Arrays.asList(moveSchoolData.getFromSchoolId(), moveSchoolData.getToSchool().getSchoolId()));
this.updateEventWithHistory(eventEntity);
} catch (ServiceException e) {
log.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.api.trax.service.institute;

import ca.bc.gov.educ.api.trax.constant.CacheKey;
import ca.bc.gov.educ.api.trax.exception.EntityNotFoundException;
import ca.bc.gov.educ.api.trax.exception.ServiceException;
import ca.bc.gov.educ.api.trax.model.dto.institute.School;
import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail;
Expand All @@ -22,7 +21,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Slf4j
@Service("InstituteSchoolService")
Expand Down Expand Up @@ -130,4 +128,15 @@ public void updateSchoolCache(String schoolId) throws ServiceException {
SchoolDetail.class, webClient);
schoolDetailRedisRepository.save(schoolDetailTransformer.transformToEntity(schoolDetail));
}

/**
* Updates the school and school details in the cache
* based on schoolId
* @param schoolIds the school id guids
*/
public void updateSchoolCache(List<String> schoolIds) throws ServiceException {
for (String schoolId : schoolIds) {
updateSchoolCache(schoolId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.springframework.boot.test.mock.mockito.MockBean;

import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.doThrow;

public class SchoolMovedServiceTest extends BaseReplicationServiceTest {
Expand All @@ -24,7 +24,7 @@ public class SchoolMovedServiceTest extends BaseReplicationServiceTest {

@Test
public void testProcessEvent_givenMOVE_SCHOOL_Event_shouldProcessEvent() throws JsonProcessingException {
final var request = TestUtils.createSchool();
final var request = TestUtils.createMoveSchoolData();
final var event = TestUtils.createEvent(EventType.MOVE_SCHOOL.toString(), request, this.replicationTestUtils.getEventRepository());
this.schoolMovedService.processEvent(request, event);
var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId());
Expand All @@ -38,8 +38,8 @@ public void testProcessEvent_givenMOVE_SCHOOL_Event_shouldProcessEvent() throws
@Test
public void testProcessEvent_givenMOVE_SCHOOL_Event_ServiceUnavailable_triggerError() throws JsonProcessingException {
final String ERROR_MSG = "Test Exception";
doThrow(new ServiceException(ERROR_MSG)).when(schoolServiceMock).updateSchoolCache(anyString());
final var request = TestUtils.createSchool();
doThrow(new ServiceException(ERROR_MSG)).when(schoolServiceMock).updateSchoolCache(anyList());
final var request = TestUtils.createMoveSchoolData();
final var event = TestUtils.createEvent(EventType.MOVE_SCHOOL.toString(), request, this.replicationTestUtils.getEventRepository());
this.schoolMovedService.processEvent(request, event);
var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId());
Expand Down
36 changes: 34 additions & 2 deletions api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import ca.bc.gov.educ.api.trax.model.dto.DistrictContact;
import ca.bc.gov.educ.api.trax.model.dto.GradStatusEventPayloadDTO;
import ca.bc.gov.educ.api.trax.model.dto.SchoolContact;
import ca.bc.gov.educ.api.trax.model.dto.institute.District;
import ca.bc.gov.educ.api.trax.model.dto.institute.School;
import ca.bc.gov.educ.api.trax.model.dto.institute.*;
import ca.bc.gov.educ.api.trax.model.entity.EventEntity;
import ca.bc.gov.educ.api.trax.model.entity.TraxStudentEntity;
import ca.bc.gov.educ.api.trax.repository.EventRepository;
Expand All @@ -16,6 +15,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.UUID;

import static ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants.DEFAULT_CREATED_BY;
Expand Down Expand Up @@ -118,6 +118,14 @@ public static School createSchool() {
return school;
}

public static MoveSchoolData createMoveSchoolData() {
var move = new MoveSchoolData();
move.setToSchool(createSchool());
move.setMoveDate(LocalDateTime.now().toString());
move.setFromSchoolId(UUID.randomUUID().toString());
return move;
}

public static DistrictContact createDistrictContact() {
var contact = new DistrictContact();
contact.setDistrictId(UUID.randomUUID().toString());
Expand Down Expand Up @@ -222,4 +230,28 @@ public static District createDistrict() {
return district;
}

public static SchoolDetail createSchoolDetail(){
String schoolId = UUID.randomUUID().toString();
SchoolAddress schoolAddress = new SchoolAddress();
schoolAddress.setSchoolId(schoolId);
schoolAddress.setAddressLine1("123 Fake St");
schoolAddress.setCity("Vancouverland");
schoolAddress.setCountryCode("CAN");
schoolAddress.setPostal("VQV2L2");
SchoolDetail schoolDetail = new SchoolDetail();
schoolDetail.setSchoolId(schoolId);
schoolDetail.setSchoolNumber("96006");
schoolDetail.setDistrictId(UUID.randomUUID().toString());
schoolDetail.setAddresses(Arrays.asList(schoolAddress));
schoolDetail.setCreateDate(LocalDateTime.now().toString());
schoolDetail.setCanIssueCertificates(true);
schoolDetail.setDisplayName("Blah");
schoolDetail.setCreateUser("Test");
schoolDetail.setUpdateDate(LocalDateTime.now().toString());
schoolDetail.setUpdateUser("Test");
schoolDetail.setCreateDate(LocalDateTime.now().toString());
schoolDetail.setCanIssueTranscripts(true);
schoolDetail.setDisplayNameNoSpecialChars("blah blah");
return schoolDetail;
}
}

0 comments on commit d53e67b

Please sign in to comment.