diff --git a/.github/workflows/swagger.yml b/.github/workflows/swagger.yml index 6264d4244..92383e959 100644 --- a/.github/workflows/swagger.yml +++ b/.github/workflows/swagger.yml @@ -1,17 +1,16 @@ name: Publish Swagger Specs - on: push: branches: - master - + - CCD-6801-fix-swagger-ui-ft-patch jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - name: Set up Cache - uses: actions/cache@v4 + uses: actions/cache@v3 with: path: ~/.gradle/caches key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} @@ -29,11 +28,13 @@ jobs: cd swagger-staging git init git config user.email "github-actions@users.noreply.github.com" - git config user.name "CCD GitHub action" - git remote add upstream https://${{ secrets.SWAGGER_PUBLISHER_API_TOKEN }}@github.com/hmcts/cnp-api-docs.git + git config user.name "GitHub action" + git remote add upstream "https://jenkins-reform-hmcts:${{ secrets.SWAGGER_PUBLISHER_API_TOKEN }}@github.com/hmcts/cnp-api-docs.git" git pull upstream master repo=`echo "$GITHUB_REPOSITORY" | cut -f2- -d/` - echo "$(cat /tmp/swagger-specs.json)" > "docs/specs/$repo.json" - git add "docs/specs/$repo.json" + git add "docs/specs/ccd-data-store-api.v1_internal.json" + git add "docs/specs/ccd-data-store-api.v1_external.json" + git add "docs/specs/ccd-data-store-api.v2_internal.json" + git add "docs/specs/ccd-data-store-api.v2_external.json" # Only commit and push if we have changes. git diff --quiet && git diff --staged --quiet || (git commit -m "Update spec for $repo#${GITHUB_SHA:7}"; git push --set-upstream upstream master) diff --git a/src/functionalTest/java/uk/gov/hmcts/ccd/documentam/befta/CaseDocumentAmTestAutomationAdapter.java b/src/functionalTest/java/uk/gov/hmcts/ccd/documentam/befta/CaseDocumentAmTestAutomationAdapter.java index b23cc34b5..35cc03109 100644 --- a/src/functionalTest/java/uk/gov/hmcts/ccd/documentam/befta/CaseDocumentAmTestAutomationAdapter.java +++ b/src/functionalTest/java/uk/gov/hmcts/ccd/documentam/befta/CaseDocumentAmTestAutomationAdapter.java @@ -25,6 +25,9 @@ protected BeftaTestDataLoader buildTestDataLoader() { public synchronized Object calculateCustomValue(BackEndFunctionalTestScenarioContext scenarioContext, Object key) { //the docAMUrl is is referring the self link in PR String docAmUrl = EnvironmentVariableUtils.getRequiredVariable("TEST_URL"); + if (key.toString().startsWith("contains ") && key.toString().contains(" and does not contain ")) { + return getContainsAndDoesNotContainPlainText(scenarioContext, key.toString()); + } switch (key.toString()) { case ("documentIdInTheResponse"): return getDocumentIdInTheRresponse(scenarioContext); @@ -40,6 +43,25 @@ public synchronized Object calculateCustomValue(BackEndFunctionalTestScenarioCon } + private Object getContainsAndDoesNotContainPlainText(BackEndFunctionalTestScenarioContext scenarioContext, + String key) { + try { + String actualValueStr = (String) ReflectionUtils.deepGetFieldInObject(scenarioContext, + "testData.actualResponse.body.__plainTextValue__"); + String[] expectedValues = key.split(" and does not contain ", 2); + String expectedPresentValueStr = expectedValues[0].replace("contains ", ""); + String expectedAbsentValueStr = expectedValues[1]; + + if (actualValueStr.contains(expectedPresentValueStr) + && !actualValueStr.contains(expectedAbsentValueStr)) { + return actualValueStr; + } + return "response did not match plain text expectations"; + } catch (Exception e) { + throw new FunctionalTestException("Problem checking acceptable response payload: ", e); + } + } + private Object getHashTokenDifferentFromPrevious(BackEndFunctionalTestScenarioContext scenarioContext) { try { String newHashToken = (String) ReflectionUtils diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125.feature b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125.feature new file mode 100644 index 000000000..f44684d14 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125.feature @@ -0,0 +1,71 @@ +#=============================================== +@F-125 +Feature: F-125: Swagger Pages and Open API Specs +#=============================================== + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +@S-125.1 +Scenario: must show Swagger UI page for Internal V1 APIs + + Given an appropriate test context as detailed in the test data source, + + When a request is prepared with appropriate values, + And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api], + + Then a positive response is received, + And the response has all the details as expected + And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V1_Internal]. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +@S-125.2 +Scenario: must show Swagger UI page for External V1 APIs + + Given an appropriate test context as detailed in the test data source, + + When a request is prepared with appropriate values, + And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api], + + Then a positive response is received, + And the response has all the details as expected + And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V1_External]. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +@S-125.3 +Scenario: must show Swagger UI page for Internal V2 APIs + + Given an appropriate test context as detailed in the test data source, + + When a request is prepared with appropriate values, + And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api], + + Then a positive response is received, + And the response has all the details as expected + And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V2_Internal]. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +@S-125.4 +Scenario: must show Swagger UI page for External V2 APIs + + Given an appropriate test context as detailed in the test data source, + + When a request is prepared with appropriate values, + And it is submitted to call the [Get Swagger UI Page] operation of [CCD Case Document Am Api], + + Then a positive response is received, + And the response has all the details as expected + And a call [to observe the swagger json content] will get the expected response as in [S-125_Swagger_JSON_V2_External]. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +@S-125.5 +Scenario: must show Swagger Config JSON Page + + Given an appropriate test context as detailed in the test data source, + + When a request is prepared with appropriate values, + And it is submitted to call the [Get Swagger Config JSON Page] operation of [CCD Case Document Am Api], + + Then a positive response is received, + And the response has all the details as expected + And a call [to observe the swagger config json content] will get the expected response as in [S-125.5]. + +#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_JSON.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_JSON.td.json new file mode 100644 index 000000000..70889f1e8 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_JSON.td.json @@ -0,0 +1,22 @@ +{ + "_guid_": "F-125_Swagger_JSON", + "title": "Verify swagger JSON Content", + + "productName": "CCD Case Document Am Api", + "operationName": "Get Swagger JSON", + + "method": "GET", + "uri": "https://hmcts.github.io/cnp-api-docs/specs/{ccd-case-document-am-api-version}", + + "expectedResponse": { + "headers" : { + "Content-Encoding" : "gzip", + "Content-Length" : "${[scenarioContext][customValues][approximately 5838]}", + "Content-Type" : "application/json; charset=utf-8", + "Date" : "[[ANYTHING_PRESENT]]", + "Expires" : "[[ANYTHING_PRESENT]]", + "Last-Modified" : "[[ANYTHING_PRESENT]]", + "Server" : "GitHub.com" + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_UI.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_UI.td.json new file mode 100644 index 000000000..8db003ced --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Swagger_UI.td.json @@ -0,0 +1,24 @@ +{ + "_guid_": "F-125_Swagger_UI", + "title": "Verify swagger UI Content", + + "productName": "CCD Case Document Am Api", + "operationName": "Get Swagger UI Page", + + "method": "GET", + "uri": "/swagger-ui/index.html", + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "headers" : { + "Accept-Ranges" : "bytes", + "Content-Encoding" : "gzip", + "Content-Length" : "${[scenarioContext][customValues][approximately 1190]}", + "Content-Type" : "text/html" + }, + "body" : { + "__plainTextValue__": "${[scenarioContext][customValues][contains Swagger UI and does not contain Failed to load remote configuration]}" + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Test_Swagger_Config_Base_Data.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Test_Swagger_Config_Base_Data.td.json new file mode 100644 index 000000000..f5744e30f --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/F-125_Test_Swagger_Config_Base_Data.td.json @@ -0,0 +1,20 @@ +{ + "_guid_": "F-125_Test_Swagger_Config_Base_Data", + "title": "Verify swagger Config", + + "productName": "CCD Case Document Am Api", + "operationName": "Get Swagger Config JSON Page", + + "method": "GET", + "uri": "/v3/api-docs/swagger-config", + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "headers" : { + "Accept-Ranges" : "bytes", + "Content-Encoding" : "gzip", + "Content-Type" : "application/json" + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.1.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.1.td.json new file mode 100644 index 000000000..149e85bb0 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.1.td.json @@ -0,0 +1,17 @@ +{ + "_guid_": "S-125.1", + "title": "must show Swagger UI page for Internal V1 APIs", + "_extends_": "F-125_Swagger_UI", + + "specs": [ + "to observe the swagger UI content" + ], + + "request": { + "queryParams": { + "urls.primaryName": "v1_internal" + } + } + +} + diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.2.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.2.td.json new file mode 100644 index 000000000..05f2559ed --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.2.td.json @@ -0,0 +1,17 @@ +{ + "_guid_": "S-125.2", + "title": "must show Swagger UI page for External V1 APIs", + "_extends_": "F-125_Swagger_UI", + + "specs": [ + "to observe the swagger UI content" + ], + + "request": { + "queryParams": { + "urls.primaryName": "v1_internal" + } + } + +} + diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.3.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.3.td.json new file mode 100644 index 000000000..41aeed9fc --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.3.td.json @@ -0,0 +1,17 @@ +{ + "_guid_": "S-125.3", + "title": "must show Swagger UI page for Internal V2 APIs", + "_extends_": "F-125_Swagger_UI", + + "specs": [ + "to observe the swagger UI content" + ], + + "request": { + "queryParams": { + "urls.primaryName": "v1_internal" + } + } + +} + diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.4.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.4.td.json new file mode 100644 index 000000000..2545d94af --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.4.td.json @@ -0,0 +1,17 @@ +{ + "_guid_": "S-125.4", + "title": "must show Swagger UI page for External V2 APIs", + "_extends_": "F-125_Swagger_UI", + + "specs": [ + "to observe the swagger UI content" + ], + + "request": { + "queryParams": { + "urls.primaryName": "v1_internal" + } + } + +} + diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.5.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.5.td.json new file mode 100644 index 000000000..16cf25785 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125.5.td.json @@ -0,0 +1,21 @@ +{ + "_guid_": "S-125.5", + "title": "Must return a positive appropriate response when Swagger config URL is accessed", + "_extends_": "F-125_Test_Swagger_Config_Base_Data", + + "specs": [ + "to observe the swagger config json content" + ], + + "request" :{ + }, + + "expectedResponse": { + "body" : { + "configUrl" : "[[ANYTHING_PRESENT]]", + "url" : "[[ANYTHING_PRESENT]]", + "oauth2RedirectUrl" : "[[ANYTHING_PRESENT]]", + "validatorUrl" : "[[ANYTHING_PRESENT]]" + } + } +} \ No newline at end of file diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_External.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_External.td.json new file mode 100644 index 000000000..9913d048a --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_External.td.json @@ -0,0 +1,36 @@ +{ + "_guid_": "S-125_Swagger_JSON_V1_External", + "title": "Must return a positive appropriate response when Swagger JSON External V1 URL is accessed", + "_extends_": "F-125_Swagger_JSON", + + "specs": [ + "to observe the swagger json content" + ], + + "request" :{ + "pathVariables" : { + "ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_external.json" + } + }, + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "body" : { + "host" : "[[ANYTHING_PRESENT]]", + "basePath": "/", + "tags": "[[ANYTHING_PRESENT]]", + "paths": "[[ANYTHING_PRESENT]]", + "definitions": "[[ANYTHING_PRESENT]]", + "swagger": "2.0", + "info": { + "description": "Create, modify, retrieve and search cases", + "title": "Core Case Data - Data store API", + "contact":"[[ANYTHING_PRESENT]]", + "license": "[[ANYTHING_PRESENT]]", + "version": "[[ANYTHING_PRESENT]]" + + } + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_Internal.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_Internal.td.json new file mode 100644 index 000000000..9dcf17063 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V1_Internal.td.json @@ -0,0 +1,36 @@ +{ + "_guid_": "S-125_Swagger_JSON_V1_Internal", + "title": "Must return a positive appropriate response when Swagger JSON Internal V1 URL is accessed", + "_extends_": "F-125_Swagger_JSON", + + "specs": [ + "to observe the swagger json content" + ], + + "request" :{ + "pathVariables" : { + "ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_internal.json" + } + }, + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "body" : { + "host" : "[[ANYTHING_PRESENT]]", + "basePath": "/", + "tags": "[[ANYTHING_PRESENT]]", + "paths": "[[ANYTHING_PRESENT]]", + "definitions": "[[ANYTHING_PRESENT]]", + "swagger": "2.0", + "info": { + "description": "Create, modify, retrieve and search cases", + "title": "Core Case Data - Data store API", + "contact":"[[ANYTHING_PRESENT]]", + "license": "[[ANYTHING_PRESENT]]", + "version": "[[ANYTHING_PRESENT]]" + + } + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_External.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_External.td.json new file mode 100644 index 000000000..0b41dc3ad --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_External.td.json @@ -0,0 +1,36 @@ +{ + "_guid_": "S-125_Swagger_JSON_V2_External", + "title": "Must return a positive appropriate response when Swagger JSON External V2 URL is accessed", + "_extends_": "F-125_Swagger_JSON", + + "specs": [ + "to observe the swagger json content" + ], + + "request" :{ + "pathVariables" : { + "ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_external.json" + } + }, + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "body" : { + "host" : "[[ANYTHING_PRESENT]]", + "basePath": "/", + "tags": "[[ANYTHING_PRESENT]]", + "paths": "[[ANYTHING_PRESENT]]", + "definitions": "[[ANYTHING_PRESENT]]", + "swagger": "2.0", + "info": { + "description": "Create, modify, retrieve and search cases", + "title": "CCD Data Store API", + "contact":"[[ANYTHING_PRESENT]]", + "license": "[[ANYTHING_PRESENT]]", + "version": "[[ANYTHING_PRESENT]]" + + } + } + } +} diff --git a/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_Internal.td.json b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_Internal.td.json new file mode 100644 index 000000000..373847e26 --- /dev/null +++ b/src/functionalTest/resources/features/F-125 - Swagger Pages and API Specs/S-125_Swagger_JSON_V2_Internal.td.json @@ -0,0 +1,36 @@ +{ + "_guid_": "S-125_Swagger_JSON_V2_Internal", + "title": "Must return a positive appropriate response when Swagger JSON Internal V2 URL is accessed", + "_extends_": "F-125_Swagger_JSON", + + "specs": [ + "to observe the swagger json content" + ], + + "request" :{ + "pathVariables" : { + "ccd-case-document-am-api-version": "ccd-case-document-am-api-version.v3_internal.json" + } + }, + + "expectedResponse": { + "responseCode" : 200, + "responseMessage" : "OK", + "body" : { + "host" : "[[ANYTHING_PRESENT]]", + "basePath": "/", + "tags": "[[ANYTHING_PRESENT]]", + "paths": "[[ANYTHING_PRESENT]]", + "definitions": "[[ANYTHING_PRESENT]]", + "swagger": "2.0", + "info": { + "description": "Create, modify, retrieve and search cases", + "title": "CCD Case Document Am Api", + "contact":"[[ANYTHING_PRESENT]]", + "license": "[[ANYTHING_PRESENT]]", + "version": "[[ANYTHING_PRESENT]]" + + } + } + } +}