Skip to content

CFTS-6684 :: Added swagger end point tests #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2ac2899
bumped test-definitions and befta-fw to latest
dinesh1patel Jan 8, 2025
2764490
addition of swagger FTs and fix for git workflow action
dinesh1patel Apr 7, 2025
f6d12ac
Merge branch 'master' into CFTS-6684-Swagger-Enpoint-Tests
dinesh1patel Apr 7, 2025
8e94021
Update swagger.yml
dinesh1patel Apr 7, 2025
2f63144
fix typo
dinesh1patel Apr 7, 2025
463f4cc
fix param
dinesh1patel Apr 7, 2025
5efefc4
updated swagger json
dinesh1patel Apr 7, 2025
9c23e06
updated to java 17 swagger tests
dinesh1patel Apr 7, 2025
7bb6c41
updated Swagger api details
dinesh1patel Apr 7, 2025
96ba2e8
updated spec
dinesh1patel Apr 7, 2025
65169d0
updated spec with actual results
dinesh1patel Apr 7, 2025
84feaf8
empty commit to trigger build
dinesh1patel Apr 7, 2025
5e562f5
empty commit to trigger build
dinesh1patel Apr 7, 2025
0d6d72e
empty commit to trigger build
dinesh1patel Apr 8, 2025
9238d68
Update S-125.2.td.json
dinesh1patel Apr 8, 2025
dfa5977
Update S-125.1.td.json
dinesh1patel Apr 8, 2025
d5ac0d0
Update S-125.1.td.json
dinesh1patel Apr 8, 2025
68a4843
Update UserProfileTestAutomationAdapter.java
dinesh1patel Apr 9, 2025
d834f8f
Update F-125_Test_Swagger_UI_Base_Data.td.json
dinesh1patel Apr 9, 2025
7f03449
Update build.gradle
dinesh1patel Apr 9, 2025
2394075
Added missing code for contains
dinesh1patel Apr 9, 2025
e176102
Update swagger.yml
dinesh1patel Apr 11, 2025
d3c57ba
Merge branch 'master' into CFTS-6684-Swagger-Enpoint-Tests
dinesh1patel Jun 19, 2025
8846b7d
Merge branch 'master' into CFTS-6684-Swagger-Enpoint-Tests
dinesh1patel Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
java-version: 21
distribution: 'temurin'
- name: Run Swagger Publisher
run: ./gradlew test --tests uk.gov.hmcts.ccd.swagger.SwaggerPublisher
run: ./gradlew integrationTest --tests uk.gov.hmcts.ccd.swagger.OpenApiPublisher
- name: Commit to repository
run: |
mkdir swagger-staging
cd swagger-staging
git init
git config user.email "[email protected]"
git config user.name "GitHub action"
git remote add upstream https://${{ secrets.GH_TOKEN }}@github.com/hmcts/cnp-api-docs.git
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"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ dependencies {
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'

testImplementation group: 'com.github.hmcts', name: 'ccd-test-definitions', version: '7.24.2'
testImplementation group: 'com.github.hmcts', name: 'befta-fw', version: '9.2.0'
testImplementation group: 'com.github.hmcts', name: 'befta-fw', version: '9.2.3'
testImplementation 'com.github.hmcts:fortify-client:1.4.8:all'
testImplementation 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.9.11'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
package uk.gov.hmcts.ccd.userprofile.befta;

import uk.gov.hmcts.befta.DefaultTestAutomationAdapter;
import uk.gov.hmcts.befta.exception.FunctionalTestException;
import uk.gov.hmcts.befta.player.BackEndFunctionalTestScenarioContext;
import uk.gov.hmcts.befta.util.ReflectionUtils;

public class UserProfileTestAutomationAdapter extends DefaultTestAutomationAdapter {

@Override
public synchronized Object calculateCustomValue(BackEndFunctionalTestScenarioContext scenarioContext, Object key) {
if (key.toString().startsWith("no_dynamic_injection_")) {
return key.toString().replace("no_dynamic_injection_","");
} else if (key.toString().startsWith("approximately ")) {
try {
String actualSizeFromHeaderStr = (String) ReflectionUtils.deepGetFieldInObject(scenarioContext,
"testData.actualResponse.headers.Content-Length");
String expectedSizeStr = key.toString().replace("approximately ", "");

int actualSize = Integer.parseInt(actualSizeFromHeaderStr);
int expectedSize = Integer.parseInt(expectedSizeStr);

if (Math.abs(actualSize - expectedSize) < (actualSize * 10 / 100)) {
return actualSizeFromHeaderStr;
}
return expectedSize;
} catch (Exception e) {
throw new FunctionalTestException("Problem checking acceptable response payload: ", e);
}
} else if (key.toString().startsWith("contains ")) {
try {
String actualValueStr = (String) ReflectionUtils.deepGetFieldInObject(scenarioContext,
"testData.actualResponse.body.__plainTextValue__");
String expectedValueStr = key.toString().replace("contains ", "");

if (actualValueStr.contains(expectedValueStr)) {
return actualValueStr;
}
return "expectedValueStr " + expectedValueStr + " not present in response ";
} catch (Exception e) {
throw new FunctionalTestException("Problem checking acceptable response payload: ", e);
}
}
return super.calculateCustomValue(scenarioContext, key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#===============================================
@F-125
Feature: F-125: Swagger Pages and Open API Specs
#===============================================

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.1
Scenario: must show Swagger UI page 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 User Profile],

Then a positive response is received,
And the response has all the details as expected
And a call [to observe the swagger UI content] will get the expected response as in [S-125.1].
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@S-125.2
Scenario: must show Swagger Json 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 Json API] operation of [CCD User Profile],

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.2].

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"_guid_": "F-125_Test_Swagger_JSON_Base_Data",
"title": "Verify swagger JSON Content",

"productName": "CCD User Profile",
"operationName": "Get Swagger Json API",

"method": "GET",
"uri": "https://hmcts.github.io/cnp-api-docs/specs/{ccd-user-profile-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"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_guid_": "F-125_Test_Swagger_UI_Base_Data",
"title": "Verify swagger UI Content",

"productName": "CCD User Profile",
"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]}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_guid_": "S-125.1",
"title": "must show Swagger UI page for APIs",
"_extends_": "F-125_Test_Swagger_UI_Base_Data",

"specs": [
"to observe the swagger UI content"
],

"request" :{
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"_guid_": "S-125.2",
"title": "Must return a positive appropriate response when Swagger JSON URL is accessed",
"_extends_": "F-125_Test_Swagger_JSON_Base_Data",

"specs": [
"to observe the swagger json content"
],

"request" :{
"pathVariables" : {
"ccd-user-profile-api-version": "ccd-user-profile-api.json"
}
},

"expectedResponse": {
"responseCode" : 200,
"responseMessage" : "OK",
"body" : {
"openapi" : "[[ANYTHING_PRESENT]]",
"servers" : "[[ANYTHING_PRESENT]]",
"components" : "[[ANYTHING_PRESENT]]",
"paths": "[[ANYTHING_PRESENT]]",
"info": {
"description": "API to store and retrieve user profile data.",
"title": "User Profile API",
"version": "[[ANYTHING_PRESENT]]"
}
}
}
}
5 changes: 0 additions & 5 deletions src/integrationTest/java/uk/gov/hmcts/ccd/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand Down Expand Up @@ -47,10 +46,6 @@ static void setProperties(DynamicPropertyRegistry registry) {
@BeforeAll
public static void beforeAll() {
postgresqlContainer.start();
}

@BeforeClass
public static void init() {
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/gov/hmcts/ccd/OpenApiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class OpenApiConfig {
@Bean
public OpenAPI api() {
return new OpenAPI()
.info(new Info().title("SpringShop API")
.description("Spring shop sample application")
.info(new Info().title("User Profile API")
.description("API to store and retrieve user profile data.")
.version("v0.0.1")
);
}
Expand Down