Skip to content

Commit

Permalink
#91 contract validator allows consumer to ignore body of a response
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzy committed Dec 1, 2019
1 parent 4c49e93 commit 60fd5a1
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
validation.response.body.missing=INFO
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
}
}
26 changes: 26 additions & 0 deletions judge-d-server/src/test/resources/pact-ignored-response-body.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}

0 comments on commit 60fd5a1

Please sign in to comment.