From 021f04419a2741e2f68dfda1ac1c2c6f5257860d Mon Sep 17 00:00:00 2001 From: Chris Ditcher Date: Wed, 29 May 2024 08:31:38 -0700 Subject: [PATCH] Created messaging subscribers for Institute contact events (#325) * Initial commit of Event handling for Institute Events * Replace logger with slf4j * Added model and services for contact updates * Added handler services for institute contact events * Updating events * Minor change * Flyway to expand update and create user in replication table to be in line with edx, institute. * Flyway to expand update and create user in replication table to be in line with edx, institute. * Added unit testing. * Removed TODOs * Added another test. * Bumping test coverage again. * Addressing maintainability issues. --------- Co-authored-by: chris.ditcher --- .../ChoreographEventHandler.java | 80 +++++++++++++++---- .../api/trax/config/RestErrorHandler.java | 3 +- .../educ/api/trax/constant/EventOutcome.java | 41 ++++++++++ .../gov/educ/api/trax/constant/EventType.java | 43 +++++++++- .../bc/gov/educ/api/trax/constant/Topics.java | 3 +- .../api/trax/controller/SchoolController.java | 2 - .../trax/messaging/jetstream/Subscriber.java | 5 ++ .../api/trax/model/dto/AuthorityContact.java | 36 +++++++++ .../educ/api/trax/model/dto/BaseModel.java | 6 +- .../api/trax/model/dto/DistrictContact.java | 38 +++++++++ .../api/trax/model/dto/SchoolContact.java | 38 +++++++++ .../AuthorityContactCreatedService.java | 24 ++++++ .../AuthorityContactDeletedService.java | 25 ++++++ .../AuthorityContactUpdatedService.java | 24 ++++++ .../educ/api/trax/service/CodeService.java | 6 +- .../DistrictContactCreatedService.java | 25 ++++++ .../DistrictContactDeletedService.java | 25 ++++++ .../DistrictContactUpdatedService.java | 25 ++++++ .../api/trax/service/EventBaseService.java | 23 ++++++ .../api/trax/service/EventCommonService.java | 32 ++++---- .../service/EventHandlerDelegatorService.java | 4 +- .../educ/api/trax/service/EventService.java | 4 +- .../service/GradStudentGraduatedService.java | 2 +- .../GradStudentUndoCompletionService.java | 2 +- .../service/GradStudentUpdatedService.java | 2 +- .../service/SchoolContactCreatedService.java | 25 ++++++ .../service/SchoolContactDeletedService.java | 25 ++++++ .../service/SchoolContactUpdatedService.java | 25 ++++++ .../trax/util/EducGradTraxApiConstants.java | 2 + ....27__DDL-ALTER_TABLE-replecation-event.sql | 4 + .../trax/controller/PsiControllerTest.java | 1 - .../AuthorityContactCreatedServiceTest.java | 28 +++++++ .../AuthorityContactDeletedServiceTest.java | 28 +++++++ .../AuthorityContactUpdatedServiceTest.java | 28 +++++++ .../service/BaseReplicationServiceTest.java | 48 +++++++++++ .../DistrictContactCreatedServiceTest.java | 28 +++++++ .../DistrictContactDeletedServiceTest.java | 28 +++++++ .../DistrictContactUpdatedServiceTest.java | 28 +++++++ .../api/trax/service/DistrictServiceTest.java | 4 - .../educ/api/trax/service/EdwServiceTest.java | 1 - .../EventHandlerDelegatorServiceTest.java | 30 +++++++ .../SchoolContactCreatedServiceTest.java | 28 +++++++ .../SchoolContactDeletedServiceTest.java | 28 +++++++ .../SchoolContactUpdatedServiceTest.java | 28 +++++++ .../api/trax/service/SchoolServiceTest.java | 10 --- .../gov/educ/api/trax/support/TestUtils.java | 72 ++++++++++++++++- .../api/trax/util/ReplicationTestUtils.java | 27 +++++++ api/src/test/resources/application.yaml | 2 + 48 files changed, 975 insertions(+), 71 deletions(-) create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/AuthorityContact.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/DistrictContact.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/SchoolContact.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/EventBaseService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedService.java create mode 100644 api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedService.java create mode 100644 api/src/main/resources/db/migration/1.0/V1.0.27__DDL-ALTER_TABLE-replecation-event.sql create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedServiceTest.java create mode 100644 api/src/test/java/ca/bc/gov/educ/api/trax/util/ReplicationTestUtils.java diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/choreographer/ChoreographEventHandler.java b/api/src/main/java/ca/bc/gov/educ/api/trax/choreographer/ChoreographEventHandler.java index 246bfa36..41c27084 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/choreographer/ChoreographEventHandler.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/choreographer/ChoreographEventHandler.java @@ -1,11 +1,16 @@ package ca.bc.gov.educ.api.trax.choreographer; +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.AuthorityContact; +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.entity.Event; import ca.bc.gov.educ.api.trax.service.EventService; import ca.bc.gov.educ.api.trax.util.JsonUtil; import com.google.common.util.concurrent.ThreadFactoryBuilder; import lombok.extern.slf4j.Slf4j; +import lombok.val; import org.jboss.threads.EnhancedQueueExecutor; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; @@ -41,25 +46,68 @@ public void handleEvent(@NonNull final Event event) { //only one thread will process all the request. since RDB won't handle concurrent requests. this.eventExecutor.execute(() -> { try { - switch (event.getEventType()) { - case "GRAD_STUDENT_GRADUATED": + switch (EventType.valueOf(event.getEventType())) { + case GRAD_STUDENT_GRADUATED -> { log.debug("Processing GRAD_STUDENT_GRADUATED event record :: {} ", event); - final GradStatusEventPayloadDTO eventPayload1 = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); - this.eventServiceMap.get(GRAD_STUDENT_GRADUATED.toString()).processEvent(eventPayload1, event); - break; - case "GRAD_STUDENT_UPDATED": + val studentGraduated = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); + this.eventServiceMap.get(GRAD_STUDENT_GRADUATED.toString()).processEvent(studentGraduated, event); + } + case GRAD_STUDENT_UPDATED -> { log.debug("Processing GRAD_STUDENT_UPDATED event record :: {} ", event); - final GradStatusEventPayloadDTO eventPayload2 = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); - this.eventServiceMap.get(GRAD_STUDENT_UPDATED.toString()).processEvent(eventPayload2, event); - break; - case "GRAD_STUDENT_UNDO_COMPLETION": + val studentUpdated = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); + this.eventServiceMap.get(GRAD_STUDENT_UPDATED.toString()).processEvent(studentUpdated, event); + } + case GRAD_STUDENT_UNDO_COMPLETION -> { log.debug("Processing GRAD_STUDENT_UNDO_COMPLETION event record :: {} ", event); - final GradStatusEventPayloadDTO eventPayload3 = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); - this.eventServiceMap.get(GRAD_STUDENT_UNDO_COMPLETION.toString()).processEvent(eventPayload3, event); - break; - default: - log.warn("Silently ignoring event: {}", event); - break; + val studentUndoCompletion = JsonUtil.getJsonObjectFromString(GradStatusEventPayloadDTO.class, event.getEventPayload()); + this.eventServiceMap.get(GRAD_STUDENT_UNDO_COMPLETION.toString()).processEvent(studentUndoCompletion, event); + } + case CREATE_SCHOOL_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val schoolContactCreated = JsonUtil.getJsonObjectFromString(SchoolContact.class, event.getEventPayload()); + this.eventServiceMap.get(CREATE_SCHOOL_CONTACT.toString()).processEvent(schoolContactCreated, event); + } + case UPDATE_SCHOOL_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val schoolContactUpdated = JsonUtil.getJsonObjectFromString(SchoolContact.class, event.getEventPayload()); + this.eventServiceMap.get(UPDATE_SCHOOL_CONTACT.toString()).processEvent(schoolContactUpdated, event); + } + case DELETE_SCHOOL_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val schoolContactDeleted = JsonUtil.getJsonObjectFromString(SchoolContact.class, event.getEventPayload()); + this.eventServiceMap.get(DELETE_SCHOOL_CONTACT.toString()).processEvent(schoolContactDeleted, event); + } + case CREATE_AUTHORITY_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val authorityContactCreated = JsonUtil.getJsonObjectFromString(AuthorityContact.class, event.getEventPayload()); + this.eventServiceMap.get(CREATE_AUTHORITY_CONTACT.toString()).processEvent(authorityContactCreated, event); + } + case UPDATE_AUTHORITY_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val authorityContactUpdated = JsonUtil.getJsonObjectFromString(AuthorityContact.class, event.getEventPayload()); + this.eventServiceMap.get(UPDATE_AUTHORITY_CONTACT.toString()).processEvent(authorityContactUpdated, event); + } + case DELETE_AUTHORITY_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val authorityContactDeleted = JsonUtil.getJsonObjectFromString(AuthorityContact.class, event.getEventPayload()); + this.eventServiceMap.get(DELETE_AUTHORITY_CONTACT.toString()).processEvent(authorityContactDeleted, event); + } + case CREATE_DISTRICT_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val districtContactCreated = JsonUtil.getJsonObjectFromString(DistrictContact.class, event.getEventPayload()); + this.eventServiceMap.get(CREATE_DISTRICT_CONTACT.toString()).processEvent(districtContactCreated, event); + } + case UPDATE_DISTRICT_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val districtContactUpdated = JsonUtil.getJsonObjectFromString(DistrictContact.class, event.getEventPayload()); + this.eventServiceMap.get(UPDATE_DISTRICT_CONTACT.toString()).processEvent(districtContactUpdated, event); + } + case DELETE_DISTRICT_CONTACT -> { + log.debug("Processing {} event record :: {} ", event.getEventType(), event); + val districtContactDeleted = JsonUtil.getJsonObjectFromString(DistrictContact.class, event.getEventPayload()); + this.eventServiceMap.get(DELETE_DISTRICT_CONTACT.toString()).processEvent(districtContactDeleted, event); + } + default -> log.warn("Silently ignoring event: {}", event); } } catch (final Exception exception) { log.error("Exception while processing event :: {}", event, exception); diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/config/RestErrorHandler.java b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RestErrorHandler.java index 43e91256..0b3c8933 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/config/RestErrorHandler.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/config/RestErrorHandler.java @@ -1,8 +1,7 @@ package ca.bc.gov.educ.api.trax.config; -import ca.bc.gov.educ.api.trax.exception.BusinessException; -import ca.bc.gov.educ.api.trax.util.ApiResponseMessage.MessageTypeEnum; import ca.bc.gov.educ.api.trax.exception.GradBusinessRuleException; +import ca.bc.gov.educ.api.trax.util.ApiResponseMessage.MessageTypeEnum; import ca.bc.gov.educ.api.trax.util.ApiResponseModel; import ca.bc.gov.educ.api.trax.util.GradValidation; import org.hibernate.dialect.lock.OptimisticEntityLockException; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventOutcome.java b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventOutcome.java index fbf0374b..9a3c2a3c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventOutcome.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventOutcome.java @@ -12,4 +12,45 @@ public enum EventOutcome { * Student updated event outcome. */ TRAX_STUDENT_MASTER_UPDATED, + + /** + * Institute API even outcomes + */ + SCHOOL_UPDATED, + + SCHOOL_CREATED, + + DISTRICT_UPDATED, + + DISTRICT_CREATED, + + AUTHORITY_UPDATED, + + AUTHORITY_CREATED, + + AUTHORITY_FOUND, + + AUTHORITY_NOT_FOUND, + + SCHOOL_NOT_FOUND, + + SCHOOL_MOVED, + + SCHOOL_CONTACT_CREATED, + + SCHOOL_CONTACT_UPDATED, + + SCHOOL_CONTACT_DELETED, + + DISTRICT_CONTACT_CREATED, + + DISTRICT_CONTACT_UPDATED, + + DISTRICT_CONTACT_DELETED, + + AUTHORITY_CONTACT_CREATED, + + AUTHORITY_CONTACT_UPDATED, + + AUTHORITY_CONTACT_DELETED } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventType.java b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventType.java index 60817a70..405b3554 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventType.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/EventType.java @@ -22,5 +22,46 @@ public enum EventType { XPROGRAM, ASSESSMENT, COURSE, - FI10ADD + FI10ADD, + + /** + * INSTITUTE API EVENT TYPES + */ + UPDATE_SCHOOL, + + CREATE_SCHOOL, + + UPDATE_DISTRICT, + + CREATE_DISTRICT, + + UPDATE_AUTHORITY, + + CREATE_AUTHORITY, + + GET_AUTHORITY, + + GET_PAGINATED_SCHOOLS, + + GET_PAGINATED_AUTHORITIES, + + MOVE_SCHOOL, + + CREATE_SCHOOL_CONTACT, + + UPDATE_SCHOOL_CONTACT, + + DELETE_SCHOOL_CONTACT, + + CREATE_DISTRICT_CONTACT, + + UPDATE_DISTRICT_CONTACT, + + DELETE_DISTRICT_CONTACT, + + CREATE_AUTHORITY_CONTACT, + + UPDATE_AUTHORITY_CONTACT, + + DELETE_AUTHORITY_CONTACT } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/Topics.java b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/Topics.java index dc5f6fab..93d6fa50 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/constant/Topics.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/constant/Topics.java @@ -11,6 +11,7 @@ public enum Topics { /** * TraxUpdate events topic. */ - TRAX_UPDATE_EVENT_TOPIC + TRAX_UPDATE_EVENT_TOPIC, + INSTITUTE_EVENTS_TOPIC } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java index 53058d6b..fde0ff76 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/SchoolController.java @@ -14,8 +14,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.extern.slf4j.Slf4j; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/messaging/jetstream/Subscriber.java b/api/src/main/java/ca/bc/gov/educ/api/trax/messaging/jetstream/Subscriber.java index a8fa6e2a..4e3c2e5e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/messaging/jetstream/Subscriber.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/messaging/jetstream/Subscriber.java @@ -72,6 +72,11 @@ private void initializeStreamTopicMap() { final List traxStatusEventsTopics = new ArrayList<>(); traxStatusEventsTopics.add(Topics.TRAX_UPDATE_EVENT_TOPIC.name()); this.streamTopicsMap.put(EducGradTraxApiConstants.TRAX_STREAM_NAME, traxStatusEventsTopics); + + final List instituteEventsTopics = new ArrayList<>(); + instituteEventsTopics.add(Topics.INSTITUTE_EVENTS_TOPIC.name()); + this.streamTopicsMap.put(EducGradTraxApiConstants.INSTITUTE_STREAM_NAME, instituteEventsTopics); + } @PostConstruct diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/AuthorityContact.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/AuthorityContact.java new file mode 100644 index 00000000..4e9c0474 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/AuthorityContact.java @@ -0,0 +1,36 @@ +package ca.bc.gov.educ.api.trax.model.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@Builder +@EqualsAndHashCode(callSuper = true) +public class AuthorityContact extends BaseModel { + + private String authorityContactId; + + private String independentAuthorityId; + + private String authorityContactTypeCode; + + private String phoneNumber; + + private String phoneExtension; + + private String alternatePhoneNumber; + + private String alternatePhoneExtension; + + private String email; + + private String firstName; + + private String lastName; + + private String effectiveDate; + + private String expiryDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/BaseModel.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/BaseModel.java index cc9f97de..5b3d5120 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/BaseModel.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/BaseModel.java @@ -2,12 +2,10 @@ import lombok.Data; -import java.sql.Date; - @Data public class BaseModel { private String createUser; - private Date createDate; + private String createDate; private String updateUser; - private Date updateDate; + private String updateDate; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/DistrictContact.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/DistrictContact.java new file mode 100644 index 00000000..e5c3362e --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/DistrictContact.java @@ -0,0 +1,38 @@ +package ca.bc.gov.educ.api.trax.model.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@Builder +@EqualsAndHashCode(callSuper = true) +public class DistrictContact extends BaseModel { + + private String districtContactId; + + private String districtId; + + private String districtContactTypeCode; + + private String phoneNumber; + + private String jobTitle; + + private String phoneExtension; + + private String alternatePhoneNumber; + + private String alternatePhoneExtension; + + private String email; + + private String firstName; + + private String lastName; + + private String effectiveDate; + + private String expiryDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/SchoolContact.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/SchoolContact.java new file mode 100644 index 00000000..6fbe94c7 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/SchoolContact.java @@ -0,0 +1,38 @@ +package ca.bc.gov.educ.api.trax.model.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@Builder +@EqualsAndHashCode(callSuper = true) +public class SchoolContact extends BaseModel { + + private String schoolContactId; + + private String schoolId; + + private String schoolContactTypeCode; + + private String phoneNumber; + + private String jobTitle; + + private String phoneExtension; + + private String alternatePhoneNumber; + + private String alternatePhoneExtension; + + private String email; + + private String firstName; + + private String lastName; + + private String effectiveDate; + + private String expiryDate; + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedService.java new file mode 100644 index 00000000..6786d604 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedService.java @@ -0,0 +1,24 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.AuthorityContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +@Service +@Slf4j +public class AuthorityContactCreatedService extends EventBaseService { + + @Override + public void processEvent(final AuthorityContact districtContact, Event event) { + log.debug("Processing Authority Contact Created"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.CREATE_AUTHORITY_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedService.java new file mode 100644 index 00000000..80e45c63 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.AuthorityContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class AuthorityContactDeletedService extends EventBaseService { + + @Override + public void processEvent(final AuthorityContact districtContact, Event event) { + log.debug("Processing Authority Contact Deleted"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.DELETE_AUTHORITY_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedService.java new file mode 100644 index 00000000..5495e37b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedService.java @@ -0,0 +1,24 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.AuthorityContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +@Service +@Slf4j +public class AuthorityContactUpdatedService extends EventBaseService { + + @Override + public void processEvent(final AuthorityContact districtContact, Event event) { + log.debug("Processing Authority Contact Updated"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.UPDATE_AUTHORITY_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java index d232ae98..e492228e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/CodeService.java @@ -8,8 +8,8 @@ import ca.bc.gov.educ.api.trax.model.transformer.GradProvinceTransformer; import ca.bc.gov.educ.api.trax.repository.GradCountryRepository; import ca.bc.gov.educ.api.trax.repository.GradProvinceRepository; -import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; import ca.bc.gov.educ.api.trax.util.GradValidation; +import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +17,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; -import jakarta.transaction.Transactional; -import java.util.*; +import java.util.List; +import java.util.Optional; @Service public class CodeService { diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedService.java new file mode 100644 index 00000000..ee41531f --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.DistrictContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class DistrictContactCreatedService extends EventBaseService { + + @Override + public void processEvent(final DistrictContact districtContact, Event event) { + log.debug("Processing District Contact Created"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.CREATE_DISTRICT_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedService.java new file mode 100644 index 00000000..04dfb5b2 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.DistrictContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class DistrictContactDeletedService extends EventBaseService { + + @Override + public void processEvent(final DistrictContact districtContact, Event event) { + log.debug("Processing District Contact Deleted"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.DELETE_DISTRICT_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedService.java new file mode 100644 index 00000000..bdb80990 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.DistrictContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class DistrictContactUpdatedService extends EventBaseService { + + @Override + public void processEvent(final DistrictContact districtContact, Event event) { + log.debug("Processing District Contact Deleted"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.UPDATE_DISTRICT_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventBaseService.java new file mode 100644 index 00000000..aed619fa --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventBaseService.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventStatus; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import ca.bc.gov.educ.api.trax.repository.EventRepository; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; + +public abstract class EventBaseService implements EventService { + + @Autowired + protected EventRepository eventRepository; + + protected void updateEvent(final Event event) { + this.eventRepository.findByEventId(event.getEventId()).ifPresent(existingEvent -> { + existingEvent.setEventStatus(EventStatus.PROCESSED.toString()); + existingEvent.setUpdateDate(LocalDateTime.now()); + this.eventRepository.save(existingEvent); + }); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java index 22991ea8..d07b18ee 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventCommonService.java @@ -4,29 +4,27 @@ import ca.bc.gov.educ.api.trax.model.dto.GradStatusEventPayloadDTO; import ca.bc.gov.educ.api.trax.model.entity.Event; import ca.bc.gov.educ.api.trax.model.entity.TraxStudentEntity; -import ca.bc.gov.educ.api.trax.repository.EventRepository; import ca.bc.gov.educ.api.trax.repository.TraxStudentRepository; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiUtils; import ca.bc.gov.educ.api.trax.util.ReplicationUtils; +import jakarta.persistence.EntityManager; +import jakarta.persistence.EntityTransaction; +import lombok.extern.slf4j.Slf4j; import lombok.val; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import jakarta.persistence.EntityManager; -import jakarta.persistence.EntityTransaction; import java.time.LocalDateTime; import java.util.*; import static ca.bc.gov.educ.api.trax.constant.EventStatus.PROCESSED; -public abstract class EventCommonService implements EventService { - - private static Logger logger = LoggerFactory.getLogger(EventCommonService.class); +@Slf4j +public abstract class EventCommonService extends EventBaseService { + public static final String FIELD_GRAD_REQT_YEAR = "GRAD_REQT_YEAR"; public static final String FIELD_GRAD_REQT_YEAR_AT_GRAD = "GRAD_REQT_YEAR_AT_GRAD"; @@ -48,12 +46,10 @@ public abstract class EventCommonService implements EventService { @Autowired private TraxStudentRepository traxStudentRepository; @Autowired - private EventRepository eventRepository; - @Autowired private EducGradTraxApiConstants constants; @Override - public void processEvent(T request, Event event) { + public void processEvent(T request, Event event) { GradStatusEventPayloadDTO gradStatusUpdate = (GradStatusEventPayloadDTO) request; val em = this.getEntityManager(); @@ -62,14 +58,14 @@ public void processEvent(T request, Event event) { try { process(existingStudent, gradStatusUpdate, em, tx, constants.isTraxUpdateEnabled()); - var existingEvent = eventRepository.findByEventId(event.getEventId()); + var existingEvent = this.eventRepository.findByEventId(event.getEventId()); existingEvent.ifPresent(eventRecord -> { eventRecord.setEventStatus(PROCESSED.toString()); eventRecord.setUpdateDate(LocalDateTime.now()); eventRepository.saveAndFlush(eventRecord); }); } catch (Exception e) { - logger.error("Error occurred saving entity {}", e.getMessage()); + log.error("Error occurred saving entity {}", e.getMessage()); tx.rollback(); } finally { if (em.isOpen()) { @@ -80,7 +76,7 @@ public void processEvent(T request, Event event) { private void process(Optional existingStudent, GradStatusEventPayloadDTO gradStatusUpdate, EntityManager em, EntityTransaction tx, boolean updateTrax) { if (updateTrax && existingStudent.isPresent()) { - logger.debug("==========> Start - Trax Incremental Update: pen# [{}]", gradStatusUpdate.getPen()); + log.debug("==========> Start - Trax Incremental Update: pen# [{}]", gradStatusUpdate.getPen()); Map> updateFieldsMap = setupUpdateFieldsMap(); specialHandlingOnUpdateFieldsMap(updateFieldsMap, existingStudent.get(), gradStatusUpdate); // Needs to update required fields from GraduationStatus to TraxStudentEntity @@ -91,11 +87,11 @@ private void process(Optional existingStudent, GradStatusEven em.createNativeQuery(buildUpdateQuery(gradStatusUpdate.getPen(), updateFieldsMap)) .setHint("javax.persistence.query.timeout", 10000).executeUpdate(); tx.commit(); - logger.debug(" === Update Transaction is committed! ==="); + log.debug(" === Update Transaction is committed! ==="); } else { - logger.debug(" === Skip Transaction as no changes are detected!!! ==="); + log.debug(" === Skip Transaction as no changes are detected!!! ==="); } - logger.debug("==========> End - Trax Incremental Update: pen# [{}]", gradStatusUpdate.getPen()); + log.debug("==========> End - Trax Incremental Update: pen# [{}]", gradStatusUpdate.getPen()); } } @@ -259,7 +255,7 @@ private String buildUpdateQuery(String pen, Map> sb.append(" WHERE STUD_NO=" + "'" + StringUtils.rightPad(pen, 10) + "'"); // a space is appended CAREFUL not to remove. - logger.debug("Update Query: {}", sb); + log.debug("Update Query: {}", sb); return sb.toString(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorService.java index a6c217e0..50ccb473 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorService.java @@ -46,11 +46,11 @@ public void handleChoreographyEvent(@NonNull final ChoreographedEvent choreograp if (message.getSubject().equalsIgnoreCase(TRAX_UPDATE_EVENT_TOPIC.toString())) { this.choreographedEventPersistenceService.updateEventStatus(choreographedEvent); message.ack(); - log.warn("acknowledged to Jet Stream for TRAX UPDATE EVENT sent..."); + log.debug("acknowledged to Jet Stream for TRAX UPDATE EVENT sent..."); } else { final var persistedEvent = this.choreographedEventPersistenceService.persistEventToDB(choreographedEvent); message.ack(); // acknowledge to Jet Stream that api got the message and it is now in DB. - log.warn("acknowledged to Jet Stream for GRAD STATUS EVENT received..."); + log.debug("acknowledged to Jet Stream for EVENT received: {}", persistedEvent.getEventType()); this.choreographer.handleEvent(persistedEvent); } } catch (final BusinessException businessException) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventService.java index ad25697e..eed4fe00 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/EventService.java @@ -2,9 +2,9 @@ import ca.bc.gov.educ.api.trax.model.entity.Event; -public interface EventService { +public interface EventService { - void processEvent(T request, Event event); + void processEvent(T request, Event event); String getEventType(); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedService.java index 46681dff..fab1d826 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentGraduatedService.java @@ -17,7 +17,7 @@ @Service @Slf4j -public class GradStudentGraduatedService extends EventCommonService { +public class GradStudentGraduatedService extends EventCommonService { private final EntityManagerFactory emf; @Autowired diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionService.java index 67766d45..20d96946 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUndoCompletionService.java @@ -17,7 +17,7 @@ @Service @Slf4j -public class GradStudentUndoCompletionService extends EventCommonService { +public class GradStudentUndoCompletionService extends EventCommonService { private final EntityManagerFactory emf; @Autowired diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedService.java index 32d200a4..9ef8b2b5 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/GradStudentUpdatedService.java @@ -17,7 +17,7 @@ @Service @Slf4j -public class GradStudentUpdatedService extends EventCommonService { +public class GradStudentUpdatedService extends EventCommonService { private final EntityManagerFactory emf; @Autowired diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedService.java new file mode 100644 index 00000000..2401fcb9 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.SchoolContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class SchoolContactCreatedService extends EventBaseService { + + @Override + public void processEvent(final SchoolContact districtContact, Event event) { + log.debug("Processing School Contact Created"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.CREATE_SCHOOL_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedService.java new file mode 100644 index 00000000..8ae2fbe4 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.SchoolContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class SchoolContactDeletedService extends EventBaseService { + + @Override + public void processEvent(final SchoolContact districtContact, Event event) { + log.debug("Processing School Contact Deleted"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.DELETE_SCHOOL_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedService.java new file mode 100644 index 00000000..12befcab --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedService.java @@ -0,0 +1,25 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.constant.EventType; +import ca.bc.gov.educ.api.trax.model.dto.SchoolContact; +import ca.bc.gov.educ.api.trax.model.entity.Event; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class SchoolContactUpdatedService extends EventBaseService { + + @Override + public void processEvent(final SchoolContact districtContact, Event event) { + log.debug("Processing School Contact Updated"); + // process the event here as per https://eccbc.atlassian.net/browse/GRAD2-2648 + this.updateEvent(event); + } + + @Override + public String getEventType() { + return EventType.UPDATE_SCHOOL_CONTACT.toString(); + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java index f4cb947c..c0198cb3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java @@ -18,6 +18,8 @@ public class EducGradTraxApiConstants { public static final String API_NAME = "GRAD-TRAX-API"; public static final String GRAD_STREAM_NAME ="GRAD_STATUS_EVENT_STREAM"; public static final String TRAX_STREAM_NAME="TRAX_STATUS_EVENT_STREAM"; + + public static final String INSTITUTE_STREAM_NAME="INSTITUTE_EVENTS"; public static final String CORRELATION_ID = "correlationID"; //API end-point Mapping constants diff --git a/api/src/main/resources/db/migration/1.0/V1.0.27__DDL-ALTER_TABLE-replecation-event.sql b/api/src/main/resources/db/migration/1.0/V1.0.27__DDL-ALTER_TABLE-replecation-event.sql new file mode 100644 index 00000000..66633a75 --- /dev/null +++ b/api/src/main/resources/db/migration/1.0/V1.0.27__DDL-ALTER_TABLE-replecation-event.sql @@ -0,0 +1,4 @@ +ALTER TABLE REPLICATION_EVENT MODIFY ( + CREATE_USER VARCHAR2(100), + UPDATE_USER VARCHAR2(100) +); \ No newline at end of file diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/PsiControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/PsiControllerTest.java index 7e3b7757..42ca5d06 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/PsiControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/PsiControllerTest.java @@ -14,7 +14,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedServiceTest.java new file mode 100644 index 00000000..93dfa196 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactCreatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class AuthorityContactCreatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private AuthorityContactCreatedService authorityContactCreatedService; + + @Test + public void testProcessEvent_givenCREATE_AUTHORITY_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createAuthorityContact(); + final var event = TestUtils.createEvent("CREATE_AUTHORITY_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.authorityContactCreatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("CREATE_AUTHORITY_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedServiceTest.java new file mode 100644 index 00000000..16b45d97 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactDeletedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class AuthorityContactDeletedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private AuthorityContactDeletedService authorityContactDeletedService; + + @Test + public void testProcessEvent_givenUPDATE_AUTHORITY_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createAuthorityContact(); + final var event = TestUtils.createEvent("DELETE_AUTHORITY_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.authorityContactDeletedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("DELETE_AUTHORITY_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedServiceTest.java new file mode 100644 index 00000000..90c1522f --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/AuthorityContactUpdatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class AuthorityContactUpdatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private AuthorityContactUpdatedService authorityContactUpdatedService; + + @Test + public void testProcessEvent_givenUPDATE_AUTHORITY_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createAuthorityContact(); + final var event = TestUtils.createEvent("UPDATE_AUTHORITY_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.authorityContactUpdatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("UPDATE_AUTHORITY_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java new file mode 100644 index 00000000..8a244580 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/BaseReplicationServiceTest.java @@ -0,0 +1,48 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.EducGradTraxApiApplication; +import ca.bc.gov.educ.api.trax.messaging.NatsConnection; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; +import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; +import ca.bc.gov.educ.api.trax.util.ReplicationTestUtils; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {EducGradTraxApiApplication.class}) +@ActiveProfiles("test") +@AutoConfigureMockMvc +public abstract class BaseReplicationServiceTest { + + @Autowired + protected ReplicationTestUtils replicationTestUtils; + + @MockBean + public Publisher publisher; + + @MockBean + public Subscriber subscriber; + + @MockBean + public NatsConnection natsConnection; + + @MockBean + public ClientRegistrationRepository clientRegistrationRepository; + + @MockBean + public OAuth2AuthorizedClientRepository oAuth2AuthorizedClientRepository; + + @Before + public void resetState() { + this.replicationTestUtils.cleanDB(); + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedServiceTest.java new file mode 100644 index 00000000..675a2b06 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactCreatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class DistrictContactCreatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private DistrictContactCreatedService districtContactCreatedService; + + @Test + public void testProcessEvent_givenCREATE_DISTRICT_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createDistrictContact(); + final var event = TestUtils.createEvent("CREATE_DISTRICT_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.districtContactCreatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("CREATE_DISTRICT_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedServiceTest.java new file mode 100644 index 00000000..14f187f6 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactDeletedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class DistrictContactDeletedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private DistrictContactDeletedService districtContactDeletedService; + + @Test + public void testProcessEvent_givenDELETE_DISTRICT_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createDistrictContact(); + final var event = TestUtils.createEvent("DELETE_DISTRICT_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.districtContactDeletedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("DELETE_DISTRICT_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedServiceTest.java new file mode 100644 index 00000000..d91b65aa --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictContactUpdatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class DistrictContactUpdatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private DistrictContactUpdatedService districtContactUpdatedService; + + @Test + public void testProcessEvent_givenUPDATE_DISTRICT_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createDistrictContact(); + final var event = TestUtils.createEvent("UPDATE_DISTRICT_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.districtContactUpdatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("UPDATE_DISTRICT_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java index 8967b0bd..e78077b4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/DistrictServiceTest.java @@ -21,20 +21,16 @@ import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; -import org.springframework.core.ParameterizedTypeReference; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; import java.util.List; import java.util.Optional; -import java.util.function.Consumer; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.openMocks; diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java index 4d19e56b..c9dc8733 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EdwServiceTest.java @@ -19,7 +19,6 @@ import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.reactive.function.client.WebClient; import java.math.BigDecimal; import java.util.Arrays; diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java new file mode 100644 index 00000000..830b79fe --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/EventHandlerDelegatorServiceTest.java @@ -0,0 +1,30 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.model.dto.ChoreographedEvent; +import io.nats.client.Message; +import org.junit.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import java.io.IOException; + +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +public class EventHandlerDelegatorServiceTest extends BaseReplicationServiceTest { + + @MockBean + private EventHandlerDelegatorService eventHandlerDelegatorService; + + @MockBean + private ChoreographedEvent choreographedEvent; + + @MockBean + private Message message; + + @Test + public void whenHandleChoreographyEvent_thenVerified() throws IOException { + this.eventHandlerDelegatorService.handleChoreographyEvent(this.choreographedEvent, this.message); + verify(eventHandlerDelegatorService, times(1)).handleChoreographyEvent(this.choreographedEvent, this.message); + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedServiceTest.java new file mode 100644 index 00000000..e5ef5b88 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactCreatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class SchoolContactCreatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private SchoolContactCreatedService schoolContactCreatedService; + + @Test + public void testProcessEvent_givenCREATE_SCHOOL_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createSchoolContact(); + final var event = TestUtils.createEvent("CREATE_SCHOOL_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.schoolContactCreatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("CREATE_SCHOOL_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedServiceTest.java new file mode 100644 index 00000000..f00dbb34 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactDeletedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import static org.assertj.core.api.Assertions.fail; + +public class SchoolContactDeletedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private SchoolContactDeletedService schoolContactDeletedService; + + @Test + public void testProcessEvent_givenDELETE_SCHOOL_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createSchoolContact(); + final var event = TestUtils.createEvent("DELETE_SCHOOL_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.schoolContactDeletedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("DELETE_SCHOOL_CONTACT failed to process"); + } + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedServiceTest.java new file mode 100644 index 00000000..7d44daba --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolContactUpdatedServiceTest.java @@ -0,0 +1,28 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.support.TestUtils; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.assertj.core.api.Assertions.fail; + +public class SchoolContactUpdatedServiceTest extends BaseReplicationServiceTest { + + @Autowired + private SchoolContactUpdatedService schoolContactUpdatedService; + + @Test + public void testProcessEvent_givenUPDATE_SCHOOL_CONTACT_Event_shouldProcessEvent() throws JsonProcessingException { + final var request = TestUtils.createSchoolContact(); + final var event = TestUtils.createEvent("UPDATE_SCHOOL_CONTACT", request, this.replicationTestUtils.getEventRepository()); + this.schoolContactUpdatedService.processEvent(request, event); + var result = this.replicationTestUtils.getEventRepository().findById(event.getReplicationEventId()); + if(result.isPresent()){ + Assert.assertEquals("PROCESSED", result.get().getEventStatus()); + } else { + fail("UPDATE_SCHOOL_CONTACT failed to process"); + } + } +} diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java index 4ca1145e..4892a7c1 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolServiceTest.java @@ -14,10 +14,8 @@ import ca.bc.gov.educ.api.trax.util.CommonSchoolCache; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -25,21 +23,13 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.system.CapturedOutput; -import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.annotation.Bean; import org.springframework.core.ParameterizedTypeReference; import org.springframework.data.jpa.domain.Specification; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider; -import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; -import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager; -import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import java.util.ArrayList; diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java b/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java index 2923ab8b..68410c42 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/support/TestUtils.java @@ -1,6 +1,9 @@ package ca.bc.gov.educ.api.trax.support; +import ca.bc.gov.educ.api.trax.model.dto.AuthorityContact; +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.entity.Event; import ca.bc.gov.educ.api.trax.model.entity.TraxStudentEntity; import ca.bc.gov.educ.api.trax.repository.EventRepository; @@ -8,7 +11,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.commons.lang3.StringUtils; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.UUID; import static ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants.DEFAULT_CREATED_BY; @@ -35,7 +40,7 @@ public static Event createEvent(String eventType, Object payload, EventRepositor var event = Event.builder() .eventType(eventType) .eventId(UUID.randomUUID()) - .eventOutcome("PROCESSED") + .eventOutcome("DB_COMMITTED") .eventPayload(JsonUtil.getJsonStringFromObject(payload)) .eventStatus(DB_COMMITTED.toString()) .createUser(DEFAULT_CREATED_BY) @@ -47,6 +52,71 @@ public static Event createEvent(String eventType, Object payload, EventRepositor return event; } + public static AuthorityContact createAuthorityContact() { + var auth = AuthorityContact.builder() + .independentAuthorityId(UUID.randomUUID().toString()) + .firstName("Bud") + .lastName("Weiser") + .phoneNumber("3216549874") + .phoneExtension("321") + .alternatePhoneNumber("3216547894") + .alternatePhoneExtension("555") + .email("bud.weiser@beers.ca") + .authorityContactTypeCode("DIRECTOR") + .effectiveDate(LocalDateTime.now().toString()) + .expiryDate(LocalDateTime.now().plus(1, ChronoUnit.DAYS).toString()) + .build(); + auth.setCreateDate(LocalDateTime.now().toString()); + auth.setCreateUser("TEST"); + auth.setUpdateDate(LocalDateTime.now().toString()); + auth.setUpdateUser("TEST"); + return auth; + } + + public static SchoolContact createSchoolContact() { + var contact = SchoolContact.builder() + .schoolId(UUID.randomUUID().toString()) + .firstName("Testy") + .lastName("MacTesterton") + .phoneNumber("3216549874") + .phoneExtension("123") + .alternatePhoneNumber("3216549874") + .alternatePhoneExtension("321") + .email("t.testerton@test.ca") + .jobTitle("The Tester") + .schoolContactTypeCode("PRINCIPAL") + .effectiveDate(LocalDate.now().toString()) + .expiryDate(LocalDateTime.now().plus(1, ChronoUnit.DAYS).toString()) + .build(); + contact.setCreateDate(LocalDateTime.now().toString()); + contact.setCreateUser("TEST"); + contact.setUpdateDate(LocalDateTime.now().toString()); + contact.setUpdateUser("TEST"); + return contact; + } + + public static DistrictContact createDistrictContact() { + var contact = DistrictContact.builder() + .districtId(UUID.randomUUID().toString()) + .firstName("Testy") + .lastName("MacTesterton") + .phoneNumber("3216549874") + .phoneExtension("123") + .alternatePhoneNumber("3216549874") + .alternatePhoneExtension("321") + .email("t.testerton@test.ca") + .jobTitle("The Tester") + .districtContactTypeCode("PRINCIPAL") + .effectiveDate(LocalDate.now().toString()) + .expiryDate(LocalDateTime.now().plus(1, ChronoUnit.DAYS).toString()) + .build(); + contact.setCreateDate(LocalDateTime.now().toString()); + contact.setCreateUser("TEST"); + contact.setUpdateDate(LocalDateTime.now().toString()); + contact.setUpdateUser("TEST"); + return contact; + } + public static TraxStudentEntity createTraxStudent(boolean isGraduated) { TraxStudentEntity entity = TraxStudentEntity.builder() .studNo("123456789 ") diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/util/ReplicationTestUtils.java b/api/src/test/java/ca/bc/gov/educ/api/trax/util/ReplicationTestUtils.java new file mode 100644 index 00000000..a6cd346f --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/util/ReplicationTestUtils.java @@ -0,0 +1,27 @@ +package ca.bc.gov.educ.api.trax.util; + +import ca.bc.gov.educ.api.trax.repository.EventRepository; +import lombok.Getter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +@Component +@Profile("test") +@Getter +public class ReplicationTestUtils { + + private final EventRepository eventRepository; + + @Autowired + public ReplicationTestUtils(EventRepository eventRepository) { + this.eventRepository = eventRepository; + } + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void cleanDB() { + this.eventRepository.deleteAll(); + } +} diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 03d1a4d5..e0b0f8df 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -1,5 +1,7 @@ #DB Properties spring: + main: + allow-bean-definition-overriding: true jmx: enabled: false datasource: