judge-d
judge-d copied to clipboard
Please add step-by-step example of posting the contract to the endpoint
Hello,
I am trying to understand how to interact with Judge D. Could you please explain how to feed the REST endpoints with the pact and swagger files described in the README.md? I've run through the tests to see how this would be done, but they are based on very simple (to say the least) data, which doesn't shed much light. I've also tried to use judge-d-ui, but the heroku page gives an error message, and the docker-compose version I put up on my machine gave no response to my browser's request to localhost:8081.
Best regards, Piotr
Hello,
I used https://github.com/HLTech/judge-d-contract-publisher-gradle-plugin to put the sample contract into judge-d-server.
This is what I get from {{baseUrl}}/contracts/services/judge-d-example/versions/1.0-SNAPSHOT
{
"name": "judge-d-example",
"version": "1.0-SNAPSHOT",
"capabilities": {
"rest": {
"value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http://www.apache.org/licenses/LICENSE-2.0\"}},\"host\":\"localhost\",\"basePath\":\"/\",\"tags\":[{\"name\":\"environment-controller\",\"description\":\"Environment Controller\"}],\"paths\":{\"/environments/{name}\":{\"put\":{\"tags\":[\"environment-controller\"],\"summary\":\"Update the environment\",\"operationId\":\"update environment\",\"consumes\":[\"application/json\"],\"produces\":[\"*/*\"],\"parameters\":[{\"name\":\"name\",\"in\":\"path\",\"description\":\"name\",\"required\":true,\"type\":\"string\"},{\"in\":\"body\",\"name\":\"services\",\"description\":\"services\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/ServiceForm\"}}}],\"responses\":{\"200\":{\"description\":\"Success\"},\"201\":{\"description\":\"Created\"},\"401\":{\"description\":\"Unauthorized\"},\"403\":{\"description\":\"Forbidden\"},\"404\":{\"description\":\"Not Found\"},\"500\":{\"description\":\"Failure\"}}}}},\"definitions\":{\"ServiceForm\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}}}}}",
"mimeType": "application/json"
}
},
"expectations": {
"judge-d-server": {
"rest": {
"value": "{\"provider\":{\"name\":\"judge-d-server\"},\"consumer\":{\"name\":\"judge-d-agent\"},\"interactions\":[{\"description\":\"publish request; 200 OK response\",\"request\":{\"method\":\"PUT\",\"path\":\"environments/El2ukVED6J\",\"headers\":{},\"query\":\"\",\"body\":[{\"name\":\"ZAEkD_yJJf\",\"version\":\"cttO3Djh8X\"}]},\"response\":{\"status\":\"200\",\"headers\":{}}}],\"metadata\":{\"pactSpecificationVersion\":\"1.0.0\"}}",
"mimeType": "application/json"
}
}
}
}
Now, how do I validate this sample contract? Calling {{baseUrl}}/environment-compatibility-report?services=judge-d-example:1.0-SNAPSHOT&environment=sample gives:
[
{
"service": {
"name": "judge-d-example",
"version": "1.0-SNAPSHOT"
},
"validationReports": [
{
"consumerAndProvider": {
"consumerName": "judge-d-example",
"consumerVersion": "1.0-SNAPSHOT",
"providerName": "judge-d-server",
"providerVersion": null
},
"interactions": [
{
"communicationInterface": "rest",
"interactionName": "any",
"validationResult": "FAILED",
"errors": [
"provider not available"
]
}
]
}
]
}
]
OK, so now I have also registered contract with the environment, which I have not done earlier, so the request to {{baseUrl}}/interrelationship/sample gives
{
"environment": "sample",
"serviceContracts": [
{
"name": "judge-d-example",
"version": "1.0-SNAPSHOT",
"capabilities": {
"rest": {
"value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http://www.apache.org/licenses/LICENSE-2.0\"}},\"host\":\"localhost\",\"basePath\":\"/\",\"tags\":[{\"name\":\"environment-controller\",\"description\":\"Environment Controller\"}],\"paths\":{\"/environments/{name}\":{\"put\":{\"tags\":[\"environment-controller\"],\"summary\":\"Update the environment\",\"operationId\":\"update environment\",\"consumes\":[\"application/json\"],\"produces\":[\"*/*\"],\"parameters\":[{\"name\":\"name\",\"in\":\"path\",\"description\":\"name\",\"required\":true,\"type\":\"string\"},{\"in\":\"body\",\"name\":\"services\",\"description\":\"services\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/ServiceForm\"}}}],\"responses\":{\"200\":{\"description\":\"Success\"},\"201\":{\"description\":\"Created\"},\"401\":{\"description\":\"Unauthorized\"},\"403\":{\"description\":\"Forbidden\"},\"404\":{\"description\":\"Not Found\"},\"500\":{\"description\":\"Failure\"}}}}},\"definitions\":{\"ServiceForm\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}}}}}",
"mimeType": "application/json"
}
},
"expectations": {
"judge-d-server": {
"rest": {
"value": "{\"provider\":{\"name\":\"judge-d-server\",\"version\":\"1.0\"},\"consumer\":{\"name\":\"judge-d-agent\"},\"interactions\":[{\"description\":\"publish request; 200 OK response\",\"request\":{\"method\":\"PUT\",\"path\":\"environments/El2ukVED6J\",\"headers\":{},\"query\":\"\",\"body\":[{\"name\":\"ZAEkD_yJJf\",\"version\":\"cttO3Djh8X\"}]},\"response\":{\"status\":\"200\",\"headers\":{}}}],\"metadata\":{\"pactSpecificationVersion\":\"1.0.0\"}}",
"mimeType": "application/json"
}
}
}
}
]
}
But the request to {{baseUrl}}/environment-compatibility-report?services=judge-d-example:1.0-SNAPSHOT&environment=sample still gives the same result.
OK, I think I'm getting somewhere.
First, I did a POST request to {{baseUrl}}/contracts/services/judge-d-server/versions/1.0 with the following body:
{
"capabilities": {
"rest": {
"value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http://www.apache.org/licenses/LICENSE-2.0\"}},\"host\":\"localhost\",\"basePath\":\"/\",\"tags\":[{\"name\":\"environment-controller\",\"description\":\"Environment Controller\"}],\"paths\":{\"/environments/{name}\":{\"put\":{\"tags\":[\"environment-controller\"],\"summary\":\"Update the environment\",\"operationId\":\"update environment\",\"consumes\":[\"application/json\"],\"produces\":[\"*/*\"],\"parameters\":[{\"name\":\"name\",\"in\":\"path\",\"description\":\"name\",\"required\":true,\"type\":\"string\"},{\"in\":\"body\",\"name\":\"services\",\"description\":\"services\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/ServiceForm\"}}}],\"responses\":{\"200\":{\"description\":\"Success\"},\"201\":{\"description\":\"Created\"},\"401\":{\"description\":\"Unauthorized\"},\"403\":{\"description\":\"Forbidden\"},\"404\":{\"description\":\"Not Found\"},\"500\":{\"description\":\"Failure\"}}}}},\"definitions\":{\"ServiceForm\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}}}}}",
"mimeType": "application/json"
}
},
"expectations": {
"judge-d-server": {
"rest": {
"value": "{\"provider\":{\"name\":\"judge-d-server\",\"version\":\"1.0\"},\"consumer\":{\"name\":\"judge-d-agent\"},\"interactions\":[{\"description\":\"publish request; 200 OK response\",\"request\":{\"method\":\"PUT\",\"path\":\"environments/El2ukVED6J\",\"headers\":{},\"query\":\"\",\"body\":[{\"name\":\"ZAEkD_yJJf\",\"version\":\"cttO3Djh8X\"}]},\"response\":{\"status\":\"200\",\"headers\":{}}}],\"metadata\":{\"pactSpecificationVersion\":\"1.0.0\"}}",
"mimeType": "application/json"
}
}
}
}
Second, I did a GET request to {{baseUrl}}/environment-compatibility-report?services=judge-d-server:1.0&environment=sample. The response is:
[
{
"service": {
"name": "judge-d-server",
"version": "1.0"
},
"validationReports": [
{
"consumerAndProvider": {
"consumerName": "judge-d-server",
"consumerVersion": "1.0",
"providerName": "judge-d-server",
"providerVersion": "1.0"
},
"interactions": [
{
"communicationInterface": "rest",
"interactionName": "publish request; 200 OK response",
"validationResult": "OK",
"errors": []
},
{
"communicationInterface": "rest",
"interactionName": "publish request; 200 OK response",
"validationResult": "OK",
"errors": []
}
]
}
]
}
]
I don'like that consumerName and providerName are both judge-d-server though.
Hi, We will provide more detailed description in the README. In your case you should specify consumer and provider as separate services with different name-version tuple. Then names will be different.
Hi,
Now I get it. I need to specify judge-d-server with capabilities and judge-d-example with expectations set. like this:
POST {{baseUrl}}/contracts/services/judge-d-server/versions/1.0
{
"capabilities": {
"rest": {
"value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http://www.apache.org/licenses/LICENSE-2.0\"}},\"host\":\"localhost\",\"basePath\":\"/\",\"tags\":[{\"name\":\"environment-controller\",\"description\":\"Environment Controller\"}],\"paths\":{\"/environments/{name}\":{\"put\":{\"tags\":[\"environment-controller\"],\"summary\":\"Update the environment\",\"operationId\":\"update environment\",\"consumes\":[\"application/json\"],\"produces\":[\"*/*\"],\"parameters\":[{\"name\":\"name\",\"in\":\"path\",\"description\":\"name\",\"required\":true,\"type\":\"string\"},{\"in\":\"body\",\"name\":\"services\",\"description\":\"services\",\"required\":true,\"schema\":{\"type\":\"array\",\"items\":{\"$ref\":\"#/definitions/ServiceForm\"}}}],\"responses\":{\"200\":{\"description\":\"Success\"},\"201\":{\"description\":\"Created\"},\"401\":{\"description\":\"Unauthorized\"},\"403\":{\"description\":\"Forbidden\"},\"404\":{\"description\":\"Not Found\"},\"500\":{\"description\":\"Failure\"}}}}},\"definitions\":{\"ServiceForm\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"version\":{\"type\":\"string\"}}}}}",
"mimeType": "application/json"
}
},
"expectations": {}
}
POST {{baseUrl}}/contracts/services/judge-d-example/versions/1.0
{
"capabilities": {},
"expectations": {
"judge-d-server": {
"rest": {
"value": "{\"provider\":{\"name\":\"judge-d-server\",\"version\":\"1.0\"},\"consumer\":{\"name\":\"judge-d-example\"},\"interactions\":[{\"description\":\"publish request; 200 OK response\",\"request\":{\"method\":\"PUT\",\"path\":\"environments/El2ukVED6J\",\"headers\":{},\"query\":\"\",\"body\":[{\"name\":\"ZAEkD_yJJf\",\"version\":\"cttO3Djh8X\"}]},\"response\":{\"status\":\"200\",\"headers\":{}}}],\"metadata\":{\"pactSpecificationVersion\":\"1.0.0\"}}",
"mimeType": "application/json"
}
}
}
}
PUT {{baseUrl}}/environments/sample
[
{
"name": "judge-d-example",
"version": "1.0"
},
{
"name": "judge-d-server",
"version": "1.0"
}
]
GET {{baseUrl}}/environment-compatibility-report?services=judge-d-example:1.0&environment=sample
[
{
"service": {
"name": "judge-d-example",
"version": "1.0"
},
"validationReports": [
{
"consumerAndProvider": {
"consumerName": "judge-d-example",
"consumerVersion": "1.0",
"providerName": "judge-d-server",
"providerVersion": "1.0"
},
"interactions": [
{
"communicationInterface": "rest",
"interactionName": "publish request; 200 OK response",
"validationResult": "OK",
"errors": []
}
]
}
]
}
]
Thanks for support!
Perfect:). I will keep this task open and we will verify here README. Maybe we can add better description there.