From 0ff72838c6119495ff5df28c8fc909b6298c439f Mon Sep 17 00:00:00 2001 From: Russell Dodd Date: Thu, 15 Feb 2024 09:46:01 +0000 Subject: [PATCH] Add new user & 'roles' entities --- .../ApplicationFunctionController.java | 61 ++++++ .../BusinessUnitUserController.java | 60 ++++++ .../opal/controllers/TemplateController.java | 58 ++++++ .../TemplateMappingController.java | 63 +++++++ .../opal/controllers/UserController.java | 58 ++++++ .../UserEntitlementController.java | 60 ++++++ .../search/ApplicationFunctionSearchDto.java | 13 ++ .../dto/search/BusinessUnitUserSearchDto.java | 13 ++ .../dto/search/TemplateMappingSearchDto.java | 14 ++ .../opal/dto/search/TemplateSearchDto.java | 13 ++ .../dto/search/UserEntitlementSearchDto.java | 13 ++ .../hmcts/opal/dto/search/UserSearchDto.java | 13 ++ .../entity/ApplicationFunctionEntity.java | 33 ++++ .../opal/entity/BusinessUnitUserEntity.java | 30 +++ .../uk/gov/hmcts/opal/entity/NoteEntity.java | 3 + .../gov/hmcts/opal/entity/TemplateEntity.java | 32 ++++ .../opal/entity/TemplateMappingEntity.java | 42 +++++ .../opal/entity/UserEntitlementEntity.java | 35 ++++ .../uk/gov/hmcts/opal/entity/UserEntity.java | 33 ++++ .../ApplicationFunctionRepository.java | 11 ++ .../BusinessUnitUserRepository.java | 11 ++ .../repository/TemplateMappingRepository.java | 12 ++ .../opal/repository/TemplateRepository.java | 11 ++ .../repository/UserEntitlementRepository.java | 11 ++ .../hmcts/opal/repository/UserRepository.java | 11 ++ .../jpa/ApplicationFunctionSpecs.java | 21 +++ .../repository/jpa/BusinessUnitUserSpecs.java | 21 +++ .../repository/jpa/TemplateMappingSpecs.java | 26 +++ .../opal/repository/jpa/TemplateSpecs.java | 20 ++ .../repository/jpa/UserEntitlementSpecs.java | 21 +++ .../hmcts/opal/repository/jpa/UserSpecs.java | 20 ++ .../ApplicationFunctionServiceInterface.java | 13 ++ .../BusinessUnitUserServiceInterface.java | 13 ++ .../TemplateMappingServiceInterface.java | 14 ++ .../service/TemplateServiceInterface.java | 13 ++ .../UserEntitlementServiceInterface.java | 13 ++ .../opal/service/UserServiceInterface.java | 13 ++ .../LegacyApplicationFunctionService.java | 37 ++++ .../legacy/LegacyBusinessUnitUserService.java | 37 ++++ .../legacy/LegacyTemplateMappingService.java | 37 ++++ .../service/legacy/LegacyTemplateService.java | 37 ++++ .../legacy/LegacyUserEntitlementService.java | 37 ++++ .../service/legacy/LegacyUserService.java | 37 ++++ .../opal/ApplicationFunctionService.java | 38 ++++ .../service/opal/BusinessUnitUserService.java | 38 ++++ .../service/opal/TemplateMappingService.java | 39 ++++ .../opal/service/opal/TemplateService.java | 38 ++++ .../service/opal/UserEntitlementService.java | 38 ++++ .../hmcts/opal/service/opal/UserService.java | 38 ++++ .../ApplicationFunctionServiceProxy.java | 37 ++++ .../proxy/BusinessUnitUserServiceProxy.java | 37 ++++ .../proxy/TemplateMappingServiceProxy.java | 38 ++++ .../service/proxy/TemplateServiceProxy.java | 37 ++++ .../proxy/UserEntitlementServiceProxy.java | 37 ++++ .../opal/service/proxy/UserServiceProxy.java | 37 ++++ .../ApplicationFunctionControllerTest.java | 67 +++++++ .../BusinessUnitUserControllerTest.java | 67 +++++++ .../controllers/TemplateControllerTest.java | 65 +++++++ .../TemplateMappingControllerTest.java | 68 +++++++ .../opal/controllers/UserControllerTest.java | 66 +++++++ .../UserEntitlementControllerTest.java | 66 +++++++ .../LegacyApplicationFunctionServiceTest.java | 61 ++++++ .../LegacyBusinessUnitUserServiceTest.java | 60 ++++++ .../LegacyTemplateMappingServiceTest.java | 58 ++++++ .../legacy/LegacyTemplateServiceTest.java | 60 ++++++ .../LegacyUserEntitlementServiceTest.java | 60 ++++++ .../service/legacy/LegacyUserServiceTest.java | 60 ++++++ .../opal/ApplicationFunctionServiceTest.java | 74 ++++++++ .../opal/BusinessUnitUserServiceTest.java | 74 ++++++++ .../opal/TemplateMappingServiceTest.java | 76 ++++++++ .../service/opal/TemplateServiceTest.java | 72 +++++++ .../opal/UserEntitlementServiceTest.java | 74 ++++++++ .../opal/service/opal/UserServiceTest.java | 72 +++++++ .../AccountTransferServiceProxyTest.java | 87 ++++----- .../ApplicationFunctionServiceProxyTest.java | 101 ++++++++++ .../proxy/BusinessUnitServiceProxyTest.java | 86 ++++----- .../BusinessUnitUserServiceProxyTest.java | 99 ++++++++++ ...mittalWarrantProgressServiceProxyTest.java | 92 ++++----- .../service/proxy/CourtServiceProxyTest.java | 85 ++++----- .../proxy/DebtorDetailServiceProxyTest.java | 86 ++++----- .../DefendantAccountServiceProxyTest.java | 177 ++++++++---------- .../DocumentInstanceServiceProxyTest.java | 87 ++++----- .../proxy/DocumentServiceProxyTest.java | 87 ++++----- .../proxy/EnforcementServiceProxyTest.java | 85 ++++----- .../proxy/EnforcerServiceProxyTest.java | 85 ++++----- .../LocalJusticeAreaServiceProxyTest.java | 87 ++++----- .../proxy/MisDebtorServiceProxyTest.java | 85 ++++----- .../service/proxy/NoteServiceProxyTest.java | 85 ++++----- .../service/proxy/PartyServiceProxyTest.java | 148 +++++++-------- .../proxy/PaymentInServiceProxyTest.java | 85 ++++----- .../proxy/PaymentTermsServiceProxyTest.java | 86 ++++----- .../service/proxy/PrisonServiceProxyTest.java | 85 ++++----- .../opal/service/proxy/ProxyTestsBase.java | 22 +++ .../TemplateMappingServiceProxyTest.java | 100 ++++++++++ .../proxy/TemplateServiceProxyTest.java | 97 ++++++++++ .../service/proxy/TillServiceProxyTest.java | 85 ++++----- .../UserEntitlementServiceProxyTest.java | 99 ++++++++++ .../service/proxy/UserServiceProxyTest.java | 97 ++++++++++ 98 files changed, 4136 insertions(+), 978 deletions(-) create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/TemplateController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/TemplateMappingController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/UserController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/controllers/UserEntitlementController.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/ApplicationFunctionSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/BusinessUnitUserSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/TemplateMappingSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/TemplateSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/UserEntitlementSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/dto/search/UserSearchDto.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/ApplicationFunctionEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitUserEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/TemplateEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/TemplateMappingEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/UserEntitlementEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/entity/UserEntity.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/ApplicationFunctionRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/BusinessUnitUserRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/TemplateMappingRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/TemplateRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/UserEntitlementRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/UserRepository.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/ApplicationFunctionSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitUserSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateMappingSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/UserEntitlementSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/repository/jpa/UserSpecs.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/ApplicationFunctionServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/BusinessUnitUserServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/TemplateMappingServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/TemplateServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/UserEntitlementServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/UserServiceInterface.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/TemplateMappingService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/TemplateService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/UserEntitlementService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/opal/UserService.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxy.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxy.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxy.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxy.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxy.java create mode 100644 src/main/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxy.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/TemplateControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/TemplateMappingControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/UserControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/controllers/UserEntitlementControllerTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/TemplateMappingServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/TemplateServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/UserEntitlementServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/opal/UserServiceTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxyTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxyTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/ProxyTestsBase.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxyTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxyTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxyTest.java create mode 100644 src/test/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxyTest.java diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionController.java b/src/main/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionController.java new file mode 100644 index 000000000..10293c9da --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionController.java @@ -0,0 +1,61 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.service.ApplicationFunctionServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/application-function") +@Slf4j(topic = "ApplicationFunctionController") +@Tag(name = "ApplicationFunction Controller") +public class ApplicationFunctionController { + + private final ApplicationFunctionServiceInterface applicationFunctionService; + + public ApplicationFunctionController( + @Qualifier("applicationFunctionServiceProxy") ApplicationFunctionServiceInterface applicationFunctionService) { + this.applicationFunctionService = applicationFunctionService; + } + + @GetMapping(value = "/{applicationFunctionId}") + @Operation(summary = "Returns the ApplicationFunction for the given applicationFunctionId.") + public ResponseEntity getApplicationFunctionById( + @PathVariable Long applicationFunctionId) { + + log.info(":GET:getApplicationFunctionById: applicationFunctionId: {}", applicationFunctionId); + + ApplicationFunctionEntity response = applicationFunctionService.getApplicationFunction(applicationFunctionId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches ApplicationFunctions based upon criteria in request body") + public ResponseEntity> postApplicationFunctionsSearch( + @RequestBody ApplicationFunctionSearchDto criteria) { + log.info(":POST:postApplicationFunctionsSearch: query: \n{}", criteria); + + List response = applicationFunctionService.searchApplicationFunctions(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserController.java b/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserController.java new file mode 100644 index 000000000..af421ca70 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserController.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.service.BusinessUnitUserServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/business-unit-user") +@Slf4j(topic = "BusinessUnitUserController") +@Tag(name = "BusinessUnitUser Controller") +public class BusinessUnitUserController { + + private final BusinessUnitUserServiceInterface businessUnitUserService; + + public BusinessUnitUserController( + @Qualifier("businessUnitUserServiceProxy") BusinessUnitUserServiceInterface businessUnitUserService) { + this.businessUnitUserService = businessUnitUserService; + } + + @GetMapping(value = "/{businessUnitUserId}") + @Operation(summary = "Returns the BusinessUnitUser for the given businessUnitUserId.") + public ResponseEntity getBusinessUnitUserById(@PathVariable String businessUnitUserId) { + + log.info(":GET:getBusinessUnitUserById: businessUnitUserId: {}", businessUnitUserId); + + BusinessUnitUserEntity response = businessUnitUserService.getBusinessUnitUser(businessUnitUserId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches BusinessUnitUsers based upon criteria in request body") + public ResponseEntity> postBusinessUnitUsersSearch( + @RequestBody BusinessUnitUserSearchDto criteria) { + log.info(":POST:postBusinessUnitUsersSearch: query: \n{}", criteria); + + List response = businessUnitUserService.searchBusinessUnitUsers(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/TemplateController.java b/src/main/java/uk/gov/hmcts/opal/controllers/TemplateController.java new file mode 100644 index 000000000..758cd2c49 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/TemplateController.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.service.TemplateServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/template") +@Slf4j(topic = "TemplateController") +@Tag(name = "Template Controller") +public class TemplateController { + + private final TemplateServiceInterface templateService; + + public TemplateController(@Qualifier("templateServiceProxy") TemplateServiceInterface templateService) { + this.templateService = templateService; + } + + @GetMapping(value = "/{templateId}") + @Operation(summary = "Returns the Template for the given templateId.") + public ResponseEntity getTemplateById(@PathVariable Long templateId) { + + log.info(":GET:getTemplateById: templateId: {}", templateId); + + TemplateEntity response = templateService.getTemplate(templateId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches Templates based upon criteria in request body") + public ResponseEntity> postTemplatesSearch(@RequestBody TemplateSearchDto criteria) { + log.info(":POST:postTemplatesSearch: query: \n{}", criteria); + + List response = templateService.searchTemplates(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/TemplateMappingController.java b/src/main/java/uk/gov/hmcts/opal/controllers/TemplateMappingController.java new file mode 100644 index 000000000..ead887e8a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/TemplateMappingController.java @@ -0,0 +1,63 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.service.TemplateMappingServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/template-mapping") +@Slf4j(topic = "TemplateMappingController") +@Tag(name = "TemplateMapping Controller") +public class TemplateMappingController { + + private final TemplateMappingServiceInterface templateMappingService; + + public TemplateMappingController( + @Qualifier("templateMappingServiceProxy") TemplateMappingServiceInterface templateMappingService) { + this.templateMappingService = templateMappingService; + } + + @GetMapping(value = "/{templateId}/{applicationFunctionId}") + @Operation(summary = "Returns the TemplateMapping for the given templateMappingId.") + public ResponseEntity getTemplateMappingById(@PathVariable Long templateId, + @PathVariable Long applicationFunctionId) { + + MappingId mappingId = new MappingId(templateId, applicationFunctionId); + log.info(":GET:getTemplateMappingById: mappingId: {}", mappingId); + + TemplateMappingEntity response = templateMappingService.getTemplateMapping(mappingId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches TemplateMappings based upon criteria in request body") + public ResponseEntity> postTemplateMappingsSearch( + @RequestBody TemplateMappingSearchDto criteria) { + log.info(":POST:postTemplateMappingsSearch: query: \n{}", criteria); + + List response = templateMappingService.searchTemplateMappings(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/UserController.java b/src/main/java/uk/gov/hmcts/opal/controllers/UserController.java new file mode 100644 index 000000000..005955de7 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/UserController.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.service.UserServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/user") +@Slf4j(topic = "UserController") +@Tag(name = "User Controller") +public class UserController { + + private final UserServiceInterface userService; + + public UserController(@Qualifier("userServiceProxy") UserServiceInterface userService) { + this.userService = userService; + } + + @GetMapping(value = "/{userId}") + @Operation(summary = "Returns the User for the given userId.") + public ResponseEntity getUserById(@PathVariable String userId) { + + log.info(":GET:getUserById: userId: {}", userId); + + UserEntity response = userService.getUser(userId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches Users based upon criteria in request body") + public ResponseEntity> postUsersSearch(@RequestBody UserSearchDto criteria) { + log.info(":POST:postUsersSearch: query: \n{}", criteria); + + List response = userService.searchUsers(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/controllers/UserEntitlementController.java b/src/main/java/uk/gov/hmcts/opal/controllers/UserEntitlementController.java new file mode 100644 index 000000000..b68cd0057 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/controllers/UserEntitlementController.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.controllers; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.service.UserEntitlementServiceInterface; + +import java.util.List; + +import static uk.gov.hmcts.opal.util.ResponseUtil.buildResponse; + + +@RestController +@RequestMapping("/api/user-entitlement") +@Slf4j(topic = "UserEntitlementController") +@Tag(name = "UserEntitlement Controller") +public class UserEntitlementController { + + private final UserEntitlementServiceInterface userEntitlementService; + + public UserEntitlementController( + @Qualifier("userEntitlementServiceProxy") UserEntitlementServiceInterface userEntitlementService) { + this.userEntitlementService = userEntitlementService; + } + + @GetMapping(value = "/{userEntitlementId}") + @Operation(summary = "Returns the UserEntitlement for the given userEntitlementId.") + public ResponseEntity getUserEntitlementById(@PathVariable Long userEntitlementId) { + + log.info(":GET:getUserEntitlementById: userEntitlementId: {}", userEntitlementId); + + UserEntitlementEntity response = userEntitlementService.getUserEntitlement(userEntitlementId); + + return buildResponse(response); + } + + @PostMapping(value = "/search", consumes = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Searches UserEntitlements based upon criteria in request body") + public ResponseEntity> postUserEntitlementsSearch( + @RequestBody UserEntitlementSearchDto criteria) { + log.info(":POST:postUserEntitlementsSearch: query: \n{}", criteria); + + List response = userEntitlementService.searchUserEntitlements(criteria); + + return buildResponse(response); + } + + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/ApplicationFunctionSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/ApplicationFunctionSearchDto.java new file mode 100644 index 000000000..fcac5b81a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/ApplicationFunctionSearchDto.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class ApplicationFunctionSearchDto implements ToJsonString { + + private String applicationFunctionId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/BusinessUnitUserSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/BusinessUnitUserSearchDto.java new file mode 100644 index 000000000..b15b7031e --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/BusinessUnitUserSearchDto.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class BusinessUnitUserSearchDto implements ToJsonString { + + private String businessUnitUserId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateMappingSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateMappingSearchDto.java new file mode 100644 index 000000000..bb9a2e05f --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateMappingSearchDto.java @@ -0,0 +1,14 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class TemplateMappingSearchDto implements ToJsonString { + + private String templateId; + private String applicationFunctionId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateSearchDto.java new file mode 100644 index 000000000..73ff8d078 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/TemplateSearchDto.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class TemplateSearchDto implements ToJsonString { + + private String templateId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/UserEntitlementSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/UserEntitlementSearchDto.java new file mode 100644 index 000000000..fb19b7051 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/UserEntitlementSearchDto.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class UserEntitlementSearchDto implements ToJsonString { + + private String userEntitlementId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/dto/search/UserSearchDto.java b/src/main/java/uk/gov/hmcts/opal/dto/search/UserSearchDto.java new file mode 100644 index 000000000..2375a4883 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/dto/search/UserSearchDto.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.dto.search; + +import lombok.Builder; +import lombok.Data; +import uk.gov.hmcts.opal.dto.ToJsonString; + +@Data +@Builder +public class UserSearchDto implements ToJsonString { + + private String userId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/ApplicationFunctionEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/ApplicationFunctionEntity.java new file mode 100644 index 000000000..848af61b0 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/ApplicationFunctionEntity.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "application_functions") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class ApplicationFunctionEntity { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "application_function_id_seq_generator") + @SequenceGenerator(name = "application_function_id_seq_generator", sequenceName = "application_function_id_seq", + allocationSize = 1) + @Column(name = "application_function_id") + private Long applicationFunctionId; + + @Column(name = "function_name", length = 200) + private String functionName; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitUserEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitUserEntity.java new file mode 100644 index 000000000..8e306df87 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/BusinessUnitUserEntity.java @@ -0,0 +1,30 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "business_unit_users") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class BusinessUnitUserEntity { + + @Id + @Column(name = "business_unit_user_id", length = 6) + private String businessUnitUserId; + + @Column(name = "business_unit_id") + private Short businessUnitId; + + @Column(name = "user_id", length = 100) + private String userId; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/NoteEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/NoteEntity.java index be8678590..7186c087a 100644 --- a/src/main/java/uk/gov/hmcts/opal/entity/NoteEntity.java +++ b/src/main/java/uk/gov/hmcts/opal/entity/NoteEntity.java @@ -49,4 +49,7 @@ public class NoteEntity { @Column(name = "posted_by", length = 20) private String postedBy; + @Column(name = "posted_by_aad", length = 100) + private String postedByAad; + } diff --git a/src/main/java/uk/gov/hmcts/opal/entity/TemplateEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/TemplateEntity.java new file mode 100644 index 000000000..3d03da696 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/TemplateEntity.java @@ -0,0 +1,32 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "templates") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TemplateEntity { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "template_id_seq_generator") + @SequenceGenerator(name = "template_id_seq_generator", sequenceName = "template_id_seq", allocationSize = 1) + @Column(name = "template_id") + private Long templateId; + + @Column(name = "template_name", length = 100) + private String templateName; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/TemplateMappingEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/TemplateMappingEntity.java new file mode 100644 index 000000000..4fb36a2b3 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/TemplateMappingEntity.java @@ -0,0 +1,42 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.IdClass; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Entity +@IdClass(TemplateMappingEntity.MappingId.class) +@Table(name = "template_mappings") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TemplateMappingEntity { + + @Id + @Column(name = "template_id") + private Long templateId; + + @Id + @Column(name = "application_function_id") + private Long applicationFunctionId; + + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class MappingId implements Serializable { + + private Long templateId; + + private Long applicationFunctionId; + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/UserEntitlementEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/UserEntitlementEntity.java new file mode 100644 index 000000000..1e3847d2f --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/UserEntitlementEntity.java @@ -0,0 +1,35 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.SequenceGenerator; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "user_entitlements") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UserEntitlementEntity { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_entitlement_id_seq_generator") + @SequenceGenerator(name = "user_entitlement_id_seq_generator", sequenceName = "user_entitlement_id_seq", + allocationSize = 1) + @Column(name = "user_entitlement_id") + private Long userEntitlementId; + + @Column(name = "business_unit_user_id", length = 6) + private String businessUnitUserId; + + @Column(name = "application_function_id") + private Long applicationFunctionId; +} diff --git a/src/main/java/uk/gov/hmcts/opal/entity/UserEntity.java b/src/main/java/uk/gov/hmcts/opal/entity/UserEntity.java new file mode 100644 index 000000000..b9ee35e6e --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/entity/UserEntity.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.opal.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "users") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class UserEntity { + + @Id + @Column(name = "user_id", length = 100) + private String userId; + + @Column(name = "username", length = 100) + private String username; + + @Column(name = "password", length = 1000) + private String password; + + @Column(name = "description", length = 100) + private String description; + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/ApplicationFunctionRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/ApplicationFunctionRepository.java new file mode 100644 index 000000000..4bdd1f3e2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/ApplicationFunctionRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; + +@Repository +public interface ApplicationFunctionRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/BusinessUnitUserRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/BusinessUnitUserRepository.java new file mode 100644 index 000000000..c0b8b2611 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/BusinessUnitUserRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; + +@Repository +public interface BusinessUnitUserRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/TemplateMappingRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/TemplateMappingRepository.java new file mode 100644 index 000000000..adec6050a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/TemplateMappingRepository.java @@ -0,0 +1,12 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; + +@Repository +public interface TemplateMappingRepository extends JpaRepository, JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/TemplateRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/TemplateRepository.java new file mode 100644 index 000000000..cf5a44f08 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/TemplateRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.TemplateEntity; + +@Repository +public interface TemplateRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/UserEntitlementRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/UserEntitlementRepository.java new file mode 100644 index 000000000..b0c2df29a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/UserEntitlementRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; + +@Repository +public interface UserEntitlementRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/UserRepository.java b/src/main/java/uk/gov/hmcts/opal/repository/UserRepository.java new file mode 100644 index 000000000..b7d3665bd --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/UserRepository.java @@ -0,0 +1,11 @@ +package uk.gov.hmcts.opal.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; +import uk.gov.hmcts.opal.entity.UserEntity; + +@Repository +public interface UserRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/ApplicationFunctionSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/ApplicationFunctionSpecs.java new file mode 100644 index 000000000..c0fbf3a52 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/ApplicationFunctionSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity_; + +public class ApplicationFunctionSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(ApplicationFunctionSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getApplicationFunctionId()).map(ApplicationFunctionSpecs::equalsApplicationFunctionId) + )); + } + + public static Specification equalsApplicationFunctionId(String applicationFunctionId) { + return (root, query, builder) -> builder.equal(root.get(ApplicationFunctionEntity_.applicationFunctionId), + applicationFunctionId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitUserSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitUserSpecs.java new file mode 100644 index 000000000..019280d4a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/BusinessUnitUserSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity_; + +public class BusinessUnitUserSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(BusinessUnitUserSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getBusinessUnitUserId()).map(BusinessUnitUserSpecs::equalsBusinessUnitUserId) + )); + } + + public static Specification equalsBusinessUnitUserId(String businessUnitUserId) { + return (root, query, builder) -> builder.equal(root.get(BusinessUnitUserEntity_.businessUnitUserId), + businessUnitUserId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateMappingSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateMappingSpecs.java new file mode 100644 index 000000000..3dc91148e --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateMappingSpecs.java @@ -0,0 +1,26 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity_; + +public class TemplateMappingSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(TemplateMappingSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getTemplateId()).map(TemplateMappingSpecs::equalsTemplateId), + notBlank(criteria.getApplicationFunctionId()).map(TemplateMappingSpecs::equalsApplicationFunctionId) + )); + } + + public static Specification equalsTemplateId(String templateId) { + return (root, query, builder) -> builder.equal(root.get(TemplateMappingEntity_.templateId), templateId); + } + + public static Specification equalsApplicationFunctionId(String applicationFunctionId) { + return (root, query, builder) -> builder.equal(root.get(TemplateMappingEntity_.applicationFunctionId), + applicationFunctionId + ); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateSpecs.java new file mode 100644 index 000000000..fa7221be2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/TemplateSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.entity.TemplateEntity_; + +public class TemplateSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(TemplateSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getTemplateId()).map(TemplateSpecs::equalsTemplateId) + )); + } + + public static Specification equalsTemplateId(String templateId) { + return (root, query, builder) -> builder.equal(root.get(TemplateEntity_.templateId), templateId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserEntitlementSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserEntitlementSpecs.java new file mode 100644 index 000000000..900caa4f2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserEntitlementSpecs.java @@ -0,0 +1,21 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity_; + +public class UserEntitlementSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(UserEntitlementSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getUserEntitlementId()).map(UserEntitlementSpecs::equalsUserEntitlementId) + )); + } + + public static Specification equalsUserEntitlementId(String userEntitlementId) { + return (root, query, builder) -> builder.equal(root.get(UserEntitlementEntity_.userEntitlementId), + userEntitlementId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserSpecs.java b/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserSpecs.java new file mode 100644 index 000000000..9a281aaba --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/repository/jpa/UserSpecs.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.opal.repository.jpa; + +import org.springframework.data.jpa.domain.Specification; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.entity.UserEntity_; + +public class UserSpecs extends EntitySpecs { + + public Specification findBySearchCriteria(UserSearchDto criteria) { + return Specification.allOf(specificationList( + notBlank(criteria.getUserId()).map(UserSpecs::equalsUserId) + )); + } + + public static Specification equalsUserId(String userId) { + return (root, query, builder) -> builder.equal(root.get(UserEntity_.userId), userId); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/ApplicationFunctionServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/ApplicationFunctionServiceInterface.java new file mode 100644 index 000000000..e81028318 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/ApplicationFunctionServiceInterface.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; + +import java.util.List; + +public interface ApplicationFunctionServiceInterface { + + ApplicationFunctionEntity getApplicationFunction(long applicationFunctionId); + + List searchApplicationFunctions(ApplicationFunctionSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/BusinessUnitUserServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/BusinessUnitUserServiceInterface.java new file mode 100644 index 000000000..3f4127e00 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/BusinessUnitUserServiceInterface.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; + +import java.util.List; + +public interface BusinessUnitUserServiceInterface { + + BusinessUnitUserEntity getBusinessUnitUser(String businessUnitUserId); + + List searchBusinessUnitUsers(BusinessUnitUserSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/TemplateMappingServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/TemplateMappingServiceInterface.java new file mode 100644 index 000000000..c3f9667e8 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/TemplateMappingServiceInterface.java @@ -0,0 +1,14 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; + +import java.util.List; + +public interface TemplateMappingServiceInterface { + + TemplateMappingEntity getTemplateMapping(MappingId templateMappingId); + + List searchTemplateMappings(TemplateMappingSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/TemplateServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/TemplateServiceInterface.java new file mode 100644 index 000000000..12577fcaa --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/TemplateServiceInterface.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; + +import java.util.List; + +public interface TemplateServiceInterface { + + TemplateEntity getTemplate(long templateId); + + List searchTemplates(TemplateSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/UserEntitlementServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/UserEntitlementServiceInterface.java new file mode 100644 index 000000000..234ea1478 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/UserEntitlementServiceInterface.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; + +import java.util.List; + +public interface UserEntitlementServiceInterface { + + UserEntitlementEntity getUserEntitlement(long userEntitlementId); + + List searchUserEntitlements(UserEntitlementSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/UserServiceInterface.java b/src/main/java/uk/gov/hmcts/opal/service/UserServiceInterface.java new file mode 100644 index 000000000..0218f0746 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/UserServiceInterface.java @@ -0,0 +1,13 @@ +package uk.gov.hmcts.opal.service; + +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; + +import java.util.List; + +public interface UserServiceInterface { + + UserEntity getUser(String userId); + + List searchUsers(UserSearchDto criteria); +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionService.java new file mode 100644 index 000000000..f4fc4a19a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.service.ApplicationFunctionServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyApplicationFunctionService") +public class LegacyApplicationFunctionService extends LegacyService implements ApplicationFunctionServiceInterface { + + public LegacyApplicationFunctionService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public ApplicationFunctionEntity getApplicationFunction(long applicationFunctionId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchApplicationFunctions(ApplicationFunctionSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserService.java new file mode 100644 index 000000000..8fde35453 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.service.BusinessUnitUserServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyBusinessUnitUserService") +public class LegacyBusinessUnitUserService extends LegacyService implements BusinessUnitUserServiceInterface { + + public LegacyBusinessUnitUserService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public BusinessUnitUserEntity getBusinessUnitUser(String businessUnitUserId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchBusinessUnitUsers(BusinessUnitUserSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingService.java new file mode 100644 index 000000000..bf174313d --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.service.TemplateMappingServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyTemplateMappingService") +public class LegacyTemplateMappingService extends LegacyService implements TemplateMappingServiceInterface { + + public LegacyTemplateMappingService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public TemplateMappingEntity getTemplateMapping(TemplateMappingEntity.MappingId templateMappingId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchTemplateMappings(TemplateMappingSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateService.java new file mode 100644 index 000000000..dd0455e2b --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.service.TemplateServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyTemplateService") +public class LegacyTemplateService extends LegacyService implements TemplateServiceInterface { + + public LegacyTemplateService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public TemplateEntity getTemplate(long templateId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchTemplates(TemplateSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementService.java new file mode 100644 index 000000000..3fb8aec12 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.service.UserEntitlementServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyUserEntitlementService") +public class LegacyUserEntitlementService extends LegacyService implements UserEntitlementServiceInterface { + + public LegacyUserEntitlementService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public UserEntitlementEntity getUserEntitlement(long userEntitlementId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchUserEntitlements(UserEntitlementSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserService.java b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserService.java new file mode 100644 index 000000000..d7e49d20c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/legacy/LegacyUserService.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.legacy; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClient; +import uk.gov.hmcts.opal.config.properties.LegacyGatewayProperties; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.service.UserServiceInterface; + +import java.util.List; + +@Service +@Slf4j(topic = "LegacyUserService") +public class LegacyUserService extends LegacyService implements UserServiceInterface { + + public LegacyUserService(LegacyGatewayProperties legacyGatewayProperties, RestClient restClient) { + super(legacyGatewayProperties, restClient); + } + + @Override + public Logger getLog() { + return log; + } + + @Override + public UserEntity getUser(String userId) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + + @Override + public List searchUsers(UserSearchDto criteria) { + throw new LegacyGatewayResponseException("Not Yet Implemented"); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionService.java new file mode 100644 index 000000000..3241885d7 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionService.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.repository.ApplicationFunctionRepository; +import uk.gov.hmcts.opal.repository.jpa.ApplicationFunctionSpecs; +import uk.gov.hmcts.opal.service.ApplicationFunctionServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ApplicationFunctionService implements ApplicationFunctionServiceInterface { + + private final ApplicationFunctionRepository applicationFunctionRepository; + + private final ApplicationFunctionSpecs specs = new ApplicationFunctionSpecs(); + + @Override + public ApplicationFunctionEntity getApplicationFunction(long applicationFunctionId) { + return applicationFunctionRepository.getReferenceById(applicationFunctionId); + } + + @Override + public List searchApplicationFunctions(ApplicationFunctionSearchDto criteria) { + Page page = applicationFunctionRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserService.java new file mode 100644 index 000000000..9c06b1cba --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserService.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.repository.BusinessUnitUserRepository; +import uk.gov.hmcts.opal.repository.jpa.BusinessUnitUserSpecs; +import uk.gov.hmcts.opal.service.BusinessUnitUserServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class BusinessUnitUserService implements BusinessUnitUserServiceInterface { + + private final BusinessUnitUserRepository businessUnitUserRepository; + + private final BusinessUnitUserSpecs specs = new BusinessUnitUserSpecs(); + + @Override + public BusinessUnitUserEntity getBusinessUnitUser(String businessUnitUserId) { + return businessUnitUserRepository.getReferenceById(businessUnitUserId); + } + + @Override + public List searchBusinessUnitUsers(BusinessUnitUserSearchDto criteria) { + Page page = businessUnitUserRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateMappingService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateMappingService.java new file mode 100644 index 000000000..41cca11f2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateMappingService.java @@ -0,0 +1,39 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.repository.TemplateMappingRepository; +import uk.gov.hmcts.opal.repository.jpa.TemplateMappingSpecs; +import uk.gov.hmcts.opal.service.TemplateMappingServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class TemplateMappingService implements TemplateMappingServiceInterface { + + private final TemplateMappingRepository templateMappingRepository; + + private final TemplateMappingSpecs specs = new TemplateMappingSpecs(); + + @Override + public TemplateMappingEntity getTemplateMapping(MappingId templateMappingId) { + return templateMappingRepository.getReferenceById(templateMappingId); + } + + @Override + public List searchTemplateMappings(TemplateMappingSearchDto criteria) { + Page page = templateMappingRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateService.java new file mode 100644 index 000000000..134bf53c2 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/TemplateService.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.repository.TemplateRepository; +import uk.gov.hmcts.opal.repository.jpa.TemplateSpecs; +import uk.gov.hmcts.opal.service.TemplateServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class TemplateService implements TemplateServiceInterface { + + private final TemplateRepository templateRepository; + + private final TemplateSpecs specs = new TemplateSpecs(); + + @Override + public TemplateEntity getTemplate(long templateId) { + return templateRepository.getReferenceById(templateId); + } + + @Override + public List searchTemplates(TemplateSearchDto criteria) { + Page page = templateRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/UserEntitlementService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/UserEntitlementService.java new file mode 100644 index 000000000..fd98c8cd1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/UserEntitlementService.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.repository.UserEntitlementRepository; +import uk.gov.hmcts.opal.repository.jpa.UserEntitlementSpecs; +import uk.gov.hmcts.opal.service.UserEntitlementServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class UserEntitlementService implements UserEntitlementServiceInterface { + + private final UserEntitlementRepository userEntitlementRepository; + + private final UserEntitlementSpecs specs = new UserEntitlementSpecs(); + + @Override + public UserEntitlementEntity getUserEntitlement(long userEntitlementId) { + return userEntitlementRepository.getReferenceById(userEntitlementId); + } + + @Override + public List searchUserEntitlements(UserEntitlementSearchDto criteria) { + Page page = userEntitlementRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/opal/UserService.java b/src/main/java/uk/gov/hmcts/opal/service/opal/UserService.java new file mode 100644 index 000000000..b44b55db5 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/opal/UserService.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.opal; + + +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.repository.UserRepository; +import uk.gov.hmcts.opal.repository.jpa.UserSpecs; +import uk.gov.hmcts.opal.service.UserServiceInterface; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class UserService implements UserServiceInterface { + + private final UserRepository userRepository; + + private final UserSpecs specs = new UserSpecs(); + + @Override + public UserEntity getUser(String userId) { + return userRepository.getReferenceById(userId); + } + + @Override + public List searchUsers(UserSearchDto criteria) { + Page page = userRepository + .findBy(specs.findBySearchCriteria(criteria), + ffq -> ffq.page(Pageable.unpaged())); + + return page.getContent(); + } + +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxy.java new file mode 100644 index 000000000..7383f5b77 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxy.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.ApplicationFunctionServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyApplicationFunctionService; +import uk.gov.hmcts.opal.service.opal.ApplicationFunctionService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("applicationFunctionServiceProxy") +public class ApplicationFunctionServiceProxy implements ApplicationFunctionServiceInterface, ProxyInterface { + + private final ApplicationFunctionService opalApplicationFunctionService; + private final LegacyApplicationFunctionService legacyApplicationFunctionService; + private final DynamicConfigService dynamicConfigService; + + private ApplicationFunctionServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyApplicationFunctionService : opalApplicationFunctionService; + } + + @Override + public ApplicationFunctionEntity getApplicationFunction(long applicationFunctionId) { + return getCurrentModeService().getApplicationFunction(applicationFunctionId); + } + + @Override + public List searchApplicationFunctions(ApplicationFunctionSearchDto criteria) { + return getCurrentModeService().searchApplicationFunctions(criteria); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxy.java new file mode 100644 index 000000000..80c45b66c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxy.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.BusinessUnitUserServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyBusinessUnitUserService; +import uk.gov.hmcts.opal.service.opal.BusinessUnitUserService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("businessUnitUserServiceProxy") +public class BusinessUnitUserServiceProxy implements BusinessUnitUserServiceInterface, ProxyInterface { + + private final BusinessUnitUserService opalBusinessUnitUserService; + private final LegacyBusinessUnitUserService legacyBusinessUnitUserService; + private final DynamicConfigService dynamicConfigService; + + private BusinessUnitUserServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyBusinessUnitUserService : opalBusinessUnitUserService; + } + + @Override + public BusinessUnitUserEntity getBusinessUnitUser(String businessUnitUserId) { + return getCurrentModeService().getBusinessUnitUser(businessUnitUserId); + } + + @Override + public List searchBusinessUnitUsers(BusinessUnitUserSearchDto criteria) { + return getCurrentModeService().searchBusinessUnitUsers(criteria); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxy.java new file mode 100644 index 000000000..a41fa42d3 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxy.java @@ -0,0 +1,38 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.TemplateMappingServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyTemplateMappingService; +import uk.gov.hmcts.opal.service.opal.TemplateMappingService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("templateMappingServiceProxy") +public class TemplateMappingServiceProxy implements TemplateMappingServiceInterface, ProxyInterface { + + private final TemplateMappingService opalTemplateMappingService; + private final LegacyTemplateMappingService legacyTemplateMappingService; + private final DynamicConfigService dynamicConfigService; + + private TemplateMappingServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyTemplateMappingService : opalTemplateMappingService; + } + + @Override + public TemplateMappingEntity getTemplateMapping(MappingId templateMappingId) { + return getCurrentModeService().getTemplateMapping(templateMappingId); + } + + @Override + public List searchTemplateMappings(TemplateMappingSearchDto criteria) { + return getCurrentModeService().searchTemplateMappings(criteria); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxy.java new file mode 100644 index 000000000..7a8d36d1d --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxy.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.TemplateServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyTemplateService; +import uk.gov.hmcts.opal.service.opal.TemplateService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("templateServiceProxy") +public class TemplateServiceProxy implements TemplateServiceInterface, ProxyInterface { + + private final TemplateService opalTemplateService; + private final LegacyTemplateService legacyTemplateService; + private final DynamicConfigService dynamicConfigService; + + private TemplateServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyTemplateService : opalTemplateService; + } + + @Override + public TemplateEntity getTemplate(long templateId) { + return getCurrentModeService().getTemplate(templateId); + } + + @Override + public List searchTemplates(TemplateSearchDto criteria) { + return getCurrentModeService().searchTemplates(criteria); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxy.java new file mode 100644 index 000000000..3b04b345e --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxy.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.UserEntitlementServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyUserEntitlementService; +import uk.gov.hmcts.opal.service.opal.UserEntitlementService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("userEntitlementServiceProxy") +public class UserEntitlementServiceProxy implements UserEntitlementServiceInterface, ProxyInterface { + + private final UserEntitlementService opalUserEntitlementService; + private final LegacyUserEntitlementService legacyUserEntitlementService; + private final DynamicConfigService dynamicConfigService; + + private UserEntitlementServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyUserEntitlementService : opalUserEntitlementService; + } + + @Override + public UserEntitlementEntity getUserEntitlement(long userEntitlementId) { + return getCurrentModeService().getUserEntitlement(userEntitlementId); + } + + @Override + public List searchUserEntitlements(UserEntitlementSearchDto criteria) { + return getCurrentModeService().searchUserEntitlements(criteria); + } +} diff --git a/src/main/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxy.java b/src/main/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxy.java new file mode 100644 index 000000000..91a51dd4f --- /dev/null +++ b/src/main/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxy.java @@ -0,0 +1,37 @@ +package uk.gov.hmcts.opal.service.proxy; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.UserServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyUserService; +import uk.gov.hmcts.opal.service.opal.UserService; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Qualifier("userServiceProxy") +public class UserServiceProxy implements UserServiceInterface, ProxyInterface { + + private final UserService opalUserService; + private final LegacyUserService legacyUserService; + private final DynamicConfigService dynamicConfigService; + + private UserServiceInterface getCurrentModeService() { + return isLegacyMode(dynamicConfigService) ? legacyUserService : opalUserService; + } + + @Override + public UserEntity getUser(String userId) { + return getCurrentModeService().getUser(userId); + } + + @Override + public List searchUsers(UserSearchDto criteria) { + return getCurrentModeService().searchUsers(criteria); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionControllerTest.java new file mode 100644 index 000000000..7af5cc0b7 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/ApplicationFunctionControllerTest.java @@ -0,0 +1,67 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.service.opal.ApplicationFunctionService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ApplicationFunctionControllerTest { + + @Mock + private ApplicationFunctionService applicationFunctionService; + + @InjectMocks + private ApplicationFunctionController applicationFunctionController; + + @Test + void testGetApplicationFunction_Success() { + // Arrange + ApplicationFunctionEntity entity = ApplicationFunctionEntity.builder().build(); + + when(applicationFunctionService.getApplicationFunction(any(Long.class))).thenReturn(entity); + + // Act + ResponseEntity response = applicationFunctionController + .getApplicationFunctionById(1L); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(applicationFunctionService, times(1)).getApplicationFunction(any(Long.class)); + } + + @Test + void testSearchApplicationFunctions_Success() { + // Arrange + ApplicationFunctionEntity entity = ApplicationFunctionEntity.builder().build(); + List applicationFunctionList = List.of(entity); + + when(applicationFunctionService.searchApplicationFunctions(any())).thenReturn(applicationFunctionList); + + // Act + ApplicationFunctionSearchDto searchDto = ApplicationFunctionSearchDto.builder().build(); + ResponseEntity> response = applicationFunctionController + .postApplicationFunctionsSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(applicationFunctionList, response.getBody()); + verify(applicationFunctionService, times(1)).searchApplicationFunctions(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserControllerTest.java new file mode 100644 index 000000000..25688e322 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/BusinessUnitUserControllerTest.java @@ -0,0 +1,67 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.service.opal.BusinessUnitUserService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class BusinessUnitUserControllerTest { + + @Mock + private BusinessUnitUserService businessUnitUserService; + + @InjectMocks + private BusinessUnitUserController businessUnitUserController; + + @Test + void testGetBusinessUnitUser_Success() { + // Arrange + BusinessUnitUserEntity entity = BusinessUnitUserEntity.builder().build(); + + when(businessUnitUserService.getBusinessUnitUser(anyString())).thenReturn(entity); + + // Act + ResponseEntity response = businessUnitUserController.getBusinessUnitUserById("1"); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(businessUnitUserService, times(1)).getBusinessUnitUser(anyString()); + } + + @Test + void testSearchBusinessUnitUsers_Success() { + // Arrange + BusinessUnitUserEntity entity = BusinessUnitUserEntity.builder().build(); + List businessUnitUserList = List.of(entity); + + when(businessUnitUserService.searchBusinessUnitUsers(any())).thenReturn(businessUnitUserList); + + // Act + BusinessUnitUserSearchDto searchDto = BusinessUnitUserSearchDto.builder().build(); + ResponseEntity> response = businessUnitUserController + .postBusinessUnitUsersSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(businessUnitUserList, response.getBody()); + verify(businessUnitUserService, times(1)).searchBusinessUnitUsers(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/TemplateControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/TemplateControllerTest.java new file mode 100644 index 000000000..6b046d661 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/TemplateControllerTest.java @@ -0,0 +1,65 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.service.opal.TemplateService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class TemplateControllerTest { + + @Mock + private TemplateService templateService; + + @InjectMocks + private TemplateController templateController; + + @Test + void testGetTemplate_Success() { + // Arrange + TemplateEntity entity = TemplateEntity.builder().build(); + + when(templateService.getTemplate(any(Long.class))).thenReturn(entity); + + // Act + ResponseEntity response = templateController.getTemplateById(1L); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(templateService, times(1)).getTemplate(any(Long.class)); + } + + @Test + void testSearchTemplates_Success() { + // Arrange + TemplateEntity entity = TemplateEntity.builder().build(); + List templateList = List.of(entity); + + when(templateService.searchTemplates(any())).thenReturn(templateList); + + // Act + TemplateSearchDto searchDto = TemplateSearchDto.builder().build(); + ResponseEntity> response = templateController.postTemplatesSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(templateList, response.getBody()); + verify(templateService, times(1)).searchTemplates(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/TemplateMappingControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/TemplateMappingControllerTest.java new file mode 100644 index 000000000..237262393 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/TemplateMappingControllerTest.java @@ -0,0 +1,68 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.service.opal.TemplateMappingService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class TemplateMappingControllerTest { + + @Mock + private TemplateMappingService templateMappingService; + + @InjectMocks + private TemplateMappingController templateMappingController; + + @Test + void testGetTemplateMapping_Success() { + // Arrange + TemplateMappingEntity entity = TemplateMappingEntity.builder().build(); + + when(templateMappingService.getTemplateMapping(any(MappingId.class))).thenReturn(entity); + + // Act + ResponseEntity response = templateMappingController + .getTemplateMappingById(1L, 1L); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(templateMappingService, times(1)).getTemplateMapping(any(MappingId.class)); + } + + @Test + void testSearchTemplateMappings_Success() { + // Arrange + TemplateMappingEntity entity = TemplateMappingEntity.builder().build(); + List templateMappingList = List.of(entity); + + when(templateMappingService.searchTemplateMappings(any())).thenReturn(templateMappingList); + + // Act + TemplateMappingSearchDto searchDto = TemplateMappingSearchDto.builder().build(); + ResponseEntity> response = templateMappingController + .postTemplateMappingsSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(templateMappingList, response.getBody()); + verify(templateMappingService, times(1)).searchTemplateMappings(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/UserControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/UserControllerTest.java new file mode 100644 index 000000000..2adf5b65b --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/UserControllerTest.java @@ -0,0 +1,66 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.service.opal.UserService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class UserControllerTest { + + @Mock + private UserService userService; + + @InjectMocks + private UserController userController; + + @Test + void testGetUser_Success() { + // Arrange + UserEntity entity = UserEntity.builder().build(); + + when(userService.getUser(anyString())).thenReturn(entity); + + // Act + ResponseEntity response = userController.getUserById("1"); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(userService, times(1)).getUser(anyString()); + } + + @Test + void testSearchUsers_Success() { + // Arrange + UserEntity entity = UserEntity.builder().build(); + List userList = List.of(entity); + + when(userService.searchUsers(any())).thenReturn(userList); + + // Act + UserSearchDto searchDto = UserSearchDto.builder().build(); + ResponseEntity> response = userController.postUsersSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(userList, response.getBody()); + verify(userService, times(1)).searchUsers(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/controllers/UserEntitlementControllerTest.java b/src/test/java/uk/gov/hmcts/opal/controllers/UserEntitlementControllerTest.java new file mode 100644 index 000000000..80e629fe4 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/controllers/UserEntitlementControllerTest.java @@ -0,0 +1,66 @@ +package uk.gov.hmcts.opal.controllers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.service.opal.UserEntitlementService; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class UserEntitlementControllerTest { + + @Mock + private UserEntitlementService userEntitlementService; + + @InjectMocks + private UserEntitlementController userEntitlementController; + + @Test + void testGetUserEntitlement_Success() { + // Arrange + UserEntitlementEntity entity = UserEntitlementEntity.builder().build(); + + when(userEntitlementService.getUserEntitlement(any(Long.class))).thenReturn(entity); + + // Act + ResponseEntity response = userEntitlementController.getUserEntitlementById(1L); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(entity, response.getBody()); + verify(userEntitlementService, times(1)).getUserEntitlement(any(Long.class)); + } + + @Test + void testSearchUserEntitlements_Success() { + // Arrange + UserEntitlementEntity entity = UserEntitlementEntity.builder().build(); + List userEntitlementList = List.of(entity); + + when(userEntitlementService.searchUserEntitlements(any())).thenReturn(userEntitlementList); + + // Act + UserEntitlementSearchDto searchDto = UserEntitlementSearchDto.builder().build(); + ResponseEntity> response = userEntitlementController + .postUserEntitlementsSearch(searchDto); + + // Assert + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertEquals(userEntitlementList, response.getBody()); + verify(userEntitlementService, times(1)).searchUserEntitlements(any()); + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionServiceTest.java new file mode 100644 index 000000000..4d540d4eb --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyApplicationFunctionServiceTest.java @@ -0,0 +1,61 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyApplicationFunctionServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyApplicationFunctionService legacyApplicationFunctionService; + + @Test + void testGetApplicationFunction() { + // Arrange + + ApplicationFunctionEntity applicationFunctionEntity = ApplicationFunctionEntity.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyApplicationFunctionService.getApplicationFunction(1) + ); + + // Assert + assertNotNull(legacyApplicationFunctionService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchApplicationFunctions() { + // Arrange + ApplicationFunctionSearchDto criteria = ApplicationFunctionSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyApplicationFunctionService.searchApplicationFunctions(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserServiceTest.java new file mode 100644 index 000000000..2257d5a94 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyBusinessUnitUserServiceTest.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyBusinessUnitUserServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyBusinessUnitUserService legacyBusinessUnitUserService; + + @Test + void testGetBusinessUnitUser() { + // Arrange + + BusinessUnitUserEntity businessUnitUserEntity = BusinessUnitUserEntity.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyBusinessUnitUserService.getBusinessUnitUser("1") + ); + + // Assert + assertNotNull(legacyBusinessUnitUserService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchBusinessUnitUsers() { + // Arrange + BusinessUnitUserSearchDto criteria = BusinessUnitUserSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyBusinessUnitUserService.searchBusinessUnitUsers(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingServiceTest.java new file mode 100644 index 000000000..4a7d2fbe6 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateMappingServiceTest.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyTemplateMappingServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyTemplateMappingService legacyTemplateMappingService; + + @Test + void testGetTemplateMapping() { + // Arrange + MappingId key = new MappingId(1L, 1L); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyTemplateMappingService.getTemplateMapping(key) + ); + + // Assert + assertNotNull(legacyTemplateMappingService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchTemplateMappings() { + // Arrange + TemplateMappingSearchDto criteria = TemplateMappingSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyTemplateMappingService.searchTemplateMappings(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateServiceTest.java new file mode 100644 index 000000000..0d99efb5e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyTemplateServiceTest.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyTemplateServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyTemplateService legacyTemplateService; + + @Test + void testGetTemplate() { + // Arrange + + TemplateEntity templateEntity = TemplateEntity.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyTemplateService.getTemplate(1) + ); + + // Assert + assertNotNull(legacyTemplateService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchTemplates() { + // Arrange + TemplateSearchDto criteria = TemplateSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyTemplateService.searchTemplates(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementServiceTest.java new file mode 100644 index 000000000..7a23fe9b8 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserEntitlementServiceTest.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyUserEntitlementServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyUserEntitlementService legacyUserEntitlementService; + + @Test + void testGetUserEntitlement() { + // Arrange + + UserEntitlementEntity userEntitlementEntity = UserEntitlementEntity.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyUserEntitlementService.getUserEntitlement(1) + ); + + // Assert + assertNotNull(legacyUserEntitlementService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchUserEntitlements() { + // Arrange + UserEntitlementSearchDto criteria = UserEntitlementSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyUserEntitlementService.searchUserEntitlements(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserServiceTest.java new file mode 100644 index 000000000..e0eee16e4 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/legacy/LegacyUserServiceTest.java @@ -0,0 +1,60 @@ +package uk.gov.hmcts.opal.service.legacy; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.slf4j.Logger; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(MockitoExtension.class) +class LegacyUserServiceTest extends LegacyTestsBase { + + @Mock + private Logger log; + + @InjectMocks + private LegacyUserService legacyUserService; + + @Test + void testGetUser() { + // Arrange + + UserEntity userEntity = UserEntity.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, + () -> legacyUserService.getUser("1") + ); + + // Assert + assertNotNull(legacyUserService.getLog()); + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + + @Test + void testSearchUsers() { + // Arrange + UserSearchDto criteria = UserSearchDto.builder().build(); + + // Act + LegacyGatewayResponseException exception = assertThrows( + LegacyGatewayResponseException.class, () -> legacyUserService.searchUsers(criteria) + ); + + // Assert + assertNotNull(exception); + assertEquals(NOT_YET_IMPLEMENTED, exception.getMessage()); + + } + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionServiceTest.java new file mode 100644 index 000000000..0eedaa815 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/ApplicationFunctionServiceTest.java @@ -0,0 +1,74 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.repository.ApplicationFunctionRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class ApplicationFunctionServiceTest { + + @Mock + private ApplicationFunctionRepository applicationFunctionRepository; + + @InjectMocks + private ApplicationFunctionService applicationFunctionService; + + @Test + void testGetApplicationFunction() { + // Arrange + + ApplicationFunctionEntity applicationFunctionEntity = ApplicationFunctionEntity.builder().build(); + when(applicationFunctionRepository.getReferenceById(any())).thenReturn(applicationFunctionEntity); + + // Act + ApplicationFunctionEntity result = applicationFunctionService.getApplicationFunction(1); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchApplicationFunctions() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + ApplicationFunctionEntity applicationFunctionEntity = ApplicationFunctionEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(applicationFunctionEntity), + Pageable.unpaged(), 999L); + when(applicationFunctionRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = applicationFunctionService + .searchApplicationFunctions(ApplicationFunctionSearchDto.builder().build()); + + // Assert + assertEquals(List.of(applicationFunctionEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserServiceTest.java new file mode 100644 index 000000000..65e916b90 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/BusinessUnitUserServiceTest.java @@ -0,0 +1,74 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.repository.BusinessUnitUserRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class BusinessUnitUserServiceTest { + + @Mock + private BusinessUnitUserRepository businessUnitUserRepository; + + @InjectMocks + private BusinessUnitUserService businessUnitUserService; + + @Test + void testGetBusinessUnitUser() { + // Arrange + + BusinessUnitUserEntity businessUnitUserEntity = BusinessUnitUserEntity.builder().build(); + when(businessUnitUserRepository.getReferenceById(any())).thenReturn(businessUnitUserEntity); + + // Act + BusinessUnitUserEntity result = businessUnitUserService.getBusinessUnitUser("1"); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchBusinessUnitUsers() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + BusinessUnitUserEntity businessUnitUserEntity = BusinessUnitUserEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(businessUnitUserEntity), + Pageable.unpaged(), 999L); + when(businessUnitUserRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = businessUnitUserService + .searchBusinessUnitUsers(BusinessUnitUserSearchDto.builder().build()); + + // Assert + assertEquals(List.of(businessUnitUserEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateMappingServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateMappingServiceTest.java new file mode 100644 index 000000000..6aaa274d9 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateMappingServiceTest.java @@ -0,0 +1,76 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.repository.TemplateMappingRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class TemplateMappingServiceTest { + + @Mock + private TemplateMappingRepository templateMappingRepository; + + @InjectMocks + private TemplateMappingService templateMappingService; + + @Test + void testGetTemplateMapping() { + // Arrange + + TemplateMappingEntity templateMappingEntity = TemplateMappingEntity.builder().build(); + when(templateMappingRepository.getReferenceById(any())).thenReturn(templateMappingEntity); + + // Act + TemplateMappingEntity result = templateMappingService.getTemplateMapping( + new MappingId(1L, 1L)); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchTemplateMappings() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + TemplateMappingEntity templateMappingEntity = TemplateMappingEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(templateMappingEntity), + Pageable.unpaged(), 999L); + when(templateMappingRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = templateMappingService + .searchTemplateMappings(TemplateMappingSearchDto.builder().build()); + + // Assert + assertEquals(List.of(templateMappingEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateServiceTest.java new file mode 100644 index 000000000..57b81a6f2 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/TemplateServiceTest.java @@ -0,0 +1,72 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.repository.TemplateRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class TemplateServiceTest { + + @Mock + private TemplateRepository templateRepository; + + @InjectMocks + private TemplateService templateService; + + @Test + void testGetTemplate() { + // Arrange + + TemplateEntity templateEntity = TemplateEntity.builder().build(); + when(templateRepository.getReferenceById(any())).thenReturn(templateEntity); + + // Act + TemplateEntity result = templateService.getTemplate(1); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchTemplates() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + TemplateEntity templateEntity = TemplateEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(templateEntity), Pageable.unpaged(), 999L); + when(templateRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = templateService.searchTemplates(TemplateSearchDto.builder().build()); + + // Assert + assertEquals(List.of(templateEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/UserEntitlementServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/UserEntitlementServiceTest.java new file mode 100644 index 000000000..2175c7804 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/UserEntitlementServiceTest.java @@ -0,0 +1,74 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.repository.UserEntitlementRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class UserEntitlementServiceTest { + + @Mock + private UserEntitlementRepository userEntitlementRepository; + + @InjectMocks + private UserEntitlementService userEntitlementService; + + @Test + void testGetUserEntitlement() { + // Arrange + + UserEntitlementEntity userEntitlementEntity = UserEntitlementEntity.builder().build(); + when(userEntitlementRepository.getReferenceById(any())).thenReturn(userEntitlementEntity); + + // Act + UserEntitlementEntity result = userEntitlementService.getUserEntitlement(1); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchUserEntitlements() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + UserEntitlementEntity userEntitlementEntity = UserEntitlementEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(userEntitlementEntity), + Pageable.unpaged(), 999L); + when(userEntitlementRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = userEntitlementService + .searchUserEntitlements(UserEntitlementSearchDto.builder().build()); + + // Assert + assertEquals(List.of(userEntitlementEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/opal/UserServiceTest.java b/src/test/java/uk/gov/hmcts/opal/service/opal/UserServiceTest.java new file mode 100644 index 000000000..b5fbd6090 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/opal/UserServiceTest.java @@ -0,0 +1,72 @@ +package uk.gov.hmcts.opal.service.opal; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.repository.query.FluentQuery; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.repository.UserRepository; + +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class UserServiceTest { + + @Mock + private UserRepository userRepository; + + @InjectMocks + private UserService userService; + + @Test + void testGetUser() { + // Arrange + + UserEntity userEntity = UserEntity.builder().build(); + when(userRepository.getReferenceById(any())).thenReturn(userEntity); + + // Act + UserEntity result = userService.getUser("1"); + + // Assert + assertNotNull(result); + + } + + @SuppressWarnings("unchecked") + @Test + void testSearchUsers() { + // Arrange + FluentQuery.FetchableFluentQuery ffq = Mockito.mock(FluentQuery.FetchableFluentQuery.class); + + UserEntity userEntity = UserEntity.builder().build(); + Page mockPage = new PageImpl<>(List.of(userEntity), Pageable.unpaged(), 999L); + when(userRepository.findBy(any(Specification.class), any())).thenAnswer(iom -> { + iom.getArgument(1, Function.class).apply(ffq); + return mockPage; + }); + + // Act + List result = userService.searchUsers(UserSearchDto.builder().build()); + + // Assert + assertEquals(List.of(userEntity), result); + + } + + +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/AccountTransferServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/AccountTransferServiceProxyTest.java index 522448118..0d6d2f350 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/AccountTransferServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/AccountTransferServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.AccountTransferSearchDto; import uk.gov.hmcts.opal.entity.AccountTransferEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.AccountTransferServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyAccountTransferService; import uk.gov.hmcts.opal.service.opal.AccountTransferService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class AccountTransferServiceProxyTest { +class AccountTransferServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private AccountTransferService opalAccountTransferService; + private AccountTransferService opalService; @Mock - private LegacyAccountTransferService legacyAccountTransferService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyAccountTransferService legacyService; @InjectMocks private AccountTransferServiceProxy accountTransferServiceProxy; @@ -48,63 +44,56 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalAccountTransferServiceWhenModeIsNotLegacy() { - // Given: a AccountTransferEntity and the app mode is set to "opal" + void testMode(AccountTransferServiceInterface targetService, AccountTransferServiceInterface otherService) { + testGetAccountTransfer(targetService, otherService); + testSearchAccountTransfers(targetService, otherService); + } + + void testGetAccountTransfer(AccountTransferServiceInterface targetService, + AccountTransferServiceInterface otherService) { + // Given: an AccountTransferEntity is returned from the target service AccountTransferEntity entity = AccountTransferEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalAccountTransferService.getAccountTransfer(anyLong())).thenReturn(entity); + when(targetService.getAccountTransfer(anyLong())).thenReturn(entity); - // When: saveAccountTransfer is called on the proxy + // When: getAccountTransfer is called on the proxy AccountTransferEntity accountTransferResult = accountTransferServiceProxy.getAccountTransfer(1); - // Then: opalAccountTransferService should be used, and the returned accountTransfer should be as expected - verify(opalAccountTransferService).getAccountTransfer(1); - verifyNoInteractions(legacyAccountTransferService); + // Then: target service should be used, and the returned accountTransfer should be as expected + verify(targetService).getAccountTransfer(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, accountTransferResult); + } - // Given: a accountTransfers list result and the app mode is set to "opal" + void testSearchAccountTransfers(AccountTransferServiceInterface targetService, + AccountTransferServiceInterface otherService) { + // Given: an accountTransfers list result is returned from the target service + AccountTransferEntity entity = AccountTransferEntity.builder().build(); List accountTransfersList = List.of(entity); - when(opalAccountTransferService.searchAccountTransfers(any())).thenReturn(accountTransfersList); + when(targetService.searchAccountTransfers(any())).thenReturn(accountTransfersList); // When: searchAccountTransfers is called on the proxy AccountTransferSearchDto criteria = AccountTransferSearchDto.builder().build(); List listResult = accountTransferServiceProxy.searchAccountTransfers(criteria); - // Then: opalAccountTransferService should be used, and the returned list should be as expected - verify(opalAccountTransferService).searchAccountTransfers(criteria); - verifyNoInteractions(legacyAccountTransferService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchAccountTransfers(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(accountTransfersList, listResult); } @Test - void shouldUseLegacyAccountTransferServiceWhenModeIsLegacy() { - // Given: a AccountTransferEntity and the app mode is set to "legacy" - AccountTransferEntity entity = AccountTransferEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyAccountTransferService.getAccountTransfer(anyLong())).thenReturn(entity); - - // When: saveAccountTransfer is called on the proxy - AccountTransferEntity result = accountTransferServiceProxy.getAccountTransfer(1); - - // Then: legacyAccountTransferService should be used, and the returned accountTransfer should be as expected - verify(legacyAccountTransferService).getAccountTransfer(1); - verifyNoInteractions(opalAccountTransferService); - Assertions.assertEquals(entity, result); - - // Given: a accountTransfers list result and the app mode is set to "legacy" - List accountTransfersList = List.of(entity); - when(legacyAccountTransferService.searchAccountTransfers(any())).thenReturn(accountTransfersList); - - // When: searchAccountTransfers is called on the proxy - AccountTransferSearchDto criteria = AccountTransferSearchDto.builder().build(); - List listResult = accountTransferServiceProxy.searchAccountTransfers(criteria); + void shouldUseOpalAccountTransferServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalAccountTransferService should be used, and the returned list should be as expected - verify(legacyAccountTransferService).searchAccountTransfers(criteria); - verifyNoInteractions(opalAccountTransferService); - Assertions.assertEquals(accountTransfersList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyAccountTransferServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxyTest.java new file mode 100644 index 000000000..a2e649028 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/ApplicationFunctionServiceProxyTest.java @@ -0,0 +1,101 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.ApplicationFunctionSearchDto; +import uk.gov.hmcts.opal.entity.ApplicationFunctionEntity; +import uk.gov.hmcts.opal.service.ApplicationFunctionServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyApplicationFunctionService; +import uk.gov.hmcts.opal.service.opal.ApplicationFunctionService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class ApplicationFunctionServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private ApplicationFunctionService opalService; + + @Mock + private LegacyApplicationFunctionService legacyService; + + @InjectMocks + private ApplicationFunctionServiceProxy applicationFunctionServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(ApplicationFunctionServiceInterface targetService, ApplicationFunctionServiceInterface otherService) { + testGetApplicationFunction(targetService, otherService); + testSearchApplicationFunctions(targetService, otherService); + } + + void testGetApplicationFunction(ApplicationFunctionServiceInterface targetService, + ApplicationFunctionServiceInterface otherService) { + // Given: a ApplicationFunctionEntity is returned from the target service + ApplicationFunctionEntity entity = ApplicationFunctionEntity.builder().build(); + when(targetService.getApplicationFunction(anyLong())).thenReturn(entity); + + // When: getApplicationFunction is called on the proxy + ApplicationFunctionEntity applicationFunctionResult = applicationFunctionServiceProxy + .getApplicationFunction(1); + + // Then: target service should be used, and the returned applicationFunction should be as expected + verify(targetService).getApplicationFunction(1); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, applicationFunctionResult); + } + + void testSearchApplicationFunctions(ApplicationFunctionServiceInterface targetService, + ApplicationFunctionServiceInterface otherService) { + // Given: a applicationFunctions list result is returned from the target service + ApplicationFunctionEntity entity = ApplicationFunctionEntity.builder().build(); + List applicationFunctionsList = List.of(entity); + when(targetService.searchApplicationFunctions(any())).thenReturn(applicationFunctionsList); + + // When: searchApplicationFunctions is called on the proxy + ApplicationFunctionSearchDto criteria = ApplicationFunctionSearchDto.builder().build(); + List listResult = applicationFunctionServiceProxy + .searchApplicationFunctions(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchApplicationFunctions(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(applicationFunctionsList, listResult); + } + + @Test + void shouldUseOpalApplicationFunctionServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyApplicationFunctionServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitServiceProxyTest.java index cfb4257e7..2a837b2b4 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; import uk.gov.hmcts.opal.entity.BusinessUnitEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.BusinessUnitServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyBusinessUnitService; import uk.gov.hmcts.opal.service.opal.BusinessUnitService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class BusinessUnitServiceProxyTest { +class BusinessUnitServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private BusinessUnitService opalBusinessUnitService; + private BusinessUnitService opalService; @Mock - private LegacyBusinessUnitService legacyBusinessUnitService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyBusinessUnitService legacyService; @InjectMocks private BusinessUnitServiceProxy businessUnitServiceProxy; @@ -48,63 +44,55 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalBusinessUnitServiceWhenModeIsNotLegacy() { - // Given: a BusinessUnitEntity and the app mode is set to "opal" + void testMode(BusinessUnitServiceInterface targetService, BusinessUnitServiceInterface otherService) { + testGetBusinessUnit(targetService, otherService); + testSearchBusinessUnits(targetService, otherService); + } + + void testGetBusinessUnit(BusinessUnitServiceInterface targetService, BusinessUnitServiceInterface otherService) { + // Given: a BusinessUnitEntity is returned from the target service BusinessUnitEntity entity = BusinessUnitEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalBusinessUnitService.getBusinessUnit(anyLong())).thenReturn(entity); + when(targetService.getBusinessUnit(anyLong())).thenReturn(entity); - // When: saveBusinessUnit is called on the proxy + // When: getBusinessUnit is called on the proxy BusinessUnitEntity businessUnitResult = businessUnitServiceProxy.getBusinessUnit(1); - // Then: opalBusinessUnitService should be used, and the returned businessUnit should be as expected - verify(opalBusinessUnitService).getBusinessUnit(1); - verifyNoInteractions(legacyBusinessUnitService); + // Then: target service should be used, and the returned businessUnit should be as expected + verify(targetService).getBusinessUnit(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, businessUnitResult); + } - // Given: a businessUnits list result and the app mode is set to "opal" + void testSearchBusinessUnits(BusinessUnitServiceInterface targetService, + BusinessUnitServiceInterface otherService) { + // Given: a businessUnits list result is returned from the target service + BusinessUnitEntity entity = BusinessUnitEntity.builder().build(); List businessUnitsList = List.of(entity); - when(opalBusinessUnitService.searchBusinessUnits(any())).thenReturn(businessUnitsList); + when(targetService.searchBusinessUnits(any())).thenReturn(businessUnitsList); // When: searchBusinessUnits is called on the proxy BusinessUnitSearchDto criteria = BusinessUnitSearchDto.builder().build(); List listResult = businessUnitServiceProxy.searchBusinessUnits(criteria); - // Then: opalBusinessUnitService should be used, and the returned list should be as expected - verify(opalBusinessUnitService).searchBusinessUnits(criteria); - verifyNoInteractions(legacyBusinessUnitService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchBusinessUnits(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(businessUnitsList, listResult); } @Test - void shouldUseLegacyBusinessUnitServiceWhenModeIsLegacy() { - // Given: a BusinessUnitEntity and the app mode is set to "legacy" - BusinessUnitEntity entity = BusinessUnitEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyBusinessUnitService.getBusinessUnit(anyLong())).thenReturn(entity); - - // When: saveBusinessUnit is called on the proxy - BusinessUnitEntity result = businessUnitServiceProxy.getBusinessUnit(1); - - // Then: legacyBusinessUnitService should be used, and the returned businessUnit should be as expected - verify(legacyBusinessUnitService).getBusinessUnit(1); - verifyNoInteractions(opalBusinessUnitService); - Assertions.assertEquals(entity, result); - - // Given: a businessUnits list result and the app mode is set to "legacy" - List businessUnitsList = List.of(entity); - when(legacyBusinessUnitService.searchBusinessUnits(any())).thenReturn(businessUnitsList); - - // When: searchBusinessUnits is called on the proxy - BusinessUnitSearchDto criteria = BusinessUnitSearchDto.builder().build(); - List listResult = businessUnitServiceProxy.searchBusinessUnits(criteria); + void shouldUseOpalBusinessUnitServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalBusinessUnitService should be used, and the returned list should be as expected - verify(legacyBusinessUnitService).searchBusinessUnits(criteria); - verifyNoInteractions(opalBusinessUnitService); - Assertions.assertEquals(businessUnitsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyBusinessUnitServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxyTest.java new file mode 100644 index 000000000..b6e0b4aa8 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/BusinessUnitUserServiceProxyTest.java @@ -0,0 +1,99 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.BusinessUnitUserSearchDto; +import uk.gov.hmcts.opal.entity.BusinessUnitUserEntity; +import uk.gov.hmcts.opal.service.BusinessUnitUserServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyBusinessUnitUserService; +import uk.gov.hmcts.opal.service.opal.BusinessUnitUserService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class BusinessUnitUserServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private BusinessUnitUserService opalService; + + @Mock + private LegacyBusinessUnitUserService legacyService; + + @InjectMocks + private BusinessUnitUserServiceProxy businessUnitUserServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(BusinessUnitUserServiceInterface targetService, BusinessUnitUserServiceInterface otherService) { + testGetBusinessUnitUser(targetService, otherService); + testSearchBusinessUnitUsers(targetService, otherService); + } + + void testGetBusinessUnitUser(BusinessUnitUserServiceInterface targetService, + BusinessUnitUserServiceInterface otherService) { + // Given: a BusinessUnitUserEntity is returned from the target service + BusinessUnitUserEntity entity = BusinessUnitUserEntity.builder().build(); + when(targetService.getBusinessUnitUser(anyString())).thenReturn(entity); + + // When: getBusinessUnitUser is called on the proxy + BusinessUnitUserEntity businessUnitUserResult = businessUnitUserServiceProxy.getBusinessUnitUser("1"); + + // Then: target service should be used, and the returned businessUnitUser should be as expected + verify(targetService).getBusinessUnitUser("1"); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, businessUnitUserResult); + } + + void testSearchBusinessUnitUsers(BusinessUnitUserServiceInterface targetService, + BusinessUnitUserServiceInterface otherService) { + // Given: a businessUnitUsers list result is returned from the target service + BusinessUnitUserEntity entity = BusinessUnitUserEntity.builder().build(); + List businessUnitUsersList = List.of(entity); + when(targetService.searchBusinessUnitUsers(any())).thenReturn(businessUnitUsersList); + + // When: searchBusinessUnitUsers is called on the proxy + BusinessUnitUserSearchDto criteria = BusinessUnitUserSearchDto.builder().build(); + List listResult = businessUnitUserServiceProxy.searchBusinessUnitUsers(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchBusinessUnitUsers(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(businessUnitUsersList, listResult); + } + + @Test + void shouldUseOpalBusinessUnitUserServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyBusinessUnitUserServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/CommittalWarrantProgressServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/CommittalWarrantProgressServiceProxyTest.java index d2d55e7c5..dd1e2671b 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/CommittalWarrantProgressServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/CommittalWarrantProgressServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.CommittalWarrantProgressSearchDto; import uk.gov.hmcts.opal.entity.CommittalWarrantProgressEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.CommittalWarrantProgressServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyCommittalWarrantProgressService; import uk.gov.hmcts.opal.service.opal.CommittalWarrantProgressService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class CommittalWarrantProgressServiceProxyTest { +class CommittalWarrantProgressServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private CommittalWarrantProgressService opalCommittalWarrantProgressService; + private CommittalWarrantProgressService opalService; @Mock - private LegacyCommittalWarrantProgressService legacyCommittalWarrantProgressService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyCommittalWarrantProgressService legacyService; @InjectMocks private CommittalWarrantProgressServiceProxy committalWarrantProgressServiceProxy; @@ -48,69 +44,59 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalCommittalWarrantProgressServiceWhenModeIsNotLegacy() { - // Given: a CommittalWarrantProgressEntity and the app mode is set to "opal" + void testMode(CommittalWarrantProgressServiceInterface targetService, + CommittalWarrantProgressServiceInterface otherService) { + testGetCommittalWarrantProgress(targetService, otherService); + testSearchCommittalWarrantProgresss(targetService, otherService); + } + + void testGetCommittalWarrantProgress(CommittalWarrantProgressServiceInterface targetService, + CommittalWarrantProgressServiceInterface otherService) { + // Given: a CommittalWarrantProgressEntity is returned from the target service CommittalWarrantProgressEntity entity = CommittalWarrantProgressEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalCommittalWarrantProgressService.getCommittalWarrantProgress(anyLong())).thenReturn(entity); + when(targetService.getCommittalWarrantProgress(anyLong())).thenReturn(entity); - // When: saveCommittalWarrantProgress is called on the proxy + // When: getCommittalWarrantProgress is called on the proxy CommittalWarrantProgressEntity committalWarrantProgressResult = committalWarrantProgressServiceProxy .getCommittalWarrantProgress(1); - // Then: opalCommittalWarrantProgressService should be used - verify(opalCommittalWarrantProgressService).getCommittalWarrantProgress(1); - verifyNoInteractions(legacyCommittalWarrantProgressService); + // Then: target service should be used, and the returned committalWarrantProgress should be as expected + verify(targetService).getCommittalWarrantProgress(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, committalWarrantProgressResult); + } - // Given: a committalWarrantProgresss list result and the app mode is set to "opal" + void testSearchCommittalWarrantProgresss(CommittalWarrantProgressServiceInterface targetService, + CommittalWarrantProgressServiceInterface otherService) { + // Given: a committalWarrantProgresss list result is returned from the target service + CommittalWarrantProgressEntity entity = CommittalWarrantProgressEntity.builder().build(); List committalWarrantProgresssList = List.of(entity); - when(opalCommittalWarrantProgressService.searchCommittalWarrantProgresss(any())) - .thenReturn(committalWarrantProgresssList); + when(targetService.searchCommittalWarrantProgresss(any())).thenReturn(committalWarrantProgresssList); // When: searchCommittalWarrantProgresss is called on the proxy CommittalWarrantProgressSearchDto criteria = CommittalWarrantProgressSearchDto.builder().build(); List listResult = committalWarrantProgressServiceProxy .searchCommittalWarrantProgresss(criteria); - // Then: opalCommittalWarrantProgressService should be used, and the returned list should be as expected - verify(opalCommittalWarrantProgressService).searchCommittalWarrantProgresss(criteria); - verifyNoInteractions(legacyCommittalWarrantProgressService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchCommittalWarrantProgresss(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(committalWarrantProgresssList, listResult); } @Test - void shouldUseLegacyCommittalWarrantProgressServiceWhenModeIsLegacy() { - // Given: a CommittalWarrantProgressEntity and the app mode is set to "legacy" - CommittalWarrantProgressEntity entity = CommittalWarrantProgressEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyCommittalWarrantProgressService.getCommittalWarrantProgress(anyLong())).thenReturn(entity); - - // When: saveCommittalWarrantProgress is called on the proxy - CommittalWarrantProgressEntity result = committalWarrantProgressServiceProxy - .getCommittalWarrantProgress(1); - - // Then: legacyCommittalWarrantProgressService should be used - verify(legacyCommittalWarrantProgressService).getCommittalWarrantProgress(1); - verifyNoInteractions(opalCommittalWarrantProgressService); - Assertions.assertEquals(entity, result); - - // Given: a committalWarrantProgresss list result and the app mode is set to "legacy" - List committalWarrantProgresssList = List.of(entity); - when(legacyCommittalWarrantProgressService.searchCommittalWarrantProgresss(any())) - .thenReturn(committalWarrantProgresssList); - - // When: searchCommittalWarrantProgresss is called on the proxy - CommittalWarrantProgressSearchDto criteria = CommittalWarrantProgressSearchDto.builder().build(); - List listResult = committalWarrantProgressServiceProxy - .searchCommittalWarrantProgresss(criteria); + void shouldUseOpalCommittalWarrantProgressServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalCommittalWarrantProgressService should be used, and the returned list should be as expected - verify(legacyCommittalWarrantProgressService).searchCommittalWarrantProgresss(criteria); - verifyNoInteractions(opalCommittalWarrantProgressService); - Assertions.assertEquals(committalWarrantProgresssList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyCommittalWarrantProgressServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/CourtServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/CourtServiceProxyTest.java index 3395042dc..1c227c47a 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/CourtServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/CourtServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.CourtSearchDto; import uk.gov.hmcts.opal.entity.CourtEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.CourtServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyCourtService; import uk.gov.hmcts.opal.service.opal.CourtService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class CourtServiceProxyTest { +class CourtServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private CourtService opalCourtService; + private CourtService opalService; @Mock - private LegacyCourtService legacyCourtService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyCourtService legacyService; @InjectMocks private CourtServiceProxy courtServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalCourtServiceWhenModeIsNotLegacy() { - // Given: a CourtEntity and the app mode is set to "opal" + void testMode(CourtServiceInterface targetService, CourtServiceInterface otherService) { + testGetCourt(targetService, otherService); + testSearchCourts(targetService, otherService); + } + + void testGetCourt(CourtServiceInterface targetService, CourtServiceInterface otherService) { + // Given: a CourtEntity is returned from the target service CourtEntity entity = CourtEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalCourtService.getCourt(anyLong())).thenReturn(entity); + when(targetService.getCourt(anyLong())).thenReturn(entity); - // When: saveCourt is called on the proxy + // When: getCourt is called on the proxy CourtEntity courtResult = courtServiceProxy.getCourt(1); - // Then: opalCourtService should be used, and the returned court should be as expected - verify(opalCourtService).getCourt(1); - verifyNoInteractions(legacyCourtService); + // Then: target service should be used, and the returned court should be as expected + verify(targetService).getCourt(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, courtResult); + } - // Given: a courts list result and the app mode is set to "opal" + void testSearchCourts(CourtServiceInterface targetService, CourtServiceInterface otherService) { + // Given: a courts list result is returned from the target service + CourtEntity entity = CourtEntity.builder().build(); List courtsList = List.of(entity); - when(opalCourtService.searchCourts(any())).thenReturn(courtsList); + when(targetService.searchCourts(any())).thenReturn(courtsList); // When: searchCourts is called on the proxy CourtSearchDto criteria = CourtSearchDto.builder().build(); List listResult = courtServiceProxy.searchCourts(criteria); - // Then: opalCourtService should be used, and the returned list should be as expected - verify(opalCourtService).searchCourts(criteria); - verifyNoInteractions(legacyCourtService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchCourts(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(courtsList, listResult); } @Test - void shouldUseLegacyCourtServiceWhenModeIsLegacy() { - // Given: a CourtEntity and the app mode is set to "legacy" - CourtEntity entity = CourtEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyCourtService.getCourt(anyLong())).thenReturn(entity); - - // When: saveCourt is called on the proxy - CourtEntity result = courtServiceProxy.getCourt(1); - - // Then: legacyCourtService should be used, and the returned court should be as expected - verify(legacyCourtService).getCourt(1); - verifyNoInteractions(opalCourtService); - Assertions.assertEquals(entity, result); - - // Given: a courts list result and the app mode is set to "legacy" - List courtsList = List.of(entity); - when(legacyCourtService.searchCourts(any())).thenReturn(courtsList); - - // When: searchCourts is called on the proxy - CourtSearchDto criteria = CourtSearchDto.builder().build(); - List listResult = courtServiceProxy.searchCourts(criteria); + void shouldUseOpalCourtServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalCourtService should be used, and the returned list should be as expected - verify(legacyCourtService).searchCourts(criteria); - verifyNoInteractions(opalCourtService); - Assertions.assertEquals(courtsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyCourtServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/DebtorDetailServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/DebtorDetailServiceProxyTest.java index 7c7fd4f3e..ff835fac6 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/DebtorDetailServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/DebtorDetailServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.DebtorDetailSearchDto; import uk.gov.hmcts.opal.entity.DebtorDetailEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.DebtorDetailServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyDebtorDetailService; import uk.gov.hmcts.opal.service.opal.DebtorDetailService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class DebtorDetailServiceProxyTest { +class DebtorDetailServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private DebtorDetailService opalDebtorDetailService; + private DebtorDetailService opalService; @Mock - private LegacyDebtorDetailService legacyDebtorDetailService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyDebtorDetailService legacyService; @InjectMocks private DebtorDetailServiceProxy debtorDetailServiceProxy; @@ -48,63 +44,55 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalDebtorDetailServiceWhenModeIsNotLegacy() { - // Given: a DebtorDetailEntity and the app mode is set to "opal" + void testMode(DebtorDetailServiceInterface targetService, DebtorDetailServiceInterface otherService) { + testGetDebtorDetail(targetService, otherService); + testSearchDebtorDetails(targetService, otherService); + } + + void testGetDebtorDetail(DebtorDetailServiceInterface targetService, DebtorDetailServiceInterface otherService) { + // Given: a DebtorDetailEntity is returned from the target service DebtorDetailEntity entity = DebtorDetailEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalDebtorDetailService.getDebtorDetail(anyLong())).thenReturn(entity); + when(targetService.getDebtorDetail(anyLong())).thenReturn(entity); - // When: saveDebtorDetail is called on the proxy + // When: getDebtorDetail is called on the proxy DebtorDetailEntity debtorDetailResult = debtorDetailServiceProxy.getDebtorDetail(1); - // Then: opalDebtorDetailService should be used, and the returned debtorDetail should be as expected - verify(opalDebtorDetailService).getDebtorDetail(1); - verifyNoInteractions(legacyDebtorDetailService); + // Then: target service should be used, and the returned debtorDetail should be as expected + verify(targetService).getDebtorDetail(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, debtorDetailResult); + } - // Given: a debtorDetails list result and the app mode is set to "opal" + void testSearchDebtorDetails(DebtorDetailServiceInterface targetService, + DebtorDetailServiceInterface otherService) { + // Given: a debtorDetails list result is returned from the target service + DebtorDetailEntity entity = DebtorDetailEntity.builder().build(); List debtorDetailsList = List.of(entity); - when(opalDebtorDetailService.searchDebtorDetails(any())).thenReturn(debtorDetailsList); + when(targetService.searchDebtorDetails(any())).thenReturn(debtorDetailsList); // When: searchDebtorDetails is called on the proxy DebtorDetailSearchDto criteria = DebtorDetailSearchDto.builder().build(); List listResult = debtorDetailServiceProxy.searchDebtorDetails(criteria); - // Then: opalDebtorDetailService should be used, and the returned list should be as expected - verify(opalDebtorDetailService).searchDebtorDetails(criteria); - verifyNoInteractions(legacyDebtorDetailService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchDebtorDetails(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(debtorDetailsList, listResult); } @Test - void shouldUseLegacyDebtorDetailServiceWhenModeIsLegacy() { - // Given: a DebtorDetailEntity and the app mode is set to "legacy" - DebtorDetailEntity entity = DebtorDetailEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyDebtorDetailService.getDebtorDetail(anyLong())).thenReturn(entity); - - // When: saveDebtorDetail is called on the proxy - DebtorDetailEntity result = debtorDetailServiceProxy.getDebtorDetail(1); - - // Then: legacyDebtorDetailService should be used, and the returned debtorDetail should be as expected - verify(legacyDebtorDetailService).getDebtorDetail(1); - verifyNoInteractions(opalDebtorDetailService); - Assertions.assertEquals(entity, result); - - // Given: a debtorDetails list result and the app mode is set to "legacy" - List debtorDetailsList = List.of(entity); - when(legacyDebtorDetailService.searchDebtorDetails(any())).thenReturn(debtorDetailsList); - - // When: searchDebtorDetails is called on the proxy - DebtorDetailSearchDto criteria = DebtorDetailSearchDto.builder().build(); - List listResult = debtorDetailServiceProxy.searchDebtorDetails(criteria); + void shouldUseOpalDebtorDetailServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalDebtorDetailService should be used, and the returned list should be as expected - verify(legacyDebtorDetailService).searchDebtorDetails(criteria); - verifyNoInteractions(opalDebtorDetailService); - Assertions.assertEquals(debtorDetailsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyDebtorDetailServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/DefendantAccountServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/DefendantAccountServiceProxyTest.java index 92d69312c..9d3e007b2 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/DefendantAccountServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/DefendantAccountServiceProxyTest.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.opal.service.proxy; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -10,31 +11,28 @@ import uk.gov.hmcts.opal.dto.AccountEnquiryDto; import uk.gov.hmcts.opal.dto.search.AccountSearchDto; import uk.gov.hmcts.opal.dto.search.AccountSearchResultsDto; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.entity.DefendantAccountEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.DefendantAccountServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyDefendantAccountService; import uk.gov.hmcts.opal.service.opal.DefendantAccountService; + import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -import static org.junit.jupiter.api.Assertions.assertEquals; -class DefendantAccountServiceProxyTest { +class DefendantAccountServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private DefendantAccountService opalDefendantAccountService; - - @Mock - private LegacyDefendantAccountService legacyDefendantAccountService; + private DefendantAccountService opalService; @Mock - private DynamicConfigService dynamicConfigService; + private LegacyDefendantAccountService legacyService; @InjectMocks private DefendantAccountServiceProxy defendantAccountServiceProxy; @@ -49,118 +47,89 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalDefendantAccountServiceWhenModeIsNotLegacy() { - // Given: a AccountSearchDto and the app mode is set to "opal" - AccountSearchDto searchDto = AccountSearchDto.builder().build(); - AccountSearchResultsDto resultsDto = AccountSearchResultsDto.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalDefendantAccountService.searchDefendantAccounts(searchDto)).thenReturn(resultsDto); - - // When: searchDefendantAccounts is called on the proxy - AccountSearchResultsDto result = defendantAccountServiceProxy.searchDefendantAccounts(searchDto); - - // Then: opalDefendantAccountService should be used, and the returned note should be as expected - verify(opalDefendantAccountService).searchDefendantAccounts(searchDto); - verifyNoInteractions(legacyDefendantAccountService); - assertEquals(resultsDto, result); + void testMode(DefendantAccountServiceInterface targetService, DefendantAccountServiceInterface otherService) { + testGetDefendantAccount(targetService, otherService); + testSearchDefendantAccounts(targetService, otherService); + testGetAccountDetails(targetService, otherService); + testPutDefendantAccount(targetService, otherService); + } - // Given + void testGetDefendantAccount(DefendantAccountServiceInterface targetService, + DefendantAccountServiceInterface otherService) { + // Given: a DefendantAccountEntity is returned from the target service + DefendantAccountEntity entity = DefendantAccountEntity.builder().build(); AccountEnquiryDto enquiryDto = AccountEnquiryDto.builder().build(); - DefendantAccountEntity accountEntity = DefendantAccountEntity.builder().build(); - when(opalDefendantAccountService.getDefendantAccount(enquiryDto)).thenReturn(accountEntity); - - // When - DefendantAccountEntity resultEntity = defendantAccountServiceProxy.getDefendantAccount(enquiryDto); - - // Then - verify(opalDefendantAccountService).getDefendantAccount(enquiryDto); - verifyNoInteractions(legacyDefendantAccountService); - assertEquals(resultEntity, accountEntity); - - // Given - AccountDetailsDto accountDetails = AccountDetailsDto.builder().build(); - when(opalDefendantAccountService.getAccountDetailsByDefendantAccountId(any(Long.class))) - .thenReturn(accountDetails); - - // When - AccountDetailsDto resultDetails = defendantAccountServiceProxy.getAccountDetailsByDefendantAccountId(1L); - - // Then - verify(opalDefendantAccountService).getAccountDetailsByDefendantAccountId(1L); - verifyNoInteractions(legacyDefendantAccountService); - assertEquals(accountDetails, resultDetails); - + when(targetService.getDefendantAccount(any(AccountEnquiryDto.class))).thenReturn(entity); - // Given - when(opalDefendantAccountService.putDefendantAccount(accountEntity)) - .thenReturn(accountEntity); + // When: getDefendantAccount is called on the proxy + DefendantAccountEntity defendantAccountResult = defendantAccountServiceProxy.getDefendantAccount(enquiryDto); - // When - DefendantAccountEntity resultEntity2 = defendantAccountServiceProxy.putDefendantAccount(accountEntity); - - // Then - verify(opalDefendantAccountService).putDefendantAccount(accountEntity); - verifyNoInteractions(legacyDefendantAccountService); - assertEquals(accountEntity, resultEntity2); + // Then: target service should be used, and the returned defendantAccount should be as expected + verify(targetService).getDefendantAccount(enquiryDto); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, defendantAccountResult); } - @Test - void shouldUseLegacyDefendantAccountServiceWhenModeIsLegacy() { - // Given: a AccountSearchDto and the app mode is set to "legacy" - AccountSearchDto searchDto = AccountSearchDto.builder().build(); + void testSearchDefendantAccounts(DefendantAccountServiceInterface targetService, + DefendantAccountServiceInterface otherService) { + // Given: a defendantAccounts results dto result is returned from the target service AccountSearchResultsDto resultsDto = AccountSearchResultsDto.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyDefendantAccountService.searchDefendantAccounts(searchDto)).thenReturn(resultsDto); + when(targetService.searchDefendantAccounts(any())).thenReturn(resultsDto); // When: searchDefendantAccounts is called on the proxy - AccountSearchResultsDto result = defendantAccountServiceProxy.searchDefendantAccounts(searchDto); - - // Then: legacyDefendantAccountService should be used, and the returned note should be as expected - verify(legacyDefendantAccountService).searchDefendantAccounts(searchDto); - verifyNoInteractions(opalDefendantAccountService); - assertEquals(resultsDto, result); + AccountSearchDto criteria = AccountSearchDto.builder().build(); + AccountSearchResultsDto listResult = defendantAccountServiceProxy.searchDefendantAccounts(criteria); - // Given - AccountEnquiryDto enquiryDto = AccountEnquiryDto.builder().build(); - DefendantAccountEntity accountEntity = DefendantAccountEntity.builder().build(); - when(legacyDefendantAccountService.getDefendantAccount(enquiryDto)).thenReturn(accountEntity); - - // When - DefendantAccountEntity resultEntity = defendantAccountServiceProxy.getDefendantAccount(enquiryDto); - - // Then - verify(legacyDefendantAccountService).getDefendantAccount(enquiryDto); - verifyNoInteractions(opalDefendantAccountService); - assertEquals(resultEntity, accountEntity); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchDefendantAccounts(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(resultsDto, listResult); + } - // Given + void testGetAccountDetails(DefendantAccountServiceInterface targetService, + DefendantAccountServiceInterface otherService) { + // Given: a DefendantAccountEntity is returned from the target service AccountDetailsDto accountDetails = AccountDetailsDto.builder().build(); - when(legacyDefendantAccountService.getAccountDetailsByDefendantAccountId(any(Long.class))) - .thenReturn(accountDetails); + when(targetService.getAccountDetailsByDefendantAccountId(anyLong())).thenReturn(accountDetails); - // When - AccountDetailsDto resultDetails = defendantAccountServiceProxy.getAccountDetailsByDefendantAccountId(1L); + // When: getDefendantAccount is called on the proxy + AccountDetailsDto defendantAccountResult = defendantAccountServiceProxy + .getAccountDetailsByDefendantAccountId(1L); - // Then - verify(legacyDefendantAccountService).getAccountDetailsByDefendantAccountId(1L); - verifyNoInteractions(opalDefendantAccountService); - assertEquals(accountDetails, resultDetails); + // Then: target service should be used, and the returned defendantAccount should be as expected + verify(targetService).getAccountDetailsByDefendantAccountId(1L); + verifyNoInteractions(otherService); + Assertions.assertEquals(accountDetails, defendantAccountResult); + } + + void testPutDefendantAccount(DefendantAccountServiceInterface targetService, + DefendantAccountServiceInterface otherService) { + // Given: a DefendantAccountEntity is returned from the target service + DefendantAccountEntity entity = DefendantAccountEntity.builder().build(); + when(targetService.putDefendantAccount(any(DefendantAccountEntity.class))).thenReturn(entity); + // When: putDefendantAccount is called on the proxy + DefendantAccountEntity defendantAccountResult = defendantAccountServiceProxy.putDefendantAccount(entity); - // Given - when(legacyDefendantAccountService.putDefendantAccount(accountEntity)) - .thenReturn(accountEntity); + // Then: target service should be used, and the returned defendantAccount should be as expected + verify(targetService).putDefendantAccount(entity); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, defendantAccountResult); + } - // When - DefendantAccountEntity resultEntity2 = defendantAccountServiceProxy.putDefendantAccount(accountEntity); + @Test + void shouldUseOpalDefendantAccountServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then - verify(legacyDefendantAccountService).putDefendantAccount(accountEntity); - verifyNoInteractions(opalDefendantAccountService); - assertEquals(accountEntity, resultEntity2); + @Test + void shouldUseLegacyDefendantAccountServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentInstanceServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentInstanceServiceProxyTest.java index 059a73312..d64505b20 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentInstanceServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentInstanceServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.DocumentInstanceSearchDto; import uk.gov.hmcts.opal.entity.DocumentInstanceEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.DocumentInstanceServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyDocumentInstanceService; import uk.gov.hmcts.opal.service.opal.DocumentInstanceService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class DocumentInstanceServiceProxyTest { +class DocumentInstanceServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private DocumentInstanceService opalDocumentInstanceService; + private DocumentInstanceService opalService; @Mock - private LegacyDocumentInstanceService legacyDocumentInstanceService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyDocumentInstanceService legacyService; @InjectMocks private DocumentInstanceServiceProxy documentInstanceServiceProxy; @@ -48,63 +44,56 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalDocumentInstanceServiceWhenModeIsNotLegacy() { - // Given: a DocumentInstanceEntity and the app mode is set to "opal" + void testMode(DocumentInstanceServiceInterface targetService, DocumentInstanceServiceInterface otherService) { + testGetDocumentInstance(targetService, otherService); + testSearchDocumentInstances(targetService, otherService); + } + + void testGetDocumentInstance(DocumentInstanceServiceInterface targetService, + DocumentInstanceServiceInterface otherService) { + // Given: a DocumentInstanceEntity is returned from the target service DocumentInstanceEntity entity = DocumentInstanceEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalDocumentInstanceService.getDocumentInstance(anyLong())).thenReturn(entity); + when(targetService.getDocumentInstance(anyLong())).thenReturn(entity); - // When: saveDocumentInstance is called on the proxy + // When: getDocumentInstance is called on the proxy DocumentInstanceEntity documentInstanceResult = documentInstanceServiceProxy.getDocumentInstance(1); - // Then: opalDocumentInstanceService should be used, and the returned documentInstance should be as expected - verify(opalDocumentInstanceService).getDocumentInstance(1); - verifyNoInteractions(legacyDocumentInstanceService); + // Then: target service should be used, and the returned documentInstance should be as expected + verify(targetService).getDocumentInstance(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, documentInstanceResult); + } - // Given: a documentInstances list result and the app mode is set to "opal" + void testSearchDocumentInstances(DocumentInstanceServiceInterface targetService, + DocumentInstanceServiceInterface otherService) { + // Given: a documentInstances list result is returned from the target service + DocumentInstanceEntity entity = DocumentInstanceEntity.builder().build(); List documentInstancesList = List.of(entity); - when(opalDocumentInstanceService.searchDocumentInstances(any())).thenReturn(documentInstancesList); + when(targetService.searchDocumentInstances(any())).thenReturn(documentInstancesList); // When: searchDocumentInstances is called on the proxy DocumentInstanceSearchDto criteria = DocumentInstanceSearchDto.builder().build(); List listResult = documentInstanceServiceProxy.searchDocumentInstances(criteria); - // Then: opalDocumentInstanceService should be used, and the returned list should be as expected - verify(opalDocumentInstanceService).searchDocumentInstances(criteria); - verifyNoInteractions(legacyDocumentInstanceService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchDocumentInstances(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(documentInstancesList, listResult); } @Test - void shouldUseLegacyDocumentInstanceServiceWhenModeIsLegacy() { - // Given: a DocumentInstanceEntity and the app mode is set to "legacy" - DocumentInstanceEntity entity = DocumentInstanceEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyDocumentInstanceService.getDocumentInstance(anyLong())).thenReturn(entity); - - // When: saveDocumentInstance is called on the proxy - DocumentInstanceEntity result = documentInstanceServiceProxy.getDocumentInstance(1); - - // Then: legacyDocumentInstanceService should be used, and the returned documentInstance should be as expected - verify(legacyDocumentInstanceService).getDocumentInstance(1); - verifyNoInteractions(opalDocumentInstanceService); - Assertions.assertEquals(entity, result); - - // Given: a documentInstances list result and the app mode is set to "legacy" - List documentInstancesList = List.of(entity); - when(legacyDocumentInstanceService.searchDocumentInstances(any())).thenReturn(documentInstancesList); - - // When: searchDocumentInstances is called on the proxy - DocumentInstanceSearchDto criteria = DocumentInstanceSearchDto.builder().build(); - List listResult = documentInstanceServiceProxy.searchDocumentInstances(criteria); + void shouldUseOpalDocumentInstanceServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalDocumentInstanceService should be used, and the returned list should be as expected - verify(legacyDocumentInstanceService).searchDocumentInstances(criteria); - verifyNoInteractions(opalDocumentInstanceService); - Assertions.assertEquals(documentInstancesList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyDocumentInstanceServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java index 73d6f3087..b9ff185f7 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/DocumentServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.DocumentSearchDto; import uk.gov.hmcts.opal.entity.DocumentEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.DocumentServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyDocumentService; import uk.gov.hmcts.opal.service.opal.DocumentService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class DocumentServiceProxyTest { +class DocumentServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private DocumentService opalDocumentService; + private DocumentService opalService; @Mock - private LegacyDocumentService legacyDocumentService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyDocumentService legacyService; @InjectMocks private DocumentServiceProxy documentServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalDocumentServiceWhenModeIsNotLegacy() { - // Given: a DocumentEntity and the app mode is set to "opal" + void testMode(DocumentServiceInterface targetService, DocumentServiceInterface otherService) { + testGetDocument(targetService, otherService); + testSearchDocuments(targetService, otherService); + } + + void testGetDocument(DocumentServiceInterface targetService, DocumentServiceInterface otherService) { + // Given: a DocumentEntity is returned from the target service DocumentEntity entity = DocumentEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalDocumentService.getDocument(anyString())).thenReturn(entity); + when(targetService.getDocument(anyString())).thenReturn(entity); - // When: saveDocument is called on the proxy - DocumentEntity documentResult = documentServiceProxy.getDocument("ID1"); + // When: getDocument is called on the proxy + DocumentEntity documentResult = documentServiceProxy.getDocument("1"); - // Then: opalDocumentService should be used, and the returned document should be as expected - verify(opalDocumentService).getDocument("ID1"); - verifyNoInteractions(legacyDocumentService); + // Then: target service should be used, and the returned document should be as expected + verify(targetService).getDocument("1"); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, documentResult); + } - // Given: a documents list result and the app mode is set to "opal" + void testSearchDocuments(DocumentServiceInterface targetService, DocumentServiceInterface otherService) { + // Given: a documents list result is returned from the target service + DocumentEntity entity = DocumentEntity.builder().build(); List documentsList = List.of(entity); - when(opalDocumentService.searchDocuments(any())).thenReturn(documentsList); + when(targetService.searchDocuments(any())).thenReturn(documentsList); // When: searchDocuments is called on the proxy DocumentSearchDto criteria = DocumentSearchDto.builder().build(); List listResult = documentServiceProxy.searchDocuments(criteria); - // Then: opalDocumentService should be used, and the returned list should be as expected - verify(opalDocumentService).searchDocuments(criteria); - verifyNoInteractions(legacyDocumentService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchDocuments(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(documentsList, listResult); } @Test - void shouldUseLegacyDocumentServiceWhenModeIsLegacy() { - // Given: a DocumentEntity and the app mode is set to "legacy" - DocumentEntity entity = DocumentEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyDocumentService.getDocument(anyString())).thenReturn(entity); - - // When: saveDocument is called on the proxy - DocumentEntity result = documentServiceProxy.getDocument("ID1"); - - // Then: legacyDocumentService should be used, and the returned document should be as expected - verify(legacyDocumentService).getDocument("ID1"); - verifyNoInteractions(opalDocumentService); - Assertions.assertEquals(entity, result); - - // Given: a documents list result and the app mode is set to "legacy" - List documentsList = List.of(entity); - when(legacyDocumentService.searchDocuments(any())).thenReturn(documentsList); - - // When: searchDocuments is called on the proxy - DocumentSearchDto criteria = DocumentSearchDto.builder().build(); - List listResult = documentServiceProxy.searchDocuments(criteria); + void shouldUseOpalDocumentServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalDocumentService should be used, and the returned list should be as expected - verify(legacyDocumentService).searchDocuments(criteria); - verifyNoInteractions(opalDocumentService); - Assertions.assertEquals(documentsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyDocumentServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxyTest.java index 3907b6818..a674e70df 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcementServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.EnforcementSearchDto; import uk.gov.hmcts.opal.entity.EnforcementEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.EnforcementServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyEnforcementService; import uk.gov.hmcts.opal.service.opal.EnforcementService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class EnforcementServiceProxyTest { +class EnforcementServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private EnforcementService opalEnforcementService; + private EnforcementService opalService; @Mock - private LegacyEnforcementService legacyEnforcementService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyEnforcementService legacyService; @InjectMocks private EnforcementServiceProxy enforcementServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalEnforcementServiceWhenModeIsNotLegacy() { - // Given: a EnforcementEntity and the app mode is set to "opal" + void testMode(EnforcementServiceInterface targetService, EnforcementServiceInterface otherService) { + testGetEnforcement(targetService, otherService); + testSearchEnforcements(targetService, otherService); + } + + void testGetEnforcement(EnforcementServiceInterface targetService, EnforcementServiceInterface otherService) { + // Given: an EnforcementEntity is returned from the target service EnforcementEntity entity = EnforcementEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalEnforcementService.getEnforcement(anyLong())).thenReturn(entity); + when(targetService.getEnforcement(anyLong())).thenReturn(entity); - // When: saveEnforcement is called on the proxy + // When: getEnforcement is called on the proxy EnforcementEntity enforcementResult = enforcementServiceProxy.getEnforcement(1); - // Then: opalEnforcementService should be used, and the returned enforcement should be as expected - verify(opalEnforcementService).getEnforcement(1); - verifyNoInteractions(legacyEnforcementService); + // Then: target service should be used, and the returned enforcement should be as expected + verify(targetService).getEnforcement(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, enforcementResult); + } - // Given: a enforcements list result and the app mode is set to "opal" + void testSearchEnforcements(EnforcementServiceInterface targetService, EnforcementServiceInterface otherService) { + // Given: an enforcements list result is returned from the target service + EnforcementEntity entity = EnforcementEntity.builder().build(); List enforcementsList = List.of(entity); - when(opalEnforcementService.searchEnforcements(any())).thenReturn(enforcementsList); + when(targetService.searchEnforcements(any())).thenReturn(enforcementsList); // When: searchEnforcements is called on the proxy EnforcementSearchDto criteria = EnforcementSearchDto.builder().build(); List listResult = enforcementServiceProxy.searchEnforcements(criteria); - // Then: opalEnforcementService should be used, and the returned list should be as expected - verify(opalEnforcementService).searchEnforcements(criteria); - verifyNoInteractions(legacyEnforcementService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchEnforcements(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(enforcementsList, listResult); } @Test - void shouldUseLegacyEnforcementServiceWhenModeIsLegacy() { - // Given: a EnforcementEntity and the app mode is set to "legacy" - EnforcementEntity entity = EnforcementEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyEnforcementService.getEnforcement(anyLong())).thenReturn(entity); - - // When: saveEnforcement is called on the proxy - EnforcementEntity result = enforcementServiceProxy.getEnforcement(1); - - // Then: legacyEnforcementService should be used, and the returned enforcement should be as expected - verify(legacyEnforcementService).getEnforcement(1); - verifyNoInteractions(opalEnforcementService); - Assertions.assertEquals(entity, result); - - // Given: a enforcements list result and the app mode is set to "legacy" - List enforcementsList = List.of(entity); - when(legacyEnforcementService.searchEnforcements(any())).thenReturn(enforcementsList); - - // When: searchEnforcements is called on the proxy - EnforcementSearchDto criteria = EnforcementSearchDto.builder().build(); - List listResult = enforcementServiceProxy.searchEnforcements(criteria); + void shouldUseOpalEnforcementServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalEnforcementService should be used, and the returned list should be as expected - verify(legacyEnforcementService).searchEnforcements(criteria); - verifyNoInteractions(opalEnforcementService); - Assertions.assertEquals(enforcementsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyEnforcementServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxyTest.java index f8bb10bb4..fe52f7fd2 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/EnforcerServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; import uk.gov.hmcts.opal.entity.EnforcerEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.EnforcerServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyEnforcerService; import uk.gov.hmcts.opal.service.opal.EnforcerService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class EnforcerServiceProxyTest { +class EnforcerServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private EnforcerService opalEnforcerService; + private EnforcerService opalService; @Mock - private LegacyEnforcerService legacyEnforcerService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyEnforcerService legacyService; @InjectMocks private EnforcerServiceProxy enforcerServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalEnforcerServiceWhenModeIsNotLegacy() { - // Given: a EnforcerEntity and the app mode is set to "opal" + void testMode(EnforcerServiceInterface targetService, EnforcerServiceInterface otherService) { + testGetEnforcer(targetService, otherService); + testSearchEnforcers(targetService, otherService); + } + + void testGetEnforcer(EnforcerServiceInterface targetService, EnforcerServiceInterface otherService) { + // Given: an EnforcerEntity is returned from the target service EnforcerEntity entity = EnforcerEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalEnforcerService.getEnforcer(anyLong())).thenReturn(entity); + when(targetService.getEnforcer(anyLong())).thenReturn(entity); - // When: saveEnforcer is called on the proxy + // When: getEnforcer is called on the proxy EnforcerEntity enforcerResult = enforcerServiceProxy.getEnforcer(1); - // Then: opalEnforcerService should be used, and the returned enforcer should be as expected - verify(opalEnforcerService).getEnforcer(1); - verifyNoInteractions(legacyEnforcerService); + // Then: target service should be used, and the returned enforcer should be as expected + verify(targetService).getEnforcer(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, enforcerResult); + } - // Given: a enforcers list result and the app mode is set to "opal" + void testSearchEnforcers(EnforcerServiceInterface targetService, EnforcerServiceInterface otherService) { + // Given: an enforcers list result is returned from the target service + EnforcerEntity entity = EnforcerEntity.builder().build(); List enforcersList = List.of(entity); - when(opalEnforcerService.searchEnforcers(any())).thenReturn(enforcersList); + when(targetService.searchEnforcers(any())).thenReturn(enforcersList); // When: searchEnforcers is called on the proxy EnforcerSearchDto criteria = EnforcerSearchDto.builder().build(); List listResult = enforcerServiceProxy.searchEnforcers(criteria); - // Then: opalEnforcerService should be used, and the returned list should be as expected - verify(opalEnforcerService).searchEnforcers(criteria); - verifyNoInteractions(legacyEnforcerService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchEnforcers(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(enforcersList, listResult); } @Test - void shouldUseLegacyEnforcerServiceWhenModeIsLegacy() { - // Given: a EnforcerEntity and the app mode is set to "legacy" - EnforcerEntity entity = EnforcerEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyEnforcerService.getEnforcer(anyLong())).thenReturn(entity); - - // When: saveEnforcer is called on the proxy - EnforcerEntity result = enforcerServiceProxy.getEnforcer(1); - - // Then: legacyEnforcerService should be used, and the returned enforcer should be as expected - verify(legacyEnforcerService).getEnforcer(1); - verifyNoInteractions(opalEnforcerService); - Assertions.assertEquals(entity, result); - - // Given: a enforcers list result and the app mode is set to "legacy" - List enforcersList = List.of(entity); - when(legacyEnforcerService.searchEnforcers(any())).thenReturn(enforcersList); - - // When: searchEnforcers is called on the proxy - EnforcerSearchDto criteria = EnforcerSearchDto.builder().build(); - List listResult = enforcerServiceProxy.searchEnforcers(criteria); + void shouldUseOpalEnforcerServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalEnforcerService should be used, and the returned list should be as expected - verify(legacyEnforcerService).searchEnforcers(criteria); - verifyNoInteractions(opalEnforcerService); - Assertions.assertEquals(enforcersList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyEnforcerServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java index fa290a350..3bbf3e57d 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/LocalJusticeAreaServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.LocalJusticeAreaSearchDto; import uk.gov.hmcts.opal.entity.LocalJusticeAreaEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.LocalJusticeAreaServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyLocalJusticeAreaService; import uk.gov.hmcts.opal.service.opal.LocalJusticeAreaService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class LocalJusticeAreaServiceProxyTest { +class LocalJusticeAreaServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private LocalJusticeAreaService opalLocalJusticeAreaService; + private LocalJusticeAreaService opalService; @Mock - private LegacyLocalJusticeAreaService legacyLocalJusticeAreaService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyLocalJusticeAreaService legacyService; @InjectMocks private LocalJusticeAreaServiceProxy localJusticeAreaServiceProxy; @@ -48,63 +44,56 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalLocalJusticeAreaServiceWhenModeIsNotLegacy() { - // Given: a LocalJusticeAreaEntity and the app mode is set to "opal" + void testMode(LocalJusticeAreaServiceInterface targetService, LocalJusticeAreaServiceInterface otherService) { + testGetLocalJusticeArea(targetService, otherService); + testSearchLocalJusticeAreas(targetService, otherService); + } + + void testGetLocalJusticeArea(LocalJusticeAreaServiceInterface targetService, + LocalJusticeAreaServiceInterface otherService) { + // Given: a LocalJusticeAreaEntity is returned from the target service LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalLocalJusticeAreaService.getLocalJusticeArea(anyShort())).thenReturn(entity); + when(targetService.getLocalJusticeArea(anyShort())).thenReturn(entity); - // When: saveLocalJusticeArea is called on the proxy + // When: getLocalJusticeArea is called on the proxy LocalJusticeAreaEntity localJusticeAreaResult = localJusticeAreaServiceProxy.getLocalJusticeArea((short)1); - // Then: opalLocalJusticeAreaService should be used, and the returned localJusticeArea should be as expected - verify(opalLocalJusticeAreaService).getLocalJusticeArea((short)1); - verifyNoInteractions(legacyLocalJusticeAreaService); + // Then: target service should be used, and the returned localJusticeArea should be as expected + verify(targetService).getLocalJusticeArea((short)1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, localJusticeAreaResult); + } - // Given: a localJusticeAreas list result and the app mode is set to "opal" + void testSearchLocalJusticeAreas(LocalJusticeAreaServiceInterface targetService, + LocalJusticeAreaServiceInterface otherService) { + // Given: a localJusticeAreas list result is returned from the target service + LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); List localJusticeAreasList = List.of(entity); - when(opalLocalJusticeAreaService.searchLocalJusticeAreas(any())).thenReturn(localJusticeAreasList); + when(targetService.searchLocalJusticeAreas(any())).thenReturn(localJusticeAreasList); // When: searchLocalJusticeAreas is called on the proxy LocalJusticeAreaSearchDto criteria = LocalJusticeAreaSearchDto.builder().build(); List listResult = localJusticeAreaServiceProxy.searchLocalJusticeAreas(criteria); - // Then: opalLocalJusticeAreaService should be used, and the returned list should be as expected - verify(opalLocalJusticeAreaService).searchLocalJusticeAreas(criteria); - verifyNoInteractions(legacyLocalJusticeAreaService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchLocalJusticeAreas(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(localJusticeAreasList, listResult); } @Test - void shouldUseLegacyLocalJusticeAreaServiceWhenModeIsLegacy() { - // Given: a LocalJusticeAreaEntity and the app mode is set to "legacy" - LocalJusticeAreaEntity entity = LocalJusticeAreaEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyLocalJusticeAreaService.getLocalJusticeArea(anyShort())).thenReturn(entity); - - // When: saveLocalJusticeArea is called on the proxy - LocalJusticeAreaEntity result = localJusticeAreaServiceProxy.getLocalJusticeArea((short)1); - - // Then: legacyLocalJusticeAreaService should be used, and the returned localJusticeArea should be as expected - verify(legacyLocalJusticeAreaService).getLocalJusticeArea((short)1); - verifyNoInteractions(opalLocalJusticeAreaService); - Assertions.assertEquals(entity, result); - - // Given: a localJusticeAreas list result and the app mode is set to "legacy" - List localJusticeAreasList = List.of(entity); - when(legacyLocalJusticeAreaService.searchLocalJusticeAreas(any())).thenReturn(localJusticeAreasList); - - // When: searchLocalJusticeAreas is called on the proxy - LocalJusticeAreaSearchDto criteria = LocalJusticeAreaSearchDto.builder().build(); - List listResult = localJusticeAreaServiceProxy.searchLocalJusticeAreas(criteria); + void shouldUseOpalLocalJusticeAreaServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalLocalJusticeAreaService should be used, and the returned list should be as expected - verify(legacyLocalJusticeAreaService).searchLocalJusticeAreas(criteria); - verifyNoInteractions(opalLocalJusticeAreaService); - Assertions.assertEquals(localJusticeAreasList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyLocalJusticeAreaServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxyTest.java index 2e3dc4635..b1500ca98 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/MisDebtorServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.MisDebtorSearchDto; import uk.gov.hmcts.opal.entity.MisDebtorEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.MisDebtorServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyMisDebtorService; import uk.gov.hmcts.opal.service.opal.MisDebtorService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class MisDebtorServiceProxyTest { +class MisDebtorServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private MisDebtorService opalMisDebtorService; + private MisDebtorService opalService; @Mock - private LegacyMisDebtorService legacyMisDebtorService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyMisDebtorService legacyService; @InjectMocks private MisDebtorServiceProxy misDebtorServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalMisDebtorServiceWhenModeIsNotLegacy() { - // Given: a MisDebtorEntity and the app mode is set to "opal" + void testMode(MisDebtorServiceInterface targetService, MisDebtorServiceInterface otherService) { + testGetMisDebtor(targetService, otherService); + testSearchMisDebtors(targetService, otherService); + } + + void testGetMisDebtor(MisDebtorServiceInterface targetService, MisDebtorServiceInterface otherService) { + // Given: a MisDebtorEntity is returned from the target service MisDebtorEntity entity = MisDebtorEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalMisDebtorService.getMisDebtor(anyLong())).thenReturn(entity); + when(targetService.getMisDebtor(anyLong())).thenReturn(entity); - // When: saveMisDebtor is called on the proxy + // When: getMisDebtor is called on the proxy MisDebtorEntity misDebtorResult = misDebtorServiceProxy.getMisDebtor(1); - // Then: opalMisDebtorService should be used, and the returned misDebtor should be as expected - verify(opalMisDebtorService).getMisDebtor(1); - verifyNoInteractions(legacyMisDebtorService); + // Then: target service should be used, and the returned misDebtor should be as expected + verify(targetService).getMisDebtor(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, misDebtorResult); + } - // Given: a misDebtors list result and the app mode is set to "opal" + void testSearchMisDebtors(MisDebtorServiceInterface targetService, MisDebtorServiceInterface otherService) { + // Given: a misDebtors list result is returned from the target service + MisDebtorEntity entity = MisDebtorEntity.builder().build(); List misDebtorsList = List.of(entity); - when(opalMisDebtorService.searchMisDebtors(any())).thenReturn(misDebtorsList); + when(targetService.searchMisDebtors(any())).thenReturn(misDebtorsList); // When: searchMisDebtors is called on the proxy MisDebtorSearchDto criteria = MisDebtorSearchDto.builder().build(); List listResult = misDebtorServiceProxy.searchMisDebtors(criteria); - // Then: opalMisDebtorService should be used, and the returned list should be as expected - verify(opalMisDebtorService).searchMisDebtors(criteria); - verifyNoInteractions(legacyMisDebtorService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchMisDebtors(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(misDebtorsList, listResult); } @Test - void shouldUseLegacyMisDebtorServiceWhenModeIsLegacy() { - // Given: a MisDebtorEntity and the app mode is set to "legacy" - MisDebtorEntity entity = MisDebtorEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyMisDebtorService.getMisDebtor(anyLong())).thenReturn(entity); - - // When: saveMisDebtor is called on the proxy - MisDebtorEntity result = misDebtorServiceProxy.getMisDebtor(1); - - // Then: legacyMisDebtorService should be used, and the returned misDebtor should be as expected - verify(legacyMisDebtorService).getMisDebtor(1); - verifyNoInteractions(opalMisDebtorService); - Assertions.assertEquals(entity, result); - - // Given: a misDebtors list result and the app mode is set to "legacy" - List misDebtorsList = List.of(entity); - when(legacyMisDebtorService.searchMisDebtors(any())).thenReturn(misDebtorsList); - - // When: searchMisDebtors is called on the proxy - MisDebtorSearchDto criteria = MisDebtorSearchDto.builder().build(); - List listResult = misDebtorServiceProxy.searchMisDebtors(criteria); + void shouldUseOpalMisDebtorServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalMisDebtorService should be used, and the returned list should be as expected - verify(legacyMisDebtorService).searchMisDebtors(criteria); - verifyNoInteractions(opalMisDebtorService); - Assertions.assertEquals(misDebtorsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyMisDebtorServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/NoteServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/NoteServiceProxyTest.java index 02563cbad..ab618577b 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/NoteServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/NoteServiceProxyTest.java @@ -11,13 +11,11 @@ import uk.gov.hmcts.opal.dto.NoteDto; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.NoteSearchDto; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.NoteServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyNoteService; import uk.gov.hmcts.opal.service.opal.NoteService; -import java.util.Collections; import java.util.List; import static org.mockito.ArgumentMatchers.any; @@ -25,18 +23,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class NoteServiceProxyTest { +class NoteServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private NoteService opalNoteService; + private NoteService opalService; @Mock - private LegacyNoteService legacyNoteService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyNoteService legacyService; @InjectMocks private NoteServiceProxy noteServiceProxy; @@ -51,64 +46,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalNoteServiceWhenModeIsNotLegacy() { - // Given: a NoteDto and the app mode is set to "opal" + void testMode(NoteServiceInterface targetService, NoteServiceInterface otherService) { + testSaveNote(targetService, otherService); + testSearchNotes(targetService, otherService); + } + + void testSaveNote(NoteServiceInterface targetService, NoteServiceInterface otherService) { + // Given: a NoteDto is returned from the target service NoteDto noteDto = new NoteDto(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalNoteService.saveNote(noteDto)).thenReturn(noteDto); + when(targetService.saveNote(any(NoteDto.class))).thenReturn(noteDto); // When: saveNote is called on the proxy NoteDto noteResult = noteServiceProxy.saveNote(noteDto); - // Then: opalNoteService should be used, and the returned note should be as expected - verify(opalNoteService).saveNote(noteDto); - verifyNoInteractions(legacyNoteService); + // Then: target service should be used, and the returned note should be as expected + verify(targetService).saveNote(noteDto); + verifyNoInteractions(otherService); Assertions.assertEquals(noteDto, noteResult); + } - // Given: a notes list result and the app mode is set to "opal" + void testSearchNotes(NoteServiceInterface targetService, NoteServiceInterface otherService) { + // Given: a notes list result is returned from the target service + NoteDto noteDto = NoteDto.builder().build(); List notesList = List.of(noteDto); - when(opalNoteService.searchNotes(any())).thenReturn(notesList); + when(targetService.searchNotes(any())).thenReturn(notesList); // When: searchNotes is called on the proxy NoteSearchDto criteria = NoteSearchDto.builder().build(); List listResult = noteServiceProxy.searchNotes(criteria); - // Then: opalNoteService should be used, and the returned list should be as expected - verify(opalNoteService).searchNotes(criteria); - verifyNoInteractions(legacyNoteService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchNotes(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(notesList, listResult); } @Test - void shouldUseLegacyNoteServiceWhenModeIsLegacy() { - // Given: a NoteDto and the app mode is set to "legacy" - NoteDto noteDto = new NoteDto(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyNoteService.saveNote(noteDto)).thenReturn(noteDto); - - // When: saveNote is called on the proxy - NoteDto result = noteServiceProxy.saveNote(noteDto); - - // Then: legacyNoteService should be used, and the returned note should be as expected - verify(legacyNoteService).saveNote(noteDto); - verifyNoInteractions(opalNoteService); - Assertions.assertEquals(noteDto, result); - - // Given: a notes list result and the app mode is set to "legacy" - List notesList = List.of(noteDto); - when(opalNoteService.searchNotes(any())).thenReturn(notesList); - - // When: searchNotes is called on the proxy - NoteSearchDto criteria = NoteSearchDto.builder().build(); - List listResult = noteServiceProxy.searchNotes(criteria); + void shouldUseOpalNoteServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalNoteService should be used, and the returned list should be as expected - verify(legacyNoteService).searchNotes(criteria); - verifyNoInteractions(opalNoteService); - Assertions.assertEquals(Collections.emptyList(), listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyNoteServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxyTest.java index a5d7cc64c..33bb010dc 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/PartyServiceProxyTest.java @@ -8,12 +8,11 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import uk.gov.hmcts.opal.dto.search.AccountSearchDto; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.PartyDto; import uk.gov.hmcts.opal.dto.search.PartySearchDto; import uk.gov.hmcts.opal.entity.PartyEntity; import uk.gov.hmcts.opal.entity.PartySummary; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PartyServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPartyService; import uk.gov.hmcts.opal.service.opal.PartyService; @@ -21,22 +20,20 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class PartyServiceProxyTest { +class PartyServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private PartyService opalPartyService; + private PartyService opalService; @Mock - private LegacyPartyService legacyPartyService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyPartyService legacyService; @InjectMocks private PartyServiceProxy partyServiceProxy; @@ -51,101 +48,84 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalPartyServiceWhenModeIsNotLegacy() { - // Given: a PartyDto and the app mode is set to "opal" - PartyDto partyDto = new PartyDto(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalPartyService.saveParty(partyDto)).thenReturn(partyDto); - when(opalPartyService.getParty(1L)).thenReturn(partyDto); - when(opalPartyService.searchForParty(any())).thenReturn(Collections.emptyList()); - - // When: saveParty is called on the proxy - PartyDto result1 = partyServiceProxy.saveParty(partyDto); + void testMode(PartyServiceInterface targetService, PartyServiceInterface otherService) { + testGetParty(targetService, otherService); + testSearchParties(targetService, otherService); + testSaveParty(targetService, otherService); + testSearchForParty(targetService, otherService); + } - // Then: opalPartyService should be used, and the returned party should be as expected - verify(opalPartyService).saveParty(partyDto); - verifyNoInteractions(legacyPartyService); - Assertions.assertEquals(partyDto, result1); + void testGetParty(PartyServiceInterface targetService, PartyServiceInterface otherService) { + // Given: a PartyEntity is returned from the target service + // PartyEntity entity = PartyEntity.builder().build(); + PartyDto partyDto = PartyDto.builder().build(); + when(targetService.getParty(anyLong())).thenReturn(partyDto); // When: getParty is called on the proxy - PartyDto result2 = partyServiceProxy.getParty(1L); + PartyDto partyResult = partyServiceProxy.getParty(1); - // Then: opalPartyService should be used, and the returned party should be as expected - verify(opalPartyService).getParty(1L); - verifyNoInteractions(legacyPartyService); - Assertions.assertEquals(partyDto, result2); - - // When - List result3 = partyServiceProxy.searchForParty(AccountSearchDto.builder().build()); - - // Then - verify(opalPartyService).searchForParty(any()); - verifyNoInteractions(legacyPartyService); + // Then: target service should be used, and the returned party should be as expected + verify(targetService).getParty(1); + verifyNoInteractions(otherService); + Assertions.assertEquals(partyDto, partyResult); + } - // Given: a courts list result and the app mode is set to "opal" + void testSearchParties(PartyServiceInterface targetService, PartyServiceInterface otherService) { + // Given: a party list result is returned from the target service PartyEntity entity = PartyEntity.builder().build(); - List courtsList = List.of(entity); - when(opalPartyService.searchParties(any())).thenReturn(courtsList); + List partysList = List.of(entity); + when(targetService.searchParties(any())).thenReturn(partysList); - // When: searchCourts is called on the proxy + // When: searchParties is called on the proxy PartySearchDto criteria = PartySearchDto.builder().build(); List listResult = partyServiceProxy.searchParties(criteria); - // Then: opalCourtService should be used, and the returned list should be as expected - verify(opalPartyService).searchParties(criteria); - verifyNoInteractions(legacyPartyService); - Assertions.assertEquals(courtsList, listResult); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchParties(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(partysList, listResult); } - @Test - void shouldUseLegacyPartyServiceWhenModeIsLegacy() { - // Given: a PartyDto and the app mode is set to "legacy" - PartyDto partyDto = new PartyDto(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyPartyService.saveParty(partyDto)).thenReturn(partyDto); - when(legacyPartyService.getParty(1L)).thenReturn(partyDto); - when(legacyPartyService.searchForParty(any())).thenReturn(Collections.emptyList()); + void testSaveParty(PartyServiceInterface targetService, PartyServiceInterface otherService) { + // Given: a PartyDto is returned from the target service + PartyDto partyDto = PartyDto.builder().build(); + when(targetService.saveParty(any(PartyDto.class))).thenReturn(partyDto); // When: saveParty is called on the proxy - PartyDto result1 = partyServiceProxy.saveParty(partyDto); - - // Then: legacyPartyService should be used, and the returned party should be as expected - verify(legacyPartyService).saveParty(partyDto); - verifyNoInteractions(opalPartyService); - Assertions.assertEquals(partyDto, result1); - - // When: getParty is called on the proxy - PartyDto result2 = partyServiceProxy.getParty(1L); - - // Then: opalPartyService should be used, and the returned party should be as expected - verify(legacyPartyService).getParty(1L); - verifyNoInteractions(opalPartyService); - Assertions.assertEquals(partyDto, result2); + PartyDto partyResult = partyServiceProxy.saveParty(partyDto); + // Then: target service should be used, and the returned party should be as expected + verify(targetService).saveParty(partyDto); + verifyNoInteractions(otherService); + Assertions.assertEquals(partyDto, partyResult); + } - // When - List result3 = partyServiceProxy.searchForParty(AccountSearchDto.builder().build()); + void testSearchForParty(PartyServiceInterface targetService, PartyServiceInterface otherService) { + // Given: a party list summary result is returned from the target service + when(targetService.searchForParty(any())).thenReturn(Collections.emptyList()); - // Then - verify(legacyPartyService).searchForParty(any()); - verifyNoInteractions(opalPartyService); + // When: searchForParty is called on the proxy + PartySearchDto criteria = PartySearchDto.builder().build(); + List listResult = partyServiceProxy.searchForParty(AccountSearchDto.builder().build()); - // Given: a courts list result and the app mode is set to "legacy" - PartyEntity entity = PartyEntity.builder().build(); - List courtsList = List.of(entity); - when(legacyPartyService.searchParties(any())).thenReturn(courtsList); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchForParty(any()); + verifyNoInteractions(otherService); + } - // When: searchCourts is called on the proxy - PartySearchDto criteria = PartySearchDto.builder().build(); - List listResult = partyServiceProxy.searchParties(criteria); + @Test + void shouldUseOpalPartyServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalCourtService should be used, and the returned list should be as expected - verify(legacyPartyService).searchParties(criteria); - verifyNoInteractions(opalPartyService); - Assertions.assertEquals(courtsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyPartyServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxyTest.java index 6b0d7a696..10f819526 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentInServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.PaymentInSearchDto; import uk.gov.hmcts.opal.entity.PaymentInEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PaymentInServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPaymentInService; import uk.gov.hmcts.opal.service.opal.PaymentInService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class PaymentInServiceProxyTest { +class PaymentInServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private PaymentInService opalPaymentInService; + private PaymentInService opalService; @Mock - private LegacyPaymentInService legacyPaymentInService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyPaymentInService legacyService; @InjectMocks private PaymentInServiceProxy paymentInServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalPaymentInServiceWhenModeIsNotLegacy() { - // Given: a PaymentInEntity and the app mode is set to "opal" + void testMode(PaymentInServiceInterface targetService, PaymentInServiceInterface otherService) { + testGetPaymentIn(targetService, otherService); + testSearchPaymentIns(targetService, otherService); + } + + void testGetPaymentIn(PaymentInServiceInterface targetService, PaymentInServiceInterface otherService) { + // Given: a PaymentInEntity is returned from the target service PaymentInEntity entity = PaymentInEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalPaymentInService.getPaymentIn(anyLong())).thenReturn(entity); + when(targetService.getPaymentIn(anyLong())).thenReturn(entity); - // When: savePaymentIn is called on the proxy + // When: getPaymentIn is called on the proxy PaymentInEntity paymentInResult = paymentInServiceProxy.getPaymentIn(1); - // Then: opalPaymentInService should be used, and the returned paymentIn should be as expected - verify(opalPaymentInService).getPaymentIn(1); - verifyNoInteractions(legacyPaymentInService); + // Then: target service should be used, and the returned paymentIn should be as expected + verify(targetService).getPaymentIn(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, paymentInResult); + } - // Given: a paymentIns list result and the app mode is set to "opal" + void testSearchPaymentIns(PaymentInServiceInterface targetService, PaymentInServiceInterface otherService) { + // Given: a paymentIns list result is returned from the target service + PaymentInEntity entity = PaymentInEntity.builder().build(); List paymentInsList = List.of(entity); - when(opalPaymentInService.searchPaymentIns(any())).thenReturn(paymentInsList); + when(targetService.searchPaymentIns(any())).thenReturn(paymentInsList); // When: searchPaymentIns is called on the proxy PaymentInSearchDto criteria = PaymentInSearchDto.builder().build(); List listResult = paymentInServiceProxy.searchPaymentIns(criteria); - // Then: opalPaymentInService should be used, and the returned list should be as expected - verify(opalPaymentInService).searchPaymentIns(criteria); - verifyNoInteractions(legacyPaymentInService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchPaymentIns(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(paymentInsList, listResult); } @Test - void shouldUseLegacyPaymentInServiceWhenModeIsLegacy() { - // Given: a PaymentInEntity and the app mode is set to "legacy" - PaymentInEntity entity = PaymentInEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyPaymentInService.getPaymentIn(anyLong())).thenReturn(entity); - - // When: savePaymentIn is called on the proxy - PaymentInEntity result = paymentInServiceProxy.getPaymentIn(1); - - // Then: legacyPaymentInService should be used, and the returned paymentIn should be as expected - verify(legacyPaymentInService).getPaymentIn(1); - verifyNoInteractions(opalPaymentInService); - Assertions.assertEquals(entity, result); - - // Given: a paymentIns list result and the app mode is set to "legacy" - List paymentInsList = List.of(entity); - when(legacyPaymentInService.searchPaymentIns(any())).thenReturn(paymentInsList); - - // When: searchPaymentIns is called on the proxy - PaymentInSearchDto criteria = PaymentInSearchDto.builder().build(); - List listResult = paymentInServiceProxy.searchPaymentIns(criteria); + void shouldUseOpalPaymentInServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalPaymentInService should be used, and the returned list should be as expected - verify(legacyPaymentInService).searchPaymentIns(criteria); - verifyNoInteractions(opalPaymentInService); - Assertions.assertEquals(paymentInsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyPaymentInServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxyTest.java index e14a21c67..ab7bb89b7 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/PaymentTermsServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.PaymentTermsSearchDto; import uk.gov.hmcts.opal.entity.PaymentTermsEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PaymentTermsServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPaymentTermsService; import uk.gov.hmcts.opal.service.opal.PaymentTermsService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class PaymentTermsServiceProxyTest { +class PaymentTermsServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private PaymentTermsService opalPaymentTermsService; + private PaymentTermsService opalService; @Mock - private LegacyPaymentTermsService legacyPaymentTermsService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyPaymentTermsService legacyService; @InjectMocks private PaymentTermsServiceProxy paymentTermsServiceProxy; @@ -48,63 +44,55 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalPaymentTermsServiceWhenModeIsNotLegacy() { - // Given: a PaymentTermsEntity and the app mode is set to "opal" + void testMode(PaymentTermsServiceInterface targetService, PaymentTermsServiceInterface otherService) { + testGetPaymentTerms(targetService, otherService); + testSearchPaymentTermss(targetService, otherService); + } + + void testGetPaymentTerms(PaymentTermsServiceInterface targetService, PaymentTermsServiceInterface otherService) { + // Given: a PaymentTermsEntity is returned from the target service PaymentTermsEntity entity = PaymentTermsEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalPaymentTermsService.getPaymentTerms(anyLong())).thenReturn(entity); + when(targetService.getPaymentTerms(anyLong())).thenReturn(entity); - // When: savePaymentTerms is called on the proxy + // When: getPaymentTerms is called on the proxy PaymentTermsEntity paymentTermsResult = paymentTermsServiceProxy.getPaymentTerms(1); - // Then: opalPaymentTermsService should be used, and the returned paymentTerms should be as expected - verify(opalPaymentTermsService).getPaymentTerms(1); - verifyNoInteractions(legacyPaymentTermsService); + // Then: target service should be used, and the returned paymentTerms should be as expected + verify(targetService).getPaymentTerms(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, paymentTermsResult); + } - // Given: a paymentTermss list result and the app mode is set to "opal" + void testSearchPaymentTermss(PaymentTermsServiceInterface targetService, + PaymentTermsServiceInterface otherService) { + // Given: a paymentTermss list result is returned from the target service + PaymentTermsEntity entity = PaymentTermsEntity.builder().build(); List paymentTermssList = List.of(entity); - when(opalPaymentTermsService.searchPaymentTerms(any())).thenReturn(paymentTermssList); + when(targetService.searchPaymentTerms(any())).thenReturn(paymentTermssList); // When: searchPaymentTermss is called on the proxy PaymentTermsSearchDto criteria = PaymentTermsSearchDto.builder().build(); List listResult = paymentTermsServiceProxy.searchPaymentTerms(criteria); - // Then: opalPaymentTermsService should be used, and the returned list should be as expected - verify(opalPaymentTermsService).searchPaymentTerms(criteria); - verifyNoInteractions(legacyPaymentTermsService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchPaymentTerms(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(paymentTermssList, listResult); } @Test - void shouldUseLegacyPaymentTermsServiceWhenModeIsLegacy() { - // Given: a PaymentTermsEntity and the app mode is set to "legacy" - PaymentTermsEntity entity = PaymentTermsEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyPaymentTermsService.getPaymentTerms(anyLong())).thenReturn(entity); - - // When: savePaymentTerms is called on the proxy - PaymentTermsEntity result = paymentTermsServiceProxy.getPaymentTerms(1); - - // Then: legacyPaymentTermsService should be used, and the returned paymentTerms should be as expected - verify(legacyPaymentTermsService).getPaymentTerms(1); - verifyNoInteractions(opalPaymentTermsService); - Assertions.assertEquals(entity, result); - - // Given: a paymentTermss list result and the app mode is set to "legacy" - List paymentTermssList = List.of(entity); - when(legacyPaymentTermsService.searchPaymentTerms(any())).thenReturn(paymentTermssList); - - // When: searchPaymentTermss is called on the proxy - PaymentTermsSearchDto criteria = PaymentTermsSearchDto.builder().build(); - List listResult = paymentTermsServiceProxy.searchPaymentTerms(criteria); + void shouldUseOpalPaymentTermsServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalPaymentTermsService should be used, and the returned list should be as expected - verify(legacyPaymentTermsService).searchPaymentTerms(criteria); - verifyNoInteractions(opalPaymentTermsService); - Assertions.assertEquals(paymentTermssList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyPaymentTermsServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxyTest.java index 2cfae87f8..343d4a495 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/PrisonServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.PrisonSearchDto; import uk.gov.hmcts.opal.entity.PrisonEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.PrisonServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyPrisonService; import uk.gov.hmcts.opal.service.opal.PrisonService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class PrisonServiceProxyTest { +class PrisonServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private PrisonService opalPrisonService; + private PrisonService opalService; @Mock - private LegacyPrisonService legacyPrisonService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyPrisonService legacyService; @InjectMocks private PrisonServiceProxy prisonServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalPrisonServiceWhenModeIsNotLegacy() { - // Given: a PrisonEntity and the app mode is set to "opal" + void testMode(PrisonServiceInterface targetService, PrisonServiceInterface otherService) { + testGetPrison(targetService, otherService); + testSearchPrisons(targetService, otherService); + } + + void testGetPrison(PrisonServiceInterface targetService, PrisonServiceInterface otherService) { + // Given: a PrisonEntity is returned from the target service PrisonEntity entity = PrisonEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalPrisonService.getPrison(anyLong())).thenReturn(entity); + when(targetService.getPrison(anyLong())).thenReturn(entity); - // When: savePrison is called on the proxy + // When: getPrison is called on the proxy PrisonEntity prisonResult = prisonServiceProxy.getPrison(1); - // Then: opalPrisonService should be used, and the returned prison should be as expected - verify(opalPrisonService).getPrison(1); - verifyNoInteractions(legacyPrisonService); + // Then: target service should be used, and the returned prison should be as expected + verify(targetService).getPrison(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, prisonResult); + } - // Given: a prisons list result and the app mode is set to "opal" + void testSearchPrisons(PrisonServiceInterface targetService, PrisonServiceInterface otherService) { + // Given: a prisons list result is returned from the target service + PrisonEntity entity = PrisonEntity.builder().build(); List prisonsList = List.of(entity); - when(opalPrisonService.searchPrisons(any())).thenReturn(prisonsList); + when(targetService.searchPrisons(any())).thenReturn(prisonsList); // When: searchPrisons is called on the proxy PrisonSearchDto criteria = PrisonSearchDto.builder().build(); List listResult = prisonServiceProxy.searchPrisons(criteria); - // Then: opalPrisonService should be used, and the returned list should be as expected - verify(opalPrisonService).searchPrisons(criteria); - verifyNoInteractions(legacyPrisonService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchPrisons(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(prisonsList, listResult); } @Test - void shouldUseLegacyPrisonServiceWhenModeIsLegacy() { - // Given: a PrisonEntity and the app mode is set to "legacy" - PrisonEntity entity = PrisonEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyPrisonService.getPrison(anyLong())).thenReturn(entity); - - // When: savePrison is called on the proxy - PrisonEntity result = prisonServiceProxy.getPrison(1); - - // Then: legacyPrisonService should be used, and the returned prison should be as expected - verify(legacyPrisonService).getPrison(1); - verifyNoInteractions(opalPrisonService); - Assertions.assertEquals(entity, result); - - // Given: a prisons list result and the app mode is set to "legacy" - List prisonsList = List.of(entity); - when(legacyPrisonService.searchPrisons(any())).thenReturn(prisonsList); - - // When: searchPrisons is called on the proxy - PrisonSearchDto criteria = PrisonSearchDto.builder().build(); - List listResult = prisonServiceProxy.searchPrisons(criteria); + void shouldUseOpalPrisonServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalPrisonService should be used, and the returned list should be as expected - verify(legacyPrisonService).searchPrisons(criteria); - verifyNoInteractions(opalPrisonService); - Assertions.assertEquals(prisonsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyPrisonServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/ProxyTestsBase.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/ProxyTestsBase.java new file mode 100644 index 000000000..e2ab993f9 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/ProxyTestsBase.java @@ -0,0 +1,22 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.mockito.Mock; +import uk.gov.hmcts.opal.dto.AppMode; +import uk.gov.hmcts.opal.service.DynamicConfigService; + +import static org.mockito.Mockito.when; + +public abstract class ProxyTestsBase { + + static final String LEGACY = "legacy"; + + static final String OPAL = "opal"; + + @Mock + private DynamicConfigService dynamicConfigService; + + void setMode(String mode) { + AppMode appMode = AppMode.builder().mode(mode).build(); + when(dynamicConfigService.getAppMode()).thenReturn(appMode); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxyTest.java new file mode 100644 index 000000000..aa6815b7e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateMappingServiceProxyTest.java @@ -0,0 +1,100 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.TemplateMappingSearchDto; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity; +import uk.gov.hmcts.opal.entity.TemplateMappingEntity.MappingId; +import uk.gov.hmcts.opal.service.TemplateMappingServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyTemplateMappingService; +import uk.gov.hmcts.opal.service.opal.TemplateMappingService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class TemplateMappingServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private TemplateMappingService opalService; + + @Mock + private LegacyTemplateMappingService legacyService; + + @InjectMocks + private TemplateMappingServiceProxy templateMappingServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(TemplateMappingServiceInterface targetService, TemplateMappingServiceInterface otherService) { + testGetTemplateMapping(targetService, otherService); + testSearchTemplateMappings(targetService, otherService); + } + + void testGetTemplateMapping(TemplateMappingServiceInterface targetService, + TemplateMappingServiceInterface otherService) { + // Given: a TemplateMappingEntity is returned from the target service + TemplateMappingEntity entity = TemplateMappingEntity.builder().build(); + when(targetService.getTemplateMapping(any(MappingId.class))).thenReturn(entity); + + // When: getTemplateMapping is called on the proxy + MappingId key = new MappingId(1L, 1L); + TemplateMappingEntity templateMappingResult = templateMappingServiceProxy.getTemplateMapping(key); + + // Then: target service should be used, and the returned templateMapping should be as expected + verify(targetService).getTemplateMapping(key); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, templateMappingResult); + } + + void testSearchTemplateMappings(TemplateMappingServiceInterface targetService, + TemplateMappingServiceInterface otherService) { + // Given: a templateMappings list result is returned from the target service + TemplateMappingEntity entity = TemplateMappingEntity.builder().build(); + List templateMappingsList = List.of(entity); + when(targetService.searchTemplateMappings(any())).thenReturn(templateMappingsList); + + // When: searchTemplateMappings is called on the proxy + TemplateMappingSearchDto criteria = TemplateMappingSearchDto.builder().build(); + List listResult = templateMappingServiceProxy.searchTemplateMappings(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchTemplateMappings(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(templateMappingsList, listResult); + } + + @Test + void shouldUseOpalTemplateMappingServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyTemplateMappingServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxyTest.java new file mode 100644 index 000000000..8269c97f0 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/TemplateServiceProxyTest.java @@ -0,0 +1,97 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.TemplateSearchDto; +import uk.gov.hmcts.opal.entity.TemplateEntity; +import uk.gov.hmcts.opal.service.TemplateServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyTemplateService; +import uk.gov.hmcts.opal.service.opal.TemplateService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class TemplateServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private TemplateService opalService; + + @Mock + private LegacyTemplateService legacyService; + + @InjectMocks + private TemplateServiceProxy templateServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(TemplateServiceInterface targetService, TemplateServiceInterface otherService) { + testGetTemplate(targetService, otherService); + testSearchTemplates(targetService, otherService); + } + + void testGetTemplate(TemplateServiceInterface targetService, TemplateServiceInterface otherService) { + // Given: a TemplateEntity is returned from the target service + TemplateEntity entity = TemplateEntity.builder().build(); + when(targetService.getTemplate(anyLong())).thenReturn(entity); + + // When: getTemplate is called on the proxy + TemplateEntity templateResult = templateServiceProxy.getTemplate(1); + + // Then: target service should be used, and the returned template should be as expected + verify(targetService).getTemplate(1); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, templateResult); + } + + void testSearchTemplates(TemplateServiceInterface targetService, TemplateServiceInterface otherService) { + // Given: a templates list result is returned from the target service + TemplateEntity entity = TemplateEntity.builder().build(); + List templatesList = List.of(entity); + when(targetService.searchTemplates(any())).thenReturn(templatesList); + + // When: searchTemplates is called on the proxy + TemplateSearchDto criteria = TemplateSearchDto.builder().build(); + List listResult = templateServiceProxy.searchTemplates(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchTemplates(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(templatesList, listResult); + } + + @Test + void shouldUseOpalTemplateServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyTemplateServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxyTest.java index a2915c75a..27863d1b3 100644 --- a/src/test/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxyTest.java +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/TillServiceProxyTest.java @@ -7,10 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import uk.gov.hmcts.opal.dto.AppMode; import uk.gov.hmcts.opal.dto.search.TillSearchDto; import uk.gov.hmcts.opal.entity.TillEntity; -import uk.gov.hmcts.opal.service.DynamicConfigService; +import uk.gov.hmcts.opal.service.TillServiceInterface; import uk.gov.hmcts.opal.service.legacy.LegacyTillService; import uk.gov.hmcts.opal.service.opal.TillService; @@ -22,18 +21,15 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; -class TillServiceProxyTest { +class TillServiceProxyTest extends ProxyTestsBase { private AutoCloseable closeable; @Mock - private TillService opalTillService; + private TillService opalService; @Mock - private LegacyTillService legacyTillService; - - @Mock - private DynamicConfigService dynamicConfigService; + private LegacyTillService legacyService; @InjectMocks private TillServiceProxy tillServiceProxy; @@ -48,63 +44,54 @@ void tearDown() throws Exception { closeable.close(); } - @Test - void shouldUseOpalTillServiceWhenModeIsNotLegacy() { - // Given: a TillEntity and the app mode is set to "opal" + void testMode(TillServiceInterface targetService, TillServiceInterface otherService) { + testGetTill(targetService, otherService); + testSearchTills(targetService, otherService); + } + + void testGetTill(TillServiceInterface targetService, TillServiceInterface otherService) { + // Given: a TillEntity is returned from the target service TillEntity entity = TillEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("opal").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(opalTillService.getTill(anyLong())).thenReturn(entity); + when(targetService.getTill(anyLong())).thenReturn(entity); - // When: saveTill is called on the proxy + // When: getTill is called on the proxy TillEntity tillResult = tillServiceProxy.getTill(1); - // Then: opalTillService should be used, and the returned till should be as expected - verify(opalTillService).getTill(1); - verifyNoInteractions(legacyTillService); + // Then: target service should be used, and the returned till should be as expected + verify(targetService).getTill(1); + verifyNoInteractions(otherService); Assertions.assertEquals(entity, tillResult); + } - // Given: a tills list result and the app mode is set to "opal" + void testSearchTills(TillServiceInterface targetService, TillServiceInterface otherService) { + // Given: a tills list result is returned from the target service + TillEntity entity = TillEntity.builder().build(); List tillsList = List.of(entity); - when(opalTillService.searchTills(any())).thenReturn(tillsList); + when(targetService.searchTills(any())).thenReturn(tillsList); // When: searchTills is called on the proxy TillSearchDto criteria = TillSearchDto.builder().build(); List listResult = tillServiceProxy.searchTills(criteria); - // Then: opalTillService should be used, and the returned list should be as expected - verify(opalTillService).searchTills(criteria); - verifyNoInteractions(legacyTillService); + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchTills(criteria); + verifyNoInteractions(otherService); Assertions.assertEquals(tillsList, listResult); } @Test - void shouldUseLegacyTillServiceWhenModeIsLegacy() { - // Given: a TillEntity and the app mode is set to "legacy" - TillEntity entity = TillEntity.builder().build(); - AppMode appMode = AppMode.builder().mode("legacy").build(); - when(dynamicConfigService.getAppMode()).thenReturn(appMode); - when(legacyTillService.getTill(anyLong())).thenReturn(entity); - - // When: saveTill is called on the proxy - TillEntity result = tillServiceProxy.getTill(1); - - // Then: legacyTillService should be used, and the returned till should be as expected - verify(legacyTillService).getTill(1); - verifyNoInteractions(opalTillService); - Assertions.assertEquals(entity, result); - - // Given: a tills list result and the app mode is set to "legacy" - List tillsList = List.of(entity); - when(legacyTillService.searchTills(any())).thenReturn(tillsList); - - // When: searchTills is called on the proxy - TillSearchDto criteria = TillSearchDto.builder().build(); - List listResult = tillServiceProxy.searchTills(criteria); + void shouldUseOpalTillServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } - // Then: opalTillService should be used, and the returned list should be as expected - verify(legacyTillService).searchTills(criteria); - verifyNoInteractions(opalTillService); - Assertions.assertEquals(tillsList, listResult); // Not yet implemented in Legacy mode + @Test + void shouldUseLegacyTillServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); } } diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxyTest.java new file mode 100644 index 000000000..147cfc75a --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/UserEntitlementServiceProxyTest.java @@ -0,0 +1,99 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.UserEntitlementSearchDto; +import uk.gov.hmcts.opal.entity.UserEntitlementEntity; +import uk.gov.hmcts.opal.service.UserEntitlementServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyUserEntitlementService; +import uk.gov.hmcts.opal.service.opal.UserEntitlementService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class UserEntitlementServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private UserEntitlementService opalService; + + @Mock + private LegacyUserEntitlementService legacyService; + + @InjectMocks + private UserEntitlementServiceProxy userEntitlementServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(UserEntitlementServiceInterface targetService, UserEntitlementServiceInterface otherService) { + testGetUserEntitlement(targetService, otherService); + testSearchUserEntitlements(targetService, otherService); + } + + void testGetUserEntitlement(UserEntitlementServiceInterface targetService, + UserEntitlementServiceInterface otherService) { + // Given: a UserEntitlementEntity is returned from the target service + UserEntitlementEntity entity = UserEntitlementEntity.builder().build(); + when(targetService.getUserEntitlement(anyLong())).thenReturn(entity); + + // When: getUserEntitlement is called on the proxy + UserEntitlementEntity userEntitlementResult = userEntitlementServiceProxy.getUserEntitlement(1); + + // Then: target service should be used, and the returned userEntitlement should be as expected + verify(targetService).getUserEntitlement(1); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, userEntitlementResult); + } + + void testSearchUserEntitlements(UserEntitlementServiceInterface targetService, + UserEntitlementServiceInterface otherService) { + // Given: a userEntitlements list result is returned from the target service + UserEntitlementEntity entity = UserEntitlementEntity.builder().build(); + List userEntitlementsList = List.of(entity); + when(targetService.searchUserEntitlements(any())).thenReturn(userEntitlementsList); + + // When: searchUserEntitlements is called on the proxy + UserEntitlementSearchDto criteria = UserEntitlementSearchDto.builder().build(); + List listResult = userEntitlementServiceProxy.searchUserEntitlements(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchUserEntitlements(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(userEntitlementsList, listResult); + } + + @Test + void shouldUseOpalUserEntitlementServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyUserEntitlementServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +} diff --git a/src/test/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxyTest.java b/src/test/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxyTest.java new file mode 100644 index 000000000..b7f49822f --- /dev/null +++ b/src/test/java/uk/gov/hmcts/opal/service/proxy/UserServiceProxyTest.java @@ -0,0 +1,97 @@ +package uk.gov.hmcts.opal.service.proxy; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import uk.gov.hmcts.opal.dto.search.UserSearchDto; +import uk.gov.hmcts.opal.entity.UserEntity; +import uk.gov.hmcts.opal.service.UserServiceInterface; +import uk.gov.hmcts.opal.service.legacy.LegacyUserService; +import uk.gov.hmcts.opal.service.opal.UserService; + +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +class UserServiceProxyTest extends ProxyTestsBase { + + private AutoCloseable closeable; + + @Mock + private UserService opalService; + + @Mock + private LegacyUserService legacyService; + + @InjectMocks + private UserServiceProxy userServiceProxy; + + @BeforeEach + void setUp() { + closeable = MockitoAnnotations.openMocks(this); + } + + @AfterEach + void tearDown() throws Exception { + closeable.close(); + } + + void testMode(UserServiceInterface targetService, UserServiceInterface otherService) { + testGetUser(targetService, otherService); + testSearchUsers(targetService, otherService); + } + + void testGetUser(UserServiceInterface targetService, UserServiceInterface otherService) { + // Given: a UserEntity is returned from the target service + UserEntity entity = UserEntity.builder().build(); + when(targetService.getUser(anyString())).thenReturn(entity); + + // When: getUser is called on the proxy + UserEntity userResult = userServiceProxy.getUser("1"); + + // Then: target service should be used, and the returned user should be as expected + verify(targetService).getUser("1"); + verifyNoInteractions(otherService); + Assertions.assertEquals(entity, userResult); + } + + void testSearchUsers(UserServiceInterface targetService, UserServiceInterface otherService) { + // Given: a users list result is returned from the target service + UserEntity entity = UserEntity.builder().build(); + List usersList = List.of(entity); + when(targetService.searchUsers(any())).thenReturn(usersList); + + // When: searchUsers is called on the proxy + UserSearchDto criteria = UserSearchDto.builder().build(); + List listResult = userServiceProxy.searchUsers(criteria); + + // Then: target service should be used, and the returned list should be as expected + verify(targetService).searchUsers(criteria); + verifyNoInteractions(otherService); + Assertions.assertEquals(usersList, listResult); + } + + @Test + void shouldUseOpalUserServiceWhenModeIsNotLegacy() { + // Given: app mode is set + setMode(OPAL); + // Then: the target service is called, but the other service is not + testMode(opalService, legacyService); + } + + @Test + void shouldUseLegacyUserServiceWhenModeIsLegacy() { + // Given: app mode is set + setMode(LEGACY); + // Then: the target service is called, but the other service is not + testMode(legacyService, opalService); + } +}