From c3c799058d4410c707f796322200a94c755b0fd7 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 10 Jul 2024 14:15:41 +0100 Subject: [PATCH 01/11] feat: DBC and HeeUser requests from TSS TIS21-6272 --- pom.xml | 2 +- .../java/uk/nhs/tis/sync/dto/DmsDtoType.java | 5 ++++ .../uk/nhs/tis/sync/dto/HeeUserDmsDto.java | 14 +++++++++++ .../uk/nhs/tis/sync/mapper/HeeUserMapper.java | 25 +++++++++++++++++++ .../tis/sync/service/DataRequestService.java | 18 ++++++++++++- .../tis/sync/service/DmsRecordAssembler.java | 1 - .../java/uk/nhs/tis/sync/ApplicationTest.java | 5 ++++ .../listener/JobRunningListenerTest.java | 3 +++ .../sync/job/PersonOwnerRebuildJobTest.java | 3 +++ ...tEmployingBodyTrustJobIntegrationTest.java | 5 ++++ ...ntTrainingBodyTrustJobIntegrationTest.java | 5 ++++ .../PersonRecordStatusJobIntegrationTest.java | 6 +++++ ...tEmployingBodyTrustJobIntegrationTest.java | 5 ++++ ...stTrainingBodyTrustJobIntegrationTest.java | 5 ++++ ...urrentPlacementSyncJobIntegrationTest.java | 5 ++++ .../RevalCurrentPmSyncJobIntegrationTest.java | 5 ++++ .../sync/service/DataRequestServiceTest.java | 6 ++++- 17 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java create mode 100644 src/main/java/uk/nhs/tis/sync/mapper/HeeUserMapper.java diff --git a/pom.xml b/pom.xml index e6ad9030..3acdf607 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ uk.nhs.tis sync - 1.22.0 + 1.23.0 jar sync Separate Microservice for synchronisation diff --git a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java index ff3defaa..3f4bb941 100644 --- a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java +++ b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java @@ -1,5 +1,7 @@ package uk.nhs.tis.sync.dto; +import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; +import com.transformuk.hee.tis.reference.api.dto.DBCDTO; import com.transformuk.hee.tis.reference.api.dto.GradeDTO; import com.transformuk.hee.tis.reference.api.dto.SiteDTO; import com.transformuk.hee.tis.reference.api.dto.TrustDTO; @@ -22,6 +24,7 @@ import uk.nhs.tis.sync.mapper.CurriculumMembershipMapper; import uk.nhs.tis.sync.mapper.DmsMapper; import uk.nhs.tis.sync.mapper.GradeMapper; +import uk.nhs.tis.sync.mapper.HeeUserMapper; import uk.nhs.tis.sync.mapper.PersonMapper; import uk.nhs.tis.sync.mapper.PlacementSpecialtyMapper; import uk.nhs.tis.sync.mapper.PlacementSummaryMapper; @@ -45,9 +48,11 @@ public enum DmsDtoType { CURRICULUM(CurriculumDTO.class, "tcs", "Curriculum", CurriculumMapper.class), CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, "tcs", "CurriculumMembership", CurriculumMembershipMapper.class), + DBC_DETAILS(DBCDTO.class, "reference", "DBC", null), GDC_DETAILS(GdcDetailsDTO.class, "tcs", "GdcDetails", null), GMC_DETAILS(GmcDetailsDTO.class, "tcs", "GmcDetails", null), GRADE(GradeDTO.class, "reference", "Grade", GradeMapper.class), + HEE_USER(HeeUserDTO.class, "auth", "HeeUser", HeeUserMapper.class), PERSON(PersonDTO.class, "tcs", "Person", PersonMapper.class), PERSONAL_DETAILS(PersonalDetailsDTO.class, "tcs", "PersonalDetails", null), PLACEMENT_DETAILS(PlacementSummaryDTO.class, "tcs", "Placement", PlacementSummaryMapper.class), diff --git a/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java b/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java new file mode 100644 index 00000000..68797ddb --- /dev/null +++ b/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java @@ -0,0 +1,14 @@ +package uk.nhs.tis.sync.dto; + +import lombok.Data; + +@Data +public class HeeUserDmsDto { + private final String name; + private final String firstName; + private final String lastName; + private final String gmcId; + private final String phoneNumber; + private final String emailAddress; + private final String active; +} diff --git a/src/main/java/uk/nhs/tis/sync/mapper/HeeUserMapper.java b/src/main/java/uk/nhs/tis/sync/mapper/HeeUserMapper.java new file mode 100644 index 00000000..dca89846 --- /dev/null +++ b/src/main/java/uk/nhs/tis/sync/mapper/HeeUserMapper.java @@ -0,0 +1,25 @@ +package uk.nhs.tis.sync.mapper; + +import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import uk.nhs.tis.sync.dto.HeeUserDmsDto; + +/** + * A mapper to map between Profile and DMS DTOs for the HeeUser data type. + */ +@Mapper(componentModel = "spring") +public interface HeeUserMapper extends DmsMapper { + + //note that password, roles, etc. in the HeeUserDTO are excluded from HeeUserDmsDto: we simply + //map the 'base' record fields + @Mapping(target = "active", source = "active", + qualifiedByName = "getBooleanAsZeroOrOne") + HeeUserDmsDto toDmsDto(HeeUserDTO heeUserDto); + + @Named("getBooleanAsZeroOrOne") + default String getBooleanAsZeroOrOne(boolean bool) { + return bool ? "1" : "0"; + } +} diff --git a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java index 999a6586..a4b9a4cb 100644 --- a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java +++ b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java @@ -1,5 +1,6 @@ package uk.nhs.tis.sync.service; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.reference.client.impl.ReferenceServiceImpl; import com.transformuk.hee.tis.tcs.api.dto.PersonDTO; import com.transformuk.hee.tis.tcs.api.dto.PlacementDetailsDTO; @@ -24,7 +25,9 @@ public class DataRequestService { private static final String TABLE_CURRICULUM = "Curriculum"; private static final String TABLE_CURRICULUM_MEMBERSHIP = "CurriculumMembership"; + private static final String TABLE_DBC = "DBC"; private static final String TABLE_GRADE = "Grade"; + private static final String TABLE_HEE_USER = "HeeUser"; private static final String TABLE_PERSON = "Person"; private static final String TABLE_PLACEMENT = "Placement"; private static final String TABLE_PLACEMENT_SPECIALTY = "PlacementSpecialty"; @@ -39,9 +42,13 @@ public class DataRequestService { private final ReferenceServiceImpl referenceServiceImpl; - DataRequestService(TcsServiceImpl tcsServiceImpl, ReferenceServiceImpl referenceServiceImpl) { + private final ProfileServiceImpl profileServiceImpl; + + DataRequestService(TcsServiceImpl tcsServiceImpl, ReferenceServiceImpl referenceServiceImpl, + ProfileServiceImpl profileServiceImpl) { this.tcsServiceImpl = tcsServiceImpl; this.referenceServiceImpl = referenceServiceImpl; + this.profileServiceImpl = profileServiceImpl; } /** @@ -74,6 +81,15 @@ public List retrieveDtos(Map message) { .collect(Collectors.toList()); } + if(table.equals(TABLE_HEE_USER) && message.containsKey("name")) { + String name = message.get("name"); + return createNonNullList(profileServiceImpl.getSingleAdminUser(name)); + } + if(table.equals(TABLE_DBC) && message.containsKey("dbc")) { + String dbc = message.get("dbc"); + return createNonNullList(referenceServiceImpl.getDBCByCode(dbc)); + } + if (message.containsKey("id")) { long id = Long.parseLong(message.get("id")); diff --git a/src/main/java/uk/nhs/tis/sync/service/DmsRecordAssembler.java b/src/main/java/uk/nhs/tis/sync/service/DmsRecordAssembler.java index 2f7443f6..f48968c9 100644 --- a/src/main/java/uk/nhs/tis/sync/service/DmsRecordAssembler.java +++ b/src/main/java/uk/nhs/tis/sync/service/DmsRecordAssembler.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; import org.mapstruct.factory.Mappers; diff --git a/src/test/java/uk/nhs/tis/sync/ApplicationTest.java b/src/test/java/uk/nhs/tis/sync/ApplicationTest.java index d136824b..e9a5676e 100644 --- a/src/test/java/uk/nhs/tis/sync/ApplicationTest.java +++ b/src/test/java/uk/nhs/tis/sync/ApplicationTest.java @@ -3,10 +3,12 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import uk.nhs.tis.sync.job.RecordResendingJob; @@ -15,6 +17,9 @@ @SpringBootTest public class ApplicationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired Application testClass; diff --git a/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java b/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java index b0da2210..42f83707 100644 --- a/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java +++ b/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java @@ -3,6 +3,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +30,8 @@ public class JobRunningListenerTest { private RevalCurrentPmSyncJob revalCurrentPmSyncJob; @MockBean private PostFundingStatusSyncJob postFundingStatusSyncJob; + @MockBean + ProfileServiceImpl profileService; @Autowired JobRunningListener testClass; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java index f2f62f4e..902109ae 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java @@ -11,6 +11,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonRepository; import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; @@ -30,6 +31,8 @@ public class PersonOwnerRebuildJobTest { @MockBean private PersonRepository repo; + @MockBean + ProfileServiceImpl profileService; @Test public void testPersonOwnerRebuildJob() { diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java index ae332220..1c809f61 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java @@ -1,5 +1,6 @@ package uk.nhs.tis.sync.job; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -9,6 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -17,6 +19,9 @@ //@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PersonPlacementEmployingBodyTrustJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired PersonPlacementEmployingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java index 0915e2bd..1d9ab2af 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java @@ -1,5 +1,6 @@ package uk.nhs.tis.sync.job; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -9,6 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -17,6 +19,9 @@ //@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PersonPlacementTrainingBodyTrustJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired PersonPlacementTrainingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java index 2a6439b4..ac55e12f 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; import org.hamcrest.CoreMatchers; @@ -13,8 +14,10 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -23,6 +26,9 @@ //TODO @Sql(scripts = {"/scripts/deleteProgrammeMemberships.sql","/scripts/deletePersonRows.sql","/scripts/deleteProgrammes.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) class PersonRecordStatusJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired PersonRecordStatusJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java index af8bde4d..8b2f921b 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java @@ -1,5 +1,6 @@ package uk.nhs.tis.sync.job; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -9,6 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.junit4.SpringRunner; @@ -19,6 +21,9 @@ @Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PostEmployingBodyTrustJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired PostEmployingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java index 5c7a6db5..15e957d2 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java @@ -1,5 +1,6 @@ package uk.nhs.tis.sync.job; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -9,6 +10,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.junit4.SpringRunner; @@ -19,6 +21,9 @@ @Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PostTrainingBodyTrustJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired PostTrainingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java index 201dff10..aa17fdba 100644 --- a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.mockito.Mockito.verify; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.Set; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; @@ -18,6 +19,7 @@ import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; @@ -28,6 +30,9 @@ @SpringBootTest class RevalCurrentPlacementSyncJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired RevalCurrentPlacementSyncJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java index 36a36181..0063d63d 100644 --- a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.mockito.Mockito.verify; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.Set; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; @@ -18,6 +19,7 @@ import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; @@ -32,6 +34,9 @@ "/scripts/deletePersonRows.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) class RevalCurrentPmSyncJobIntegrationTest { + @MockBean + ProfileServiceImpl profileService; + @Autowired RevalCurrentPmSyncJob job; diff --git a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java index 14f810e7..bdcd2961 100644 --- a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java +++ b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.reference.api.dto.GradeDTO; import com.transformuk.hee.tis.reference.api.dto.SiteDTO; import com.transformuk.hee.tis.reference.api.dto.TrustDTO; @@ -61,11 +62,14 @@ class DataRequestServiceTest { private ReferenceServiceImpl referenceService; + private ProfileServiceImpl profileService; + @BeforeEach void setUp() { tcsService = mock(TcsServiceImpl.class); referenceService = mock(ReferenceServiceImpl.class); - service = new DataRequestService(tcsService, referenceService); + profileService = mock(ProfileServiceImpl.class); + service = new DataRequestService(tcsService, referenceService, profileService); } @Test From deba79890ae9088d0b00e23636264dffe65df7e9 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 10 Jul 2024 15:21:05 +0100 Subject: [PATCH 02/11] fix: tests and DBC api return --- .../tis/sync/service/DataRequestService.java | 6 +- .../tis/sync/mapper/HeeUserMapperTest.java | 62 ++++++++++++++++++ .../sync/service/DataRequestServiceTest.java | 63 +++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java diff --git a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java index a4b9a4cb..b5935218 100644 --- a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java +++ b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java @@ -1,6 +1,7 @@ package uk.nhs.tis.sync.service; import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; +import com.transformuk.hee.tis.reference.api.dto.DBCDTO; import com.transformuk.hee.tis.reference.client.impl.ReferenceServiceImpl; import com.transformuk.hee.tis.tcs.api.dto.PersonDTO; import com.transformuk.hee.tis.tcs.api.dto.PlacementDetailsDTO; @@ -16,6 +17,7 @@ import java.util.UUID; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import uk.nhs.tis.sync.dto.CurriculumMembershipWrapperDto; @@ -85,9 +87,11 @@ public List retrieveDtos(Map message) { String name = message.get("name"); return createNonNullList(profileServiceImpl.getSingleAdminUser(name)); } + if(table.equals(TABLE_DBC) && message.containsKey("dbc")) { String dbc = message.get("dbc"); - return createNonNullList(referenceServiceImpl.getDBCByCode(dbc)); + ResponseEntity responseEntity = referenceServiceImpl.getDBCByCode(dbc); + return createNonNullList(responseEntity.getBody()); } if (message.containsKey("id")) { diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java new file mode 100644 index 00000000..802767a0 --- /dev/null +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -0,0 +1,62 @@ +package uk.nhs.tis.sync.mapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.transformuk.hee.tis.profile.dto.RoleDTO; +import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; +import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO; +import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import uk.nhs.tis.sync.dto.HeeUserDmsDto; + +public class HeeUserMapperTest { + + private HeeUserMapper mapper; + + private HeeUserDTO heeUserDto; + + @Before + public void setUp() { + mapper = new HeeUserMapperImpl(); + + heeUserDto = new HeeUserDTO(); + heeUserDto.setActive(true); + HashSet assocProgrammes = new HashSet<>(); + assocProgrammes.add(new UserProgrammeDTO()); + heeUserDto.setAssociatedProgrammes(assocProgrammes); + HashSet userTrusts = new HashSet<>(); + userTrusts.add(new UserTrustDTO()); + heeUserDto.setAssociatedTrusts(userTrusts); + heeUserDto.setFirstName("first name"); + heeUserDto.setName("name"); + Set dbcs = new HashSet<>(); + dbcs.add("dbc1"); + heeUserDto.setDesignatedBodyCodes(dbcs); + heeUserDto.setEmailAddress("email"); + heeUserDto.setGmcId("gmc"); + heeUserDto.setLastName("last name"); + heeUserDto.setPassword("password"); + heeUserDto.setPhoneNumber("phone"); + HashSet roles = new HashSet<>(); + roles.add(new RoleDTO()); + heeUserDto.setRoles(roles); + heeUserDto.setTemporaryPassword(true); + } + + @Test + public void shouldMapAHeeUserDtoToADataDmsDto() { + HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto); + + assertEquals("1", heeUserDmsDto.getActive()); + assertEquals("name", heeUserDmsDto.getName()); + assertEquals("first name", heeUserDmsDto.getFirstName()); + assertEquals("gmc", heeUserDmsDto.getGmcId()); + assertEquals("last name", heeUserDmsDto.getLastName()); + assertEquals("email", heeUserDmsDto.getEmailAddress()); + assertEquals("phone", heeUserDmsDto.getPhoneNumber()); + //other HeeUserDto properties are ignored + } +} diff --git a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java index bdcd2961..54a314d1 100644 --- a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java +++ b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java @@ -11,6 +11,8 @@ import static org.mockito.Mockito.when; import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; +import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; +import com.transformuk.hee.tis.reference.api.dto.DBCDTO; import com.transformuk.hee.tis.reference.api.dto.GradeDTO; import com.transformuk.hee.tis.reference.api.dto.SiteDTO; import com.transformuk.hee.tis.reference.api.dto.TrustDTO; @@ -45,6 +47,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.client.HttpClientErrorException; import uk.nhs.tis.sync.dto.CurriculumMembershipWrapperDto; @@ -52,6 +55,8 @@ class DataRequestServiceTest { private static final String FORENAMES = "Joe"; private static final String SURNAME = "Bloggs"; + private static final String HEE_USER_NAME = "the user name"; + private static final String DBC_VALUE = "theDBC"; private static final String GDC_NUMBER = "gdc123"; private static final String GMC_NUMBER = "gmc123"; @@ -795,4 +800,62 @@ void shouldReturnEmptyWhenFindGradesIdInThrowsException() { assertThat("Unexpected DTO count.", grades.size(), is(0)); } + + @Test + void shouldReturnHeeUserWhenHeeUserFound() { + HeeUserDTO expectedDto = new HeeUserDTO(); + when(profileService.getSingleAdminUser(HEE_USER_NAME)).thenReturn(expectedDto); + + Map message = new HashMap() {{ + put("table", "HeeUser"); + put("name", HEE_USER_NAME); + }}; + List retrievedDtos = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", retrievedDtos.size(), is(1)); + assertThat("Unexpected DTO.", retrievedDtos.get(0), sameInstance(expectedDto)); + } + + @Test + void shouldReturnEmptyWhenHeeUserNotFound() { + when(profileService.getSingleAdminUser(HEE_USER_NAME)).thenReturn(null); + + Map message = new HashMap() {{ + put("table", "HeeUser"); + put("name", HEE_USER_NAME); + }}; + List heeUsers = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", heeUsers.size(), is(0)); + } + + @Test + void shouldReturnDbcWhenDbcFound() { + DBCDTO expectedDto = new DBCDTO(); + ResponseEntity responseEntity = new ResponseEntity<>(expectedDto, HttpStatus.OK); + when(referenceService.getDBCByCode(DBC_VALUE)).thenReturn(responseEntity); + + Map message = new HashMap() {{ + put("table", "DBC"); + put("dbc", DBC_VALUE); + }}; + List retrievedDtos = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", retrievedDtos.size(), is(1)); + assertThat("Unexpected DTO.", retrievedDtos.get(0), sameInstance(expectedDto)); + } + + @Test + void shouldReturnEmptyWhenDbcNotFound() { + ResponseEntity responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND); + when(referenceService.getDBCByCode(DBC_VALUE)).thenReturn(responseEntity); + + Map message = new HashMap() {{ + put("table", "DBC"); + put("dbc", DBC_VALUE); + }}; + List dbcs = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", dbcs.size(), is(0)); + } } From 082c40c6ddc117774375edf87cb0dcdbd2b3005c Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 10 Jul 2024 15:35:42 +0100 Subject: [PATCH 03/11] fix: code smells and coverage --- .../uk/nhs/tis/sync/dto/HeeUserDmsDto.java | 3 +++ .../tis/sync/service/DataRequestService.java | 4 ++-- .../PersonRecordStatusJobIntegrationTest.java | 1 - .../tis/sync/mapper/HeeUserMapperTest.java | 12 +++++++++- .../sync/service/DataRequestServiceTest.java | 24 +++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java b/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java index 68797ddb..07fde76e 100644 --- a/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java +++ b/src/main/java/uk/nhs/tis/sync/dto/HeeUserDmsDto.java @@ -2,6 +2,9 @@ import lombok.Data; +/** + * A DTO for transferring HeeUser data to the DMS. + */ @Data public class HeeUserDmsDto { private final String name; diff --git a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java index b5935218..edf12a54 100644 --- a/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java +++ b/src/main/java/uk/nhs/tis/sync/service/DataRequestService.java @@ -83,12 +83,12 @@ public List retrieveDtos(Map message) { .collect(Collectors.toList()); } - if(table.equals(TABLE_HEE_USER) && message.containsKey("name")) { + if (table.equals(TABLE_HEE_USER) && message.containsKey("name")) { String name = message.get("name"); return createNonNullList(profileServiceImpl.getSingleAdminUser(name)); } - if(table.equals(TABLE_DBC) && message.containsKey("dbc")) { + if (table.equals(TABLE_DBC) && message.containsKey("dbc")) { String dbc = message.get("dbc"); ResponseEntity responseEntity = referenceServiceImpl.getDBCByCode(dbc); return createNonNullList(responseEntity.getBody()); diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java index ac55e12f..1fb1010c 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java @@ -14,7 +14,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.junit.runner.RunWith; -import org.mockito.InjectMocks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 802767a0..996a98ac 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -10,9 +10,11 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import uk.nhs.tis.sync.dto.HeeUserDmsDto; -public class HeeUserMapperTest { +class HeeUserMapperTest { private HeeUserMapper mapper; @@ -59,4 +61,12 @@ public void shouldMapAHeeUserDtoToADataDmsDto() { assertEquals("phone", heeUserDmsDto.getPhoneNumber()); //other HeeUserDto properties are ignored } + + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void shouldMapBooleansToZeroOrOneString(boolean bool) { + heeUserDto.setActive(bool); + HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto); + assertEquals(bool ? "1" : "0", heeUserDmsDto.getActive()); + } } diff --git a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java index 54a314d1..6163cc08 100644 --- a/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java +++ b/src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java @@ -829,6 +829,18 @@ void shouldReturnEmptyWhenHeeUserNotFound() { assertThat("Unexpected DTO count.", heeUsers.size(), is(0)); } + @Test + void shouldReturnEmptyWhenHeeUserMessageHasWrongKey() { + Map message = new HashMap() {{ + put("table", "HeeUser"); + put("another key", HEE_USER_NAME); + }}; + List heeUsers = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", heeUsers.size(), is(0)); + verifyNoInteractions(profileService); + } + @Test void shouldReturnDbcWhenDbcFound() { DBCDTO expectedDto = new DBCDTO(); @@ -858,4 +870,16 @@ void shouldReturnEmptyWhenDbcNotFound() { assertThat("Unexpected DTO count.", dbcs.size(), is(0)); } + + @Test + void shouldReturnEmptyWhenDbcMessageHasWrongKey() { + Map message = new HashMap() {{ + put("table", "DBC"); + put("another key", DBC_VALUE); + }}; + List dbcs = service.retrieveDtos(message); + + assertThat("Unexpected DTO count.", dbcs.size(), is(0)); + verifyNoInteractions(referenceService); + } } From 810ef30f7cde2d07aaad6314a8a39d64871bdfeb Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 10 Jul 2024 15:41:20 +0100 Subject: [PATCH 04/11] fix: broken test --- src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 996a98ac..3f8c4845 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -10,6 +10,7 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import uk.nhs.tis.sync.dto.HeeUserDmsDto; @@ -20,7 +21,7 @@ class HeeUserMapperTest { private HeeUserDTO heeUserDto; - @Before + @BeforeEach public void setUp() { mapper = new HeeUserMapperImpl(); From 8b7e94feab8079de7504eeb625ec212ec1ffccb4 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Wed, 10 Jul 2024 15:45:48 +0100 Subject: [PATCH 05/11] fix: unneeded import --- src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 3f8c4845..6f44a278 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -8,7 +8,6 @@ import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO; import java.util.HashSet; import java.util.Set; -import org.junit.Before; import org.junit.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; From ba5f3559cacc844aab9d4064426e6adeb7b64e8b Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Thu, 11 Jul 2024 09:53:02 +0100 Subject: [PATCH 06/11] fix: refactor ComponentScan --- src/main/java/uk/nhs/tis/sync/Application.java | 3 ++- src/test/java/uk/nhs/tis/sync/ApplicationTest.java | 5 ----- .../java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java | 3 --- .../PersonPlacementEmployingBodyTrustJobIntegrationTest.java | 5 ----- .../PersonPlacementTrainingBodyTrustJobIntegrationTest.java | 5 ----- .../tis/sync/job/PersonRecordStatusJobIntegrationTest.java | 5 ----- .../sync/job/PostEmployingBodyTrustJobIntegrationTest.java | 5 ----- .../sync/job/PostTrainingBodyTrustJobIntegrationTest.java | 5 ----- .../reval/RevalCurrentPlacementSyncJobIntegrationTest.java | 5 ----- .../sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java | 5 ----- 10 files changed, 2 insertions(+), 44 deletions(-) diff --git a/src/main/java/uk/nhs/tis/sync/Application.java b/src/main/java/uk/nhs/tis/sync/Application.java index 91b9e645..49bb8352 100644 --- a/src/main/java/uk/nhs/tis/sync/Application.java +++ b/src/main/java/uk/nhs/tis/sync/Application.java @@ -18,7 +18,8 @@ @SpringBootApplication @ComponentScan(basePackages = {"com.transformuk.hee.tis.tcs", - "uk.nhs.tis.sync", "com.transformuk.hee.tis.reference.client"}) + "uk.nhs.tis.sync", "com.transformuk.hee.tis.reference.client", + "com.transformuk.hee.tis.profile.client"}) @EnableWebMvc @EnableSpringDataWebSupport @PropertySource({"classpath:/config/application.properties", diff --git a/src/test/java/uk/nhs/tis/sync/ApplicationTest.java b/src/test/java/uk/nhs/tis/sync/ApplicationTest.java index e9a5676e..d136824b 100644 --- a/src/test/java/uk/nhs/tis/sync/ApplicationTest.java +++ b/src/test/java/uk/nhs/tis/sync/ApplicationTest.java @@ -3,12 +3,10 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import uk.nhs.tis.sync.job.RecordResendingJob; @@ -17,9 +15,6 @@ @SpringBootTest public class ApplicationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired Application testClass; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java index 902109ae..f2f62f4e 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonOwnerRebuildJobTest.java @@ -11,7 +11,6 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonRepository; import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; @@ -31,8 +30,6 @@ public class PersonOwnerRebuildJobTest { @MockBean private PersonRepository repo; - @MockBean - ProfileServiceImpl profileService; @Test public void testPersonOwnerRebuildJob() { diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java index 1c809f61..ae332220 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementEmployingBodyTrustJobIntegrationTest.java @@ -1,6 +1,5 @@ package uk.nhs.tis.sync.job; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -10,7 +9,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -19,9 +17,6 @@ //@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PersonPlacementEmployingBodyTrustJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired PersonPlacementEmployingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java index 1d9ab2af..0915e2bd 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonPlacementTrainingBodyTrustJobIntegrationTest.java @@ -1,6 +1,5 @@ package uk.nhs.tis.sync.job; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PersonTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -10,7 +9,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -19,9 +17,6 @@ //@Sql(scripts = {"/scripts/deletePlacements.sql","/scripts/deletePersonRows.sql","/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PersonPlacementTrainingBodyTrustJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired PersonPlacementTrainingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java index 1fb1010c..2a6439b4 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PersonRecordStatusJobIntegrationTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; import org.hamcrest.CoreMatchers; @@ -16,7 +15,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @@ -25,9 +23,6 @@ //TODO @Sql(scripts = {"/scripts/deleteProgrammeMemberships.sql","/scripts/deletePersonRows.sql","/scripts/deleteProgrammes.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) class PersonRecordStatusJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired PersonRecordStatusJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java index 8b2f921b..af8bde4d 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PostEmployingBodyTrustJobIntegrationTest.java @@ -1,6 +1,5 @@ package uk.nhs.tis.sync.job; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -10,7 +9,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.junit4.SpringRunner; @@ -21,9 +19,6 @@ @Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PostEmployingBodyTrustJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired PostEmployingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java index 15e957d2..5c7a6db5 100644 --- a/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/PostTrainingBodyTrustJobIntegrationTest.java @@ -1,6 +1,5 @@ package uk.nhs.tis.sync.job; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import com.transformuk.hee.tis.tcs.service.repository.PostTrustRepository; import org.hamcrest.CoreMatchers; import org.junit.After; @@ -10,7 +9,6 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.junit4.SpringRunner; @@ -21,9 +19,6 @@ @Sql(scripts = {"/scripts/deletePosts.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) public class PostTrainingBodyTrustJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired PostTrainingBodyTrustJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java index aa17fdba..201dff10 100644 --- a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPlacementSyncJobIntegrationTest.java @@ -7,7 +7,6 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.mockito.Mockito.verify; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.Set; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; @@ -19,7 +18,6 @@ import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; @@ -30,9 +28,6 @@ @SpringBootTest class RevalCurrentPlacementSyncJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired RevalCurrentPlacementSyncJob job; diff --git a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java index 0063d63d..36a36181 100644 --- a/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java +++ b/src/test/java/uk/nhs/tis/sync/job/reval/RevalCurrentPmSyncJobIntegrationTest.java @@ -7,7 +7,6 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.mockito.Mockito.verify; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import java.util.Set; import java.util.concurrent.TimeUnit; import org.awaitility.core.ConditionTimeoutException; @@ -19,7 +18,6 @@ import org.mockito.Captor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql.ExecutionPhase; @@ -34,9 +32,6 @@ "/scripts/deletePersonRows.sql"}, executionPhase = ExecutionPhase.AFTER_TEST_METHOD) class RevalCurrentPmSyncJobIntegrationTest { - @MockBean - ProfileServiceImpl profileService; - @Autowired RevalCurrentPmSyncJob job; From f96df0c5cf663d11353aa82fb3fb21fe7ddea687 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Thu, 11 Jul 2024 09:55:44 +0100 Subject: [PATCH 07/11] fix: job runner test --- .../uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java b/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java index 42f83707..b0da2210 100644 --- a/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java +++ b/src/test/java/uk/nhs/tis/sync/event/listener/JobRunningListenerTest.java @@ -3,7 +3,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -30,8 +29,6 @@ public class JobRunningListenerTest { private RevalCurrentPmSyncJob revalCurrentPmSyncJob; @MockBean private PostFundingStatusSyncJob postFundingStatusSyncJob; - @MockBean - ProfileServiceImpl profileService; @Autowired JobRunningListener testClass; From 6258725cb3f792f4dd620454f3a2029bd3d919d5 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Fri, 12 Jul 2024 16:10:58 +0100 Subject: [PATCH 08/11] fix: pr comments --- .../java/uk/nhs/tis/sync/dto/DmsDtoType.java | 47 +++++++++++-------- .../tis/sync/mapper/HeeUserMapperTest.java | 19 ++------ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java index 3f4bb941..791fc5e4 100644 --- a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java +++ b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java @@ -44,28 +44,28 @@ @Getter public enum DmsDtoType { - CONTACT_DETAILS(ContactDetailsDTO.class, "tcs", "ContactDetails", null), - CURRICULUM(CurriculumDTO.class, "tcs", "Curriculum", CurriculumMapper.class), - CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, "tcs", "CurriculumMembership", + CONTACT_DETAILS(ContactDetailsDTO.class, Schemas.TCS, "ContactDetails", null), + CURRICULUM(CurriculumDTO.class, Schemas.TCS, "Curriculum", CurriculumMapper.class), + CURRICULUM_MEMBERSHIP(CurriculumMembershipWrapperDto.class, Schemas.TCS, "CurriculumMembership", CurriculumMembershipMapper.class), - DBC_DETAILS(DBCDTO.class, "reference", "DBC", null), - GDC_DETAILS(GdcDetailsDTO.class, "tcs", "GdcDetails", null), - GMC_DETAILS(GmcDetailsDTO.class, "tcs", "GmcDetails", null), - GRADE(GradeDTO.class, "reference", "Grade", GradeMapper.class), - HEE_USER(HeeUserDTO.class, "auth", "HeeUser", HeeUserMapper.class), - PERSON(PersonDTO.class, "tcs", "Person", PersonMapper.class), - PERSONAL_DETAILS(PersonalDetailsDTO.class, "tcs", "PersonalDetails", null), - PLACEMENT_DETAILS(PlacementSummaryDTO.class, "tcs", "Placement", PlacementSummaryMapper.class), - PLACEMENT_SPECIALTY(PlacementSpecialtyDTO.class, "tcs", "PlacementSpecialty", + DBC_DETAILS(DBCDTO.class, Schemas.REFERENCE, "DBC", null), + GDC_DETAILS(GdcDetailsDTO.class, Schemas.TCS, "GdcDetails", null), + GMC_DETAILS(GmcDetailsDTO.class, Schemas.TCS, "GmcDetails", null), + GRADE(GradeDTO.class, Schemas.REFERENCE, "Grade", GradeMapper.class), + HEE_USER(HeeUserDTO.class, Schemas.AUTH, "HeeUser", HeeUserMapper.class), + PERSON(PersonDTO.class, Schemas.TCS, "Person", PersonMapper.class), + PERSONAL_DETAILS(PersonalDetailsDTO.class, Schemas.TCS, "PersonalDetails", null), + PLACEMENT_DETAILS(PlacementSummaryDTO.class, Schemas.TCS, "Placement", PlacementSummaryMapper.class), + PLACEMENT_SPECIALTY(PlacementSpecialtyDTO.class, Schemas.TCS, "PlacementSpecialty", PlacementSpecialtyMapper.class), - POST(PostDTO.class, "tcs", "Post", PostMapper.class), - PROGRAMME(ProgrammeDTO.class, "tcs", "Programme", ProgrammeMapper.class), - PROGRAMME_MEMBERSHIP(ProgrammeMembershipDTO.class, "tcs", "ProgrammeMembership", + POST(PostDTO.class, Schemas.TCS, "Post", PostMapper.class), + PROGRAMME(ProgrammeDTO.class, Schemas.TCS, "Programme", ProgrammeMapper.class), + PROGRAMME_MEMBERSHIP(ProgrammeMembershipDTO.class, Schemas.TCS, "ProgrammeMembership", ProgrammeMembershipMapper.class), - QUALIFICATION(QualificationDTO.class, "tcs", "Qualification", QualificationMapper.class), - SITE(SiteDTO.class, "reference", "Site", SiteMapper.class), - SPECIALTY(SpecialtyDTO.class, "tcs", "Specialty", SpecialtyMapper.class), - TRUST(TrustDTO.class, "reference", "Trust", TrustMapper.class); + QUALIFICATION(QualificationDTO.class, Schemas.TCS, "Qualification", QualificationMapper.class), + SITE(SiteDTO.class, Schemas.REFERENCE, "Site", SiteMapper.class), + SPECIALTY(SpecialtyDTO.class, Schemas.TCS, "Specialty", SpecialtyMapper.class), + TRUST(TrustDTO.class, Schemas.REFERENCE, "Trust", TrustMapper.class); private final Class dtoType; private final String schema; @@ -86,4 +86,13 @@ public static DmsDtoType fromDto(Object dto) { } return null; } + + /** + * Define the schema names. + */ + private static class Schemas { + public static final String AUTH = "auth"; + public static final String REFERENCE = "reference"; + public static final String TCS = "tcs"; + } } diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 6f44a278..30afcf59 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -6,8 +6,7 @@ import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO; import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO; -import java.util.HashSet; -import java.util.Set; +import java.util.Collections; import org.junit.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; @@ -26,25 +25,17 @@ public void setUp() { heeUserDto = new HeeUserDTO(); heeUserDto.setActive(true); - HashSet assocProgrammes = new HashSet<>(); - assocProgrammes.add(new UserProgrammeDTO()); - heeUserDto.setAssociatedProgrammes(assocProgrammes); - HashSet userTrusts = new HashSet<>(); - userTrusts.add(new UserTrustDTO()); - heeUserDto.setAssociatedTrusts(userTrusts); + heeUserDto.setAssociatedProgrammes(Collections.singleton(new UserProgrammeDTO())); + heeUserDto.setAssociatedTrusts(Collections.singleton(new UserTrustDTO())); heeUserDto.setFirstName("first name"); heeUserDto.setName("name"); - Set dbcs = new HashSet<>(); - dbcs.add("dbc1"); - heeUserDto.setDesignatedBodyCodes(dbcs); + heeUserDto.setDesignatedBodyCodes(Collections.singleton("dbc1")); heeUserDto.setEmailAddress("email"); heeUserDto.setGmcId("gmc"); heeUserDto.setLastName("last name"); heeUserDto.setPassword("password"); heeUserDto.setPhoneNumber("phone"); - HashSet roles = new HashSet<>(); - roles.add(new RoleDTO()); - heeUserDto.setRoles(roles); + heeUserDto.setRoles(Collections.singleton(new RoleDTO())); heeUserDto.setTemporaryPassword(true); } From 8d51a0db5e0ee4b8aa9f3e78fc5cfef92dbcea48 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Fri, 12 Jul 2024 16:22:48 +0100 Subject: [PATCH 09/11] fix: line length --- src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java index 791fc5e4..42f2e441 100644 --- a/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java +++ b/src/main/java/uk/nhs/tis/sync/dto/DmsDtoType.java @@ -55,7 +55,8 @@ public enum DmsDtoType { HEE_USER(HeeUserDTO.class, Schemas.AUTH, "HeeUser", HeeUserMapper.class), PERSON(PersonDTO.class, Schemas.TCS, "Person", PersonMapper.class), PERSONAL_DETAILS(PersonalDetailsDTO.class, Schemas.TCS, "PersonalDetails", null), - PLACEMENT_DETAILS(PlacementSummaryDTO.class, Schemas.TCS, "Placement", PlacementSummaryMapper.class), + PLACEMENT_DETAILS(PlacementSummaryDTO.class, Schemas.TCS, "Placement", + PlacementSummaryMapper.class), PLACEMENT_SPECIALTY(PlacementSpecialtyDTO.class, Schemas.TCS, "PlacementSpecialty", PlacementSpecialtyMapper.class), POST(PostDTO.class, Schemas.TCS, "Post", PostMapper.class), From f4255d01a4beba1a1b787a998c8547de0cd4d287 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Fri, 12 Jul 2024 16:44:09 +0100 Subject: [PATCH 10/11] fix: Junit5 --- src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 30afcf59..1d4a0662 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -7,7 +7,7 @@ import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO; import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; From e1067346a4829f34bced7822f9be4c3ffdb28980 Mon Sep 17 00:00:00 2001 From: Reuben Roberts Date: Fri, 12 Jul 2024 16:48:27 +0100 Subject: [PATCH 11/11] fix: code smell --- src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java index 1d4a0662..4c39f072 100644 --- a/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java +++ b/src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java @@ -40,7 +40,7 @@ public void setUp() { } @Test - public void shouldMapAHeeUserDtoToADataDmsDto() { + void shouldMapAHeeUserDtoToADataDmsDto() { HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto); assertEquals("1", heeUserDmsDto.getActive());