diff --git a/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/MoveSchoolOrchestratorTest.java b/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/MoveSchoolOrchestratorTest.java index 5695da83..ba1c44f2 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/MoveSchoolOrchestratorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/MoveSchoolOrchestratorTest.java @@ -15,7 +15,6 @@ import ca.bc.gov.educ.api.edx.struct.v1.*; import ca.bc.gov.educ.api.edx.utils.JsonUtil; import com.fasterxml.jackson.core.JsonProcessingException; -import lombok.extern.slf4j.Slf4j; import lombok.val; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -25,7 +24,6 @@ import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; - import java.io.IOException; import java.time.LocalDateTime; import java.util.List; @@ -50,9 +48,15 @@ class MoveSchoolOrchestratorTest extends BaseSagaControllerTest { @Autowired private EdxUserRepository edxUserRepository; + @Autowired + private EdxUserSchoolRoleRepository edxUserSchoolRoleRepository; + @Autowired private EdxUserSchoolRepository edxUserSchoolRepository; + @Autowired + private EdxUserDistrictRoleRepository edxUserDistrictRoleRepository; + @Autowired private EdxUserDistrictRepository edxUserDistrictRepository; @@ -95,8 +99,9 @@ class MoveSchoolOrchestratorTest extends BaseSagaControllerTest { public void after() { sagaEventStateRepository.deleteAll(); sagaRepository.deleteAll(); + edxUserDistrictRoleRepository.deleteAll(); + edxUserSchoolRoleRepository.deleteAll(); edxUserSchoolRepository.deleteAll(); - } @BeforeEach @@ -119,7 +124,7 @@ public void setUp() throws JsonProcessingException { } @Test - void testMoveSchool_GivenEventAndSagaData_shouldPostEventToInstituteApi() throws IOException, InterruptedException, TimeoutException { + void testMoveSchool_GivenEventAndSagaData_shouldPostEventToInstituteApi() throws IOException { final var invocations = mockingDetails(this.messagePublisher).getInvocations().size(); final var event = Event.builder() .eventType(INITIATED) diff --git a/api/src/test/java/ca/bc/gov/educ/api/edx/schedulers/EdxUserSchedulerTest.java b/api/src/test/java/ca/bc/gov/educ/api/edx/schedulers/EdxUserSchedulerTest.java index d1fee134..25c68bff 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/edx/schedulers/EdxUserSchedulerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/edx/schedulers/EdxUserSchedulerTest.java @@ -1,26 +1,23 @@ package ca.bc.gov.educ.api.edx.schedulers; -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.LocalDateTime; -import java.util.List; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.springframework.beans.factory.annotation.Autowired; - import ca.bc.gov.educ.api.edx.BaseEdxAPITest; import ca.bc.gov.educ.api.edx.mappers.v1.EdxUserDistrictMapper; import ca.bc.gov.educ.api.edx.mappers.v1.EdxUserMapper; import ca.bc.gov.educ.api.edx.mappers.v1.EdxUserSchoolMapper; import ca.bc.gov.educ.api.edx.model.v1.EdxUserDistrictEntity; import ca.bc.gov.educ.api.edx.model.v1.EdxUserSchoolEntity; -import ca.bc.gov.educ.api.edx.repository.EdxUserDistrictRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolRepository; +import ca.bc.gov.educ.api.edx.repository.*; import ca.bc.gov.educ.api.edx.struct.v1.EdxUser; import net.javacrumbs.shedlock.core.LockAssert; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; class EdxUserSchedulerTest extends BaseEdxAPITest { @Autowired @@ -32,6 +29,12 @@ class EdxUserSchedulerTest extends BaseEdxAPITest { @Autowired private EdxUserRepository userRepository; + @Autowired + EdxUserSchoolRoleRepository edxUserSchoolRoleRepository; + + @Autowired + EdxUserDistrictRoleRepository edxUserDistrictRoleRepository; + @Autowired private EdxUserScheduler scheduler; @@ -41,6 +44,8 @@ class EdxUserSchedulerTest extends BaseEdxAPITest { @BeforeEach public void setUp() { + this.edxUserDistrictRoleRepository.deleteAll(); + this.edxUserSchoolRoleRepository.deleteAll(); this.userSchoolRepository.deleteAll(); this.userDistrictRepository.deleteAll(); this.userRepository.deleteAll(); @@ -49,6 +54,8 @@ public void setUp() { @AfterEach public void tearDown() { + this.edxUserDistrictRoleRepository.deleteAll(); + this.edxUserSchoolRoleRepository.deleteAll(); this.userSchoolRepository.deleteAll(); this.userDistrictRepository.deleteAll(); this.userRepository.deleteAll(); diff --git a/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxNewSecureExchangeOrchestratorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxNewSecureExchangeOrchestratorServiceTest.java index 25a7f98c..41780bcb 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxNewSecureExchangeOrchestratorServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxNewSecureExchangeOrchestratorServiceTest.java @@ -7,26 +7,16 @@ import ca.bc.gov.educ.api.edx.model.v1.EdxUserSchoolEntity; import ca.bc.gov.educ.api.edx.props.ApplicationProperties; import ca.bc.gov.educ.api.edx.props.EmailProperties; -import ca.bc.gov.educ.api.edx.repository.EdxPermissionRepository; -import ca.bc.gov.educ.api.edx.repository.EdxRoleRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserDistrictRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolRoleRepository; +import ca.bc.gov.educ.api.edx.repository.*; import ca.bc.gov.educ.api.edx.rest.RestUtils; import ca.bc.gov.educ.api.edx.service.v1.EdxNewSecureExchangeOrchestratorService; import ca.bc.gov.educ.api.edx.service.v1.EdxSecureExchangeCommentOrchestratorService; import ca.bc.gov.educ.api.edx.service.v1.EmailNotificationService; import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeCreate; import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeCreateSagaData; - -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; @@ -35,8 +25,6 @@ import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.openMocks; - -@TestInstance(Lifecycle.PER_CLASS) class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest { @Autowired @@ -66,6 +54,9 @@ class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest { @Autowired EdxUserSchoolRoleRepository edxUserSchoolRoleRepository; + @Autowired + EdxUserDistrictRoleRepository edxUserDistrictRoleRepository; + @Autowired EdxPermissionRepository edxPermissionRepository; @@ -78,27 +69,21 @@ class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest { @Captor private ArgumentCaptor emailBodyCaptor; - @BeforeAll - public void beforeAll() { - this.createEdxRoleForSchoolAndDistrict(this.edxRoleRepository, this.edxPermissionRepository); - } - - @AfterAll - public void afterAll() { - this.edxRoleRepository.deleteAll(); - this.edxPermissionRepository.deleteAll(); - } - @BeforeEach public void setUp() { openMocks(this); doNothing().when(this.restUtils).sendEmail(any(), any(), any(), any()); + this.createEdxRoleForSchoolAndDistrict(this.edxRoleRepository, this.edxPermissionRepository); } @AfterEach public void tearDown() { + this.edxUserDistrictRoleRepository.deleteAll(); + this.edxUserSchoolRoleRepository.deleteAll(); this.edxUserSchoolRepository.deleteAll(); this.edxUserDistrictRepository.deleteAll(); + this.edxRoleRepository.deleteAll(); + this.edxPermissionRepository.deleteAll(); } @Test diff --git a/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxSecureExchangeCommentOrchestratorServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxSecureExchangeCommentOrchestratorServiceTest.java index 36d28054..f26b4765 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxSecureExchangeCommentOrchestratorServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/edx/service/EdxSecureExchangeCommentOrchestratorServiceTest.java @@ -7,39 +7,23 @@ import ca.bc.gov.educ.api.edx.model.v1.EdxUserSchoolEntity; import ca.bc.gov.educ.api.edx.props.ApplicationProperties; import ca.bc.gov.educ.api.edx.props.EmailProperties; -import ca.bc.gov.educ.api.edx.repository.EdxPermissionRepository; -import ca.bc.gov.educ.api.edx.repository.EdxRoleRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserDistrictRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolRepository; -import ca.bc.gov.educ.api.edx.repository.EdxUserSchoolRoleRepository; +import ca.bc.gov.educ.api.edx.repository.*; import ca.bc.gov.educ.api.edx.rest.RestUtils; -import ca.bc.gov.educ.api.edx.service.v1.EdxNewSecureExchangeOrchestratorService; import ca.bc.gov.educ.api.edx.service.v1.EdxSecureExchangeCommentOrchestratorService; import ca.bc.gov.educ.api.edx.service.v1.EmailNotificationService; import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeCommentSagaData; -import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeCreate; -import ca.bc.gov.educ.api.edx.struct.v1.SecureExchangeCreateSagaData; - -import org.junit.jupiter.api.AfterAll; +import com.fasterxml.jackson.core.JsonProcessingException; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; -import com.fasterxml.jackson.core.JsonProcessingException; - import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.openMocks; - -@TestInstance(Lifecycle.PER_CLASS) class EdxSecureExchangeCommentOrchestratorServiceTest extends BaseEdxAPITest { @Autowired @@ -63,6 +47,9 @@ class EdxSecureExchangeCommentOrchestratorServiceTest extends BaseEdxAPITest { @Autowired EdxUserDistrictRepository edxUserDistrictRepository; + @Autowired + EdxUserDistrictRoleRepository edxUserDistrictRoleRepository; + @Autowired EdxRoleRepository edxRoleRepository; @@ -81,27 +68,21 @@ class EdxSecureExchangeCommentOrchestratorServiceTest extends BaseEdxAPITest { @Captor private ArgumentCaptor emailBodyCaptor; - @BeforeAll - public void beforeAll() { - this.createEdxRoleForSchoolAndDistrict(this.edxRoleRepository, this.edxPermissionRepository); - } - - @AfterAll - public void afterAll() { - this.edxRoleRepository.deleteAll(); - this.edxPermissionRepository.deleteAll(); - } - @BeforeEach public void setUp() { openMocks(this); doNothing().when(this.restUtils).sendEmail(any(), any(), any(), any()); + this.createEdxRoleForSchoolAndDistrict(this.edxRoleRepository, this.edxPermissionRepository); } @AfterEach public void tearDown() { + this.edxUserDistrictRoleRepository.deleteAll(); + this.edxUserSchoolRoleRepository.deleteAll(); this.edxUserSchoolRepository.deleteAll(); this.edxUserDistrictRepository.deleteAll(); + this.edxRoleRepository.deleteAll(); + this.edxPermissionRepository.deleteAll(); } @Test