Skip to content

Commit

Permalink
UT fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Jul 30, 2024
1 parent 7f47799 commit 46cb0dc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -95,8 +99,9 @@ class MoveSchoolOrchestratorTest extends BaseSagaControllerTest {
public void after() {
sagaEventStateRepository.deleteAll();
sagaRepository.deleteAll();
edxUserDistrictRoleRepository.deleteAll();
edxUserSchoolRoleRepository.deleteAll();
edxUserSchoolRepository.deleteAll();

}

@BeforeEach
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -32,6 +29,12 @@ class EdxUserSchedulerTest extends BaseEdxAPITest {
@Autowired
private EdxUserRepository userRepository;

@Autowired
EdxUserSchoolRoleRepository edxUserSchoolRoleRepository;

@Autowired
EdxUserDistrictRoleRepository edxUserDistrictRoleRepository;

@Autowired
private EdxUserScheduler scheduler;

Expand All @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,8 +25,6 @@
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.openMocks;


@TestInstance(Lifecycle.PER_CLASS)
class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest {

@Autowired
Expand Down Expand Up @@ -66,6 +54,9 @@ class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest {
@Autowired
EdxUserSchoolRoleRepository edxUserSchoolRoleRepository;

@Autowired
EdxUserDistrictRoleRepository edxUserDistrictRoleRepository;

@Autowired
EdxPermissionRepository edxPermissionRepository;

Expand All @@ -78,27 +69,21 @@ class EdxNewSecureExchangeOrchestratorServiceTest extends BaseEdxAPITest {
@Captor
private ArgumentCaptor<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,6 +47,9 @@ class EdxSecureExchangeCommentOrchestratorServiceTest extends BaseEdxAPITest {
@Autowired
EdxUserDistrictRepository edxUserDistrictRepository;

@Autowired
EdxUserDistrictRoleRepository edxUserDistrictRoleRepository;

@Autowired
EdxRoleRepository edxRoleRepository;

Expand All @@ -81,27 +68,21 @@ class EdxSecureExchangeCommentOrchestratorServiceTest extends BaseEdxAPITest {
@Captor
private ArgumentCaptor<String> 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
Expand Down

0 comments on commit 46cb0dc

Please sign in to comment.