From 878c9cc1f7e368cf91a8b997122c22eab0c2eb94 Mon Sep 17 00:00:00 2001 From: Rapolas Kaselis Date: Tue, 5 Nov 2024 09:04:46 +0000 Subject: [PATCH 01/13] CME-116 update rd-commons-lib --- build.gradle | 202 +++++------------- .../AuthorizationFunctionalTest.java | 2 +- .../BulkCivilApiFunctionalTest.java | 4 +- .../professionalapi/EndpointSecurityTest.java | 9 +- ...nalExternalUserFunctionalForV2ApiTest.java | 8 +- ...rofessionalExternalUserFunctionalTest.java | 9 +- ...nalInternalUserFunctionalForV2ApiTest.java | 8 +- ...rofessionalInternalUserFunctionalTest.java | 10 +- .../client/ProfessionalApiClient.java | 4 +- .../util/CustomSerenityRunner.java | 2 +- .../CreateMinimalOrganisationTest.java | 2 +- .../professionalapi/FindMFAByUserIDTest.java | 3 +- .../FindOrganisationsByPbaStatusTest.java | 2 +- .../professionalapi/FindUserByEmailTest.java | 2 +- .../ModifyUserStatusIntegrationTest.java | 7 +- ...nimalOrganisationsInfoIntegrationTest.java | 2 +- .../RetrieveOrganisationsTest.java | 2 +- .../UpdateOrganisationTest.java | 2 +- ...izationDataloadEnabledIntegrationTest.java | 9 +- .../docs/SwaggerPublisherTest.java | 6 +- .../AuthorizationEnabledIntegrationTest.java | 9 +- .../util/ProfessionalReferenceDataClient.java | 2 +- .../reform/professionalapi/Application.java | 2 - .../configuration/SecurityConfiguration.java | 15 +- .../resolver/UserIdArgumentResolver.java | 2 +- .../controller/SuperController.java | 4 +- .../request/NewUserCreationRequest.java | 2 +- .../OrganisationCreationRequestValidator.java | 3 +- .../impl/OrganisationStatusValidatorImpl.java | 2 +- .../response/ProfessionalUsersResponse.java | 2 +- .../dataload/processor/FileReadProcessor.java | 8 +- .../processor/HeaderValidationProcessor.java | 6 +- .../dataload/route/DataLoadRoute.java | 4 +- .../dataload/util/PrdDataExecutor.java | 2 +- .../generator/ProfessionalApiGenerator.java | 2 +- .../service/impl/MfaStatusServiceImpl.java | 2 +- .../impl/ProfessionalUserServiceImpl.java | 2 +- .../util/FeatureConditionEvaluation.java | 2 +- .../reform/professionalapi/SmokeTest.java | 2 +- .../mapper/BulkCustomerDetailsMapperTest.java | 2 +- .../helper/OrganisationFixtures.java | 4 +- .../impl/MfaStatusServiceImplTest.java | 2 +- .../util/FeatureConditionEvaluationTest.java | 2 +- web.config | 2 +- 44 files changed, 137 insertions(+), 243 deletions(-) diff --git a/build.gradle b/build.gradle index 3e6e311217..0f7a4500af 100644 --- a/build.gradle +++ b/build.gradle @@ -1,60 +1,56 @@ -buildscript { - repositories { - mavenLocal() - mavenCentral() - maven { url 'https://jitpack.io' } - } - dependencies { - classpath("net.serenity-bdd:serenity-gradle-plugin:2.4.34") - } -} - plugins { id 'application' + id 'idea' + id 'project-report' id 'uk.gov.hmcts.java' version '0.12.63' id 'jacoco' id 'pmd' id 'com.github.ben-manes.versions' version '0.51.0' id "info.solidsoft.pitest" version '1.15.0' id 'io.spring.dependency-management' version '1.1.6' - id 'org.sonarqube' version '5.0.0.4638' - id 'org.springframework.boot' version '3.3.4' + id 'org.sonarqube' version '5.1.0.4882' + id 'org.springframework.boot' version '3.3.5' id "org.flywaydb.flyway" version '9.22.3' - id 'au.com.dius.pact' version '4.1.7'// do not change, otherwise serenity report fails + id 'au.com.dius.pact' version '4.6.15'// do not change, otherwise serenity report fails id 'org.owasp.dependencycheck' version '10.0.3' + id 'net.serenity-bdd.serenity-gradle-plugin' version '4.2.6' } -apply plugin: 'java' -apply plugin: 'net.serenity-bdd.aggregator' -apply plugin: 'project-report' -apply plugin: 'idea' - ext { springCloudVersion = '2023.0.3' } def versions = [ - lombok : '1.18.32', + lombok : '1.18.34', gradlePitest : '1.15.0', pitest : '1.16.1', sonarPitest : '0.5', junitPitest : '1.2.1', reformLogging : '6.1.6', - camel : '3.8.0', - pact_version : '4.1.7', + camel : '3.22.2', + pact_version : '4.6.15', launchDarklySdk : '5.10.9', - junit : '5.9.2', - junitPlatform : '1.10.3', + junit : '5.11.3', + junitPlatform : '1.11.3', log4j : '2.23.1', reformS2sClient : '5.2.0', feign : '3.8.0', bytebuddy : '1.15.3', - bouncycastle : '1.78.1', + bouncycastle : '1.79', postgresql_tc : '1.20.0' ] -mainClassName = 'uk.gov.hmcts.reform.professionalapi.Application' +application { + mainClass = 'uk.gov.hmcts.reform.professionalapi.Application' + + // this is required to force Java running on the Azure Windows Server OS into using + // UTF-8 as the default character set instead of windows-1252 which causes issues. + // this setting only applies when running via gradle bootRun -- see web.config for the + // java flag that configures the deployed applications + applicationDefaultJvmArgs = ["-Dfile.encoding=UTF-8"] +} + def jarName = 'rd-professional-api.jar' group = 'uk.gov.hmcts.reform.refdata' @@ -79,13 +75,13 @@ jacocoTestCoverageVerification { } compileJava { - - options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" +// options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" + options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" //<< "-Werror" } compileTestJava { - - options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" +// options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" + options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" //<< "-Werror" } tasks.withType(JavaExec).configureEach { @@ -334,60 +330,43 @@ dependencies { implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' - implementation group: 'org.springframework.retry', name: 'spring-retry', version: '1.3.4' + implementation group: 'org.springframework.retry', name: 'spring-retry', version: '2.0.10' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache' - implementation group: 'org.springframework.security', name: 'spring-security-core' - + implementation group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: versions.bouncycastle - implementation group: 'org.springframework', name: 'spring-core' - implementation group: 'org.springframework', name: 'spring-beans' - implementation group: 'org.springframework', name: 'spring-aop' - implementation group: 'org.springframework', name: 'spring-aspects' - implementation group: 'org.springframework', name: 'spring-context' - implementation group: 'org.springframework', name: 'spring-context-support' - implementation group: 'org.springframework', name: 'spring-expression' - implementation group: 'org.springframework', name: 'spring-jcl' - implementation group: 'org.springframework', name: 'spring-jdbc' - implementation group: 'org.springframework', name: 'spring-orm' - implementation group: 'org.springframework', name: 'spring-tx' - implementation group: 'org.springframework', name: 'spring-web' - implementation group: 'org.springframework', name: 'spring-webmvc' implementation group: 'io.github.openfeign.form', name: 'feign-form', version: versions.feign implementation group: 'io.github.openfeign.form', name: 'feign-form-spring', version: versions.feign - implementation "io.github.openfeign:feign-httpclient:11.10" + implementation "io.github.openfeign:feign-httpclient:13.5" implementation group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '6.1.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: versions.log4j implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: versions.log4j implementation group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: versions.log4j implementation group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '3.1.8' - implementation group: 'com.sun.xml.bind', name: 'jaxb-osgi', version: '4.0.5' implementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: versions.reformS2sClient implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind' - implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.0', ext: 'pom' + implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.1', ext: 'pom' implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' - implementation group: 'javax.inject', name: 'javax.inject', version: '1' - implementation 'com.github.hmcts:idam-java-client:2.1.1' + implementation group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1' + implementation 'com.github.hmcts:idam-java-client:3.0.3' implementation "org.springframework.boot:spring-boot-starter-oauth2-client" implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server" - implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.41.2' - implementation group: 'commons-lang', name: 'commons-lang', version: '2.6' + implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.44' + implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0' + implementation group: 'org.apache.commons', name: 'commons-text', version: '1.12.0' implementation 'org.springframework.boot:spring-boot-starter-validation' - //Fix for CVE-2021-29425 - implementation 'commons-io:commons-io:2.8.0' - - implementation group: 'org.flywaydb', name: 'flyway-core', version: '10.18.2' + implementation group: 'org.flywaydb', name: 'flyway-core', version: '10.20.1' runtimeOnly group: 'org.flywaydb', name: 'flyway-database-postgresql', version: '10.18.2' implementation group: 'org.postgresql', name: 'postgresql', version: '42.7.4' - implementation group: 'com.google.guava', name: 'guava', version: '32.1.3-jre' - //Added org.glassfish to support javax.el - implementation group: 'org.glassfish', name: 'javax.el', version: '3.0.0' - implementation group: 'javax.el', name: 'javax.el-api', version: '3.0.0' + implementation group: 'com.google.guava', name: 'guava', version: '33.3.1-jre' + + implementation group: 'jakarta.el', name: 'jakarta.el-api', version: '6.0.1' + implementation (group: 'com.launchdarkly', name: 'launchdarkly-java-server-sdk', version: versions.launchDarklySdk) { exclude group: 'com.google.guava', module: 'guava' @@ -425,7 +404,7 @@ dependencies { implementation group: 'com.nimbusds', name: 'lang-tag', version: '1.7' - implementation group: 'org.json', name: 'json', version: '20230227' + implementation group: 'org.json', name: 'json', version: '20240303' compileOnly group: 'org.projectlombok', name: 'lombok', version: versions.lombok annotationProcessor group: 'org.projectlombok', name: 'lombok', version: versions.lombok @@ -443,8 +422,8 @@ dependencies { exclude group: "org.hamcrest", module: "hamcrest-library" } - testImplementation 'net.serenity-bdd:serenity-rest-assured:3.8.1' - testImplementation group: 'net.serenity-bdd', name: 'serenity-junit', version: '3.8.1' + testImplementation 'net.serenity-bdd:serenity-rest-assured:4.2.6' + testImplementation group: 'net.serenity-bdd', name: 'serenity-junit5', version: '4.2.6' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: versions.junit testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: versions.junit testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: versions.junit @@ -459,26 +438,15 @@ dependencies { exclude group: "net.bytebuddy", module: "byte-buddy" exclude group: "net.bytebuddy", module: "byte-buddy-agent" } - testImplementation ('com.github.hmcts:rd-commons-lib:v0.0.14'){ - exclude group: 'org.springframework.boot', module: 'spring-boot-starter-web' - exclude group: 'org.apache.groovy', module: 'groovy-json' - exclude group: 'org.apache.groovy', module: 'groovy' - exclude group: 'org.apache.groovy', module: 'groovy-xml' - } - testImplementation group: 'org.springframework', name: 'spring-test' - - testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: versions.bytebuddy - testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: versions.bytebuddy - + testImplementation 'com.github.hmcts:rd-commons-lib:0.0.19-beta3' testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.4.0' testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9' + // tests on version 2 fails on flyway migrations, something like "incorrect syntax" testImplementation group: 'com.h2database', name: 'h2', version: '1.4.200' - testImplementation('com.github.tomakehurst:wiremock:2.35.2') { - exclude group: 'com.github.jknack' - } + testImplementation group: 'org.wiremock', name: 'wiremock', version: '3.9.2' testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', { exclude group: 'junit', module: 'junit' @@ -495,24 +463,20 @@ dependencies { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' }, version: versions.sonarPitest - testImplementation 'io.github.openfeign:feign-jackson:12.5' + testImplementation 'io.github.openfeign:feign-jackson:13.5' testImplementation group: 'com.github.mifmif', name: 'generex', version: '1.0.2' implementation group: 'org.springframework.cloud', name: 'spring-cloud-contract-wiremock' - implementation group: 'com.microsoft.azure', name: 'applicationinsights-runtime-attach', version: '3.6.0' - implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '3.6.0' - + implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '3.6.2' contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'junit5', version: versions.pact_version - contractTestImplementation group: 'au.com.dius.pact.consumer', name: 'java8', version: versions.pact_version contractTestRuntimeOnly group: 'au.com.dius.pact.consumer', name: 'junit5', version: versions.pact_version - contractTestRuntimeOnly group: 'au.com.dius.pact.consumer', name: 'java8', version: versions.pact_version contractTestImplementation group: 'au.com.dius.pact.provider', name: 'junit5', version: versions.pact_version contractTestImplementation group: 'au.com.dius.pact.provider', name: 'spring', version: versions.pact_version contractTestImplementation group: 'au.com.dius.pact.provider', name: 'junit5spring', version: versions.pact_version - functionalTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.8.2' + functionalTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: versions.junit functionalTestRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: versions.junit functionalTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: versions.junit functionalTestImplementation group: 'org.junit.platform', name: 'junit-platform-commons', version: versions.junitPlatform @@ -535,8 +499,7 @@ dependencies { contractTestImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: versions.junit contractTestImplementation group: 'org.junit.platform', name: 'junit-platform-commons', version: versions.junitPlatform contractTestRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-engine', version: versions.junitPlatform - contractTestImplementation('org.scala-lang:scala-library:2.13.14') - + contractTestImplementation group: 'org.scala-lang', name: 'scala3-library_3', version: '3.6.1' integrationTestImplementation sourceSets.main.runtimeClasspath integrationTestImplementation sourceSets.test.runtimeClasspath @@ -555,34 +518,6 @@ dependencies { } dependencyManagement { - - dependencies { - - //CVE-2023-24998 - dependencySet(group: 'commons-fileupload', version: '1.5') { - entry 'commons-fileupload' - } - -// Resolves CVE-2023-4586 - dependencySet(group: 'io.netty', version: '4.1.114.Final') { - entry 'netty-buffer' - entry 'netty-codec' - entry 'netty-codec-http' - entry 'netty-codec-socks' - entry 'netty-common' - entry 'netty-handler' - entry 'netty-handler-proxy' - entry 'netty-resolver' - entry 'netty-transport' - entry 'netty-transport-classes-epoll' - entry 'netty-transport-classes-kqueue' - entry 'netty-transport-native-epoll' - entry 'netty-transport-native-kqueue' - entry 'netty-transport-native-unix-common' - } - - } - imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" } @@ -593,19 +528,6 @@ dependencyCheck { suppressionFile = 'config/owasp/suppressions.xml' } -dependencyUpdates.resolutionStrategy = { - componentSelection { rules -> - rules.all { ComponentSelection selection -> - boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier -> - selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/ - } - if (rejected) { - selection.reject('Release candidate') - } - } - } -} - gradle.startParameter.continueOnFailure = true bootJar { @@ -615,30 +537,6 @@ bootJar { } } -configurations.all { - resolutionStrategy.eachDependency { details -> - // Remedy for CVE-2020-8908, ensures launchdarkly uses correct version - if (details.requested.group == 'com.google.guava' - && details.requested.name == 'guava') { - details.useVersion "32.1.1-jre" - } - } - - resolutionStrategy.eachDependency { details -> - // Remedy for CVE-2024-22233 - remove once spring-boot transitively uses version >= 6.1.14 - if (details.requested.group == 'org.springframework' - && (details.requested.version == '6.1.12' || details.requested.version == '6.1.13')) { - details.useVersion "6.1.14" - } - } -} - -// this is required to force Java running on the Azure Windows Server OS into using -// UTF-8 as the default character set instead of windows-1252 which causes issues. -// this setting only applies when running via gradle bootRun -- see web.config for the -// java flag that configures the deployed applications -applicationDefaultJvmArgs = ["-Dfile.encoding=UTF-8"] - rootProject.tasks.named("processFunctionalTestResources") { duplicatesStrategy = 'include' } diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java index 5e5bde186e..d6c0b259d1 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java @@ -34,8 +34,8 @@ import java.util.stream.Collectors; import static java.util.Arrays.asList; -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java index 9c88dbd519..fb5d4dd1aa 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java @@ -3,6 +3,7 @@ import io.restassured.parsing.Parser; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import net.serenitybdd.rest.SerenityRest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -15,7 +16,6 @@ import org.springframework.http.HttpStatus; import org.springframework.test.context.TestPropertySource; import uk.gov.hmcts.reform.lib.client.response.S2sClient; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient; import uk.gov.hmcts.reform.professionalapi.config.TestConfigProperties; import uk.gov.hmcts.reform.professionalapi.controller.request.BulkCustomerRequest; @@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource({"classpath:application.yaml","classpath:application-functional-bulkcustomer.yaml"}) public class BulkCivilApiFunctionalTest { diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java index 56c2349c7c..c5c5aa2d7e 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java @@ -1,15 +1,16 @@ package uk.gov.hmcts.reform.professionalapi; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import static org.assertj.core.api.Assertions.assertThat; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @ActiveProfiles("functional") diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java index 66061bc76e..6813ffdb8c 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java @@ -2,13 +2,13 @@ import lombok.extern.slf4j.Slf4j; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; @@ -24,7 +24,7 @@ import static org.springframework.http.HttpStatus.OK; import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequestForV2; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java index c4ea891088..8b0fd4914c 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java @@ -2,15 +2,15 @@ import io.restassured.specification.RequestSpecification; import lombok.extern.slf4j.Slf4j; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.DeleteMultipleAddressRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; @@ -52,12 +52,11 @@ import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.TRUE; import static uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest.aUserCreationRequest; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j @SuppressWarnings("unchecked") - class ProfessionalExternalUserFunctionalTest extends AuthorizationFunctionalTest { String pumBearerToken; diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java index 3e3c9e0882..169824af62 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java @@ -2,15 +2,15 @@ import io.restassured.response.Response; import lombok.extern.slf4j.Slf4j; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationByProfileIdsRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; @@ -37,7 +37,7 @@ import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 82c1179593..88a87d1702 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -3,15 +3,15 @@ import io.restassured.path.json.JsonPath; import io.restassured.response.Response; import lombok.extern.slf4j.Slf4j; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.MfaUpdateRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; @@ -41,7 +41,7 @@ import java.util.stream.Collectors; import static java.util.Objects.nonNull; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -60,7 +60,7 @@ import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java index f9801c26d2..fb79687250 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/client/ProfessionalApiClient.java @@ -9,7 +9,7 @@ import io.restassured.specification.RequestSpecification; import lombok.extern.slf4j.Slf4j; import net.serenitybdd.rest.SerenityRest; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; @@ -44,7 +44,7 @@ import java.util.Map; import java.util.Set; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; import static org.springframework.http.HttpStatus.BAD_REQUEST; diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java index 6aeb99dc96..7da27a9414 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java @@ -13,7 +13,7 @@ import uk.gov.hmcts.reform.professionalapi.service.impl.FeatureToggleServiceImpl; import static java.lang.System.getenv; -import static org.apache.commons.lang.BooleanUtils.isNotTrue; +import static org.apache.commons.lang3.BooleanUtils.isNotTrue; @ContextConfiguration(classes = {TestConfigProperties.class, Oauth2.class}) @ComponentScan("uk.gov.hmcts.reform.professionalapi") diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/CreateMinimalOrganisationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/CreateMinimalOrganisationTest.java index ff3940e888..b842450042 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/CreateMinimalOrganisationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/CreateMinimalOrganisationTest.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.professionalapi; -import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindMFAByUserIDTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindMFAByUserIDTest.java index 09f99d4e59..0ee408532c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindMFAByUserIDTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindMFAByUserIDTest.java @@ -2,7 +2,7 @@ import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.professionalapi.domain.Organisation; import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; @@ -93,5 +93,4 @@ private Map createOrganization() { return professionalReferenceDataClient.findMFAByUserID(persistedSuperUser.getUserIdentifier()); } - } diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindOrganisationsByPbaStatusTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindOrganisationsByPbaStatusTest.java index b767ea98b6..379607718e 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindOrganisationsByPbaStatusTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindOrganisationsByPbaStatusTest.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.Set; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindUserByEmailTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindUserByEmailTest.java index 97f331e7ee..4c4114926c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindUserByEmailTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/FindUserByEmailTest.java @@ -10,7 +10,7 @@ import java.util.List; import java.util.Map; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserStatusIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserStatusIntegrationTest.java index 8f357355c6..84a39e91c1 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserStatusIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/ModifyUserStatusIntegrationTest.java @@ -1,9 +1,10 @@ package uk.gov.hmcts.reform.professionalapi; import lombok.extern.slf4j.Slf4j; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.http.HttpStatus; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.domain.RoleName; import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; import uk.gov.hmcts.reform.professionalapi.util.AuthorizationEnabledIntegrationTest; @@ -17,7 +18,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @Slf4j class ModifyUserStatusIntegrationTest extends AuthorizationEnabledIntegrationTest { @@ -105,4 +106,4 @@ private UserProfileUpdatedData createModifyUserProfileData() { userProfileUpdatedData.setRolesAdd(roles); return userProfileUpdatedData; } -} \ No newline at end of file +} diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveMinimalOrganisationsInfoIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveMinimalOrganisationsInfoIntegrationTest.java index 2dc698b86c..13cabdcc9d 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveMinimalOrganisationsInfoIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveMinimalOrganisationsInfoIntegrationTest.java @@ -16,7 +16,7 @@ import java.util.Map; import static java.util.Arrays.asList; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; import static org.springframework.http.HttpStatus.FORBIDDEN; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveOrganisationsTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveOrganisationsTest.java index 5d78f77fe4..70185eeb44 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveOrganisationsTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/RetrieveOrganisationsTest.java @@ -28,7 +28,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/UpdateOrganisationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/UpdateOrganisationTest.java index cf4382eefa..8ccbd9cb93 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/UpdateOrganisationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/UpdateOrganisationTest.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.professionalapi; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.OrgAttributeRequest; diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/dataload/camel/AuthorizationDataloadEnabledIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/dataload/camel/AuthorizationDataloadEnabledIntegrationTest.java index 4711cf3975..091f6e5ce2 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/dataload/camel/AuthorizationDataloadEnabledIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/dataload/camel/AuthorizationDataloadEnabledIntegrationTest.java @@ -1,16 +1,17 @@ package uk.gov.hmcts.reform.professionalapi.dataload.camel; import com.launchdarkly.sdk.server.LDClient; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.apache.camel.ProducerTemplate; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.configuration.LaunchDarklyConfiguration; import uk.gov.hmcts.reform.professionalapi.configuration.SecurityConfiguration; import uk.gov.hmcts.reform.professionalapi.controller.feign.UserProfileFeignClient; @@ -25,7 +26,7 @@ import uk.gov.hmcts.reform.professionalapi.service.impl.ProfessionalUserServiceImpl; import uk.gov.hmcts.reform.professionalapi.util.SpringBootIntegrationTest; -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @WithTags({@WithTag("testType:Integration")}) @TestPropertySource(properties = {"S2S_URL=http://127.0.0.1:8990", "IDAM_URL:http://127.0.0.1:5000", "USER_PROFILE_URL:http://127.0.0.1:8091"}) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/docs/SwaggerPublisherTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/docs/SwaggerPublisherTest.java index 780c067ede..efe0f21ebe 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/docs/SwaggerPublisherTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/docs/SwaggerPublisherTest.java @@ -1,8 +1,8 @@ package uk.gov.hmcts.reform.professionalapi.docs; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; import net.serenitybdd.junit.spring.integration.SpringIntegrationSerenityRunner; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; @@ -66,4 +66,4 @@ void shouldGenerateDocs() throws Exception { SWAGGER_DOC_JSON_FILE); } -} \ No newline at end of file +} diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/AuthorizationEnabledIntegrationTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/AuthorizationEnabledIntegrationTest.java index 72548657a1..1996c125e0 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/AuthorizationEnabledIntegrationTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/AuthorizationEnabledIntegrationTest.java @@ -7,10 +7,12 @@ import com.github.tomakehurst.wiremock.extension.ResponseTransformer; import com.github.tomakehurst.wiremock.http.Request; import com.github.tomakehurst.wiremock.http.Response; -import net.thucydides.core.annotations.WithTag; -import net.thucydides.core.annotations.WithTags; +import net.serenitybdd.annotations.WithTag; +import net.serenitybdd.annotations.WithTags; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -21,7 +23,6 @@ import org.springframework.security.oauth2.jwt.JwtDecoder; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; -import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; import uk.gov.hmcts.reform.professionalapi.controller.advice.ErrorResponse; import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; @@ -76,7 +77,7 @@ import static uk.gov.hmcts.reform.professionalapi.util.KeyGenUtil.getDynamicJwksResponse; @Configuration -@SerenityTest +@ExtendWith(SerenityJUnit5Extension.class) @WithTags({@WithTag("testType:Integration")}) @TestPropertySource(properties = {"S2S_URL=http://127.0.0.1:8990", "IDAM_URL:http://127.0.0.1:5000", "USER_PROFILE_URL:http://127.0.0.1:8091"}) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java index cc701b95c8..fec61452d0 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java @@ -931,7 +931,7 @@ private Map getErrorResponseMap(ResponseEntity responseE throws JsonProcessingException { Map errorResponseMap = new HashMap<>(); String body = (String) responseEntity.getBody(); - if (org.apache.commons.lang.StringUtils.isNotEmpty(body)) { + if (org.apache.commons.lang3.StringUtils.isNotEmpty(body)) { errorResponseMap.put("response_body", objectMapper.readValue( body, ErrorResponse.class)); } else { diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/Application.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/Application.java index 0e200ade0a..d8fc54f010 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/Application.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/Application.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.professionalapi; -import com.microsoft.applicationinsights.attach.ApplicationInsights; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -26,7 +25,6 @@ "checkstyle:Indentation"}) // Spring needs a constructor, its not a utility class public class Application { public static void main(final String[] args) { - ApplicationInsights.attach(); SpringApplication.run(Application.class, args); } } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SecurityConfiguration.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SecurityConfiguration.java index 320a268110..31ce640479 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SecurityConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SecurityConfiguration.java @@ -1,5 +1,8 @@ package uk.gov.hmcts.reform.professionalapi.configuration; +import jakarta.inject.Inject; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -30,7 +33,6 @@ import uk.gov.hmcts.reform.professionalapi.oidc.JwtGrantedAuthoritiesConverter; import java.util.List; -import javax.inject.Inject; @Configuration @ConfigurationProperties(prefix = "security") @@ -51,20 +53,15 @@ public class SecurityConfiguration { private ServiceAuthFilter serviceAuthFilter; @Order(2) private final SecurityEndpointFilter securityEndpointFilter; + + @Setter + @Getter List anonymousPaths; private final JwtAuthenticationConverter jwtAuthenticationConverter; private RestAuthenticationEntryPoint restAuthenticationEntryPoint; - public List getAnonymousPaths() { - return anonymousPaths; - } - - public void setAnonymousPaths(List anonymousPaths) { - this.anonymousPaths = anonymousPaths; - } - @Bean public WebSecurityCustomizer webSecurityCustomizer() { return web -> web.ignoring().requestMatchers(anonymousPaths.toArray(new String[0])) diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/resolver/UserIdArgumentResolver.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/resolver/UserIdArgumentResolver.java index 493ba93457..04ec845184 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/resolver/UserIdArgumentResolver.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/resolver/UserIdArgumentResolver.java @@ -2,7 +2,7 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/SuperController.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/SuperController.java index c435843644..ca183c1eb2 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/SuperController.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/SuperController.java @@ -4,8 +4,8 @@ import feign.Response; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Pageable; @@ -68,7 +68,7 @@ import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; -import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotEmpty; import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.CONFLICT; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/NewUserCreationRequest.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/NewUserCreationRequest.java index 2a464a91f4..2881cb5e24 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/NewUserCreationRequest.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/NewUserCreationRequest.java @@ -5,7 +5,7 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import uk.gov.hmcts.reform.professionalapi.domain.UserAccessType; import java.util.List; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/OrganisationCreationRequestValidator.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/OrganisationCreationRequestValidator.java index 3fa738cce7..a23630c16f 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/OrganisationCreationRequestValidator.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/OrganisationCreationRequestValidator.java @@ -29,7 +29,7 @@ import java.util.regex.Pattern; import static java.util.Arrays.asList; -import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isBlank; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ALPHA_NUMERIC_WITH_SPECIAL_CHAR_REGEX; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.EMAIL_REGEX; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ERROR_MESSAGE_EMPTY_CONTACT_INFORMATION; @@ -336,4 +336,3 @@ public static void setLoggingComponentName(String loggingComponentName) { } - diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/OrganisationStatusValidatorImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/OrganisationStatusValidatorImpl.java index 14c4b005d4..862ea3427f 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/OrganisationStatusValidatorImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/request/validator/impl/OrganisationStatusValidatorImpl.java @@ -13,7 +13,7 @@ import java.util.stream.Stream; import static java.util.Arrays.asList; -import static org.apache.commons.lang.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isBlank; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.EXCEPTION_MSG_NO_VALID_ORG_STATUS_PASSED; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.REG_EXP_COMMA_DILIMETER; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.ACTIVE; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/ProfessionalUsersResponse.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/ProfessionalUsersResponse.java index d0c4e56d6f..3528870b7c 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/ProfessionalUsersResponse.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/controller/response/ProfessionalUsersResponse.java @@ -4,7 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import uk.gov.hmcts.reform.professionalapi.domain.ProfessionalUser; import java.util.List; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/FileReadProcessor.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/FileReadProcessor.java index db5bf8408f..82a41813bb 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/FileReadProcessor.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/FileReadProcessor.java @@ -9,8 +9,8 @@ import org.apache.camel.ConsumerTemplate; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.apache.commons.lang.time.DateFormatUtils; -import org.apache.commons.lang.time.DateUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -24,8 +24,8 @@ import java.util.Date; import java.util.function.BiPredicate; -import static org.apache.commons.lang.StringUtils.isEmpty; -import static org.apache.commons.lang.time.DateUtils.isSameDay; +import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.apache.commons.lang3.time.DateUtils.isSameDay; import static uk.gov.hmcts.reform.professionalapi.dataload.util.BlobStatus.NEW; import static uk.gov.hmcts.reform.professionalapi.dataload.util.BlobStatus.NOT_EXISTS; import static uk.gov.hmcts.reform.professionalapi.dataload.util.BlobStatus.STALE; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/HeaderValidationProcessor.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/HeaderValidationProcessor.java index 75ad025195..e7120d06d5 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/HeaderValidationProcessor.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/HeaderValidationProcessor.java @@ -22,9 +22,9 @@ import java.util.List; import java.util.function.Predicate; -import static org.apache.commons.lang.BooleanUtils.isNotTrue; -import static org.apache.commons.lang.StringUtils.isBlank; -import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.apache.commons.lang3.BooleanUtils.isNotTrue; +import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import static uk.gov.hmcts.reform.professionalapi.dataload.util.DataLoadUtil.isStringArraysEqual; /** diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/route/DataLoadRoute.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/route/DataLoadRoute.java index 441b669a1c..ed43470d8f 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/route/DataLoadRoute.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/route/DataLoadRoute.java @@ -8,7 +8,7 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.dataformat.BindyType; import org.apache.camel.model.language.SimpleExpression; -import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; @@ -30,7 +30,7 @@ import javax.sql.DataSource; import static java.util.Objects.nonNull; -import static org.apache.commons.lang.WordUtils.uncapitalize; +import static org.apache.commons.text.WordUtils.uncapitalize; import static org.apache.logging.log4j.util.Strings.isBlank; import static uk.gov.hmcts.reform.professionalapi.dataload.util.MappingConstants.DIRECT_ROUTE; import static uk.gov.hmcts.reform.professionalapi.dataload.util.MappingConstants.IS_FILE_STALE; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/util/PrdDataExecutor.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/util/PrdDataExecutor.java index 56248bdcf1..98f986768e 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/util/PrdDataExecutor.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/dataload/util/PrdDataExecutor.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; import uk.gov.hmcts.reform.professionalapi.dataload.service.AuditServiceImpl; -import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.isNotBlank; import static uk.gov.hmcts.reform.professionalapi.dataload.util.MappingConstants.ERROR_MESSAGE; import static uk.gov.hmcts.reform.professionalapi.dataload.util.MappingConstants.FAILURE; import static uk.gov.hmcts.reform.professionalapi.dataload.util.MappingConstants.IS_READY_TO_AUDIT; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/generator/ProfessionalApiGenerator.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/generator/ProfessionalApiGenerator.java index a46ea6f0c5..2a49a5c6b4 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/generator/ProfessionalApiGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/generator/ProfessionalApiGenerator.java @@ -36,7 +36,7 @@ static UUID generateUniqueUuid() { static String generateUniqueAlphanumericId(int lengthOfString) { String generatedString = null; while (true) { - generatedString = RandomStringUtils.randomAlphanumeric(lengthOfString); + generatedString = RandomStringUtils.secure().nextAlphanumeric(lengthOfString); if (generatedString.matches(ProfessionalApiConstants.ORGANISATION_IDENTIFIER_FORMAT_REGEX)) { break; } diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImpl.java index 40f768d3d4..4b0b7eb26d 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImpl.java @@ -1,7 +1,7 @@ package uk.gov.hmcts.reform.professionalapi.service.impl; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/ProfessionalUserServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/ProfessionalUserServiceImpl.java index 200a1d0a98..2b61ad74b3 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/ProfessionalUserServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/ProfessionalUserServiceImpl.java @@ -4,7 +4,7 @@ import feign.Response; import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Page; diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluation.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluation.java index fb13d5bf10..07d6b23296 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluation.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluation.java @@ -14,7 +14,7 @@ import java.util.Map; import static java.util.Objects.nonNull; -import static org.apache.commons.lang.BooleanUtils.isNotTrue; +import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.apache.commons.lang3.StringUtils.SPACE; diff --git a/src/smokeTest/java/uk/gov/hmcts/reform/professionalapi/SmokeTest.java b/src/smokeTest/java/uk/gov/hmcts/reform/professionalapi/SmokeTest.java index 6b9c4f1e58..fa013b6976 100644 --- a/src/smokeTest/java/uk/gov/hmcts/reform/professionalapi/SmokeTest.java +++ b/src/smokeTest/java/uk/gov/hmcts/reform/professionalapi/SmokeTest.java @@ -3,7 +3,7 @@ import io.restassured.response.Response; import lombok.extern.slf4j.Slf4j; import net.serenitybdd.rest.SerenityRest; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/mapper/BulkCustomerDetailsMapperTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/mapper/BulkCustomerDetailsMapperTest.java index 20f5307d5e..75f5848b7b 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/mapper/BulkCustomerDetailsMapperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/mapper/BulkCustomerDetailsMapperTest.java @@ -11,7 +11,7 @@ import java.util.HashMap; import java.util.Map; -import static org.apache.commons.lang.StringUtils.trim; +import static org.apache.commons.lang3.StringUtils.trim; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java index 86e98801c4..37d85928a0 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.helper; -import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang3.RandomStringUtils; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.DxAddressCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrgAttributeRequest; @@ -15,8 +15,8 @@ import java.util.List; import java.util.Set; -import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; import static uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest.aContactInformationCreationRequest; import static uk.gov.hmcts.reform.professionalapi.controller.request.DxAddressCreationRequest.dxAddressCreationRequest; import static uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest.anOrganisationCreationRequest; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImplTest.java index a651253310..b0132c6ca7 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/MfaStatusServiceImplTest.java @@ -1,6 +1,6 @@ package uk.gov.hmcts.reform.professionalapi.service.impl; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluationTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluationTest.java index 65d471cf12..a4bcfe4e1c 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluationTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/util/FeatureConditionEvaluationTest.java @@ -5,7 +5,7 @@ import io.jsonwebtoken.impl.TextCodec; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/web.config b/web.config index 82f6663e1f..91280b91a8 100644 --- a/web.config +++ b/web.config @@ -9,7 +9,7 @@ + arguments="-Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\rd-professional-api.jar""> From 8f4a6ba534a60a1ca90f0f090a25c2871fc5884b Mon Sep 17 00:00:00 2001 From: Rapolas Kaselis Date: Tue, 5 Nov 2024 10:06:02 +0000 Subject: [PATCH 02/13] address warnings --- README.md | 2 +- build.gradle | 8 +-- .../processor/ExceptionProcessorTest.java | 4 +- .../dataload/util/DataLoadUtilTest.java | 55 ++++++++----------- .../helper/OrganisationFixtures.java | 28 +++------- 5 files changed, 37 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index db07ecd5af..fdf8be73a1 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ https://tools.hmcts.net/confluence/display/RTRD/Professional+Reference+Data To run the project you will need to have the following installed: -* Java 17 +* Java 21 * Docker (optional) For information about the software versions used to build this API and a complete list of it's dependencies see build.gradle diff --git a/build.gradle b/build.gradle index 0f7a4500af..47cb731b4f 100644 --- a/build.gradle +++ b/build.gradle @@ -75,13 +75,11 @@ jacocoTestCoverageVerification { } compileJava { -// options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" - options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" //<< "-Werror" + options.compilerArgs << '-parameters' << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" } compileTestJava { -// options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" - options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" //<< "-Werror" + options.compilerArgs << '-Xlint:deprecation' << "-Xlint:unchecked" << "-Werror" } tasks.withType(JavaExec).configureEach { @@ -332,7 +330,7 @@ dependencies { implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' implementation group: 'org.springframework.retry', name: 'spring-retry', version: '2.0.10' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache' - + implementation group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: versions.bouncycastle implementation group: 'io.github.openfeign.form', name: 'feign-form', version: versions.feign diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/ExceptionProcessorTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/ExceptionProcessorTest.java index ef63e828a7..eea993e641 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/ExceptionProcessorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/processor/ExceptionProcessorTest.java @@ -4,7 +4,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; @@ -74,4 +74,4 @@ public void testProcess() throws Exception { verify(auditService,times(1)).auditException(any(),any()); verify(fileResponseProcessor,times(1)).process(any()); } -} \ No newline at end of file +} diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/util/DataLoadUtilTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/util/DataLoadUtilTest.java index 3b1025062f..61a1bb66b6 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/util/DataLoadUtilTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/dataload/util/DataLoadUtilTest.java @@ -2,39 +2,42 @@ import org.apache.camel.CamelContext; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import uk.gov.hmcts.reform.professionalapi.dataload.helper.JrdTestSupport; import java.sql.Timestamp; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -@SpringBootTest +@CamelSpringBootTest @Configuration() @ContextConfiguration(classes = DataLoadUtil.class) -public class DataLoadUtilTest extends CamelTestSupport { +class DataLoadUtilTest { @Autowired DataLoadUtil dataLoadUtil; @Test - public void setGlobalConstant() throws Exception { - CamelContext camelContext = createCamelContext(); + void setGlobalConstant() { + CamelContext camelContext = new DefaultCamelContext(); camelContext.start(); dataLoadUtil.setGlobalConstant(camelContext, "judicial_leaf_scheduler"); assertNotNull("judicial_leaf_scheduler", camelContext.getGlobalOption(MappingConstants.SCHEDULER_NAME)); } @Test - @SuppressWarnings("unchecked") - public void removeGlobalConstant() throws Exception { + void removeGlobalConstant() throws Exception { CamelContext camelContext = mock(CamelContext.class); dataLoadUtil.removeGlobalConstant(camelContext); assertNull(camelContext.getGlobalOption(MappingConstants.SCHEDULER_NAME)); @@ -42,62 +45,52 @@ public void removeGlobalConstant() throws Exception { } @Test - public void test_getDateTimeStamp() { + void test_getDateTimeStamp() { Timestamp ts = DataLoadUtil.getDateTimeStamp(JrdTestSupport.createCurrentLocalDate()); assertNotNull(ts); } @Test - public void test_getCurrentTimeStamp() { + void test_getCurrentTimeStamp() { Timestamp ts = DataLoadUtil.getCurrentTimeStamp(); assertNotNull(ts); } @Test - public void isFileExecuted_test() throws Exception { - - CamelContext camelContext = createCamelContext(); - assertFalse(dataLoadUtil.isFileExecuted(camelContext,"filename")); + void isFileExecuted_test() { + CamelContext camelContext = new DefaultCamelContext(); + assertFalse(DataLoadUtil.isFileExecuted(camelContext,"filename")); } @Test - public void isStringArraysEqual_test() throws Exception { - + void isStringArraysEqual_test() { String[] exp = {"one","two","three"}; String[] act = {"one","two","three"}; - assertTrue(dataLoadUtil.isStringArraysEqual(exp,act)); - + assertTrue(DataLoadUtil.isStringArraysEqual(exp,act)); } @Test - public void isStringArraysNotEqual_test() throws Exception { - + void isStringArraysNotEqual_test() { String[] exp = {"oen","too"}; String[] act = {"one","two","three"}; - assertFalse(dataLoadUtil.isStringArraysEqual(exp,act)); - + assertFalse(DataLoadUtil.isStringArraysEqual(exp,act)); } @Test - public void isStringExpEmpty_test() throws Exception { - + void isStringExpEmpty_test() { String[] exp = null; String[] act = null; - assertFalse(dataLoadUtil.isStringArraysEqual(exp,act)); - + assertFalse(DataLoadUtil.isStringArraysEqual(exp,act)); } @Test - public void isStringUnEqualLength_test() throws Exception { - + void isStringUnEqualLength_test() { String[] exp = {"one","two"}; String[] act = {"one","two","three"}; - - assertFalse(dataLoadUtil.isStringArraysEqual(exp,act)); - + assertFalse(DataLoadUtil.isStringArraysEqual(exp,act)); } } diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java index 37d85928a0..1cb72f6547 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/helper/OrganisationFixtures.java @@ -15,8 +15,6 @@ import java.util.List; import java.util.Set; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric; import static uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest.aContactInformationCreationRequest; import static uk.gov.hmcts.reform.professionalapi.controller.request.DxAddressCreationRequest.dxAddressCreationRequest; import static uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest.anOrganisationCreationRequest; @@ -35,7 +33,7 @@ public static OrganisationCreationRequest.OrganisationCreationRequestBuilder som .superUser(aUserCreationRequest() .firstName("some-fname") .lastName("some-lname") - .email(randomAlphanumeric(7).concat("@test.com")) + .email(RandomStringUtils.secure().nextAlphanumeric(7).concat("@test.com")) .build()) .contactInformation(Arrays.asList(aContactInformationCreationRequest() .addressLine1("addressLine1") @@ -49,7 +47,7 @@ public static OrganisationCreationRequest.OrganisationCreationRequestBuilder whi return anOrganisationCreationRequest() .name(" some- org -name ") - .companyNumber(randomAlphabetic(8)) + .companyNumber(RandomStringUtils.secure().nextAlphabetic(8)) .superUser(aUserCreationRequest() .firstName(" some-fname b ") .lastName(" some- lname ") @@ -71,7 +69,7 @@ public static OrganisationCreationRequest.OrganisationCreationRequestBuilder org .sraId("sra-id") .sraRegulated("false") .companyUrl("company -url") - .companyNumber(randomAlphabetic(8)) + .companyNumber(RandomStringUtils.secure().nextAlphabetic(8)) .paymentAccount(paymentAccounts) .superUser(aUserCreationRequest() .firstName("some-fname") @@ -107,8 +105,7 @@ public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithA orgAttributeRequests.add(orgAttributeRequest); - OrganisationOtherOrgsCreationRequest organisationOtherOrgsCreationRequest = - new OrganisationOtherOrgsCreationRequest("some-org-name", + return new OrganisationOtherOrgsCreationRequest("some-org-name", "PENDING", "test", "sra-id", @@ -138,9 +135,6 @@ public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithA .build()), "Doctor", orgAttributeRequests); - - return organisationOtherOrgsCreationRequest; - } public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithAllFieldsAreUpdated() { @@ -157,8 +151,7 @@ public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithA orgAttributeRequests.add(orgAttributeRequest); - OrganisationOtherOrgsCreationRequest organisationOtherOrgsCreationRequest = - new OrganisationOtherOrgsCreationRequest("some-org-name1", + return new OrganisationOtherOrgsCreationRequest("some-org-name1", "ACTIVE", "test", "sra-id1", @@ -188,9 +181,6 @@ public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithA .build()), "Doctor1", orgAttributeRequests); - - return organisationOtherOrgsCreationRequest; - } public static OrganisationCreationRequest @@ -204,7 +194,7 @@ public static OrganisationOtherOrgsCreationRequest otherOrganisationRequestWithA .sraId("sra-id1") .sraRegulated("true") .companyUrl("company-url1") - .companyNumber(randomAlphabetic(8)) + .companyNumber(RandomStringUtils.secure().nextAlphabetic(8)) .paymentAccount(paymentAccounts) .superUser(aUserCreationRequest() .firstName("somefname") @@ -265,10 +255,6 @@ public static List getContactInformationList( } public static List createContactInformationCreationRequests() { - Set paymentAccounts = new HashSet<>(); - paymentAccounts.add("PBA" + RandomStringUtils.randomAlphabetic(7)); - paymentAccounts.add("PBA" + RandomStringUtils.randomAlphabetic(7)); - paymentAccounts.add("PBA" + RandomStringUtils.randomAlphabetic(7)); List dx1 = new LinkedList<>(); dx1.add(dxAddressCreationRequest() @@ -326,7 +312,7 @@ public static List createContactInformationCr .sraId("sra-id") .sraRegulated("false") .companyUrl("company -url") - .companyNumber(randomAlphabetic(8)) + .companyNumber(RandomStringUtils.secure().nextAlphabetic(8)) .paymentAccount(paymentAccounts) .superUser(aUserCreationRequest() .firstName("some-fname") From 44fee15b39aa4d78fd198f64094d51b3e5267630 Mon Sep 17 00:00:00 2001 From: Rapolas Kaselis Date: Wed, 13 Nov 2024 09:57:22 +0000 Subject: [PATCH 03/13] add serenity properties file --- serenity.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 serenity.properties diff --git a/serenity.properties b/serenity.properties new file mode 100644 index 0000000000..c2b7117292 --- /dev/null +++ b/serenity.properties @@ -0,0 +1,3 @@ +serenity.report.show.manual.tests=true +serenity.report.show.pending.tests=true +serenity.report.show.ignored.tests=true From 3097f82a4292e3ebad063c3b11a99dbf31e2f3be Mon Sep 17 00:00:00 2001 From: "Kiran.Yenigala" Date: Wed, 13 Nov 2024 10:25:47 +0000 Subject: [PATCH 04/13] Update mockito-junit-jupiter to latest version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 47cb731b4f..cf1bb8cbb6 100644 --- a/build.gradle +++ b/build.gradle @@ -437,7 +437,7 @@ dependencies { exclude group: "net.bytebuddy", module: "byte-buddy-agent" } testImplementation 'com.github.hmcts:rd-commons-lib:0.0.19-beta3' - testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.4.0' + testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.14.2' testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9' From e47080c5c926903514186f615be8674b523c6474 Mon Sep 17 00:00:00 2001 From: Rapolas <130578328+rapolaskaseliscgi@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:58:37 +0000 Subject: [PATCH 05/13] Cleanup --- build.gradle | 11 +- gradle.properties | 4 +- serenity.properties | 3 - .../AuthorizationFunctionalTest.java | 7 +- ...rofessionalExternalUserFunctionalTest.java | 8 +- ...rofessionalInternalUserFunctionalTest.java | 9 +- .../util/CustomSerenityRunner.java | 76 --- .../util/CustomTestExecutionListener.java | 572 ++++++++++++++++++ .../util/FeatureToggleConditionExtension.java | 53 +- .../professionalapi/util/ToggleEnable.java | 2 +- ...it.platform.launcher.TestExecutionListener | 1 + .../impl/FeatureToggleServiceImpl.java | 68 +-- .../impl/FeatureToggleServiceImplTest.java | 1 - 13 files changed, 634 insertions(+), 181 deletions(-) delete mode 100644 serenity.properties delete mode 100644 src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java create mode 100644 src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java create mode 100644 src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener diff --git a/build.gradle b/build.gradle index cf1bb8cbb6..a8b4bff020 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,8 @@ def versions = [ feign : '3.8.0', bytebuddy : '1.15.3', bouncycastle : '1.79', - postgresql_tc : '1.20.0' + postgresql_tc : '1.20.0', + serenity : '4.2.6' ] application { @@ -420,13 +421,15 @@ dependencies { exclude group: "org.hamcrest", module: "hamcrest-library" } - testImplementation 'net.serenity-bdd:serenity-rest-assured:4.2.6' - testImplementation group: 'net.serenity-bdd', name: 'serenity-junit5', version: '4.2.6' + testImplementation group: 'net.serenity-bdd', name: 'serenity-core', version: versions.serenity + testImplementation group: 'net.serenity-bdd', name: 'serenity-junit5', version: versions.serenity + testImplementation group: 'net.serenity-bdd', name: 'serenity-rest-assured', version: versions.serenity + testImplementation group: 'net.serenity-bdd', name: 'serenity-spring', version: versions.serenity testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: versions.junit - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: versions.junit testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: versions.junit testImplementation group: 'org.junit.platform', name: 'junit-platform-commons', version: versions.junitPlatform testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-engine', version: versions.junitPlatform + testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: versions.junit testImplementation ("org.mockito:mockito-core:4.3.1") { exclude group: "net.bytebuddy", module: "byte-buddy" diff --git a/gradle.properties b/gradle.properties index e59a505e4d..e301d035fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -org.gradle.jvmargs=-Xmx1024m -org.gradle.parallel=true \ No newline at end of file +org.gradle.jvmargs=-Xmx2048m +org.gradle.parallel=true diff --git a/serenity.properties b/serenity.properties deleted file mode 100644 index c2b7117292..0000000000 --- a/serenity.properties +++ /dev/null @@ -1,3 +0,0 @@ -serenity.report.show.manual.tests=true -serenity.report.show.pending.tests=true -serenity.report.show.ignored.tests=true diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java index d6c0b259d1..fa7ccf507a 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java @@ -40,7 +40,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest.aNewUserCreationRequest; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.formatDateString; @@ -204,7 +203,7 @@ protected NewUserCreationRequest createUserRequest(List userRoles, userAccessTypes.add(new UserAccessType("jurisdictionId" + random, "organisationProfileId" + random, "accessTypeId" + random, false)); String userEmail = generateRandomEmail(); - NewUserCreationRequest userCreationRequest = aNewUserCreationRequest() + NewUserCreationRequest userCreationRequest = NewUserCreationRequest.aNewUserCreationRequest() .firstName(firstName) .lastName(lastName) .email(userEmail) @@ -227,7 +226,7 @@ protected NewUserCreationRequest createUserRequest(List userRoles, boole .add(new UserAccessType("testJurisdictionId", "testOrganisationProfileId", "testAccessTypeId", true)); - userCreationRequest = aNewUserCreationRequest() + userCreationRequest = NewUserCreationRequest.aNewUserCreationRequest() .firstName(firstName) .lastName(lastName) .email(userEmail) @@ -235,7 +234,7 @@ protected NewUserCreationRequest createUserRequest(List userRoles, boole .userAccessTypes(userAccessTypes) .build(); } else { - userCreationRequest = aNewUserCreationRequest() + userCreationRequest = NewUserCreationRequest.aNewUserCreationRequest() .firstName(firstName) .lastName(lastName) .email(userEmail) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java index 8b0fd4914c..5c95294176 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java @@ -16,6 +16,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; import uk.gov.hmcts.reform.professionalapi.domain.UserAccessType; import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; @@ -50,7 +51,6 @@ import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.ACTIVE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.FALSE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.TRUE; -import static uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest.aUserCreationRequest; @ExtendWith(SerenityJUnit5Extension.class) @SpringBootTest @@ -106,7 +106,7 @@ public void setUpOrgTestData() { log.info("Setting up organization..."); superUserEmail = generateRandomEmail(); organisationCreationRequest = createOrganisationRequest() - .superUser(aUserCreationRequest() + .superUser(UserCreationRequest.aUserCreationRequest() .firstName(firstName) .lastName(lastName) .email(superUserEmail) @@ -256,7 +256,7 @@ public void inviteUserBySuperUserShouldBeSuccess() { superUserRoles(), firstName, lastName, email)); OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest() - .superUser(aUserCreationRequest().firstName(firstName).lastName(lastName).email(email).build()) + .superUser(UserCreationRequest.aUserCreationRequest().firstName(firstName).lastName(lastName).email(email).build()) .status("ACTIVE").build(); createAndActivateOrganisationWithGivenRequest(organisationCreationRequest, hmctsAdmin); @@ -344,7 +344,7 @@ public void findUsersBySystemAdminWithoutRolesRequiredShouldBeSuccess() { public void findOrganisationUsersSorted() { String superUserEmail = generateRandomEmail(); OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest() - .superUser(aUserCreationRequest().firstName(firstName) + .superUser(UserCreationRequest.aUserCreationRequest().firstName(firstName) .lastName(lastName).email(superUserEmail).build()) .status("ACTIVE").build(); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index 88a87d1702..af5b8acada 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -19,6 +19,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.request.PbaRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.PbaUpdateRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UpdatePbaRequest; +import uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.FetchPbaByStatusResponse; import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationsWithPbaStatusResponse; import uk.gov.hmcts.reform.professionalapi.domain.MFAStatus; @@ -54,8 +55,6 @@ import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequest; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PBA_STATUS_MESSAGE_ACCEPTED; -import static uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationCreationRequest.anOrganisationCreationRequest; -import static uk.gov.hmcts.reform.professionalapi.controller.request.UserCreationRequest.aUserCreationRequest; import static uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus.REVIEW; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; @@ -142,7 +141,7 @@ public void setUpTestData() { superUserEmail = generateRandomEmail(); invitedUserEmail = generateRandomEmail(); organisationCreationRequest = createOrganisationRequest() - .superUser(aUserCreationRequest() + .superUser(UserCreationRequest.aUserCreationRequest() .firstName("firstName") .lastName("lastName") .email(superUserEmail) @@ -211,8 +210,8 @@ public void deleteOrganisationScenarios() { } public void createOrganisationWithoutS2STokenShouldReturnAuthorised() { - Response response = - professionalApiClient.createOrganisationWithoutS2SToken(anOrganisationCreationRequest().build()); + Response response = professionalApiClient.createOrganisationWithoutS2SToken( + OrganisationCreationRequest.anOrganisationCreationRequest().build()); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED.value()); } diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java deleted file mode 100644 index 7da27a9414..0000000000 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityRunner.java +++ /dev/null @@ -1,76 +0,0 @@ -package uk.gov.hmcts.reform.professionalapi.util; - -import com.launchdarkly.sdk.server.LDClient; -import net.serenitybdd.junit.spring.integration.SpringIntegrationSerenityRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.util.ReflectionTestUtils; -import uk.gov.hmcts.reform.professionalapi.config.Oauth2; -import uk.gov.hmcts.reform.professionalapi.config.TestConfigProperties; -import uk.gov.hmcts.reform.professionalapi.service.impl.FeatureToggleServiceImpl; - -import static java.lang.System.getenv; -import static org.apache.commons.lang3.BooleanUtils.isNotTrue; - -@ContextConfiguration(classes = {TestConfigProperties.class, Oauth2.class}) -@ComponentScan("uk.gov.hmcts.reform.professionalapi") -@TestPropertySource("classpath:application-functional.yaml") -public class CustomSerenityRunner extends SpringIntegrationSerenityRunner { - - private static LDClient ldClient; - - private static FeatureToggleServiceImpl featureToggleService; - - private static boolean isInitialized = false; - - private static String flagName; - - public CustomSerenityRunner(Class klass) throws InitializationError { - super(klass); - } - - - @Override - protected boolean isIgnored(FrameworkMethod child) { - - if (isNotTrue(isInitialized)) { - initialize(); - } - - ToggleEnable toggleEnable = child.getAnnotation(ToggleEnable.class); - if (toggleEnable != null) { - featureToggleService.mapServiceToFlag(); - flagName = featureToggleService.getLaunchDarklyMap() - .get(toggleEnable.mapKey()); - - boolean isEnabledLD = featureToggleService.isFlagEnabled("rd_professional_api", flagName); - - if (isEnabledLD) { - if (isNotTrue(toggleEnable.withFeature())) { - return true; - } - } else { - if (toggleEnable.withFeature()) { - return true; - } - } - } - return super.isIgnored(child); - } - - private void initialize() { - ldClient = new LDClient(getenv("LD_SDK_KEY")); - featureToggleService = new FeatureToggleServiceImpl(ldClient, "rd"); - String executionEnvironment = getenv("execution_environment"); - ReflectionTestUtils.setField(featureToggleService, "environment", executionEnvironment); - - isInitialized = true; - } - - public static String getFeatureFlagName() { - return flagName; - } -} diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java new file mode 100644 index 0000000000..a47ad5d99e --- /dev/null +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java @@ -0,0 +1,572 @@ +package uk.gov.hmcts.reform.professionalapi.util; + +import net.bytebuddy.agent.ByteBuddyAgent; +import net.bytebuddy.agent.builder.AgentBuilder; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.matcher.ElementMatchers; +import net.serenitybdd.core.di.SerenityInfrastructure; +import net.serenitybdd.junit5.AssertThrowsAdvice; +import net.serenitybdd.junit5.JUnit5DataDrivenAnnotations; +import net.serenitybdd.junit5.JUnit5TestClassAnnotations; +import net.serenitybdd.junit5.JUnit5TestMethodAnnotations; +import net.serenitybdd.junit5.ParameterizedTestsOutcomeAggregator; +import net.serenitybdd.junit5.SerenityJUnit5Extension; +import net.serenitybdd.junit5.SerenityTestExecutionListener; +import net.serenitybdd.junit5.SerenityTestExecutionSummary; +import net.serenitybdd.junit5.TestMethodConfiguration; +import net.thucydides.core.pages.Pages; +import net.thucydides.core.steps.BaseStepListener; +import net.thucydides.core.steps.Listeners; +import net.thucydides.core.steps.StepAnnotations; +import net.thucydides.core.steps.StepEventBus; +import net.thucydides.model.configuration.SystemPropertiesConfiguration; +import net.thucydides.model.domain.DataTable; +import net.thucydides.model.domain.TestClassHierarchy; +import net.thucydides.model.domain.TestOutcome; +import net.thucydides.model.domain.TestResult; +import net.thucydides.model.environment.SystemEnvironmentVariables; +import net.thucydides.model.reports.ReportService; +import net.thucydides.model.steps.StepListener; +import net.thucydides.model.util.Inflector; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.platform.commons.PreconditionViolationException; +import org.junit.platform.engine.TestDescriptor; +import org.junit.platform.engine.TestExecutionResult; +import org.junit.platform.engine.TestSource; +import org.junit.platform.engine.support.descriptor.ClassSource; +import org.junit.platform.engine.support.descriptor.MethodSource; +import org.junit.platform.launcher.TestIdentifier; +import org.junit.platform.launcher.TestPlan; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.lang.instrument.Instrumentation; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static net.thucydides.model.reports.ReportService.getDefaultReporters; +import static net.thucydides.model.steps.TestSourceType.TEST_SOURCE_JUNIT5; + +@SuppressWarnings("unchecked") +public class CustomTestExecutionListener extends SerenityTestExecutionListener { + + private static final List expectedExceptions = Collections.synchronizedList(new ArrayList<>()); + + private static final Logger logger = LoggerFactory.getLogger(CustomTestExecutionListener.class); + + static { + Instrumentation inst = ByteBuddyAgent.install(); + new AgentBuilder.Default() + .type(ElementMatchers.named("org.junit.jupiter.api.Assertions")) + .transform((builder, typeDescription, classLoader, module, protectionDomain) -> + builder.method(ElementMatchers.named("assertThrows")) + .intercept(Advice.to(AssertThrowsAdvice.class)) + ).installOn(inst); + } + + private ReportService reportService; + + private SerenityTestExecutionSummary summary; + + private Pages pages; + + //key-> "ClassName.MethodName" + //entries-> DataTable associated with method + private final Map dataTables = Collections.synchronizedMap(new HashMap<>()); + + + private boolean isSerenityTest = false; + + private static File getOutputDirectory() { + SystemPropertiesConfiguration systemPropertiesConfiguration = new SystemPropertiesConfiguration(new SystemEnvironmentVariables()); + return systemPropertiesConfiguration.getOutputDirectory(); + } + + @Override + public synchronized void testPlanExecutionStarted(TestPlan testPlan) { + this.summary = new SerenityTestExecutionSummary(testPlan); + testPlan.getRoots().forEach(root -> { + Set children = testPlan.getChildren(root.getUniqueIdObject()); + children.stream().filter(this::isClassSource).filter(this::isASerenityTest).forEach(this::configureParameterizedTestDataFor); + }); + } + + private boolean isASerenityTest(TestIdentifier child) { + return isSerenityTestClass(((ClassSource) child.getSource().get()).getJavaClass()); + } + + private void configureParameterizedTestDataFor(TestIdentifier serenityTest) { + Class javaClass = ((ClassSource) serenityTest.getSource().get()).getJavaClass(); + Map parameterTablesForClass = JUnit5DataDrivenAnnotations.forClass(javaClass).getParameterTables(); + if (!parameterTablesForClass.isEmpty()) { + dataTables.putAll(parameterTablesForClass); + } + } + + @Override + public synchronized void testPlanExecutionFinished(TestPlan testPlan) { + if (!isSerenityTest) return; + List testIdentifiers = new ArrayList<>(); + List parameterizedTestIdentifiers = new ArrayList<>(); + + //TODO use getDescendants() + testPlan.getRoots().forEach(testIdentifier -> { + generateReportsForTest(testPlan, testIdentifier, testIdentifiers, parameterizedTestIdentifiers); + }); + testIdentifiers.forEach(this::generateReports); + generateReportsForParameterizedTests(parameterizedTestIdentifiers); + + logger.debug("->TestPlanExecutionFinished " + testPlan); + } + + private void generateReportsForTest(TestPlan testPlan, TestIdentifier testIdentifier, List testIdentifiers, List parameterizedTestIdentifiers) { + logger.debug("->GenerateReportsForTest " + testIdentifier); + if (testIdentifier.getUniqueId().contains("test-template-invocation")) { + parameterizedTestIdentifiers.add(testIdentifier); + } else { + testIdentifiers.add(testIdentifier); + } + testPlan.getChildren(testIdentifier).forEach(ti -> generateReportsForTest(testPlan, ti, testIdentifiers, parameterizedTestIdentifiers)); + } + + @Override + public void dynamicTestRegistered(TestIdentifier testIdentifier) { + } + + @Override + public void executionSkipped(TestIdentifier testIdentifier, String reason) { + if (!isSerenityTest) return; + processTestMethodAnnotationsFor(testIdentifier); + } + + private void processTestMethodAnnotationsFor(TestIdentifier testIdentifier) { + Optional testSource = testIdentifier.getSource(); + if (testSource.isPresent() && (testSource.get() instanceof MethodSource)) { + startTestAtEventBus(testIdentifier); + eventBusFor(testIdentifier).testIgnored(); + eventBusFor(testIdentifier).testFinished(); + } + } + + private void startTestAtEventBus(TestIdentifier testIdentifier) { + eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); + String displayName = removeEndBracketsFromDisplayName(testIdentifier.getDisplayName()); + if (isMethodSource(testIdentifier)) { + String className = ((MethodSource) testIdentifier.getSource().get()).getClassName(); + try { + eventBusFor(testIdentifier).testStarted(Optional.ofNullable(displayName).orElse("Initialisation"), Class.forName(className)); + } catch (ClassNotFoundException exception) { + logger.error("Exception when starting test at event bus ", exception); + } + } + } + + private String removeEndBracketsFromDisplayName(String displayName) { + if (displayName != null && displayName.endsWith("()")) { + displayName = displayName.substring(0, displayName.length() - 2); + } + return displayName; + } + + private static final Map, String> TEST_CASE_DISPLAY_NAMES = new ConcurrentHashMap<>(); + private static final Map DATA_DRIVEN_TEST_NAMES = new ConcurrentHashMap<>(); + @Override + public synchronized void executionStarted(TestIdentifier testIdentifier) { + Class testClass; + logger.warn("-->Execution started with TI " + testIdentifier); + if (!testIdentifier.getSource().isPresent()) { + logger.trace("No action done at executionStarted because testIdentifier is null"); + return; + } + if (isTestContainer(testIdentifier) && isClassSource(testIdentifier)) { + testClass = ((ClassSource) testIdentifier.getSource().get()).getJavaClass(); + isSerenityTest = isSerenityTestClass(testClass); + if (!isSerenityTest) { + logger.trace("-->Execution started but no SerenityClass " + testClass); + return; + } + logger.trace("-->Execution started " + testIdentifier + "----" + testIdentifier.getDisplayName() + "--" + testIdentifier.getType() + "--" + testIdentifier.getSource()); + logger.trace("-->TestSuiteStarted " + testClass); + + // Keep track of the relationship between test classes and the display names + String testClassName = null; + if (testIdentifier.getSource().isPresent() && testIdentifier.getSource().get() instanceof ClassSource) { + testClassName = ((ClassSource) testIdentifier.getSource().get()).getClassName(); + } + TestClassHierarchy.getInstance().testSuiteStarted(testClassName, + testIdentifier.getUniqueId(), + testIdentifier.getDisplayName(), + testIdentifier.getParentId().orElse(null)); + + eventBusFor(testIdentifier).getBaseStepListener().clearTestOutcomes(); + eventBusFor(testIdentifier).testSuiteStarted(testClass, testIdentifier.getDisplayName()); + TEST_CASE_DISPLAY_NAMES.put(testClass, testIdentifier.getDisplayName()); + } + + if (isMethodSource(testIdentifier)) { + MethodSource methodSource = ((MethodSource) testIdentifier.getSource().get()); + if (isSimpleTest(testIdentifier)) { + testClass = ((MethodSource) testIdentifier.getSource().get()).getJavaClass(); + testStarted(methodSource, testIdentifier, testClass); + } + String sourceMethod = methodSource.getJavaClass().getCanonicalName() + "." + methodSource.getMethodName(); + DataTable dataTable = dataTables.get(sourceMethod); + if (dataTable != null) { + logger.trace("FoundDataTable " + dataTable + " " + dataTable.getRows()); + if (isSimpleTest(testIdentifier)) { + eventBusFor(testIdentifier).useExamplesFrom(dataTable); + logger.trace("-->EventBus.useExamplesFrom" + dataTable); + int rowNumber = getTestTemplateInvocationNumber(testIdentifier); + logger.trace("-->EventBus.exampleStarted " + rowNumber + "--" + dataTable.row(rowNumber).toStringMap()); + logger.trace("-->EventBus.useExamplesFrom" + dataTable + " with parameter set number " + rowNumber); + eventBusFor(testIdentifier).exampleStarted(dataTable.row(rowNumber).toStringMap()); + } else { + DATA_DRIVEN_TEST_NAMES.put(testIdentifier.getUniqueId(), testIdentifier.getDisplayName()); + } + } + } + } + + private boolean isTestContainer(TestIdentifier testIdentifier) { + return TestDescriptor.Type.CONTAINER == testIdentifier.getType(); + } + + @Override + public synchronized void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { + if (!isSerenityTest) return; + + logger.trace("-->Execution finished " + testIdentifier); + logger.trace("-->Execution finished " + testIdentifier.getDisplayName() + "--" + testIdentifier.getType() + "--" + testIdentifier.getSource() + " with result " + testExecutionResult.getStatus()); + if (!testIdentifier.getSource().isPresent()) { + logger.debug("No action done at executionFinished because testIdentifier is null"); + return; + } + + if (isTestContainer(testIdentifier) && isClassSource(testIdentifier)) { + logger.trace("-->EventBus.TestSuiteFinished " + ((ClassSource) testIdentifier.getSource().get()).getJavaClass()); + eventBusFor(testIdentifier).testSuiteFinished(); + } + if (isSimpleTest(testIdentifier)) { + if (isMethodSource(testIdentifier)) { + MethodSource methodSource = ((MethodSource) testIdentifier.getSource().get()); + String sourceMethod = methodSource.getClassName() + "." + methodSource.getMethodName(); + testFinished(testIdentifier, methodSource, testExecutionResult); + DataTable dataTable = dataTables.get(sourceMethod); + if (dataTable != null) { + eventBusFor(testIdentifier).exampleFinished(); + } + } + } + recordSummaryData(testIdentifier, testExecutionResult); + } + + + private void recordSummaryData(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { + try { + switch (testExecutionResult.getStatus()) { + + case SUCCESSFUL: { + if (testIdentifier.isContainer()) { + this.summary.containersSucceeded.incrementAndGet(); + } + if (testIdentifier.isTest()) { + this.summary.testsSucceeded.incrementAndGet(); + } + break; + } + + case ABORTED: { + if (testIdentifier.isContainer()) { + this.summary.containersAborted.incrementAndGet(); + } + if (testIdentifier.isTest()) { + this.summary.testsAborted.incrementAndGet(); + } + break; + } + + case FAILED: { + if (testIdentifier.isContainer()) { + this.summary.containersFailed.incrementAndGet(); + } + if (testIdentifier.isTest()) { + this.summary.testsFailed.incrementAndGet(); + } + testExecutionResult.getThrowable().ifPresent(throwable -> this.summary.addFailure(testIdentifier, throwable)); + eventBusFor(testIdentifier).testFailed(testExecutionResult.getThrowable().get()); + break; + } + default: + throw new PreconditionViolationException("Unsupported execution status:" + testExecutionResult.getStatus()); + } + } finally { + expectedExceptions.clear(); + } + } + + private void testFinished(TestIdentifier testIdentifier, MethodSource methodSource, TestExecutionResult testExecutionResult) { + updateResultsUsingTestAnnotations(testIdentifier, methodSource); +// TestResult result = StepEventBus.getParallelEventBus().getBaseStepListener().getCurrentTestOutcome().getResult(); + TestResult result = eventBusFor(testIdentifier).getBaseStepListener().getCurrentTestOutcome().getResult(); + if (testExecutionResult.getStatus() == TestExecutionResult.Status.ABORTED && result == TestResult.SUCCESS) { + updateResultsUsingTestExecutionResult(testIdentifier, testExecutionResult); + } else if (testExecutionResult.getStatus() == TestExecutionResult.Status.FAILED && result.isLessSevereThan(TestResult.FAILURE)) { + updateResultsUsingTestExecutionResult(testIdentifier, testExecutionResult); + } + + eventBusFor(testIdentifier).testFinished(); + eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); + } + + private void updateResultsUsingTestExecutionResult(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { + testExecutionResult.getThrowable().ifPresent(cause -> eventBusFor(testIdentifier).getBaseStepListener().updateCurrentStepFailureCause(cause)); + if (testExecutionResult.getStatus() == TestExecutionResult.Status.ABORTED) { + eventBusFor(testIdentifier).getBaseStepListener().overrideResultTo(TestResult.ABORTED); + } + } + + private void updateResultsUsingTestAnnotations(TestIdentifier testIdentifier, MethodSource methodSource) { + + if (TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).isManual()) { + setToManual(testIdentifier, methodSource); + } + expectedExceptions.forEach(ex -> updateResultsForExpectedException(testIdentifier, ex)); + } + + private void setToManual(TestIdentifier testIdentifier, MethodSource methodSource) { + eventBusFor(testIdentifier).testIsManual(); + TestResult result = TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).getManualResult(); + eventBusFor(testIdentifier).getBaseStepListener().recordManualTestResult(result); + } + + private void updateResultsForExpectedException(TestIdentifier testIdentifier, Class expected) { + eventBusFor(testIdentifier).exceptionExpected(expected); + } + + private boolean isSimpleTest(TestIdentifier testIdentifier) { + return testIdentifier.getType() == TestDescriptor.Type.TEST; + } + + private boolean isClassSource(TestIdentifier testId) { + return testId.getSource().isPresent() && (testId.getSource().get() instanceof ClassSource); + } + + private boolean isMethodSource(TestIdentifier testId) { + return testId.getSource().isPresent() && (testId.getSource().get() instanceof MethodSource); + } + + /** + * Called when a test starts. We also need to start the test suite the first + * time, as the testRunStarted() method is not invoked for some reason. + */ + private void testStarted(MethodSource methodSource, TestIdentifier testIdentifier, Class testClass) { + if (testingThisTest(testIdentifier, testClass)) { + startTestSuiteForFirstTest(testIdentifier); + logger.debug(Thread.currentThread() + " Test started " + testIdentifier); + eventBusFor(testIdentifier).clear(); + eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); + +// String testName = StringUtils.isNotEmpty(testIdentifier.getDisplayName()) ? testIdentifier.getDisplayName() : methodSource.getMethodName(); + String testName = Inflector.getInstance().humanize(methodSource.getMethodName()); + if (testIdentifier.getDisplayName().startsWith("[")) { + testName = testName + testIdentifier.getDisplayName(); + } else if (StringUtils.isNotEmpty(testIdentifier.getDisplayName())) { + testName = testIdentifier.getDisplayName(); + } + try { + Method javaMethod = methodSource.getJavaMethod(); + + if (JUnit5TestClassAnnotations.forTest(testClass).getDisplayNameGeneration(javaMethod).isPresent()) { + testName = JUnit5TestClassAnnotations.forTest(testClass).getDisplayNameGeneration(javaMethod).get(); + } + if (JUnit5TestMethodAnnotations.forTest(javaMethod).getDisplayName().isPresent()) { + testName = JUnit5TestMethodAnnotations.forTest(javaMethod).getDisplayName().get(); + } + } catch (Exception e) { + //ignore org.junit.platform.commons.PreconditionViolationException: Could not find method with name + } + + eventBusFor(testIdentifier).testStarted(Optional.ofNullable(testName).orElse("Initialisation"), + methodSource.getJavaClass(), + methodSource.getMethodName(), + testIdentifier.getUniqueId(), + testIdentifier.getParentId().orElse(testIdentifier.getUniqueId())); + + // + // Check for @Pending tests + // + if (isPending(methodSource)) { + eventBusFor(testIdentifier).testPending(); + } + } + } + + private synchronized StepEventBus eventBusFor(TestIdentifier testIdentifier) { + String uniqueTestId = testIdentifier.getUniqueId(); + + StepEventBus currentEventBus = StepEventBus.eventBusFor(uniqueTestId); + if (!currentEventBus.isBaseStepListenerRegistered()) { + File outputDirectory = getOutputDirectory(); + BaseStepListener baseStepListener = Listeners.getBaseStepListener().withOutputDirectory(outputDirectory); + currentEventBus.registerListener(baseStepListener); +// currentEventBus.registerListener(new ConsoleLoggingListener(currentEventBus.getEnvironmentVariables())); + currentEventBus.registerListener(SerenityInfrastructure.getLoggingListener()); + logger.trace(" -> ADDED BASE LISTENER " + baseStepListener); + StepListener loggingListener = Listeners.getLoggingListener(); + currentEventBus.registerListener(loggingListener); + logger.trace(" -> ADDED LOGGING LISTENER " + loggingListener); + } + logger.trace("SETTING EVENT BUS FOR THREAD " + Thread.currentThread() + " TO " + currentEventBus); + StepEventBus.setCurrentBusToEventBusFor(uniqueTestId); + return currentEventBus; + } + + + private boolean isPending(MethodSource methodSource) { + try { + return (TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).isPending()); + } catch (Exception ex) { + return false; + } + } + + private boolean testingThisTest(TestIdentifier testIdentifier, Class testClass) { + if (isMethodSource(testIdentifier)) { + MethodSource methodSource = (MethodSource) testIdentifier.getSource().get(); + return testClass.equals(methodSource.getJavaClass()); + } + return false; + } + + + private void startTestSuiteForFirstTest(TestIdentifier testIdentifier) { + if (isMethodSource(testIdentifier)) { + Class testCase = ((MethodSource) testIdentifier.getSource().get()).getJavaClass(); + logger.trace("-->TestSuiteStarted " + testCase); + String testSuiteName = TEST_CASE_DISPLAY_NAMES.getOrDefault(testCase, testCase.getSimpleName()); + eventBusFor(testIdentifier).testSuiteStarted(((MethodSource) testIdentifier.getSource().get()).getJavaClass(), testSuiteName); + } + } + + + /** + * Find the current set of test outcomes produced by the test execution. + * + * @param testIdentifier + * @return the current list of test outcomes + */ + public List getTestOutcomes(TestIdentifier testIdentifier) { + logger.trace("GET TEST OUTCOMES FOR " + testIdentifier); + logger.trace(" - BASE STEP LISTENER: " + eventBusFor(testIdentifier).getBaseStepListener()); + List testOutcomes = eventBusFor(testIdentifier).getBaseStepListener().getTestOutcomes(); + testOutcomes.forEach( + outcome -> { + if (testIdentifier.getParentId().isPresent() && DATA_DRIVEN_TEST_NAMES.get(testIdentifier.getParentId().get()) != null) { + outcome.setTestOutlineName(DATA_DRIVEN_TEST_NAMES.get(testIdentifier.getParentId().get())); + } + } + ); + return testOutcomes; + } + + + private void generateReports(TestIdentifier testIdentifier) { + logger.trace("GENERATE REPORTS FOR TEST " + testIdentifier.getUniqueId()); + generateReportsFor(getTestOutcomes(testIdentifier)); + + StepEventBus.clearEventBusFor(testIdentifier.getUniqueId()); + } + + private void generateReportsForParameterizedTests(List testIdentifiers) { + logger.trace("GENERATE REPORTS FOR PARAMETERIZED TESTS " + testIdentifiers); + List allTestOutcomes = testIdentifiers + .stream() + .map(this::getTestOutcomes) + .flatMap(List::stream) + .collect(Collectors.toList()); + ParameterizedTestsOutcomeAggregator parameterizedTestsOutcomeAggregator = + new ParameterizedTestsOutcomeAggregator(allTestOutcomes); + + generateReportsFor(parameterizedTestsOutcomeAggregator.aggregateTestOutcomesByTestMethods()); + + testIdentifiers.stream().map(TestIdentifier::getUniqueId).forEach(StepEventBus::clearEventBusFor); + } + + /** + * A test runner can generate reports via Reporter instances that subscribe + * to the test runner. The test runner tells the reporter what directory to + * place the reports in. Then, at the end of the test, the test runner + * notifies these reporters of the test outcomes. The reporter's job is to + * process each test run outcome and do whatever is appropriate. + * + * @param testOutcomeResults the test results from the previous test run. + */ + private void generateReportsFor(final List testOutcomeResults) { + getReportService().generateReportsFor(testOutcomeResults); + getReportService().generateConfigurationsReport(); + } + + private ReportService getReportService() { + if (reportService == null) { + reportService = new ReportService(getOutputDirectory(), getDefaultReporters()); + } + return reportService; + } + + /** + * Instantiates the @ManagedPages-annotated Pages instance using current WebDriver. + * + * @param testCase A Serenity-annotated test class + */ + protected void injectAnnotatedPagesObjectInto(final Object testCase) { + StepAnnotations.injector().injectAnnotatedPagesObjectInto(testCase, pages); + } + + public static void addExpectedException(Class exceptionClass) { + expectedExceptions.add(exceptionClass); + } + + static boolean isSerenityTestClass(Class testClass) { + return classNestStructure(testClass) + .stream() + .flatMap(clazz -> Stream.of(clazz.getAnnotationsByType(ExtendWith.class))) + .anyMatch(annotation -> Arrays.asList(annotation.value()).contains(SerenityJUnit5Extension.class)); + } + + static private List> classNestStructure(Class testClass) { + List> nestedStructure = new ArrayList<>(); + nestedStructure.add(testClass); + Class declaringClass = testClass.getDeclaringClass(); + while (declaringClass != null) { + nestedStructure.add(declaringClass); + declaringClass = declaringClass.getDeclaringClass(); + } + return nestedStructure; + } + + private int getTestTemplateInvocationNumber(TestIdentifier testIdentifier) { + return getTestTemplateInvocationNumber(testIdentifier.getUniqueId()); + } + + static int getTestTemplateInvocationNumber(String uniqueTestIdentifier) { + if (!uniqueTestIdentifier.contains("test-template-invocation")) { + return -1; + } else { + int index1 = uniqueTestIdentifier.lastIndexOf("#"); + int index2 = uniqueTestIdentifier.lastIndexOf("]"); + return Integer.parseInt(uniqueTestIdentifier.substring(index1 + 1, index2)) - 1; + } + } +} diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java index af42a3147b..694476f55e 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java @@ -12,7 +12,6 @@ import java.util.Optional; import static java.lang.System.getenv; -import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; public class FeatureToggleConditionExtension implements ExecutionCondition { @@ -24,43 +23,28 @@ public class FeatureToggleConditionExtension implements ExecutionCondition { private static String flagName; @Override - @SuppressWarnings("checkstyle:Indentation") public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - - if (isNotTrue(isInitialized)) { + if (!isInitialized) { initialize(); } - final Optional element = context.getElement(); - - return element.map(annotatedElement -> { - Optional toggleEnable = findAnnotation(element, ToggleEnable.class); - - return toggleEnable.map(toggle -> { - featureToggleService.mapServiceToFlag(); - flagName = featureToggleService.getLaunchDarklyMap().get(toggle.mapKey()); - - final boolean isFlagEnabled = - featureToggleService - .isFlagEnabled("rd_professional_api", flagName); - - ConditionEvaluationResult evaluationResult = null; - - if (isFlagEnabled) { - if (isNotTrue(toggle.withFeature())) { - evaluationResult = disabled(); - } else { - evaluationResult = enabled(); - } - } else { - if (isNotTrue(toggle.withFeature()) || toggle.withFeature()) { - evaluationResult = disabled(); - } - } - return evaluationResult; - }).orElse(enabled()); - } - ).orElse(enabled()); + final Optional optElement = context.getElement(); + Optional toggleEnable = findAnnotation(optElement, ToggleEnable.class); + + if (toggleEnable.isEmpty()) { + return enabled(); + } + + ToggleEnable toggle = toggleEnable.get(); + + flagName = featureToggleService.getLaunchDarklyMap().get(toggle.mapKey()); + final boolean isFlagEnabled = featureToggleService.isFlagEnabled("rd_professional_api", flagName); + + ConditionEvaluationResult evaluationResult = disabled(); + if (isFlagEnabled && toggle.withFeature()) { + evaluationResult = enabled(); + } + return evaluationResult; } @NotNull @@ -77,7 +61,6 @@ private ConditionEvaluationResult enabled() { return ConditionEvaluationResult.enabled("Feature toggled ON"); } - @SuppressWarnings("checkstyle:CommentsIndentation") private static void initialize() { LDClient ldClient = new LDClient(getenv("LD_SDK_KEY")); featureToggleService = new FeatureToggleServiceImpl(ldClient, "rd"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/ToggleEnable.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/ToggleEnable.java index 0fdc3b545c..e0aa4c428f 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/ToggleEnable.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/ToggleEnable.java @@ -11,5 +11,5 @@ public @interface ToggleEnable { String mapKey(); - boolean withFeature(); + boolean withFeature() default true; } diff --git a/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener new file mode 100644 index 0000000000..4d316ab8a3 --- /dev/null +++ b/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -0,0 +1 @@ +uk.gov.hmcts.reform.professionalapi.util.CustomTestExecutionListener diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImpl.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImpl.java index e6d8a1f7a4..69bda456c3 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImpl.java @@ -2,13 +2,11 @@ import com.launchdarkly.sdk.LDUser; import com.launchdarkly.sdk.server.LDClient; -import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.professionalapi.service.FeatureToggleService; -import java.util.HashMap; import java.util.Map; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.PRD_CREATE_EXTERNAL_V2; @@ -34,7 +32,28 @@ public class FeatureToggleServiceImpl implements FeatureToggleService { private final String userName; - private Map launchDarklyMap; + /** + * Add Map.entry(ControllerName.methodName, FLAG_NAME) to map to apply launch darkly (ld) flag on api. + */ + @SuppressWarnings("checkstyle:linelength") + private final Map launchDarklyMap = Map.ofEntries( + Map.entry("OrganisationMfaStatusController.retrieveMfaStatusByUserId", PRD_MFA_LD_FLAG), + Map.entry("OrganisationInternalController.updateOrgMfaStatus", PRD_MFA_LD_FLAG), + Map.entry("OrganisationExternalController.deletePaymentAccountsOfOrganisation", RD_PROFESSIONAL_MULTI_PBA_LD_FLAG), + Map.entry("OrganisationInternalController.retrieveOrgByPbaStatus", RD_PROFESSIONAL_MULTI_PBA_LD_FLAG), + Map.entry("OrganisationExternalController.addPaymentAccountsToOrganisation", RD_PROFESSIONAL_MULTI_PBA_LD_FLAG), + Map.entry("OrganisationInternalController.updateAnOrganisationsRegisteredPbas", RD_PROFESSIONAL_MULTI_PBA_LD_FLAG), + Map.entry("OrganisationExternalController.addContactInformationsToOrganisation", RD_PROFESSIONAL_MULTIPLE_ADDRESS), + Map.entry("OrganisationExternalController.deleteMultipleAddressesOfOrganisation", RD_PROFESSIONAL_MULTIPLE_ADDRESS), + Map.entry("OrganisationInternalControllerV2.retrieveOrganisations", PRD_RETRIEVE_INTERNAL_V2), + Map.entry("OrganisationInternalControllerV2.createOrganisation", PRD_CREATE_INTERNAL_V2), + Map.entry("OrganisationInternalControllerV2.updatesOrganisation", PRD_UPDATE_INTERNAL_V2), + Map.entry("OrganisationInternalControllerV2.retrievePaymentAccountBySuperUserEmail", PRD_RETRIEVE_PBA_INTERNAL_V2), + Map.entry("OrganisationExternalControllerV2.retrievePaymentAccountByEmail", PRD_RETRIEVE_PBA_EXTERNAL_V2), + Map.entry("OrganisationExternalControllerV2.retrieveOrganisationUsingOrgIdentifier", PRD_RETRIEVE_EXTERNAL_V2), + Map.entry("OrganisationExternalControllerV2.createOrganisationUsingExternalController", PRD_CREATE_EXTERNAL_V2), + Map.entry("BulkCustomerDetailsInternalController.retrieveOrganisationDetailsForBulkCustomer", RD_PROFESSIONAL_BULK_CUSTOMER_LD_FLAG) + ); @Autowired public FeatureToggleServiceImpl(LDClient ldClient, @Value("${launchdarkly.sdk.user}") String userName) { @@ -42,49 +61,6 @@ public FeatureToggleServiceImpl(LDClient ldClient, @Value("${launchdarkly.sdk.us this.userName = userName; } - /** - * add controller.method name, flag name in map to apply ld flag on api like below - * launchDarklyMap.put("OrganisationExternalController.retrieveOrganisationsByStatusWithAddressDetailsOptional", - * "prd-aac-get-org-by-status"); - */ - @PostConstruct - public void mapServiceToFlag() { - launchDarklyMap = new HashMap<>(); - launchDarklyMap.put("OrganisationMfaStatusController.retrieveMfaStatusByUserId", - PRD_MFA_LD_FLAG); - launchDarklyMap.put("OrganisationInternalController.updateOrgMfaStatus", - PRD_MFA_LD_FLAG); - launchDarklyMap.put("OrganisationExternalController.deletePaymentAccountsOfOrganisation", - RD_PROFESSIONAL_MULTI_PBA_LD_FLAG); - launchDarklyMap.put("OrganisationInternalController.retrieveOrgByPbaStatus", - RD_PROFESSIONAL_MULTI_PBA_LD_FLAG); - launchDarklyMap.put("OrganisationExternalController.addPaymentAccountsToOrganisation", - RD_PROFESSIONAL_MULTI_PBA_LD_FLAG); - launchDarklyMap.put("OrganisationInternalController.updateAnOrganisationsRegisteredPbas", - RD_PROFESSIONAL_MULTI_PBA_LD_FLAG); - launchDarklyMap.put("OrganisationExternalController.addContactInformationsToOrganisation", - RD_PROFESSIONAL_MULTIPLE_ADDRESS); - launchDarklyMap.put("OrganisationExternalController.deleteMultipleAddressesOfOrganisation", - RD_PROFESSIONAL_MULTIPLE_ADDRESS); - launchDarklyMap.put("OrganisationInternalControllerV2.retrieveOrganisations", - PRD_RETRIEVE_INTERNAL_V2); - launchDarklyMap.put("OrganisationInternalControllerV2.createOrganisation", - PRD_CREATE_INTERNAL_V2); - launchDarklyMap.put("OrganisationInternalControllerV2.updatesOrganisation", - PRD_UPDATE_INTERNAL_V2); - launchDarklyMap.put("OrganisationInternalControllerV2.retrievePaymentAccountBySuperUserEmail", - PRD_RETRIEVE_PBA_INTERNAL_V2); - launchDarklyMap.put("OrganisationExternalControllerV2.retrievePaymentAccountByEmail", - PRD_RETRIEVE_PBA_EXTERNAL_V2); - launchDarklyMap.put("OrganisationExternalControllerV2.retrieveOrganisationUsingOrgIdentifier", - PRD_RETRIEVE_EXTERNAL_V2); - launchDarklyMap.put("OrganisationExternalControllerV2.createOrganisationUsingExternalController", - PRD_CREATE_EXTERNAL_V2); - launchDarklyMap.put("BulkCustomerDetailsInternalController.retrieveOrganisationDetailsForBulkCustomer", - RD_PROFESSIONAL_BULK_CUSTOMER_LD_FLAG); - - } - @Override public boolean isFlagEnabled(String serviceName, String flagName) { LDUser user = new LDUser.Builder(userName) diff --git a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImplTest.java b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImplTest.java index 1e3afccbed..c2589008a0 100644 --- a/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/reform/professionalapi/service/impl/FeatureToggleServiceImplTest.java @@ -39,7 +39,6 @@ void testIsFlagDisabled() { @Test void mapServiceToFlagTest() { flaFeatureToggleService = new FeatureToggleServiceImpl(ldClient, "rd"); - flaFeatureToggleService.mapServiceToFlag(); assertTrue(flaFeatureToggleService.getLaunchDarklyMap().size() >= 1); } } From 295e2686fba7fd41674a11f0b252b2bbe152e681 Mon Sep 17 00:00:00 2001 From: Rapolas <130578328+rapolaskaseliscgi@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:14:44 +0000 Subject: [PATCH 06/13] checkstyle --- .../ProfessionalExternalUserFunctionalTest.java | 8 +++++++- .../professionalapi/util/CustomTestExecutionListener.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java index 5c95294176..da06b276a0 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java @@ -255,8 +255,14 @@ public void inviteUserBySuperUserShouldBeSuccess() { professionalApiClient.getMultipleAuthHeaders(idamOpenIdClient.getExternalOpenIdTokenWithRetry( superUserRoles(), firstName, lastName, email)); + UserCreationRequest superUserRequest = UserCreationRequest + .aUserCreationRequest() + .firstName(firstName) + .lastName(lastName) + .email(email) + .build(); OrganisationCreationRequest organisationCreationRequest = createOrganisationRequest() - .superUser(UserCreationRequest.aUserCreationRequest().firstName(firstName).lastName(lastName).email(email).build()) + .superUser(superUserRequest) .status("ACTIVE").build(); createAndActivateOrganisationWithGivenRequest(organisationCreationRequest, hmctsAdmin); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java index a47ad5d99e..1e562bb4db 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java @@ -59,7 +59,7 @@ import static net.thucydides.model.reports.ReportService.getDefaultReporters; import static net.thucydides.model.steps.TestSourceType.TEST_SOURCE_JUNIT5; -@SuppressWarnings("unchecked") +@SuppressWarnings({"unchecked", "all"}) public class CustomTestExecutionListener extends SerenityTestExecutionListener { private static final List expectedExceptions = Collections.synchronizedList(new ArrayList<>()); From 26c10eaada36b3c06c506b77119a7c6a25c3b21e Mon Sep 17 00:00:00 2001 From: Kiran Kumar Yenigala <51748133+kiran-yenigala-hmcts@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:49:39 +0000 Subject: [PATCH 07/13] Serenity issue fix (#1712) * Fix serenity issues * Remove unused classes --- .../BulkCivilApiFunctionalTest.java | 6 +- .../professionalapi/EndpointSecurityTest.java | 4 +- ...nalExternalUserFunctionalForV2ApiTest.java | 6 +- ...rofessionalExternalUserFunctionalTest.java | 15 +- ...nalInternalUserFunctionalForV2ApiTest.java | 7 +- ...rofessionalInternalUserFunctionalTest.java | 12 +- ...ava => CustomSerenityJUnit5Extension.java} | 10 +- .../util/CustomTestExecutionListener.java | 572 ------------------ 8 files changed, 25 insertions(+), 607 deletions(-) rename src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/{FeatureToggleConditionExtension.java => CustomSerenityJUnit5Extension.java} (89%) delete mode 100644 src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java index fb5d4dd1aa..466b44f6c8 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/BulkCivilApiFunctionalTest.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.lib.client.response.S2sClient; import uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient; import uk.gov.hmcts.reform.professionalapi.config.TestConfigProperties; @@ -29,7 +30,7 @@ import uk.gov.hmcts.reform.professionalapi.repository.BulkCustomerDetailsRepository; import uk.gov.hmcts.reform.professionalapi.repository.OrganisationRepository; import uk.gov.hmcts.reform.professionalapi.repository.PaymentAccountRepository; -import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; +import uk.gov.hmcts.reform.professionalapi.util.CustomSerenityJUnit5Extension; import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; import java.util.Map; @@ -38,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @TestPropertySource({"classpath:application.yaml","classpath:application-functional-bulkcustomer.yaml"}) public class BulkCivilApiFunctionalTest { @@ -274,7 +275,6 @@ void retrieveBulkCustomerDetailsWithEmptyBulkCustomerID() { @Test @ToggleEnable(mapKey = "BulkCustomerDetailsInternalController.retrieveOrganisationDetailsForBulkCustomer", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) void retrieveBulkCustomerDetailsWithLaunchDarklyFlagOff() { BulkCustomerRequest bulkCustomerRequest = new BulkCustomerRequest(); bulkCustomerRequest.setBulkCustomerId("bulkCustomerId"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java index c5c5aa2d7e..4f958dd28a 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/EndpointSecurityTest.java @@ -7,10 +7,12 @@ import org.junit.jupiter.api.extension.ExtendWith; 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.reform.professionalapi.util.CustomSerenityJUnit5Extension; import static org.assertj.core.api.Assertions.assertThat; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @ActiveProfiles("functional") diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java index 6813ffdb8c..8b87e2f542 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalForV2ApiTest.java @@ -9,9 +9,10 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; -import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; +import uk.gov.hmcts.reform.professionalapi.util.CustomSerenityJUnit5Extension; import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; import java.util.ArrayList; @@ -24,7 +25,7 @@ import static org.springframework.http.HttpStatus.OK; import static uk.gov.hmcts.reform.professionalapi.client.ProfessionalApiClient.createOrganisationRequestForV2; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j @@ -52,7 +53,6 @@ class ProfessionalExternalUserFunctionalForV2ApiTest extends AuthorizationFuncti @DisplayName("PRD External Test Scenarios For V2 API") @ToggleEnable(mapKey = "OrganisationExternalControllerV2" + ".createOrganisationUsingExternalController", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void testExternalUserScenario() { setUpOrgTestData(); setUpUserBearerTokens(List.of(puiUserManager, puiCaseManager, puiOrgManager, puiFinanceManager, caseworker)); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java index da06b276a0..0db10c6b6d 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalExternalUserFunctionalTest.java @@ -11,6 +11,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.professionalapi.controller.request.ContactInformationCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.DeleteMultipleAddressRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; @@ -20,7 +21,7 @@ import uk.gov.hmcts.reform.professionalapi.controller.response.OrganisationMinimalInfoResponse; import uk.gov.hmcts.reform.professionalapi.domain.UserAccessType; import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; -import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; +import uk.gov.hmcts.reform.professionalapi.util.CustomSerenityJUnit5Extension; import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; import java.util.ArrayList; @@ -52,7 +53,7 @@ import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.FALSE; import static uk.gov.hmcts.reform.professionalapi.controller.constants.ProfessionalApiConstants.TRUE; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j @@ -660,7 +661,6 @@ public String inviteUser(String role, @Test @DisplayName("MFA Scenarios") - @ExtendWith(FeatureToggleConditionExtension.class) @ToggleEnable(mapKey = "OrganisationMfaStatusController.retrieveMfaStatusByUserId", withFeature = true) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void findMFAScenario() { @@ -692,7 +692,6 @@ public void findOrganisationPbaWithoutEmailByExternalUserShouldBeBadRequest() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.deletePaymentAccountsOfOrganisation", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void deletePbaOfExistingOrganisationShouldBeForbiddenWhenLDOff() { log.info("deletePbaOfExistingOrganisationShouldBeForbiddenWhenLDOff :: STARTED"); @@ -711,7 +710,6 @@ void deletePbaOfExistingOrganisationShouldBeForbiddenWhenLDOff() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.deletePaymentAccountsOfOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void deletePbaOfExistingOrganisationShouldBeSuccess() { log.info("deletePbaOfExistingOrganisationShouldBeSuccess :: STARTED"); @@ -734,7 +732,6 @@ void deletePbaOfExistingOrganisationShouldBeSuccess() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.addPaymentAccountsToOrganisation", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void addPbaOfExistingOrganisationShouldBeForbiddenWhenLDOff() { log.info("addPbaOfExistingOrganisationShouldBeForbiddenWhenLDOff :: STARTED"); @@ -753,7 +750,6 @@ void addPbaOfExistingOrganisationShouldBeForbiddenWhenLDOff() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.addPaymentAccountsToOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void addPbaOfExistingOrganisationShouldBeSuccess() { log.info("addPaymentAccountsToOrganisation :: STARTED"); @@ -787,7 +783,6 @@ void addPbaOfExistingOrganisationShouldBeSuccess() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.addContactInformationsToOrganisation", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void testAddContactsInformationsToOrganisationScenariosShouldBeForbiddenWhenLDOff() { setUpOrgTestData(); @@ -809,7 +804,6 @@ void testAddContactsInformationsToOrganisationScenariosShouldBeForbiddenWhenLDOf @Test @DisplayName("Add Contact informations to organisations Test Scenarios") @ToggleEnable(mapKey = "OrganisationExternalController.addContactInformationsToOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void testAddContactsInformationsToOrganisationScenariosShouldBeSuccessWhenLDON() { setUpOrgTestData(); @@ -868,7 +862,6 @@ public void suspendUserByPuiOrgManagerShouldBeSuccess() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.deleteMultipleAddressesOfOrganisation", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) @SuppressWarnings("checkstyle:AbbreviationAsWordInName") void deleteMultipleAddressesOfOrganisationShouldBeForbiddenWhenLDOff() { log.info("deleteMultipleAddressesOfOrganisationShouldBeForbiddenWhenLDOff :: STARTED"); @@ -889,7 +882,6 @@ void deleteMultipleAddressesOfOrganisationShouldBeForbiddenWhenLDOff() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.deleteMultipleAddressesOfOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void deleteMultipleAddressesOfOrganisationShouldBe404Failure() { log.info("deleteMultipleAddressesOfOrganisationShouldBeSuccess :: STARTED"); setUpOrgTestData(); @@ -909,7 +901,6 @@ void deleteMultipleAddressesOfOrganisationShouldBe404Failure() { @Test @ToggleEnable(mapKey = "OrganisationExternalController.deleteMultipleAddressesOfOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void deleteMultipleAddressesOfOrganisationShouldBeSuccess() { log.info("deleteMultipleAddressesOfOrganisationShouldBeSuccess :: STARTED"); setUpOrgTestData(); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java index 169824af62..2c6317270f 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalForV2ApiTest.java @@ -11,14 +11,15 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationByProfileIdsRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.OrganisationOtherOrgsCreationRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.UsersInOrganisationsByOrganisationIdentifiersRequest; import uk.gov.hmcts.reform.professionalapi.controller.response.UsersInOrganisationsByOrganisationIdentifiersResponse; import uk.gov.hmcts.reform.professionalapi.domain.OrganisationStatus; +import uk.gov.hmcts.reform.professionalapi.util.CustomSerenityJUnit5Extension; import uk.gov.hmcts.reform.professionalapi.util.DateUtils; -import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; import uk.gov.hmcts.reform.professionalapi.util.OrganisationProfileIdConstants; import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; @@ -37,7 +38,7 @@ import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j @@ -58,7 +59,6 @@ class ProfessionalInternalUserFunctionalForV2ApiTest extends AuthorizationFuncti @Test @DisplayName("PRD Internal Test Scenarios For V2 API") @ToggleEnable(mapKey = "OrganisationInternalControllerV2.createOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void testInternalUserScenario() { setUpTestData(); createOrganisationScenario(); @@ -370,7 +370,6 @@ public void findOrganisationPbaWithEmailThroughHeaderByInternalUserShouldBeSucce @Test @ToggleEnable(mapKey = "OrganisationInternalControllerV2.createOrganisation", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void findOrganisationsWithPaginationShouldReturnSuccess() { log.info("findOrganisationsWithPaginationShouldReturnSuccess :: STARTED"); professionalApiClient.createOrganisationV2(); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java index af5b8acada..ef3202eb69 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/ProfessionalInternalUserFunctionalTest.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.professionalapi.controller.constants.IdamStatus; import uk.gov.hmcts.reform.professionalapi.controller.request.MfaUpdateRequest; import uk.gov.hmcts.reform.professionalapi.controller.request.NewUserCreationRequest; @@ -27,8 +28,8 @@ import uk.gov.hmcts.reform.professionalapi.domain.PbaStatus; import uk.gov.hmcts.reform.professionalapi.domain.RoleName; import uk.gov.hmcts.reform.professionalapi.domain.UserProfileUpdatedData; +import uk.gov.hmcts.reform.professionalapi.util.CustomSerenityJUnit5Extension; import uk.gov.hmcts.reform.professionalapi.util.DateUtils; -import uk.gov.hmcts.reform.professionalapi.util.FeatureToggleConditionExtension; import uk.gov.hmcts.reform.professionalapi.util.ToggleEnable; import java.time.LocalDateTime; @@ -59,7 +60,7 @@ import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.convertStringToLocalDate; import static uk.gov.hmcts.reform.professionalapi.util.DateUtils.generateRandomDate; -@ExtendWith(SerenityJUnit5Extension.class) +@ExtendWith({CustomSerenityJUnit5Extension.class, SerenityJUnit5Extension.class, SpringExtension.class}) @SpringBootTest @WithTags({@WithTag("testType:Functional")}) @Slf4j @@ -578,7 +579,6 @@ public void validateRoles(List rolesToValidate) { } @Test - @ExtendWith(FeatureToggleConditionExtension.class) @ToggleEnable(mapKey = "OrganisationInternalController.updateOrgMfaStatus", withFeature = true) void updateOrgMfaScenario() { setUpTestData(); @@ -606,7 +606,6 @@ public void updateOrgMfaShouldBeSuccess() { @Test @DisplayName("Update Organisation's MFA should return 403 when toggled off") - @ExtendWith(FeatureToggleConditionExtension.class) @ToggleEnable(mapKey = "OrganisationInternalController.updateOrgMfaStatus", withFeature = false) void updateOrgMfaShouldReturn403WhenToggledOff() { log.info("updateOrgMFAShouldReturn403 :: STARTED"); @@ -644,7 +643,6 @@ public void updateOrgStatusShouldBeSuccess() { @Test @ToggleEnable(mapKey = "OrganisationInternalController.retrieveOrgByPbaStatus", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void retrieveOrgsByPbaStatusScenario() { setUpTestData(); findOrganisationByPbaStatusShouldBeSuccessWithPbas(); @@ -678,7 +676,6 @@ public void findOrganisationByPbaStatusShouldBeSuccessWithPbas() { @Test @ToggleEnable(mapKey = "OrganisationInternalController.retrieveOrgByPbaStatus", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) void findOrganisationByPbaStatusShouldReturn403WhenToggledOff() { log.info("findOrganisationByPbaStatusShouldReturn403WhenToggledOff :: STARTED"); @@ -690,7 +687,6 @@ void findOrganisationByPbaStatusShouldReturn403WhenToggledOff() { @Test @ToggleEnable(mapKey = "OrganisationInternalController.updateAnOrganisationsRegisteredPbas", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void updatePaymentAccountsShouldReturnSuccess() { log.info("updatePaymentAccountsShouldReturnSuccess :: STARTED"); setUpTestData(); @@ -728,7 +724,6 @@ void updatePaymentAccountsShouldReturnSuccess() { @Test @ToggleEnable(mapKey = "OrganisationInternalController.updateAnOrganisationsRegisteredPbas", withFeature = true) - @ExtendWith(FeatureToggleConditionExtension.class) void updatePaymentAccountsShouldReturnPartialSuccess() { log.info("updatePaymentAccountsShouldReturnPartialSuccess :: STARTED"); setUpTestData(); @@ -763,7 +758,6 @@ void updatePaymentAccountsShouldReturnPartialSuccess() { @Test @ToggleEnable(mapKey = "OrganisationInternalController.updateAnOrganisationsRegisteredPbas", withFeature = false) - @ExtendWith(FeatureToggleConditionExtension.class) void updatePaymentAccountsShouldReturnForbiddenWhenToggledOff() { log.info("updatePaymentAccountsShouldReturnForbiddenWhenToggledOff :: STARTED"); List pbaRequestList = new ArrayList<>(); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityJUnit5Extension.java similarity index 89% rename from src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java rename to src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityJUnit5Extension.java index 694476f55e..ca3ce786ac 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/FeatureToggleConditionExtension.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomSerenityJUnit5Extension.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.professionalapi.util; import com.launchdarkly.sdk.server.LDClient; +import net.serenitybdd.junit5.SerenityJUnit5Extension; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; @@ -12,9 +13,12 @@ import java.util.Optional; import static java.lang.System.getenv; +import static org.apache.commons.lang3.BooleanUtils.isNotTrue; import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; -public class FeatureToggleConditionExtension implements ExecutionCondition { +public class CustomSerenityJUnit5Extension extends SerenityJUnit5Extension implements ExecutionCondition { + + private static LDClient ldClient; private static FeatureToggleServiceImpl featureToggleService; @@ -24,10 +28,9 @@ public class FeatureToggleConditionExtension implements ExecutionCondition { @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - if (!isInitialized) { + if (isNotTrue(isInitialized)) { initialize(); } - final Optional optElement = context.getElement(); Optional toggleEnable = findAnnotation(optElement, ToggleEnable.class); @@ -61,6 +64,7 @@ private ConditionEvaluationResult enabled() { return ConditionEvaluationResult.enabled("Feature toggled ON"); } + private static void initialize() { LDClient ldClient = new LDClient(getenv("LD_SDK_KEY")); featureToggleService = new FeatureToggleServiceImpl(ldClient, "rd"); diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java deleted file mode 100644 index 1e562bb4db..0000000000 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/util/CustomTestExecutionListener.java +++ /dev/null @@ -1,572 +0,0 @@ -package uk.gov.hmcts.reform.professionalapi.util; - -import net.bytebuddy.agent.ByteBuddyAgent; -import net.bytebuddy.agent.builder.AgentBuilder; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.matcher.ElementMatchers; -import net.serenitybdd.core.di.SerenityInfrastructure; -import net.serenitybdd.junit5.AssertThrowsAdvice; -import net.serenitybdd.junit5.JUnit5DataDrivenAnnotations; -import net.serenitybdd.junit5.JUnit5TestClassAnnotations; -import net.serenitybdd.junit5.JUnit5TestMethodAnnotations; -import net.serenitybdd.junit5.ParameterizedTestsOutcomeAggregator; -import net.serenitybdd.junit5.SerenityJUnit5Extension; -import net.serenitybdd.junit5.SerenityTestExecutionListener; -import net.serenitybdd.junit5.SerenityTestExecutionSummary; -import net.serenitybdd.junit5.TestMethodConfiguration; -import net.thucydides.core.pages.Pages; -import net.thucydides.core.steps.BaseStepListener; -import net.thucydides.core.steps.Listeners; -import net.thucydides.core.steps.StepAnnotations; -import net.thucydides.core.steps.StepEventBus; -import net.thucydides.model.configuration.SystemPropertiesConfiguration; -import net.thucydides.model.domain.DataTable; -import net.thucydides.model.domain.TestClassHierarchy; -import net.thucydides.model.domain.TestOutcome; -import net.thucydides.model.domain.TestResult; -import net.thucydides.model.environment.SystemEnvironmentVariables; -import net.thucydides.model.reports.ReportService; -import net.thucydides.model.steps.StepListener; -import net.thucydides.model.util.Inflector; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.commons.PreconditionViolationException; -import org.junit.platform.engine.TestDescriptor; -import org.junit.platform.engine.TestExecutionResult; -import org.junit.platform.engine.TestSource; -import org.junit.platform.engine.support.descriptor.ClassSource; -import org.junit.platform.engine.support.descriptor.MethodSource; -import org.junit.platform.launcher.TestIdentifier; -import org.junit.platform.launcher.TestPlan; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.lang.instrument.Instrumentation; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static net.thucydides.model.reports.ReportService.getDefaultReporters; -import static net.thucydides.model.steps.TestSourceType.TEST_SOURCE_JUNIT5; - -@SuppressWarnings({"unchecked", "all"}) -public class CustomTestExecutionListener extends SerenityTestExecutionListener { - - private static final List expectedExceptions = Collections.synchronizedList(new ArrayList<>()); - - private static final Logger logger = LoggerFactory.getLogger(CustomTestExecutionListener.class); - - static { - Instrumentation inst = ByteBuddyAgent.install(); - new AgentBuilder.Default() - .type(ElementMatchers.named("org.junit.jupiter.api.Assertions")) - .transform((builder, typeDescription, classLoader, module, protectionDomain) -> - builder.method(ElementMatchers.named("assertThrows")) - .intercept(Advice.to(AssertThrowsAdvice.class)) - ).installOn(inst); - } - - private ReportService reportService; - - private SerenityTestExecutionSummary summary; - - private Pages pages; - - //key-> "ClassName.MethodName" - //entries-> DataTable associated with method - private final Map dataTables = Collections.synchronizedMap(new HashMap<>()); - - - private boolean isSerenityTest = false; - - private static File getOutputDirectory() { - SystemPropertiesConfiguration systemPropertiesConfiguration = new SystemPropertiesConfiguration(new SystemEnvironmentVariables()); - return systemPropertiesConfiguration.getOutputDirectory(); - } - - @Override - public synchronized void testPlanExecutionStarted(TestPlan testPlan) { - this.summary = new SerenityTestExecutionSummary(testPlan); - testPlan.getRoots().forEach(root -> { - Set children = testPlan.getChildren(root.getUniqueIdObject()); - children.stream().filter(this::isClassSource).filter(this::isASerenityTest).forEach(this::configureParameterizedTestDataFor); - }); - } - - private boolean isASerenityTest(TestIdentifier child) { - return isSerenityTestClass(((ClassSource) child.getSource().get()).getJavaClass()); - } - - private void configureParameterizedTestDataFor(TestIdentifier serenityTest) { - Class javaClass = ((ClassSource) serenityTest.getSource().get()).getJavaClass(); - Map parameterTablesForClass = JUnit5DataDrivenAnnotations.forClass(javaClass).getParameterTables(); - if (!parameterTablesForClass.isEmpty()) { - dataTables.putAll(parameterTablesForClass); - } - } - - @Override - public synchronized void testPlanExecutionFinished(TestPlan testPlan) { - if (!isSerenityTest) return; - List testIdentifiers = new ArrayList<>(); - List parameterizedTestIdentifiers = new ArrayList<>(); - - //TODO use getDescendants() - testPlan.getRoots().forEach(testIdentifier -> { - generateReportsForTest(testPlan, testIdentifier, testIdentifiers, parameterizedTestIdentifiers); - }); - testIdentifiers.forEach(this::generateReports); - generateReportsForParameterizedTests(parameterizedTestIdentifiers); - - logger.debug("->TestPlanExecutionFinished " + testPlan); - } - - private void generateReportsForTest(TestPlan testPlan, TestIdentifier testIdentifier, List testIdentifiers, List parameterizedTestIdentifiers) { - logger.debug("->GenerateReportsForTest " + testIdentifier); - if (testIdentifier.getUniqueId().contains("test-template-invocation")) { - parameterizedTestIdentifiers.add(testIdentifier); - } else { - testIdentifiers.add(testIdentifier); - } - testPlan.getChildren(testIdentifier).forEach(ti -> generateReportsForTest(testPlan, ti, testIdentifiers, parameterizedTestIdentifiers)); - } - - @Override - public void dynamicTestRegistered(TestIdentifier testIdentifier) { - } - - @Override - public void executionSkipped(TestIdentifier testIdentifier, String reason) { - if (!isSerenityTest) return; - processTestMethodAnnotationsFor(testIdentifier); - } - - private void processTestMethodAnnotationsFor(TestIdentifier testIdentifier) { - Optional testSource = testIdentifier.getSource(); - if (testSource.isPresent() && (testSource.get() instanceof MethodSource)) { - startTestAtEventBus(testIdentifier); - eventBusFor(testIdentifier).testIgnored(); - eventBusFor(testIdentifier).testFinished(); - } - } - - private void startTestAtEventBus(TestIdentifier testIdentifier) { - eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); - String displayName = removeEndBracketsFromDisplayName(testIdentifier.getDisplayName()); - if (isMethodSource(testIdentifier)) { - String className = ((MethodSource) testIdentifier.getSource().get()).getClassName(); - try { - eventBusFor(testIdentifier).testStarted(Optional.ofNullable(displayName).orElse("Initialisation"), Class.forName(className)); - } catch (ClassNotFoundException exception) { - logger.error("Exception when starting test at event bus ", exception); - } - } - } - - private String removeEndBracketsFromDisplayName(String displayName) { - if (displayName != null && displayName.endsWith("()")) { - displayName = displayName.substring(0, displayName.length() - 2); - } - return displayName; - } - - private static final Map, String> TEST_CASE_DISPLAY_NAMES = new ConcurrentHashMap<>(); - private static final Map DATA_DRIVEN_TEST_NAMES = new ConcurrentHashMap<>(); - @Override - public synchronized void executionStarted(TestIdentifier testIdentifier) { - Class testClass; - logger.warn("-->Execution started with TI " + testIdentifier); - if (!testIdentifier.getSource().isPresent()) { - logger.trace("No action done at executionStarted because testIdentifier is null"); - return; - } - if (isTestContainer(testIdentifier) && isClassSource(testIdentifier)) { - testClass = ((ClassSource) testIdentifier.getSource().get()).getJavaClass(); - isSerenityTest = isSerenityTestClass(testClass); - if (!isSerenityTest) { - logger.trace("-->Execution started but no SerenityClass " + testClass); - return; - } - logger.trace("-->Execution started " + testIdentifier + "----" + testIdentifier.getDisplayName() + "--" + testIdentifier.getType() + "--" + testIdentifier.getSource()); - logger.trace("-->TestSuiteStarted " + testClass); - - // Keep track of the relationship between test classes and the display names - String testClassName = null; - if (testIdentifier.getSource().isPresent() && testIdentifier.getSource().get() instanceof ClassSource) { - testClassName = ((ClassSource) testIdentifier.getSource().get()).getClassName(); - } - TestClassHierarchy.getInstance().testSuiteStarted(testClassName, - testIdentifier.getUniqueId(), - testIdentifier.getDisplayName(), - testIdentifier.getParentId().orElse(null)); - - eventBusFor(testIdentifier).getBaseStepListener().clearTestOutcomes(); - eventBusFor(testIdentifier).testSuiteStarted(testClass, testIdentifier.getDisplayName()); - TEST_CASE_DISPLAY_NAMES.put(testClass, testIdentifier.getDisplayName()); - } - - if (isMethodSource(testIdentifier)) { - MethodSource methodSource = ((MethodSource) testIdentifier.getSource().get()); - if (isSimpleTest(testIdentifier)) { - testClass = ((MethodSource) testIdentifier.getSource().get()).getJavaClass(); - testStarted(methodSource, testIdentifier, testClass); - } - String sourceMethod = methodSource.getJavaClass().getCanonicalName() + "." + methodSource.getMethodName(); - DataTable dataTable = dataTables.get(sourceMethod); - if (dataTable != null) { - logger.trace("FoundDataTable " + dataTable + " " + dataTable.getRows()); - if (isSimpleTest(testIdentifier)) { - eventBusFor(testIdentifier).useExamplesFrom(dataTable); - logger.trace("-->EventBus.useExamplesFrom" + dataTable); - int rowNumber = getTestTemplateInvocationNumber(testIdentifier); - logger.trace("-->EventBus.exampleStarted " + rowNumber + "--" + dataTable.row(rowNumber).toStringMap()); - logger.trace("-->EventBus.useExamplesFrom" + dataTable + " with parameter set number " + rowNumber); - eventBusFor(testIdentifier).exampleStarted(dataTable.row(rowNumber).toStringMap()); - } else { - DATA_DRIVEN_TEST_NAMES.put(testIdentifier.getUniqueId(), testIdentifier.getDisplayName()); - } - } - } - } - - private boolean isTestContainer(TestIdentifier testIdentifier) { - return TestDescriptor.Type.CONTAINER == testIdentifier.getType(); - } - - @Override - public synchronized void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { - if (!isSerenityTest) return; - - logger.trace("-->Execution finished " + testIdentifier); - logger.trace("-->Execution finished " + testIdentifier.getDisplayName() + "--" + testIdentifier.getType() + "--" + testIdentifier.getSource() + " with result " + testExecutionResult.getStatus()); - if (!testIdentifier.getSource().isPresent()) { - logger.debug("No action done at executionFinished because testIdentifier is null"); - return; - } - - if (isTestContainer(testIdentifier) && isClassSource(testIdentifier)) { - logger.trace("-->EventBus.TestSuiteFinished " + ((ClassSource) testIdentifier.getSource().get()).getJavaClass()); - eventBusFor(testIdentifier).testSuiteFinished(); - } - if (isSimpleTest(testIdentifier)) { - if (isMethodSource(testIdentifier)) { - MethodSource methodSource = ((MethodSource) testIdentifier.getSource().get()); - String sourceMethod = methodSource.getClassName() + "." + methodSource.getMethodName(); - testFinished(testIdentifier, methodSource, testExecutionResult); - DataTable dataTable = dataTables.get(sourceMethod); - if (dataTable != null) { - eventBusFor(testIdentifier).exampleFinished(); - } - } - } - recordSummaryData(testIdentifier, testExecutionResult); - } - - - private void recordSummaryData(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { - try { - switch (testExecutionResult.getStatus()) { - - case SUCCESSFUL: { - if (testIdentifier.isContainer()) { - this.summary.containersSucceeded.incrementAndGet(); - } - if (testIdentifier.isTest()) { - this.summary.testsSucceeded.incrementAndGet(); - } - break; - } - - case ABORTED: { - if (testIdentifier.isContainer()) { - this.summary.containersAborted.incrementAndGet(); - } - if (testIdentifier.isTest()) { - this.summary.testsAborted.incrementAndGet(); - } - break; - } - - case FAILED: { - if (testIdentifier.isContainer()) { - this.summary.containersFailed.incrementAndGet(); - } - if (testIdentifier.isTest()) { - this.summary.testsFailed.incrementAndGet(); - } - testExecutionResult.getThrowable().ifPresent(throwable -> this.summary.addFailure(testIdentifier, throwable)); - eventBusFor(testIdentifier).testFailed(testExecutionResult.getThrowable().get()); - break; - } - default: - throw new PreconditionViolationException("Unsupported execution status:" + testExecutionResult.getStatus()); - } - } finally { - expectedExceptions.clear(); - } - } - - private void testFinished(TestIdentifier testIdentifier, MethodSource methodSource, TestExecutionResult testExecutionResult) { - updateResultsUsingTestAnnotations(testIdentifier, methodSource); -// TestResult result = StepEventBus.getParallelEventBus().getBaseStepListener().getCurrentTestOutcome().getResult(); - TestResult result = eventBusFor(testIdentifier).getBaseStepListener().getCurrentTestOutcome().getResult(); - if (testExecutionResult.getStatus() == TestExecutionResult.Status.ABORTED && result == TestResult.SUCCESS) { - updateResultsUsingTestExecutionResult(testIdentifier, testExecutionResult); - } else if (testExecutionResult.getStatus() == TestExecutionResult.Status.FAILED && result.isLessSevereThan(TestResult.FAILURE)) { - updateResultsUsingTestExecutionResult(testIdentifier, testExecutionResult); - } - - eventBusFor(testIdentifier).testFinished(); - eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); - } - - private void updateResultsUsingTestExecutionResult(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { - testExecutionResult.getThrowable().ifPresent(cause -> eventBusFor(testIdentifier).getBaseStepListener().updateCurrentStepFailureCause(cause)); - if (testExecutionResult.getStatus() == TestExecutionResult.Status.ABORTED) { - eventBusFor(testIdentifier).getBaseStepListener().overrideResultTo(TestResult.ABORTED); - } - } - - private void updateResultsUsingTestAnnotations(TestIdentifier testIdentifier, MethodSource methodSource) { - - if (TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).isManual()) { - setToManual(testIdentifier, methodSource); - } - expectedExceptions.forEach(ex -> updateResultsForExpectedException(testIdentifier, ex)); - } - - private void setToManual(TestIdentifier testIdentifier, MethodSource methodSource) { - eventBusFor(testIdentifier).testIsManual(); - TestResult result = TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).getManualResult(); - eventBusFor(testIdentifier).getBaseStepListener().recordManualTestResult(result); - } - - private void updateResultsForExpectedException(TestIdentifier testIdentifier, Class expected) { - eventBusFor(testIdentifier).exceptionExpected(expected); - } - - private boolean isSimpleTest(TestIdentifier testIdentifier) { - return testIdentifier.getType() == TestDescriptor.Type.TEST; - } - - private boolean isClassSource(TestIdentifier testId) { - return testId.getSource().isPresent() && (testId.getSource().get() instanceof ClassSource); - } - - private boolean isMethodSource(TestIdentifier testId) { - return testId.getSource().isPresent() && (testId.getSource().get() instanceof MethodSource); - } - - /** - * Called when a test starts. We also need to start the test suite the first - * time, as the testRunStarted() method is not invoked for some reason. - */ - private void testStarted(MethodSource methodSource, TestIdentifier testIdentifier, Class testClass) { - if (testingThisTest(testIdentifier, testClass)) { - startTestSuiteForFirstTest(testIdentifier); - logger.debug(Thread.currentThread() + " Test started " + testIdentifier); - eventBusFor(testIdentifier).clear(); - eventBusFor(testIdentifier).setTestSource(TEST_SOURCE_JUNIT5.getValue()); - -// String testName = StringUtils.isNotEmpty(testIdentifier.getDisplayName()) ? testIdentifier.getDisplayName() : methodSource.getMethodName(); - String testName = Inflector.getInstance().humanize(methodSource.getMethodName()); - if (testIdentifier.getDisplayName().startsWith("[")) { - testName = testName + testIdentifier.getDisplayName(); - } else if (StringUtils.isNotEmpty(testIdentifier.getDisplayName())) { - testName = testIdentifier.getDisplayName(); - } - try { - Method javaMethod = methodSource.getJavaMethod(); - - if (JUnit5TestClassAnnotations.forTest(testClass).getDisplayNameGeneration(javaMethod).isPresent()) { - testName = JUnit5TestClassAnnotations.forTest(testClass).getDisplayNameGeneration(javaMethod).get(); - } - if (JUnit5TestMethodAnnotations.forTest(javaMethod).getDisplayName().isPresent()) { - testName = JUnit5TestMethodAnnotations.forTest(javaMethod).getDisplayName().get(); - } - } catch (Exception e) { - //ignore org.junit.platform.commons.PreconditionViolationException: Could not find method with name - } - - eventBusFor(testIdentifier).testStarted(Optional.ofNullable(testName).orElse("Initialisation"), - methodSource.getJavaClass(), - methodSource.getMethodName(), - testIdentifier.getUniqueId(), - testIdentifier.getParentId().orElse(testIdentifier.getUniqueId())); - - // - // Check for @Pending tests - // - if (isPending(methodSource)) { - eventBusFor(testIdentifier).testPending(); - } - } - } - - private synchronized StepEventBus eventBusFor(TestIdentifier testIdentifier) { - String uniqueTestId = testIdentifier.getUniqueId(); - - StepEventBus currentEventBus = StepEventBus.eventBusFor(uniqueTestId); - if (!currentEventBus.isBaseStepListenerRegistered()) { - File outputDirectory = getOutputDirectory(); - BaseStepListener baseStepListener = Listeners.getBaseStepListener().withOutputDirectory(outputDirectory); - currentEventBus.registerListener(baseStepListener); -// currentEventBus.registerListener(new ConsoleLoggingListener(currentEventBus.getEnvironmentVariables())); - currentEventBus.registerListener(SerenityInfrastructure.getLoggingListener()); - logger.trace(" -> ADDED BASE LISTENER " + baseStepListener); - StepListener loggingListener = Listeners.getLoggingListener(); - currentEventBus.registerListener(loggingListener); - logger.trace(" -> ADDED LOGGING LISTENER " + loggingListener); - } - logger.trace("SETTING EVENT BUS FOR THREAD " + Thread.currentThread() + " TO " + currentEventBus); - StepEventBus.setCurrentBusToEventBusFor(uniqueTestId); - return currentEventBus; - } - - - private boolean isPending(MethodSource methodSource) { - try { - return (TestMethodConfiguration.forMethod(methodSource.getJavaMethod()).isPending()); - } catch (Exception ex) { - return false; - } - } - - private boolean testingThisTest(TestIdentifier testIdentifier, Class testClass) { - if (isMethodSource(testIdentifier)) { - MethodSource methodSource = (MethodSource) testIdentifier.getSource().get(); - return testClass.equals(methodSource.getJavaClass()); - } - return false; - } - - - private void startTestSuiteForFirstTest(TestIdentifier testIdentifier) { - if (isMethodSource(testIdentifier)) { - Class testCase = ((MethodSource) testIdentifier.getSource().get()).getJavaClass(); - logger.trace("-->TestSuiteStarted " + testCase); - String testSuiteName = TEST_CASE_DISPLAY_NAMES.getOrDefault(testCase, testCase.getSimpleName()); - eventBusFor(testIdentifier).testSuiteStarted(((MethodSource) testIdentifier.getSource().get()).getJavaClass(), testSuiteName); - } - } - - - /** - * Find the current set of test outcomes produced by the test execution. - * - * @param testIdentifier - * @return the current list of test outcomes - */ - public List getTestOutcomes(TestIdentifier testIdentifier) { - logger.trace("GET TEST OUTCOMES FOR " + testIdentifier); - logger.trace(" - BASE STEP LISTENER: " + eventBusFor(testIdentifier).getBaseStepListener()); - List testOutcomes = eventBusFor(testIdentifier).getBaseStepListener().getTestOutcomes(); - testOutcomes.forEach( - outcome -> { - if (testIdentifier.getParentId().isPresent() && DATA_DRIVEN_TEST_NAMES.get(testIdentifier.getParentId().get()) != null) { - outcome.setTestOutlineName(DATA_DRIVEN_TEST_NAMES.get(testIdentifier.getParentId().get())); - } - } - ); - return testOutcomes; - } - - - private void generateReports(TestIdentifier testIdentifier) { - logger.trace("GENERATE REPORTS FOR TEST " + testIdentifier.getUniqueId()); - generateReportsFor(getTestOutcomes(testIdentifier)); - - StepEventBus.clearEventBusFor(testIdentifier.getUniqueId()); - } - - private void generateReportsForParameterizedTests(List testIdentifiers) { - logger.trace("GENERATE REPORTS FOR PARAMETERIZED TESTS " + testIdentifiers); - List allTestOutcomes = testIdentifiers - .stream() - .map(this::getTestOutcomes) - .flatMap(List::stream) - .collect(Collectors.toList()); - ParameterizedTestsOutcomeAggregator parameterizedTestsOutcomeAggregator = - new ParameterizedTestsOutcomeAggregator(allTestOutcomes); - - generateReportsFor(parameterizedTestsOutcomeAggregator.aggregateTestOutcomesByTestMethods()); - - testIdentifiers.stream().map(TestIdentifier::getUniqueId).forEach(StepEventBus::clearEventBusFor); - } - - /** - * A test runner can generate reports via Reporter instances that subscribe - * to the test runner. The test runner tells the reporter what directory to - * place the reports in. Then, at the end of the test, the test runner - * notifies these reporters of the test outcomes. The reporter's job is to - * process each test run outcome and do whatever is appropriate. - * - * @param testOutcomeResults the test results from the previous test run. - */ - private void generateReportsFor(final List testOutcomeResults) { - getReportService().generateReportsFor(testOutcomeResults); - getReportService().generateConfigurationsReport(); - } - - private ReportService getReportService() { - if (reportService == null) { - reportService = new ReportService(getOutputDirectory(), getDefaultReporters()); - } - return reportService; - } - - /** - * Instantiates the @ManagedPages-annotated Pages instance using current WebDriver. - * - * @param testCase A Serenity-annotated test class - */ - protected void injectAnnotatedPagesObjectInto(final Object testCase) { - StepAnnotations.injector().injectAnnotatedPagesObjectInto(testCase, pages); - } - - public static void addExpectedException(Class exceptionClass) { - expectedExceptions.add(exceptionClass); - } - - static boolean isSerenityTestClass(Class testClass) { - return classNestStructure(testClass) - .stream() - .flatMap(clazz -> Stream.of(clazz.getAnnotationsByType(ExtendWith.class))) - .anyMatch(annotation -> Arrays.asList(annotation.value()).contains(SerenityJUnit5Extension.class)); - } - - static private List> classNestStructure(Class testClass) { - List> nestedStructure = new ArrayList<>(); - nestedStructure.add(testClass); - Class declaringClass = testClass.getDeclaringClass(); - while (declaringClass != null) { - nestedStructure.add(declaringClass); - declaringClass = declaringClass.getDeclaringClass(); - } - return nestedStructure; - } - - private int getTestTemplateInvocationNumber(TestIdentifier testIdentifier) { - return getTestTemplateInvocationNumber(testIdentifier.getUniqueId()); - } - - static int getTestTemplateInvocationNumber(String uniqueTestIdentifier) { - if (!uniqueTestIdentifier.contains("test-template-invocation")) { - return -1; - } else { - int index1 = uniqueTestIdentifier.lastIndexOf("#"); - int index2 = uniqueTestIdentifier.lastIndexOf("]"); - return Integer.parseInt(uniqueTestIdentifier.substring(index1 + 1, index2)) - 1; - } - } -} From b43af341656289a4559ee32dcb2b996f6ee82358 Mon Sep 17 00:00:00 2001 From: "Kiran.Yenigala" Date: Wed, 4 Dec 2024 14:08:37 +0000 Subject: [PATCH 08/13] CME-116: serenity properties file added --- serenity.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 serenity.properties diff --git a/serenity.properties b/serenity.properties new file mode 100644 index 0000000000..96d0f903dd --- /dev/null +++ b/serenity.properties @@ -0,0 +1,3 @@ +serenity.project.name=ProfessionalAPI Functional Testing Report +serenity.test.root=uk.gov.hmcts.reform.professionalapi +serenity.outputDirectory=target/site/serenity \ No newline at end of file From 0e2b0e8709673f111c686e8b5429e770a7486697 Mon Sep 17 00:00:00 2001 From: "Kiran.Yenigala" Date: Wed, 4 Dec 2024 14:10:03 +0000 Subject: [PATCH 09/13] CME-116: serenity properties file added --- .../services/org.junit.platform.launcher.TestExecutionListener | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener diff --git a/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener deleted file mode 100644 index 4d316ab8a3..0000000000 --- a/src/functionalTest/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener +++ /dev/null @@ -1 +0,0 @@ -uk.gov.hmcts.reform.professionalapi.util.CustomTestExecutionListener From 820e0f1536c1c90bf5e31e58564fed8e81d7b69f Mon Sep 17 00:00:00 2001 From: "Kiran.Yenigala" Date: Wed, 4 Dec 2024 14:27:28 +0000 Subject: [PATCH 10/13] CME-116: remove serenity properties file added --- build.gradle | 25 +++++++++---------- gradle/wrapper/gradle-wrapper.properties | 2 +- serenity.properties | 3 --- .../AuthorizationFunctionalTest.java | 13 +++++----- .../configuration/SwaggerConfiguration.java | 2 +- 5 files changed, 20 insertions(+), 25 deletions(-) delete mode 100644 serenity.properties diff --git a/build.gradle b/build.gradle index a8b4bff020..ac5f348431 100644 --- a/build.gradle +++ b/build.gradle @@ -8,12 +8,12 @@ plugins { id 'com.github.ben-manes.versions' version '0.51.0' id "info.solidsoft.pitest" version '1.15.0' id 'io.spring.dependency-management' version '1.1.6' - id 'org.sonarqube' version '5.1.0.4882' - id 'org.springframework.boot' version '3.3.5' + id 'org.sonarqube' version '6.0.1.5171' + id 'org.springframework.boot' version '3.3.6' id "org.flywaydb.flyway" version '9.22.3' - id 'au.com.dius.pact' version '4.6.15'// do not change, otherwise serenity report fails - id 'org.owasp.dependencycheck' version '10.0.3' - id 'net.serenity-bdd.serenity-gradle-plugin' version '4.2.6' + id 'au.com.dius.pact' version '4.6.15' + id 'org.owasp.dependencycheck' version '11.1.1' + id 'net.serenity-bdd.serenity-gradle-plugin' version '4.2.8' } @@ -22,7 +22,7 @@ ext { } def versions = [ - lombok : '1.18.34', + lombok : '1.18.36', gradlePitest : '1.15.0', pitest : '1.16.1', sonarPitest : '0.5', @@ -39,7 +39,7 @@ def versions = [ bytebuddy : '1.15.3', bouncycastle : '1.79', postgresql_tc : '1.20.0', - serenity : '4.2.6' + serenity : '4.2.9' ] application { @@ -170,7 +170,7 @@ check.dependsOn jacocoTestCoverageVerification pmd { - toolVersion = '6.55.0' + toolVersion = '7.8.0' ignoreFailures = true sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest, sourceSets.functionalTest, sourceSets.smokeTest] reportsDir = file("$project.buildDir/reports/pmd") @@ -348,13 +348,13 @@ dependencies { implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind' - implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.1', ext: 'pom' + implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.2', ext: 'pom' implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' implementation group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1' implementation 'com.github.hmcts:idam-java-client:3.0.3' implementation "org.springframework.boot:spring-boot-starter-oauth2-client" implementation "org.springframework.boot:spring-boot-starter-oauth2-resource-server" - implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.44' + implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.47' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.17.0' implementation group: 'org.apache.commons', name: 'commons-text', version: '1.12.0' implementation 'org.springframework.boot:spring-boot-starter-validation' @@ -382,7 +382,6 @@ dependencies { implementation "com.github.hmcts.java-logging:logging:${versions.reformLogging}" implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.6.0' - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.8.0' implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-bootstrap' implementation group: 'org.apache.camel', name: 'camel-csv', version: versions.camel @@ -439,7 +438,7 @@ dependencies { exclude group: "net.bytebuddy", module: "byte-buddy" exclude group: "net.bytebuddy", module: "byte-buddy-agent" } - testImplementation 'com.github.hmcts:rd-commons-lib:0.0.19-beta3' + testImplementation 'com.github.hmcts:rd-commons-lib:0.1.0' testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '5.14.2' testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.9' @@ -447,7 +446,7 @@ dependencies { // tests on version 2 fails on flyway migrations, something like "incorrect syntax" testImplementation group: 'com.h2database', name: 'h2', version: '1.4.200' - testImplementation group: 'org.wiremock', name: 'wiremock', version: '3.9.2' + testImplementation group: 'org.wiremock', name: 'wiremock', version: '3.10.0' testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', { exclude group: 'junit', module: 'junit' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72b8b..e2847c8200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/serenity.properties b/serenity.properties deleted file mode 100644 index 96d0f903dd..0000000000 --- a/serenity.properties +++ /dev/null @@ -1,3 +0,0 @@ -serenity.project.name=ProfessionalAPI Functional Testing Report -serenity.test.root=uk.gov.hmcts.reform.professionalapi -serenity.outputDirectory=target/site/serenity \ No newline at end of file diff --git a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java index fa7ccf507a..8278c4b9a7 100644 --- a/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java +++ b/src/functionalTest/java/uk/gov/hmcts/reform/professionalapi/AuthorizationFunctionalTest.java @@ -203,14 +203,13 @@ protected NewUserCreationRequest createUserRequest(List userRoles, userAccessTypes.add(new UserAccessType("jurisdictionId" + random, "organisationProfileId" + random, "accessTypeId" + random, false)); String userEmail = generateRandomEmail(); - NewUserCreationRequest userCreationRequest = NewUserCreationRequest.aNewUserCreationRequest() + return NewUserCreationRequest.aNewUserCreationRequest() .firstName(firstName) .lastName(lastName) .email(userEmail) .roles(userRoles) .userAccessTypes(userAccessTypes) .build(); - return userCreationRequest; } protected NewUserCreationRequest createUserRequest(List userRoles, boolean hasAccessTypes) { @@ -403,9 +402,9 @@ public void validateAccessTypesInRetrievedUser(Map searchRespons assertEquals(true, userAccessTypeList.get(0).get("enabled")); } - HashMap userMap = professionalUsersResponses.get(0); + HashMap userMap = professionalUsersResponses.getFirst(); assertThat(userMap).isNotEmpty(); - validateUserResponse(userMap, searchResponse); + validateUserResponse(userMap, searchResponse, expectedStatus); if (rolesReturned) { assertThat(userMap.get("roles")).isNotNull(); @@ -427,7 +426,7 @@ public void validateAccessTypesAndRolesInRetrievedUser(Map searc HashMap userMap = professionalUsersResponses.get(0); assertThat(userMap).isNotEmpty(); - validateUserResponse(userMap, searchResponse); + validateUserResponse(userMap, searchResponse, "ACTIVE"); assertThat(userAccessTypeList).hasSize(2); if (rolesReturned) { @@ -438,7 +437,7 @@ public void validateAccessTypesAndRolesInRetrievedUser(Map searc } } - public void validateUserResponse(HashMap userMap, Map searchResponse) { + public void validateUserResponse(HashMap userMap, Map searchResponse, String expectedStatus) { assertThat(searchResponse.get("users")).asList().isNotEmpty(); assertThat(searchResponse.get("organisationIdentifier")).isNotNull(); assertThat(searchResponse.get("organisationProfileIds")).isNotNull(); @@ -448,7 +447,7 @@ public void validateUserResponse(HashMap userMap, Map searchResp assertThat(userMap.get("lastName")).isNotNull(); assertThat(userMap.get("email")).isNotNull(); assertThat(userMap.get("lastUpdated")).isNotNull(); - assertThat(userMap.get("idamStatus").equals(IdamStatus.ACTIVE.name())); + assertThat(userMap.get("idamStatus")).isEqualTo(expectedStatus); } public UserProfileUpdatedData deleteRoleRequest(String role) { diff --git a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SwaggerConfiguration.java b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SwaggerConfiguration.java index 9f24e53dba..7f5340f1b5 100644 --- a/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SwaggerConfiguration.java +++ b/src/main/java/uk/gov/hmcts/reform/professionalapi/configuration/SwaggerConfiguration.java @@ -7,8 +7,8 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.StringSchema; import io.swagger.v3.oas.models.parameters.Parameter; -import org.springdoc.core.GroupedOpenApi; import org.springdoc.core.customizers.OperationCustomizer; +import org.springdoc.core.models.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.HandlerMethod; From 29adb679467ccf747d3da066e6d09b90078fec6f Mon Sep 17 00:00:00 2001 From: Rapolas <130578328+rapolaskaseliscgi@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:15:48 +0000 Subject: [PATCH 11/13] reduce pitest failure threshold --- build.gradle | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index ac5f348431..c088433bed 100644 --- a/build.gradle +++ b/build.gradle @@ -23,9 +23,8 @@ ext { def versions = [ lombok : '1.18.36', - gradlePitest : '1.15.0', - pitest : '1.16.1', sonarPitest : '0.5', + jackson : '2.18.2', junitPitest : '1.2.1', reformLogging : '6.1.6', camel : '3.22.2', @@ -263,7 +262,6 @@ jacocoTestReport { } pitest { - pitestVersion = versions.pitest junit5PluginVersion = versions.junitPitest targetClasses = ['uk.gov.hmcts.reform.professionalapi.*'] excludedClasses = [ @@ -285,7 +283,7 @@ pitest { historyOutputLocation = 'build/reports/pitest/fastermutationtestingoutput' outputFormats = ['XML', 'HTML'] timestampedReports = false - mutationThreshold = 85 + mutationThreshold = 80 } @@ -346,9 +344,9 @@ dependencies { implementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: versions.reformS2sClient - implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310' - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind' - implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.2', ext: 'pom' + implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: versions.jackson + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: versions.jackson + implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: versions.jackson, ext: 'pom' implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' implementation group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1' implementation 'com.github.hmcts:idam-java-client:3.0.3' @@ -453,15 +451,7 @@ dependencies { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } - - testImplementation group: 'org.pitest', name: 'pitest', version: versions.pitest - testImplementation group: 'info.solidsoft.gradle.pitest', name: 'gradle-pitest-plugin', version: versions.gradlePitest - testImplementation group: 'org.pitest', name: 'pitest-junit5-plugin', version: versions.junitPitest - - testImplementation group: 'org.codehaus.sonar-plugins', name: 'sonar-pitest-plugin', { - exclude group: 'junit', module: 'junit' - exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' - }, version: versions.sonarPitest + testImplementation group: 'org.codehaus.sonar-plugins', name: 'sonar-pitest-plugin', version: versions.sonarPitest testImplementation 'io.github.openfeign:feign-jackson:13.5' testImplementation group: 'com.github.mifmif', name: 'generex', version: '1.0.2' From 26106f0782c2b1c513ecfe87f7f52e73e7af59e0 Mon Sep 17 00:00:00 2001 From: Rapolas <130578328+rapolaskaseliscgi@users.noreply.github.com> Date: Tue, 10 Dec 2024 15:06:47 +0000 Subject: [PATCH 12/13] revert jackson --- build.gradle | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index c088433bed..3d4e8fece0 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,6 @@ ext { def versions = [ lombok : '1.18.36', sonarPitest : '0.5', - jackson : '2.18.2', junitPitest : '1.2.1', reformLogging : '6.1.6', camel : '3.22.2', @@ -344,9 +343,9 @@ dependencies { implementation group: 'com.github.hmcts', name: 'service-auth-provider-java-client', version: versions.reformS2sClient - implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: versions.jackson - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: versions.jackson - implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: versions.jackson, ext: 'pom' + implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind' + implementation group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.18.2', ext: 'pom' implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1' implementation group: 'jakarta.inject', name: 'jakarta.inject-api', version: '2.0.1' implementation 'com.github.hmcts:idam-java-client:3.0.3' From 971a51f6028b17a6ab540a5e2ebbd7495f803ab5 Mon Sep 17 00:00:00 2001 From: Rapolas <130578328+rapolaskaseliscgi@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:14:37 +0000 Subject: [PATCH 13/13] change import --- .../professionalapi/util/ProfessionalReferenceDataClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java index fec61452d0..1eef97df56 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/professionalapi/util/ProfessionalReferenceDataClient.java @@ -7,6 +7,7 @@ import com.nimbusds.jwt.JWT; import com.nimbusds.jwt.JWTParser; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.PropertySource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -931,7 +932,7 @@ private Map getErrorResponseMap(ResponseEntity responseE throws JsonProcessingException { Map errorResponseMap = new HashMap<>(); String body = (String) responseEntity.getBody(); - if (org.apache.commons.lang3.StringUtils.isNotEmpty(body)) { + if (StringUtils.isNotEmpty(body)) { errorResponseMap.put("response_body", objectMapper.readValue( body, ErrorResponse.class)); } else {