diff --git a/judge-d-server/src/main/resources/swagger-validator.properties b/judge-d-server/src/main/resources/swagger-validator.properties new file mode 100644 index 00000000..2c00aee9 --- /dev/null +++ b/judge-d-server/src/main/resources/swagger-validator.properties @@ -0,0 +1 @@ +validation.response.body.missing=INFO diff --git a/judge-d-server/src/test/groovy/dev/hltech/dredd/domain/validation/rest/RestContractValidatorUT.groovy b/judge-d-server/src/test/groovy/dev/hltech/dredd/domain/validation/rest/RestContractValidatorUT.groovy index 187fd046..bee10e2f 100644 --- a/judge-d-server/src/test/groovy/dev/hltech/dredd/domain/validation/rest/RestContractValidatorUT.groovy +++ b/judge-d-server/src/test/groovy/dev/hltech/dredd/domain/validation/rest/RestContractValidatorUT.groovy @@ -6,6 +6,7 @@ import spock.lang.Specification import static au.com.dius.pact.model.PactReader.loadPact import static com.google.common.io.ByteStreams.toByteArray import static dev.hltech.dredd.domain.validation.InterfaceContractValidator.InteractionValidationStatus.FAILED +import static dev.hltech.dredd.domain.validation.InterfaceContractValidator.InteractionValidationStatus.OK import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric class RestContractValidatorUT extends Specification { @@ -33,7 +34,7 @@ class RestContractValidatorUT extends Specification { def 'should return validation result with all interactions validated when validate swagger with pact'() { given: - def swagger = new String(toByteArray(getClass().getResourceAsStream("/backend-provider-swagger.json"))) + def swagger = new String(toByteArray(getClass().getResourceAsStream("/swagger-backend-provider.json"))) def pact = (RequestResponsePact) loadPact(getClass().getResourceAsStream("/pact-frontend-to-backend-provider.json")) when: def validationResult = validator.validate(pact, swagger) @@ -45,4 +46,18 @@ class RestContractValidatorUT extends Specification { errors.size() == 1 } } + + def 'should not return validation errors when validate given consumer ignores body'() { + given: + def swagger = new String(toByteArray(getClass().getResourceAsStream("/swagger-ignored-response-body.json"))) + def pact = (RequestResponsePact) loadPact(getClass().getResourceAsStream("/pact-ignored-response-body.json")) + when: + def validationResult = validator.validate(pact, swagger) + then: + for (report in validationResult) { + with(report) { + status == OK + } + } + } } diff --git a/judge-d-server/src/main/resources/pact-frontend-to-backend-provider.json b/judge-d-server/src/test/resources/pact-frontend-to-backend-provider.json similarity index 100% rename from judge-d-server/src/main/resources/pact-frontend-to-backend-provider.json rename to judge-d-server/src/test/resources/pact-frontend-to-backend-provider.json diff --git a/judge-d-server/src/test/resources/pact-ignored-response-body.json b/judge-d-server/src/test/resources/pact-ignored-response-body.json new file mode 100644 index 00000000..34cf3581 --- /dev/null +++ b/judge-d-server/src/test/resources/pact-ignored-response-body.json @@ -0,0 +1,26 @@ +{ + "provider": { + "name": "provider" + }, + "consumer": { + "name": "consumer" + }, + "interactions": [ + { + "description": "health request; 200 OK response", + "request": { + "method": "GET", + "path": "health", + "headers": {}, + "query": "" + }, + "response": { + "status": "200", + "headers": {} + } + } + ], + "metadata": { + "pactSpecificationVersion": "1.0.0" + } +} diff --git a/judge-d-server/src/main/resources/backend-provider-swagger.json b/judge-d-server/src/test/resources/swagger-backend-provider.json similarity index 100% rename from judge-d-server/src/main/resources/backend-provider-swagger.json rename to judge-d-server/src/test/resources/swagger-backend-provider.json diff --git a/judge-d-server/src/test/resources/swagger-ignored-response-body.json b/judge-d-server/src/test/resources/swagger-ignored-response-body.json new file mode 100644 index 00000000..345f1ad1 --- /dev/null +++ b/judge-d-server/src/test/resources/swagger-ignored-response-body.json @@ -0,0 +1,42 @@ +{ + "swagger" : "2.0", + "info" : { + "version" : "latest", + "title" : "Provider" + }, + "paths" : { + "/health" : { + "get" : { + "operationId" : "healthProbe", + "responses" : { + "200" : { + "description" : "successful operation", + "schema" : { + "$ref" : "#/definitions/Health" + } + } + } + } + } + }, + "definitions" : { + "Health" : { + "type" : "object", + "properties" : { + "description" : { + "type" : "string" + }, + "status" : { + "type" : "string", + "readOnly" : true + }, + "details" : { + "type" : "object", + "additionalProperties" : { + "type" : "object" + } + } + } + } + } +}