diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 12fa29a..e284168 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,8 +1 @@ -* @hmcts/platform-operations @hmcts/developer-enablement - -# Ignore files updated by Renovate -gradle/wrapper/gradle-wrapper.properties -Dockerfile -build.gradle -charts/**/Chart.yaml -.github/workflows/*.yaml +* @hmcts/cp-x-cjs-data-api diff --git a/.github/workflows/ci-build-publish.yml b/.github/workflows/ci-build-publish.yml index 71d0b27..102efb2 100644 --- a/.github/workflows/ci-build-publish.yml +++ b/.github/workflows/ci-build-publish.yml @@ -9,6 +9,8 @@ on: required: true HMCTS_ADO_PAT: required: true + PACT_BROKER_TOKEN: + required: true inputs: is_release: required: false @@ -23,6 +25,12 @@ on: trigger_deploy: required: true type: boolean + pacticipant: + required: true + type: string + pact_env: + required: true + type: string jobs: Artefact-Version: @@ -49,6 +57,10 @@ jobs: outputs: repo_name: ${{ steps.repo_vars.outputs.repo_name }} artefact_name: ${{ steps.repo_vars.outputs.artefact_name }} + env: + PACT_BROKER_BASE_URL: "https://hmcts-dts.pactflow.io" + PACT_ENV: "dev/pactTest" + steps: - name: Checkout source code uses: actions/checkout@v4 @@ -64,36 +76,12 @@ jobs: with: gradle-version: current - - name: Gradle Build and Publish + - name: Gradle Build env: ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} - AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} run: | echo "Building with ARTEFACT_VERSION=$ARTEFACT_VERSION" - - gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION - - if [ -z "AZURE_DEVOPS_ARTIFACT_USERNAME" ]; then - echo "::warning::AZURE_DEVOPS_ARTIFACT_USERNAME is null or not set" - fi - - if [ -z "$AZURE_DEVOPS_ARTIFACT_TOKEN" ]; then - echo "::warning::AZURE_DEVOPS_ARTIFACT_TOKEN is null or not set" - fi - - if [ "${{ inputs.is_publish }}" == "true" ]; then - echo "Publishing artefact for version: $ARTEFACT_VERSION" - - gradle publish \ - -DARTEFACT_VERSION=$ARTEFACT_VERSION \ - -DGITHUB_REPOSITORY=${{ github.repository }} \ - -DGITHUB_ACTOR=${{ github.actor }} \ - -DGITHUB_TOKEN=$GITHUB_TOKEN \ - -DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \ - -DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN - fi + gradle build -DARTEFACT_VERSION=$ARTEFACT_VERSION - name: Extract repo name id: repo_vars @@ -108,8 +96,87 @@ jobs: name: app.jar path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar + Provider-Deploy: + needs: [ Artefact-Version, Build ] + runs-on: ubuntu-latest + env: + PACT_PROVIDER_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }} + PACT_BROKER_URL: "https://hmcts-dts.pactflow.io" + PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} + PACT_ENV: ${{ inputs.pact_env }} + PACTICIPANT: ${{ inputs.pacticipant }} + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + with: + gradle-version: current + + # If the results are not published, the Pact Broker will not be able to find the version + # NOTE: if the version is not found and verification step is successful, check that 'pact.verifier.publishResults' is set to true in the gradle task + - name: Pact Provider Verification and Publish Results + env: + PACT_PROVIDER_BRANCH: ${{ github.ref_name }} + PACT_VERIFIER_PUBLISH_RESULTS: true + run: | + echo "PACT_PROVIDER_VERSION=$PACT_PROVIDER_VERSION" + echo "PACT_VERIFIER_PUBLISH_RESULTS=$PACT_VERIFIER_PUBLISH_RESULTS" + echo "PACT_PROVIDER_BRANCH=$PACT_PROVIDER_BRANCH" + echo "PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN" + echo "PACT_BROKER_URL=$PACT_BROKER_URL" + echo "PACT_ENV=$PACT_ENV" + + gradle pactVerificationTest \ + -Dpact.provider.version="$PACT_PROVIDER_VERSION" \ + -Dpact.verifier.publishResults="$PACT_VERIFIER_PUBLISH_RESULTS" \ + -Dpact.provider.branch="$PACT_PROVIDER_BRANCH" \ + -Dpact.broker.token="$PACT_BROKER_TOKEN" \ + -Dpact.broker.url="$PACT_BROKER_URL" \ + -Dpact.env="$PACT_ENV" + + - uses: hmcts/pact-can-i-deploy@main + with: + pact_broker_token: ${{ secrets.PACT_BROKER_TOKEN }} + pacticipant: ${{ inputs.pacticipant }} + pacticipant_version: ${{ env.PACT_PROVIDER_VERSION }} + pact_env: ${{ env.PACT_ENV }} + + - name: Gradle Publish + if: ${{ inputs.is_publish }} + env: + ARTEFACT_VERSION: ${{ needs.Artefact-Version.outputs.artefact_version }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} + AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} + run: | + if [ -z "AZURE_DEVOPS_ARTIFACT_USERNAME" ]; then + echo "::warning::AZURE_DEVOPS_ARTIFACT_USERNAME is null or not set" + fi + + if [ -z "$AZURE_DEVOPS_ARTIFACT_TOKEN" ]; then + echo "::warning::AZURE_DEVOPS_ARTIFACT_TOKEN is null or not set" + fi + + echo "Publishing artefact for version: $ARTEFACT_VERSION" + + gradle publish \ + -DARTEFACT_VERSION=$ARTEFACT_VERSION \ + -DGITHUB_REPOSITORY=${{ github.repository }} \ + -DGITHUB_ACTOR=${{ github.actor }} \ + -DGITHUB_TOKEN=$GITHUB_TOKEN \ + -DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \ + -DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN + Build-Docker: - needs: [ Build, Artefact-Version ] + needs: [ Provider-Deploy, Build, Artefact-Version ] if: ${{ inputs.trigger_docker }} runs-on: ubuntu-latest steps: @@ -145,7 +212,7 @@ jobs: JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar Deploy: - needs: [ Build, Artefact-Version ] + needs: [ Provider-Deploy, Build, Artefact-Version ] if: ${{ inputs.trigger_deploy }} runs-on: ubuntu-latest steps: @@ -163,4 +230,4 @@ jobs: "ARTIFACT_ID": "${{ env.REPO_NAME }}", "ARTIFACT_VERSION": "${{ needs.Artefact-Version.outputs.artefact_version }}", "TARGET_REPOSITORY": "${{ github.repository }}" - } \ No newline at end of file + } diff --git a/.github/workflows/ci-draft.yml b/.github/workflows/ci-draft.yml index e8d3dee..0948c42 100644 --- a/.github/workflows/ci-draft.yml +++ b/.github/workflows/ci-draft.yml @@ -17,8 +17,10 @@ jobs: AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} HMCTS_ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }} + PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} with: is_publish: ${{ github.event_name == 'push' }} trigger_docker: ${{ github.event_name == 'push' }} trigger_deploy: ${{ github.event_name == 'push' }} - + pacticipant: CPCourtScheduleProvider + pact_env: dev/pactTest diff --git a/.github/workflows/ci-released.yml b/.github/workflows/ci-released.yml index aac7797..694d957 100644 --- a/.github/workflows/ci-released.yml +++ b/.github/workflows/ci-released.yml @@ -12,8 +12,11 @@ jobs: AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }} AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }} HMCTS_ADO_PAT: ${{ secrets.HMCTS_ADO_PAT }} + PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} with: is_release: true is_publish: true trigger_docker: true trigger_deploy: true + pacticipant: CPCourtScheduleProvider + pact_env: dev/pactTest diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index db49a95..e331522 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -36,7 +36,6 @@ jobs: languages: ${{ matrix.language }} queries: security-extended - - uses: actions/setup-java@v4 with: distribution: 'temurin' @@ -47,14 +46,9 @@ jobs: with: gradle-version: current - - name: Gradle Build and Publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Gradle Build run: | - gradle build cyclonedxBom -x test \ - -DGITHUB_REPOSITORY=${{ github.repository }} \ - -DGITHUB_ACTOR=${{ github.actor }} \ - -DGITHUB_TOKEN=$GITHUB_TOKEN + gradle build cyclonedxBom -x test # ℹ️ Command-line programs to run using the OS shell. # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun diff --git a/.github/workflows/publish-pact-verification.yml b/.github/workflows/publish-pact-verification.yml deleted file mode 100644 index 95e77d3..0000000 --- a/.github/workflows/publish-pact-verification.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Run pact provider test and publish verification report to pact broker - -on: - push: - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - publish-provider-pacts: - runs-on: ubuntu-latest - - env: - PACT_BROKER_URL: https://hmcts-dts.pactflow.io - PACT_BROKER_HOST: hmcts-dts.pactflow.io - PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} - PACT_VERIFIER_PUBLISH_RESULTS: true - GIT_COMMIT: ${{ github.sha }} - GIT_BRANCH: ${{ github.ref_name }} - PACT_ENV: dev/pactTest - - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 21 - - - name: Install Pact CLI - run: npm install -g @pact-foundation/pact-cli - - - name: Make provider script executable - run: chmod +x publish-pacts.sh - - - name: Run Pact verification Test and publish verification report - run: ./publish-pacts.sh \ No newline at end of file diff --git a/README.md b/README.md index e89b95d..3f9bcf5 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,21 @@ Further documentation see the [HMCTS Marketplace Springboot template readme](https://github.com/hmcts/service-hmcts-marketplace-springboot-template/blob/main/README.md). -### Run pact provider test and publish verification report to pact broker locally +## Pact Provider Test -update .env file with below details -PACT_BROKER_URL= <> -PACT_BROKER_HOST=<> -PACT_BROKER_TOKEN= <> -PACT_ENV= << This is the environment in PactFlow broker to which we tag the contracts> -PACT_VERIFIER_PUBLISH_RESULTS=true -run ./publish-pacts.sh +Run pact provider test and publish verification report to pact broker locally + +Update .env file with below details (replacing placeholders with actual values): +```bash +export PACT_BROKER_URL="https://hmcts-dts.pactflow.io" +export PACT_BROKER_TOKEN="YOUR_PACTFLOW_BROKER_TOKEN" +export PACT_ENV="local" # or value based on the environment you are testing against +export PACT_VERIFIER_PUBLISH_RESULTS=true +``` +Run Pact tests: +```bash +gradle pactVerificationTest +``` ## License diff --git a/build.gradle b/build.gradle index e9927e1..fec1923 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'application' id 'java' id 'io.spring.dependency-management' version '1.1.7' - id 'org.springframework.boot' version '3.5.0' + id 'org.springframework.boot' version '3.5.3' id 'jacoco' id 'maven-publish' id "com.github.ben-manes.versions" version "0.52.0" @@ -21,32 +21,12 @@ def azureADOArtifactRepository = 'https://pkgs.dev.azure.com/hmcts/Artifacts/_pa def azureADOArtifactActor = System.getenv("AZURE_DEVOPS_ARTIFACT_USERNAME") def azureADOArtifactToken = System.getenv("AZURE_DEVOPS_ARTIFACT_TOKEN") -//debugging -// if (githubActor != null) { -// println "🔐 Configuring GitHub Packages publishing to: https://maven.pkg.github.com/$githubRepo" -// } -// println "GitHub Packages publishing required environment variables:" -// println " - GITHUB_ACTOR=${githubActor != null ? ' ✔ FOUND' : '❌'}" -// println " - GITHUB_TOKEN=${githubToken != null ? ' ✔ FOUND' : '❌'}" -// println " - GITHUB_REPOSITORY=${githubRepo != null ? ' ✔ FOUND' : '❌'}" - -//println "Azure ADO publishing required environment variables:" -//println " - AZURE_DEVOPS_ARTIFACT_USERNAME=${!azureADOArtifactActor || azureADOArtifactActor.isBlank() ? '❌NULL or EMPTY' : ' ✔ FOUND'}" -//println " - AZURE_DEVOPS_ARTIFACT_USERNAME=${!azureADOArtifactToken || azureADOArtifactToken.isBlank() ? '❌NULL or EMPTY' : ' ✔ FOUND'}" - java { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 } sourceSets { - functionalTest { - java { - compileClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.main.output - } - resources.srcDir file('src/functionalTest/resources') - } integrationTest { java { compileClasspath += sourceSets.main.output @@ -64,9 +44,6 @@ sourceSets { } configurations { - functionalTestImplementation.extendsFrom testImplementation - functionalTestRuntimeOnly.extendsFrom runtimeOnly - integrationTestImplementation.extendsFrom testImplementation integrationTestRuntimeOnly.extendsFrom runtimeOnly @@ -90,7 +67,9 @@ tasks.withType(JavaExec).configureEach { } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform{ + excludeTags 'pact' + } systemProperty 'API_SPEC_VERSION', project.version failFast = true // Mockito must be added as an agent, see: @@ -104,16 +83,16 @@ tasks.named('test') { showStandardStreams = true } reports { - junitXml.required.set(true) // For CI tools (e.g. Jenkins, GitHub Actions) - html.required.set(true) // Human-readable browser report + junitXml.required.set(true) + html.required.set(true) } } -tasks.register('functional', Test) { - description = "Runs functional tests" +tasks.register('integration', Test) { + description = "Runs integration tests" group = "Verification" - testClassesDirs = sourceSets.functionalTest.output.classesDirs - classpath = sourceSets.functionalTest.runtimeClasspath + testClassesDirs = sourceSets.integrationTest.output.classesDirs + classpath = sourceSets.integrationTest.runtimeClasspath useJUnitPlatform() failFast = true testLogging { @@ -122,32 +101,39 @@ tasks.register('functional', Test) { showStandardStreams = true } reports { - junitXml.required.set(true) // For CI tools (e.g. Jenkins, GitHub Actions) - html.required.set(true) // Human-readable browser report + junitXml.required.set(true) + html.required.set(true) } } -tasks.register('integration', Test) { - description = "Runs integration tests" + +tasks.register('pactVerificationTest', Test) { + description = "Runs Pact provider verification tests" group = "Verification" - testClassesDirs = sourceSets.integrationTest.output.classesDirs - classpath = sourceSets.integrationTest.runtimeClasspath - useJUnitPlatform() + testClassesDirs = sourceSets.pactVerificationTest.output.classesDirs + classpath = sourceSets.pactVerificationTest.runtimeClasspath + useJUnitPlatform { + includeTags 'pact' + } failFast = true - testLogging { - events "passed", "skipped", "failed" - exceptionFormat = 'full' - showStandardStreams = true + + def sysOrEnv = { String key -> + System.getProperty(key) ?: System.getenv(key.toUpperCase().replace('.', '_')) } + systemProperty 'pact.broker.url', sysOrEnv('pact.broker.url') + systemProperty 'pact.broker.token', sysOrEnv('pact.broker.token') + systemProperty 'pact.provider.version', sysOrEnv('pact.provider.version') + systemProperty 'pact.provider.branch', sysOrEnv('pact.provider.branch') + systemProperty 'pact.verifier.publishResults', sysOrEnv('pact.verifier.publishResults') + systemProperty 'pact.env', sysOrEnv( 'pact.env') ?: 'local' reports { - junitXml.required.set(true) // For CI tools (e.g. Jenkins, GitHub Actions) - html.required.set(true) // Human-readable browser report + junitXml.required.set(true) + html.required.set(true) } } tasks.named('build') { dependsOn tasks.named('test') dependsOn tasks.named('integration') -// dependsOn tasks.named('functional') disabling until functional tests are implemented } tasks.named('jacocoTestReport') { @@ -159,6 +145,10 @@ tasks.named('jacocoTestReport') { } } +tasks.named('check') { + dependsOn tasks.named('integration') +} + // check dependencies upon release ONLY tasks.named("dependencyUpdates").configure { def isNonStable = { String version -> @@ -251,10 +241,12 @@ tasks.named('processPactVerificationTestResources') { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } + dependencies { implementation "uk.gov.hmcts.cp:api-cp-crime-schedulingandlisting-courtschedule:$apiCourtScheduleVersion" implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9' - implementation 'io.swagger.core.v3:swagger-core:2.2.33' + implementation 'io.swagger.core.v3:swagger-core:2.2.34' + implementation 'javax.xml.bind:jaxb-api:2.3.1' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-actuator' @@ -276,49 +268,19 @@ dependencies { implementation 'org.hibernate.validator:hibernate-validator:9.0.1.Final' implementation 'org.apache.commons:commons-text:1.13.1' - implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2' - implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.19.1' +// implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2' compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion - testImplementation(platform('org.junit:junit-bom:5.13.1')) - testImplementation 'org.mockito:mockito-core:5.18.0' - testRuntimeOnly 'org.mockito:mockito-inline:5.2.0' + testImplementation(platform('org.junit:junit-bom:5.13.3')) testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' - testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.5.0', { + testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '3.5.3', { exclude group: 'junit', module: 'junit' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } testImplementation 'au.com.dius.pact.provider:junit5:4.6.17' testImplementation 'au.com.dius.pact.provider:spring6:4.6.17' - - test{ - useJUnitPlatform { - excludeTags 'pact' - } - } - - tasks.register('pactVerificationTest', Test) { - description = "Runs Pact provider verification tests" - group = "Verification" - testClassesDirs = sourceSets.pactVerificationTest.output.classesDirs - classpath = sourceSets.pactVerificationTest.runtimeClasspath - useJUnitPlatform { - includeTags 'pact' - } - failFast = true - systemProperty 'pact.broker.url', System.getenv('PACT_BROKER_URL') - systemProperty 'pact.broker.token', System.getenv('PACT_BROKER_TOKEN') - systemProperty 'pact.provider.version', System.getenv('GIT_COMMIT') ?: 'dev' - systemProperty 'pact.provider.branch', System.getenv('GIT_BRANCH') - systemProperty 'pact.verifier.publishResults', System.getenv('PACT_VERIFIER_PUBLISH_RESULTS') - systemProperty 'pact.broker.host', System.getenv('PACT_BROKER_HOST') - systemProperty 'pact.env', System.getenv('PACT_ENV') - reports { - junitXml.required.set(true) - html.required.set(true) - } - } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 002b867..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/publish-pacts.sh b/publish-pacts.sh deleted file mode 100755 index 5b5a564..0000000 --- a/publish-pacts.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -# Load env vars from .env if available -if [ -f .env ]; then - set -a - source .env - set +a -fi - -# Export Git metadata -export GIT_COMMIT=$(git rev-parse HEAD) - -if [ -n "$GIT_BRANCH" ]; then - BRANCH_NAME="$GIT_BRANCH" -else - BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) -fi - -export GIT_BRANCH="$BRANCH_NAME" - -# Run provider verification with results published -gradle pactVerificationTest \ - -Dpact.provider.version="$GIT_COMMIT" \ - -Dpact.verifier.publishResults=true \ - -Dpact.provider.branch="$GIT_BRANCH" \ - -DPACT_BROKER_TOKEN="$PACT_BROKER_TOKEN" \ - -DPACT_BROKER_HOST="$PACT_BROKER_URL" - -# Tag provider in the broker -pact-broker create-version-tag \ - --pacticipant "CPCourtScheduleProvider" \ - --version "$GIT_COMMIT" \ - --tag "$PACT_ENV" \ - --broker-base-url "$PACT_BROKER_URL" \ - --broker-token "$PACT_BROKER_TOKEN" - -# Can-I-Deploy check -echo "Running can-i-deploy check for provider compatibility..." -pact-broker can-i-deploy \ - --pacticipant "CPCourtScheduleProvider" \ - --version "$GIT_COMMIT" \ - --to-environment "$PACT_ENV" \ - --broker-base-url "$PACT_BROKER_URL" \ - --broker-token "$PACT_BROKER_TOKEN" \ - --output table - -CAN_I_DEPLOY_STATUS=$? - -if [ "$CAN_I_DEPLOY_STATUS" -ne 0 ]; then - echo "❌ Can-I-Deploy failed — this version is NOT safe to deploy to $PACT_ENV." - exit 1 -else - echo "✅ Can-I-Deploy succeeded — this version is safe to deploy to $PACT_ENV." -fi \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 1fd2ec0..e864936 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -2,7 +2,6 @@ server: port: 4550 shutdown: "graceful" -# If you use a database then uncomment the `group:, readiness: and include: "db"` lines in the health probes and uncomment the datasource section management: endpoint: health: @@ -24,28 +23,12 @@ spring: config: import: "optional:configtree:/mnt/secrets/rpe/" application: - name: Spring Boot Template -# datasource: -# driver-class-name: org.postgresql.Driver -# url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}${DB_OPTIONS:} -# username: ${DB_USER_NAME} -# password: ${DB_PASSWORD} -# properties: -# charSet: UTF-8 -# hikari: -# minimumIdle: 2 -# maximumPoolSize: 10 -# idleTimeout: 10000 -# poolName: {to-be-defined}HikariCP -# maxLifetime: 7200000 -# connectionTimeout: 30000 -# jpa: -# properties: -# hibernate: -# jdbc: -# lob: -# # silence the 'wall-of-text' - unnecessary exception throw about blob types -# non_contextual_creation: true + name: service-cp-refdata-courthearing-judges +# azure: +# cosmos: +# endpoint: ${COSMOSDB_ENDPOINT} +# key: ${COSMOSDB_KEY} +# database: ${COSMOSDB_DATABASE} azure: application-insights: diff --git a/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/helper/JsonFileToObject.java b/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/helper/JsonFileToObject.java index 6b5c4f0..5b0128b 100644 --- a/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/helper/JsonFileToObject.java +++ b/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/helper/JsonFileToObject.java @@ -14,4 +14,4 @@ public static T readJsonFromResources(String fileName, Class clazz) throw File file = new File(JsonFileToObject.class.getClassLoader().getResource(fileName).toURI()); return mapper.readValue(file, clazz); } -} +} \ No newline at end of file diff --git a/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/provider/CourtScheduleProviderPactTest.java b/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/provider/CourtScheduleProviderPactTest.java index 361a71a..0c3d5ed 100644 --- a/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/provider/CourtScheduleProviderPactTest.java +++ b/src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/provider/CourtScheduleProviderPactTest.java @@ -11,6 +11,8 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; @@ -23,13 +25,14 @@ @ExtendWith({SpringExtension.class, PactVerificationInvocationContextProvider.class}) @Provider("CPCourtScheduleProvider") @PactBroker( - scheme = "https", - host = "${pact.broker.host}", + url = "${pact.broker.url}", authentication = @PactBrokerAuth(token = "${pact.broker.token}") ) @Tag("pact") public class CourtScheduleProviderPactTest { + private static final Logger LOG = LoggerFactory.getLogger(CourtScheduleProviderPactTest.class); + @Autowired private CourtScheduleRepository courtScheduleRepository; @@ -38,9 +41,9 @@ public class CourtScheduleProviderPactTest { @BeforeEach void setupTarget(PactVerificationContext context) { - System.out.println("Running test on port: " + port); + LOG.atDebug().log("Running test on port: " + port); context.setTarget(new HttpTestTarget("localhost", port)); - System.out.println("pact.verifier.publishResults: " + System.getProperty("pact.verifier.publishResults")); + LOG.atDebug().log("pact.verifier.publishResults: " + System.getProperty("pact.verifier.publishResults")); } @State("court schedule for case 456789 exists") @@ -54,4 +57,4 @@ public void setupCourtSchedule() throws Exception{ void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } -} +} \ No newline at end of file diff --git a/src/test/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerTest.java b/src/test/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerTest.java index ba85ddd..3174af6 100644 --- a/src/test/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerTest.java +++ b/src/test/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerTest.java @@ -28,14 +28,11 @@ class CourtScheduleControllerTest { private static final Logger log = LoggerFactory.getLogger(CourtScheduleControllerTest.class); - private CourtScheduleRepository courtScheduleRepository; - private CourtScheduleService courtScheduleService; private CourtScheduleController courtScheduleController; @BeforeEach void setUp() { - courtScheduleRepository = new InMemoryCourtScheduleRepositoryImpl(); - courtScheduleService = new CourtScheduleService(courtScheduleRepository); + CourtScheduleService courtScheduleService = new CourtScheduleService(new InMemoryCourtScheduleRepositoryImpl()); courtScheduleController = new CourtScheduleController(courtScheduleService); }