diff --git a/build.gradle b/build.gradle index f6c7d7bc93..a5754b96f7 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,9 @@ plugins { id 'io.spring.dependency-management' version '1.1.5' id 'org.springframework.boot' version '3.2.5' id 'com.github.ben-manes.versions' version '0.50.0' - id 'hmcts.ccd.sdk' version '5.5.2' + id 'hmcts.ccd.sdk' version '5.5.10' id "au.com.dius.pact" version "4.3.10" - id 'com.github.hmcts.rse-cft-lib' version '0.19.1253' + id 'com.github.hmcts.rse-cft-lib' version '0.19.1307' } apply plugin: 'cz.habarta.typescript-generator' @@ -393,7 +393,7 @@ dependencyManagement { } //CVE-2022-31692, CVE-2022-31690 - dependencySet(group: 'org.springframework.security', version: '6.2.2'){ + dependencySet(group: 'org.springframework.security', version: '6.2.4'){ entry 'spring-security-core' entry 'spring-security-acl' entry 'spring-security-aspects' @@ -417,7 +417,7 @@ dependencyManagement { } //Override spring-security-rsa version and update org.bouncycastle:bcpkix-jdk18on for CVE-2023-33202 - dependency group:'org.springframework.security', name: 'spring-security-rsa', version: '1.1.1' + dependency group:'org.springframework.security', name: 'spring-security-rsa', version: '1.1.3' dependency group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: '1.77' dependency group: 'org.camunda.connect', name: 'camunda-connect-connectors-all', version: '1.6.0' @@ -438,7 +438,7 @@ def versions = [ jackson : '2.16.0', junit : '5.10.3', junitPlatform : '1.10.3', - lombok : '1.18.32', + lombok : '1.18.34', pact : '4.1.34', springBoot : springBoot.class.package.implementationVersion ] @@ -470,20 +470,20 @@ dependencies { implementation 'io.swagger:swagger-annotations:1.6.14' implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' - implementation group: 'org.apache.groovy', name: 'groovy', version: '4.0.21' - implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.4.12' - implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.4.12' + implementation group: 'org.apache.groovy', name: 'groovy', version: '4.0.22' + implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6' + implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.5.6' implementation group: 'com.github.hmcts', name: 'ccd-client', version: '4.9.2' implementation group: 'com.github.hmcts', name:'ccd-case-document-am-client', version: '1.59' implementation group: 'com.github.hmcts', name: 'idam-java-client', version: '3.0.3' implementation group: 'com.github.hmcts', name: 'java-logging', version: '6.1.5' - implementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: '5.1.2' + implementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: '5.1.3' implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.4' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.22.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: '2.22.0' - implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.24' - implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-websocket', version: '10.1.20' - implementation group: 'org.elasticsearch', name: 'elasticsearch' , version: '7.17.6' + implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '10.1.26' + implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-websocket', version: '10.1.23' + implementation group: 'org.elasticsearch', name: 'elasticsearch' , version: '7.17.22' implementation group: 'org.projectlombok', name: 'lombok', version: versions.lombok implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.3.0' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' @@ -506,7 +506,7 @@ dependencies { implementation 'org.camunda.bpm:camunda-external-task-client:7.21.0' annotationProcessor group: 'org.projectlombok', name: 'lombok', version: versions.lombok - testImplementation 'com.github.hmcts:fortify-client:1.3.0:all' + testImplementation 'com.github.hmcts:fortify-client:1.4.3:all' testImplementation libraries.junit5 testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', { @@ -548,8 +548,7 @@ dependencies { functionalTestImplementation group: 'com.github.hmcts', name: 'document-management-client', version: '7.0.1' functionalTestImplementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: '5.1.2' - contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'junit5', version: '4.1.41' - contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'java8', version: '4.1.43' + contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'junit5', version: '4.6.11' contractTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.3' contractTestRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.3' contractTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.3' diff --git a/src/contractTest/java/uk.gov.hmcts.sptribs/IdamConsumerTest.java b/src/contractTest/java/uk.gov.hmcts.sptribs/IdamConsumerTest.java index d72a123141..40803be39c 100644 --- a/src/contractTest/java/uk.gov.hmcts.sptribs/IdamConsumerTest.java +++ b/src/contractTest/java/uk.gov.hmcts.sptribs/IdamConsumerTest.java @@ -1,11 +1,11 @@ package uk.gov.hmcts.sptribs; import au.com.dius.pact.consumer.MockServer; -import au.com.dius.pact.consumer.dsl.DslPart; +import au.com.dius.pact.consumer.dsl.PactDslJsonBody; import au.com.dius.pact.consumer.dsl.PactDslWithProvider; import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; import au.com.dius.pact.consumer.junit5.PactTestFor; -import au.com.dius.pact.core.model.RequestResponsePact; +import au.com.dius.pact.core.model.V4Pact; import au.com.dius.pact.core.model.annotations.Pact; import au.com.dius.pact.core.model.annotations.PactDirectory; import io.restassured.RestAssured; @@ -19,7 +19,6 @@ import java.util.Map; -import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonBody; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpStatus.OK; @@ -27,10 +26,11 @@ @ExtendWith(SpringExtension.class) @PactDirectory("pacts") class IdamConsumerTest { + private static final String IDAM_USER_DETAILS = "/details"; @Pact(provider = "idam_user_details", consumer = "sptribs-case-api") - RequestResponsePact executeIdamUserDetailApi(PactDslWithProvider builder) { + V4Pact executeIdamUserDetailApi(PactDslWithProvider builder) { Map responseHeaders = Map.of(HttpHeaders.AUTHORIZATION, "Bearer UserAuthToken"); return builder @@ -42,13 +42,12 @@ RequestResponsePact executeIdamUserDetailApi(PactDslWithProvider builder) { .status(OK.value()) .headers(responseHeaders) .body(createAuthResponse()) - .toPact(); + .toPact(V4Pact.class); } @Test @PactTestFor(pactMethod = "executeIdamUserDetailApi") void shouldReceiveUserDetails(MockServer mockServer) { - String responseBody = RestAssured .given() .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE) @@ -65,13 +64,15 @@ void shouldReceiveUserDetails(MockServer mockServer) { Assertions.assertThat(response).isNotNull(); } - private DslPart createAuthResponse() { - return newJsonBody((o) -> o.stringType("id", - "123432") + private PactDslJsonBody createAuthResponse() { + return new PactDslJsonBody() + .stringType("id", "123432") .stringType("forename", "Joe") .stringType("surname", "Bloggs") .stringType("email", "joe.bloggs@hmcts.net") .booleanType("active", true) - .array("roles", role -> role.stringType("caseworker").stringType("citizen"))).build(); + .minArrayLike("roles", 2) + .stringType("caseworker") + .stringType("citizen"); } } diff --git a/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/ExtendedCaseDetails.java b/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/ExtendedCaseDetails.java index 952cc71702..ec2c456272 100644 --- a/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/ExtendedCaseDetails.java +++ b/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/ExtendedCaseDetails.java @@ -8,7 +8,6 @@ import java.util.Map; - @Data @Builder(toBuilder = true) @JsonIgnoreProperties(ignoreUnknown = true) @@ -17,7 +16,6 @@ public class ExtendedCaseDetails { private Long id; - @JsonProperty("data_classification") + @JsonProperty("dataClassification") private Map dataClassification; } - diff --git a/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/HearingDate.java b/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/HearingDate.java index 9ffe1cc079..f0174cc049 100644 --- a/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/HearingDate.java +++ b/src/main/java/uk/gov/hmcts/sptribs/ciccase/model/HearingDate.java @@ -39,8 +39,8 @@ public class HearingDate { @JsonCreator public HearingDate(@JsonProperty("hearingVenueDate") LocalDate hearingVenueDate, - @JsonProperty("session") HearingSession hearingVenueSession, - @JsonProperty("hearingTime") String hearingVenueTime) { + @JsonProperty("hearingVenueSession") HearingSession hearingVenueSession, + @JsonProperty("hearingVenueTime") String hearingVenueTime) { this.hearingVenueDate = hearingVenueDate; this.hearingVenueSession = hearingVenueSession; this.hearingVenueTime = hearingVenueTime; diff --git a/src/main/java/uk/gov/hmcts/sptribs/common/config/jackson/JacksonConfiguration.java b/src/main/java/uk/gov/hmcts/sptribs/common/config/jackson/JacksonConfiguration.java index c55a6c374b..212eeb3978 100644 --- a/src/main/java/uk/gov/hmcts/sptribs/common/config/jackson/JacksonConfiguration.java +++ b/src/main/java/uk/gov/hmcts/sptribs/common/config/jackson/JacksonConfiguration.java @@ -1,19 +1,22 @@ package uk.gov.hmcts.sptribs.common.config.jackson; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import uk.gov.hmcts.ccd.sdk.api.HasRole; import uk.gov.hmcts.reform.ccd.document.am.healthcheck.InternalHealth; +import static com.fasterxml.jackson.annotation.JsonCreator.Mode.PROPERTIES; +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; +import static com.fasterxml.jackson.core.JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION; import static com.fasterxml.jackson.databind.MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS; import static com.fasterxml.jackson.databind.MapperFeature.INFER_BUILDER_TYPE_BINDINGS; +import static com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer.INSTANCE; @Configuration public class JacksonConfiguration { @@ -24,7 +27,7 @@ public ObjectMapper getMapper() { ObjectMapper mapper = JsonMapper.builder() .configure(ACCEPT_CASE_INSENSITIVE_ENUMS, true) .enable(INFER_BUILDER_TYPE_BINDINGS) - .serializationInclusion(JsonInclude.Include.NON_NULL) + .serializationInclusion(NON_NULL) .build(); SimpleModule deserialization = new SimpleModule(); @@ -33,8 +36,10 @@ public ObjectMapper getMapper() { mapper.registerModule(deserialization); JavaTimeModule datetime = new JavaTimeModule(); - datetime.addSerializer(LocalDateSerializer.INSTANCE); + datetime.addSerializer(INSTANCE); mapper.registerModule(datetime); + mapper.registerModule(new ParameterNamesModule(PROPERTIES)); + mapper.enable(INCLUDE_SOURCE_IN_LOCATION); return mapper; } diff --git a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicCreateCaseEventTest.java b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicCreateCaseEventTest.java index 107703d4dd..4f34e17518 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicCreateCaseEventTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicCreateCaseEventTest.java @@ -6,9 +6,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse; @@ -25,11 +22,7 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_CASE_ID; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; - @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class CicCreateCaseEventTest { @InjectMocks diff --git a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicSubmitCaseEventTest.java b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicSubmitCaseEventTest.java index 5918e7c261..f3859a5397 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicSubmitCaseEventTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicSubmitCaseEventTest.java @@ -11,9 +11,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl; import uk.gov.hmcts.ccd.sdk.api.CaseDetails; import uk.gov.hmcts.ccd.sdk.api.Event; @@ -65,9 +62,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith({MockitoExtension.class}) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class CicSubmitCaseEventTest { final ConfigBuilderImpl configBuilder = createCaseDataConfigBuilder(); diff --git a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicUpdateCaseEventTest.java b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicUpdateCaseEventTest.java index 79ccae8589..936e84ff89 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicUpdateCaseEventTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/citizen/event/CicUpdateCaseEventTest.java @@ -6,9 +6,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl; import uk.gov.hmcts.ccd.sdk.api.Event; @@ -28,9 +25,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASE_DATA_CIC_ID; @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class CicUpdateCaseEventTest { @InjectMocks private CicUpdateCaseEvent cicUpdateCaseEvent; diff --git a/src/test/java/uk/gov/hmcts/sptribs/controllers/CaseManagementControllerTest.java b/src/test/java/uk/gov/hmcts/sptribs/controllers/CaseManagementControllerTest.java index eb96973b21..91e5c3b145 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/controllers/CaseManagementControllerTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/controllers/CaseManagementControllerTest.java @@ -9,10 +9,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.ciccase.model.CaseData; import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData; @@ -43,9 +41,8 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith(SpringExtension.class) -@SpringBootTest -@ActiveProfiles("test") class CaseManagementControllerTest { + private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); @InjectMocks diff --git a/src/test/java/uk/gov/hmcts/sptribs/controllers/DocumentManagementControllerTest.java b/src/test/java/uk/gov/hmcts/sptribs/controllers/DocumentManagementControllerTest.java index f5236c08b2..524be5de3d 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/controllers/DocumentManagementControllerTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/controllers/DocumentManagementControllerTest.java @@ -7,12 +7,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.exception.DocumentUploadOrDeleteException; import uk.gov.hmcts.sptribs.model.DocumentInfo; @@ -40,11 +37,7 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_URL; import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; - @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class DocumentManagementControllerTest { @InjectMocks diff --git a/src/test/java/uk/gov/hmcts/sptribs/exception/CaseCreateOrUpdateExceptionTest.java b/src/test/java/uk/gov/hmcts/sptribs/exception/CaseCreateOrUpdateExceptionTest.java index a56c365da7..f56f1c6681 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/exception/CaseCreateOrUpdateExceptionTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/exception/CaseCreateOrUpdateExceptionTest.java @@ -8,8 +8,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.ciccase.model.CaseData; import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData; @@ -32,8 +30,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith(SpringExtension.class) -@SpringBootTest -@ActiveProfiles("test") class CaseCreateOrUpdateExceptionTest { private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); @@ -51,7 +47,6 @@ void setUp() { @Test void createCaseDataCaseCreateUpdateException() throws IOException { - final String createCaseTestAuth = CASE_TEST_AUTHORIZATION; final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final DssCaseData dssCaseData = mapper.readValue(caseDataJson, DssCaseData.class); @@ -69,7 +64,6 @@ void createCaseDataCaseCreateUpdateException() throws IOException { @Test void updateCaseDataCaseCreateUpdateException() throws IOException { - final String updateCaseTestAuth = CASE_TEST_AUTHORIZATION; final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -87,7 +81,6 @@ void updateCaseDataCaseCreateUpdateException() throws IOException { @Test void fetchCaseDataCaseCreateUpdateException() { - final String fetchCaseTestAuth = CASE_TEST_AUTHORIZATION; when(caseManagementService.fetchCaseDetails(fetchCaseTestAuth,TEST_CASE_ID)) diff --git a/src/test/java/uk/gov/hmcts/sptribs/exception/DocumentUploadOrDeleteExceptionTest.java b/src/test/java/uk/gov/hmcts/sptribs/exception/DocumentUploadOrDeleteExceptionTest.java index 9285c05da5..a62152dda0 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/exception/DocumentUploadOrDeleteExceptionTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/exception/DocumentUploadOrDeleteExceptionTest.java @@ -6,9 +6,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.controllers.DocumentManagementController; import uk.gov.hmcts.sptribs.model.DocumentInfo; @@ -30,10 +28,7 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_URL; import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; - @ExtendWith(SpringExtension.class) -@SpringBootTest -@ActiveProfiles("test") class DocumentUploadOrDeleteExceptionTest { private DocumentInfo documentInfo; @@ -47,7 +42,6 @@ class DocumentUploadOrDeleteExceptionTest { @BeforeEach public void setUp() { MockitoAnnotations.openMocks(this); - } @Test @@ -78,7 +72,6 @@ void deleteDocumentUploadOrDeleteException() { @Test void updateDocumentUploadOrDeleteException() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); documentInfo = DocumentInfo.builder() diff --git a/src/test/java/uk/gov/hmcts/sptribs/services/CaseManagementServiceTest.java b/src/test/java/uk/gov/hmcts/sptribs/services/CaseManagementServiceTest.java index cdfd9c7677..2e0b37c886 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/services/CaseManagementServiceTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/services/CaseManagementServiceTest.java @@ -8,9 +8,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; @@ -47,9 +44,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class CaseManagementServiceTest { private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); @@ -65,9 +59,6 @@ class CaseManagementServiceTest { @Mock private AppsConfig.AppsDetails cicAppDetail; - @Mock - private AppsUtil appsUtil; - @Mock CaseApiService caseApiService; @@ -130,7 +121,7 @@ void shouldCreateCaseCicFailsWhenCaseTypeIsInvalid() throws Exception { final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); final DssCaseData dssCaseData = DssCaseData.builder().caseTypeOfApplication(CASE_DATA_CIC_ID).build(); - when(appsUtil.isValidCaseTypeOfApplication(appsConfig,dssCaseData)) + when(AppsUtil.isValidCaseTypeOfApplication(appsConfig,dssCaseData)) .thenThrow(new CaseCreateOrUpdateException("Invalid Case type application. Please check the request.")); final CaseCreateOrUpdateException caseCreateOrUpdateException = @@ -273,7 +264,7 @@ void shouldUpdateCaseCicFailsWhenCaseTypeIsInvalid() throws Exception { final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); final DssCaseData dssCaseData = DssCaseData.builder().caseTypeOfApplication(CASE_DATA_CIC_ID).build(); - when(appsUtil.isValidCaseTypeOfApplication(appsConfig,dssCaseData)) + when(AppsUtil.isValidCaseTypeOfApplication(appsConfig,dssCaseData)) .thenThrow(new CaseCreateOrUpdateException("Invalid Case type application. Please check the request.")); final CaseCreateOrUpdateException caseCreateOrUpdateException = diff --git a/src/test/java/uk/gov/hmcts/sptribs/services/DocumentManagementServiceTest.java b/src/test/java/uk/gov/hmcts/sptribs/services/DocumentManagementServiceTest.java index a44f78c0d8..4d12e2c86c 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/services/DocumentManagementServiceTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/services/DocumentManagementServiceTest.java @@ -6,10 +6,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.common.config.AppsConfig; import uk.gov.hmcts.sptribs.constants.CommonConstants; @@ -39,12 +36,9 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_URL; import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; - @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class DocumentManagementServiceTest { + @InjectMocks private DocumentManagementService documentManagementService; @@ -60,7 +54,6 @@ class DocumentManagementServiceTest { @BeforeEach public void setUp() { MockitoAnnotations.openMocks(this); - } @Test @@ -118,7 +111,6 @@ void shouldUploadFgmDocument() throws Exception { @Test void shouldUploadFgmDocumentFailedWithException() throws Exception { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final MockMultipartFile multipartFile = new MockMultipartFile( @@ -167,7 +159,6 @@ void shouldDeleteDocument() { verify(caseDocumentApiService, times(1)) .deleteDocument(CASE_TEST_AUTHORIZATION, documentInfo.getDocumentId()); - } @Test @@ -195,6 +186,5 @@ void shouldDeleteFgmDocumentFailedWithException() { assertNotNull(documentUploadOrDeleteException.getCause()); assertTrue(documentUploadOrDeleteException.getCause() instanceof RuntimeException); assertTrue(documentUploadOrDeleteException.getMessage().contains(DOCUMENT_DELETE_FAILURE_MSG)); - } } diff --git a/src/test/java/uk/gov/hmcts/sptribs/services/ccd/CaseApiServiceTest.java b/src/test/java/uk/gov/hmcts/sptribs/services/ccd/CaseApiServiceTest.java index e4a17c8c7e..4a9e7da4f7 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/services/ccd/CaseApiServiceTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/services/ccd/CaseApiServiceTest.java @@ -8,10 +8,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; import uk.gov.hmcts.reform.ccd.client.CoreCaseDataApi; @@ -23,9 +19,11 @@ import uk.gov.hmcts.reform.idam.client.models.UserDetails; import uk.gov.hmcts.sptribs.ciccase.model.CaseData; import uk.gov.hmcts.sptribs.common.config.AppsConfig; +import uk.gov.hmcts.sptribs.constants.CommonConstants; import uk.gov.hmcts.sptribs.idam.IdamService; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -33,6 +31,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CITIZEN_CIC_CREATE_CASE; +import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CITIZEN_CIC_SUBMIT_CASE; +import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CITIZEN_CIC_UPDATE_CASE; +import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CITIZEN_DSS_UPDATE_CASE_SUBMISSION; import static uk.gov.hmcts.sptribs.constants.CommonConstants.ST_CIC_CASE_TYPE; import static uk.gov.hmcts.sptribs.constants.CommonConstants.ST_CIC_JURISDICTION; import static uk.gov.hmcts.sptribs.controllers.model.DssCaseDataRequest.convertDssCaseDataToRequest; @@ -44,17 +46,12 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_CASE_ID; import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_USER; import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; -import static uk.gov.hmcts.sptribs.util.AppsUtil.getExactAppsDetailsByCaseType; - @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") class CaseApiServiceTest { + private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); private static final String TEST_CASE_REFERENCE = "123"; - private AppsConfig.AppsDetails cicAppDetails; @InjectMocks private CaseApiService caseApiService; @@ -74,8 +71,8 @@ class CaseApiServiceTest { @Mock IdamService idamService; - @Autowired - AppsConfig appsConfig; + @Mock + private AppsConfig.AppsDetails cicAppDetails; @Mock CoreCaseDataApi coreCaseDataApi; @@ -83,12 +80,22 @@ class CaseApiServiceTest { @BeforeEach public void setUp() { MockitoAnnotations.openMocks(this); - cicAppDetails = appsConfig.getApps().stream().filter(eachApps -> eachApps.getCaseTypeOfApplication().contains( - CASE_DATA_CIC_ID)).findAny().orElse(null); + + cicAppDetails = new AppsConfig.AppsDetails(); + cicAppDetails.setCaseType(CommonConstants.ST_CIC_CASE_TYPE); + cicAppDetails.setJurisdiction(CommonConstants.ST_CIC_JURISDICTION); + cicAppDetails.setCaseTypeOfApplication(List.of(CASE_DATA_CIC_ID)); + + final AppsConfig.EventsConfig eventsConfig = new AppsConfig.EventsConfig(); + eventsConfig.setCreateEvent(CITIZEN_CIC_CREATE_CASE); + eventsConfig.setSubmitEvent(CITIZEN_CIC_SUBMIT_CASE); + eventsConfig.setUpdateEvent(CITIZEN_CIC_UPDATE_CASE); + eventsConfig.setUpdateCaseEvent(CITIZEN_DSS_UPDATE_CASE_SUBMISSION); + cicAppDetails.setEventIds(eventsConfig); } @Test - void shouldfgmCreateCaseData() throws Exception { + void shouldCreateCaseData() throws Exception { final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -102,7 +109,7 @@ void shouldfgmCreateCaseData() throws Exception { .build(); eventRes = StartEventResponse.builder() - .eventId(getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getSubmitEvent()) + .eventId(CITIZEN_CIC_SUBMIT_CASE) .caseDetails(caseDetail) .token(TEST_AUTHORIZATION_TOKEN) .build(); @@ -121,15 +128,12 @@ void shouldfgmCreateCaseData() throws Exception { TEST_USER, ST_CIC_JURISDICTION, ST_CIC_CASE_TYPE, - getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getCreateEvent() + CITIZEN_CIC_CREATE_CASE )).thenReturn(eventRes); final CaseDataContent caseDataContent = CaseDataContent.builder() .data(caseData) - .event(Event.builder().id(getExactAppsDetailsByCaseType( - appsConfig, - ST_CIC_CASE_TYPE - ).getEventIds().getCreateEvent()).build()) + .event(Event.builder().id(CITIZEN_CIC_CREATE_CASE).build()) .eventToken(TEST_AUTHORIZATION_TOKEN) .build(); @@ -154,7 +158,6 @@ void shouldfgmCreateCaseData() throws Exception { @Test void shouldUpdateCaseData() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -168,7 +171,7 @@ void shouldUpdateCaseData() throws IOException { .build(); eventRes = StartEventResponse.builder() - .eventId(getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getUpdateEvent()) + .eventId(CITIZEN_CIC_UPDATE_CASE) .caseDetails(caseDetail) .token(TEST_AUTHORIZATION_TOKEN) .build(); @@ -188,15 +191,12 @@ void shouldUpdateCaseData() throws IOException { ST_CIC_JURISDICTION, ST_CIC_CASE_TYPE, TEST_CASE_ID.toString(), - getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getUpdateEvent() + CITIZEN_CIC_UPDATE_CASE )).thenReturn(eventRes); final CaseDataContent caseDataContent = CaseDataContent.builder() .data(convertDssCaseDataToRequest(caseData.getDssCaseData())) - .event(Event.builder().id(getExactAppsDetailsByCaseType( - appsConfig, - ST_CIC_CASE_TYPE - ).getEventIds().getUpdateEvent()).build()) + .event(Event.builder().id(CITIZEN_CIC_UPDATE_CASE).build()) .eventToken(TEST_AUTHORIZATION_TOKEN) .build(); @@ -227,7 +227,6 @@ void shouldUpdateCaseData() throws IOException { @Test void shouldGetEventToken() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -241,7 +240,7 @@ void shouldGetEventToken() throws IOException { .build(); eventRes = StartEventResponse.builder() - .eventId(getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getCreateEvent()) + .eventId(CITIZEN_CIC_CREATE_CASE) .caseDetails(caseDetail) .token(TEST_AUTHORIZATION_TOKEN) .build(); @@ -252,7 +251,7 @@ void shouldGetEventToken() throws IOException { TEST_USER, ST_CIC_JURISDICTION, ST_CIC_CASE_TYPE, - getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getCreateEvent() + CITIZEN_CIC_CREATE_CASE )).thenReturn(eventRes); final String result = caseApiService.getEventToken( @@ -270,7 +269,6 @@ void shouldGetEventToken() throws IOException { @Test void shouldGetEventTokenForUpdate() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -284,7 +282,7 @@ void shouldGetEventTokenForUpdate() throws IOException { .build(); eventRes = StartEventResponse.builder() - .eventId(getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getUpdateEvent()) + .eventId(CITIZEN_CIC_UPDATE_CASE) .caseDetails(caseDetail) .token(TEST_AUTHORIZATION_TOKEN) .build(); @@ -296,7 +294,7 @@ void shouldGetEventTokenForUpdate() throws IOException { ST_CIC_JURISDICTION, ST_CIC_CASE_TYPE, TEST_CASE_ID.toString(), - getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getUpdateEvent() + CITIZEN_CIC_UPDATE_CASE )).thenReturn(eventRes); final String result = caseApiService.getEventTokenForUpdate( @@ -313,7 +311,6 @@ void shouldGetEventTokenForUpdate() throws IOException { @Test void shouldUpdateCaseDataWithSubmitEvent() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final CaseData caseData = mapper.readValue(caseDataJson, CaseData.class); @@ -327,7 +324,7 @@ void shouldUpdateCaseDataWithSubmitEvent() throws IOException { .build(); eventRes = StartEventResponse.builder() - .eventId(getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getSubmitEvent()) + .eventId(CITIZEN_CIC_SUBMIT_CASE) .caseDetails(caseDetail) .token(TEST_AUTHORIZATION_TOKEN) .build(); @@ -347,15 +344,12 @@ void shouldUpdateCaseDataWithSubmitEvent() throws IOException { ST_CIC_JURISDICTION, ST_CIC_CASE_TYPE, TEST_CASE_ID.toString(), - getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE).getEventIds().getSubmitEvent() + CITIZEN_CIC_SUBMIT_CASE )).thenReturn(eventRes); final CaseDataContent caseDataContent = CaseDataContent.builder() .data(convertDssCaseDataToRequest(caseData.getDssCaseData())) - .event(Event.builder().id(getExactAppsDetailsByCaseType( - appsConfig, - ST_CIC_CASE_TYPE - ).getEventIds().getSubmitEvent()).build()) + .event(Event.builder().id(CITIZEN_CIC_SUBMIT_CASE).build()) .eventToken(TEST_AUTHORIZATION_TOKEN) .build(); @@ -431,21 +425,21 @@ void verifyDssUpdateCaseSubmissionEventIsStartedForCitizen() throws IOException StartEventResponse startEventResponse = StartEventResponse.builder() .caseDetails(caseDetail) - .eventId("citizen-cic-dss-update-case") - .token("event token") + .eventId(CITIZEN_CIC_UPDATE_CASE) + .token(TEST_AUTHORIZATION_TOKEN) .build(); when(idamService.retrieveUser(CASE_TEST_AUTHORIZATION)).thenReturn(user); when(user.getUserDetails()).thenReturn(userDetails); when(userDetails.getId()).thenReturn(TEST_USER); when(coreCaseDataApi.startEventForCitizen( - "testAuth", + CASE_TEST_AUTHORIZATION, authTokenGenerator.generate(), - "TestUser", - "ST_CIC", - "CriminalInjuriesCompensation", + TEST_USER, + ST_CIC_JURISDICTION, + ST_CIC_CASE_TYPE, TEST_CASE_ID.toString(), - "citizen-cic-dss-update-case") + CITIZEN_DSS_UPDATE_CASE_SUBMISSION) ).thenReturn(startEventResponse); caseApiService.updateCase( @@ -457,13 +451,13 @@ void verifyDssUpdateCaseSubmissionEventIsStartedForCitizen() throws IOException ); verify(coreCaseDataApi).startEventForCitizen( - "testAuth", + CASE_TEST_AUTHORIZATION, authTokenGenerator.generate(), - "TestUser", - "ST_CIC", - "CriminalInjuriesCompensation", + TEST_USER, + ST_CIC_JURISDICTION, + ST_CIC_CASE_TYPE, TEST_CASE_ID.toString(), - "citizen-cic-dss-update-case" + CITIZEN_DSS_UPDATE_CASE_SUBMISSION ); } } diff --git a/src/test/java/uk/gov/hmcts/sptribs/services/cdam/CaseDocumentApiServiceTest.java b/src/test/java/uk/gov/hmcts/sptribs/services/cdam/CaseDocumentApiServiceTest.java index 5c58b9af7c..9dbaf3ed1d 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/services/cdam/CaseDocumentApiServiceTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/services/cdam/CaseDocumentApiServiceTest.java @@ -6,9 +6,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; @@ -39,8 +37,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith(SpringExtension.class) -@SpringBootTest -@ActiveProfiles("test") class CaseDocumentApiServiceTest { @InjectMocks @@ -59,7 +55,6 @@ public void setUp() { @Test void shouldUploadDocuments() throws Exception { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final MockMultipartFile multipartFile = new MockMultipartFile( @@ -132,7 +127,6 @@ void shouldUploadDocuments() throws Exception { @Test void shouldDeleteDocument() { - final DocumentInfo documentInfo = DocumentInfo.builder() .documentId(UUID.randomUUID().toString()) .url(TEST_URL) diff --git a/src/test/java/uk/gov/hmcts/sptribs/services/cdam/DssCaseDocumentClientTest.java b/src/test/java/uk/gov/hmcts/sptribs/services/cdam/DssCaseDocumentClientTest.java index fb40a4b3cb..c4690aabf1 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/services/cdam/DssCaseDocumentClientTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/services/cdam/DssCaseDocumentClientTest.java @@ -4,10 +4,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.multipart.MultipartFile; import uk.gov.hmcts.reform.ccd.document.am.model.Classification; @@ -34,9 +31,6 @@ import static uk.gov.hmcts.sptribs.testutil.TestFileUtil.loadJson; @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@ActiveProfiles("test") public class DssCaseDocumentClientTest { @InjectMocks @@ -47,23 +41,19 @@ public class DssCaseDocumentClientTest { @Test public void shouldUploadDocuments() { - // Given final UploadResponse response = new UploadResponse(); when(caseDocumentClientApi.uploadDocuments(eq("authorisation"), eq("serviceAuthorisation"), any(DocumentUploadRequest.class))).thenReturn(response); - // When final UploadResponse uploadResponse = caseDocumentClient.uploadDocuments("authorisation", "serviceAuthorisation", "CriminalInjuriesCompensation", "ST_CIC", new ArrayList<>()); - // Then assertEquals(response, uploadResponse); assertEquals(response.getDocuments(), uploadResponse.getDocuments()); } @Test void shouldUploadDocumentsWithClassification() throws IOException { - final String caseDataJson = loadJson(CASE_DATA_FILE_CIC); final MockMultipartFile multipartFile = new MockMultipartFile( @@ -97,13 +87,10 @@ void shouldUploadDocumentsWithClassification() throws IOException { @Test public void shouldDeleteDocument() { - // Given final UUID docUUID = UUID.randomUUID(); - // When caseDocumentClient.deleteDocument("authorisation", "serviceAuthorisation", docUUID, true); - // Then verify(caseDocumentClientApi).deleteDocument(eq("authorisation"), eq("serviceAuthorisation"), eq(docUUID), eq(true)); } diff --git a/src/test/java/uk/gov/hmcts/sptribs/testutil/AppsUtilTest.java b/src/test/java/uk/gov/hmcts/sptribs/testutil/AppsUtilTest.java index 404e893331..c01673ee85 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/testutil/AppsUtilTest.java +++ b/src/test/java/uk/gov/hmcts/sptribs/testutil/AppsUtilTest.java @@ -1,15 +1,18 @@ package uk.gov.hmcts.sptribs.testutil; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.sptribs.ciccase.model.DssCaseData; import uk.gov.hmcts.sptribs.common.config.AppsConfig; +import uk.gov.hmcts.sptribs.constants.CommonConstants; import uk.gov.hmcts.sptribs.util.AppsUtil; +import java.util.List; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -18,31 +21,63 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASE_DATA_CIC_ID; @ExtendWith(SpringExtension.class) -@SpringBootTest -@TestPropertySource("classpath:application.yaml") -@SuppressWarnings("PMD") public class AppsUtilTest { - @Autowired - AppsConfig appsConfig; + @Mock + private AppsConfig.AppsDetails cicAppDetails; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + + cicAppDetails = new AppsConfig.AppsDetails(); + cicAppDetails.setCaseType(CommonConstants.ST_CIC_CASE_TYPE); + cicAppDetails.setJurisdiction(CommonConstants.ST_CIC_JURISDICTION); + cicAppDetails.setCaseTypeOfApplication(List.of(CASE_DATA_CIC_ID)); + } @Test void isValidCaseTypeOfApplicationTest() { DssCaseData a100CaseData = DssCaseData.builder().caseTypeOfApplication(CASE_DATA_CIC_ID).build(); + AppsConfig appsConfig = getDefaultAppsConfig(); assertTrue(AppsUtil.isValidCaseTypeOfApplication(appsConfig, a100CaseData)); } @Test void inValidCaseTypeOfApplicationTest() { DssCaseData a100CaseData = DssCaseData.builder().caseTypeOfApplication("dummy").build(); + AppsConfig appsConfig = getDefaultAppsConfig(); assertFalse(AppsUtil.isValidCaseTypeOfApplication(appsConfig, a100CaseData)); } @Test void validateExactAppDetailsTest() { DssCaseData cicCaseData = DssCaseData.builder().caseTypeOfApplication(CASE_DATA_CIC_ID).build(); + AppsConfig appsConfig = getDefaultAppsConfig(); AppsConfig.AppsDetails appDetails = AppsUtil.getExactAppsDetails(appsConfig, cicCaseData); assertEquals(ST_CIC_CASE_TYPE, appDetails.getCaseType()); assertEquals(ST_CIC_JURISDICTION, appDetails.getJurisdiction()); } + + @Test + void validateExactAppDetailsByCaseTypeOfApplicationTest() { + AppsConfig appsConfig = getDefaultAppsConfig(); + AppsConfig.AppsDetails appDetails = AppsUtil.getExactAppsDetails(appsConfig, CASE_DATA_CIC_ID); + assertEquals(ST_CIC_CASE_TYPE, appDetails.getCaseType()); + assertEquals(ST_CIC_JURISDICTION, appDetails.getJurisdiction()); + } + + @Test + void validateExactAppDetailsByCaseTypeTest() { + AppsConfig appsConfig = getDefaultAppsConfig(); + AppsConfig.AppsDetails appDetails = AppsUtil.getExactAppsDetailsByCaseType(appsConfig, ST_CIC_CASE_TYPE); + assertEquals(CASE_DATA_CIC_ID, appDetails.getCaseTypeOfApplication().get(0)); + assertEquals(ST_CIC_JURISDICTION, appDetails.getJurisdiction()); + } + + private AppsConfig getDefaultAppsConfig() { + AppsConfig appsConfig = new AppsConfig(); + appsConfig.setApps(List.of(cicAppDetails)); + return appsConfig; + } }