diff --git a/diffblue-cover/diffblue-legal-age-web/pom.xml b/diffblue-cover/diffblue-legal-age-web/pom.xml index 61e7799..1a30651 100644 --- a/diffblue-cover/diffblue-legal-age-web/pom.xml +++ b/diffblue-cover/diffblue-legal-age-web/pom.xml @@ -63,8 +63,34 @@ org.json json - 20220924 + 20231013 + + + + org.openapitools + openapi-generator-maven-plugin + + 7.2.0 + + + + + generate + + + ${project.basedir}/src/main/resources/openapi.yaml + ${project.build.directory}/site/openapi + html2 + + false + + + + + + + diff --git a/diffblue-cover/diffblue-legal-age-web/src/bank.yaml b/diffblue-cover/diffblue-legal-age-web/src/bank.yaml deleted file mode 100644 index 29682b2..0000000 --- a/diffblue-cover/diffblue-legal-age-web/src/bank.yaml +++ /dev/null @@ -1,29 +0,0 @@ -openapi: 3.1.0 -info: - title: Sample of Bank API - description: >- - Sample of Bank API with only one end-point - version: 1.0.0 -servers: - - url: 'http://localhost:8182' - description: Local server -paths: - /age: - get: - summary: Validate that person is legal age - description: >- - Validate that person is legal age - operationId: legalAgeValidator - parameters: - - name: birthDate - in: query - description: >- - Birth date of person - required: true - schema: - type: string - format: date - responses: - '200': - description: >- - Person is legal age diff --git a/diffblue-cover/diffblue-legal-age-web/src/main/java/diffblue/age/web/AgeResource.java b/diffblue-cover/diffblue-legal-age-web/src/main/java/diffblue/age/web/AgeResource.java index d8f566a..65c3e62 100644 --- a/diffblue-cover/diffblue-legal-age-web/src/main/java/diffblue/age/web/AgeResource.java +++ b/diffblue-cover/diffblue-legal-age-web/src/main/java/diffblue/age/web/AgeResource.java @@ -2,6 +2,7 @@ import diffblue.legalage.LegalAgePredicate; +import org.restlet.data.Status; import org.restlet.resource.Get; import org.restlet.resource.ServerResource; import org.json.JSONObject; @@ -22,6 +23,7 @@ public String legalAgeValidator() { birthday = LocalDate.parse(birthdayString, DateTimeFormatter.ISO_DATE); } catch (DateTimeParseException e) { response.put("error", "Invalid birthday format. Use yyyy-mm-dd."); + setStatus(Status.CLIENT_ERROR_BAD_REQUEST); return response.toString(); } diff --git a/diffblue-cover/diffblue-legal-age-web/src/main/resources/openapi.yaml b/diffblue-cover/diffblue-legal-age-web/src/main/resources/openapi.yaml new file mode 100644 index 0000000..36bc401 --- /dev/null +++ b/diffblue-cover/diffblue-legal-age-web/src/main/resources/openapi.yaml @@ -0,0 +1,75 @@ +openapi: 3.0.0 +info: + title: Sample of Bank API + description: >- + Sample of Bank API with only one end-point + version: 1.0.0 +servers: + - url: 'http://localhost:8182' + description: Local server +paths: + /age: + get: + summary: Validate that person is legal age + description: >- + Verifies the person has reached the age of 18 years. + It returns a boolean value `true` if the answer is positive. + + operationId: legalAgeValidator + parameters: + - $ref: '#/components/parameters/BirthDate' + responses: + 200: + $ref: '#/components/responses/LegalAgeResponse' + 400: + $ref: '#/components/responses/ErrorResponse' + +components: + parameters: + BirthDate: + name: birthDate + in: query + description: >- + Birth date of person + required: true + schema: + type: string + format: date + example: 2000-01-01 + schemas: + LegalAgeInfo: + type: object + properties: + message: + type: string + description: Birthday message and legal age status + birthday: + type: string + format: date + description: The birthday in yyyy-mm-dd format + isLegalAge: + type: boolean + description: Indicates if the person is of legal age + required: + - message + - birthday + - isLegalAge + responses: + LegalAgeResponse: + description: Legal age validation response + content: + application/json: + schema: + $ref: '#/components/schemas/LegalAgeInfo' + ErrorResponse: + description: Error response + content: + application/json: + schema: + type: object + properties: + error: + type: string + description: Error message + required: + - error diff --git a/diffblue-cover/diffblue-legal-age-web/src/rest/legal-age-invalid.http b/diffblue-cover/diffblue-legal-age-web/src/rest/legal-age-invalid.http new file mode 100644 index 0000000..0959021 --- /dev/null +++ b/diffblue-cover/diffblue-legal-age-web/src/rest/legal-age-invalid.http @@ -0,0 +1,13 @@ +### + +GET {{host}}/age?birthday=xxx + +> {% + const data = JSON.parse(response.body.toString()); + client.test("Returns 400 - Bad Request", function() { + client.assert(response.status === 400, "Response status is not 400"); + }); + client.test("Error message is correct", function() { + client.assert(data.error === "Invalid birthday format. Use yyyy-mm-dd.", "error message is incorrect"); + }); +%} diff --git a/pom.xml b/pom.xml index 574ba6f..71bcf8d 100644 --- a/pom.xml +++ b/pom.xml @@ -118,7 +118,7 @@ org.mockito mockito-core - 5.4.0 + 5.8.0 test @@ -139,7 +139,7 @@ org.apache.groovy groovy - 4.0.16 + 4.0.17 test @@ -180,7 +180,7 @@ maven-surefire-plugin - 3.2.2 + 3.2.3 false @@ -200,13 +200,13 @@ maven-failsafe-plugin - 3.2.2 + 3.2.3 maven-surefire-report-plugin - 3.2.2 + 3.2.3 @@ -224,7 +224,7 @@ maven-javadoc-plugin - 3.6.2 + 3.6.3 maven-dependency-plugin @@ -254,7 +254,7 @@ com.github.spotbugs spotbugs-maven-plugin - 4.8.1.0 + 4.8.2.0 org.apache.maven.plugins @@ -264,7 +264,7 @@ org.owasp dependency-check-maven - 9.0.2 + 9.0.7 @@ -278,7 +278,7 @@ com.diffplug.spotless spotless-maven-plugin - 2.41.0 + 2.41.1 origin/main