Skip to content

Commit

Permalink
Media Type tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe444 committed Jun 19, 2020
1 parent 59f4240 commit 64d1183
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public List<ServiceDto> getEnvironment(@PathVariable("name") String name) {
.collect(toList());
}

@PutMapping(value = "environments/{name}")
@PutMapping(
value = "environments/{name}",
consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Update the environment", nickname = "update environment")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hltech.judged.server.domain.validation


import com.hltech.judged.server.domain.JudgeD
import com.hltech.judged.server.domain.contracts.InMemoryServiceContractsRepository
import com.hltech.judged.server.domain.contracts.ServiceContracts
import com.hltech.judged.server.domain.environment.EnvironmentAggregate
import com.hltech.judged.server.domain.environment.InMemoryEnvironmentRepository
Expand All @@ -15,7 +16,7 @@ import static org.assertj.core.util.Lists.newArrayList

class JudgeDUT extends Specification {

def serviceContractsRepository = new com.hltech.judged.server.domain.contracts.InMemoryServiceContractsRepository();
def serviceContractsRepository = new InMemoryServiceContractsRepository();
def environmentRepository = new InMemoryEnvironmentRepository()
def contractValidator = new PingContractValidator()
def judgeD = new JudgeD(environmentRepository, serviceContractsRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,23 @@ class RestContractValidatorUT extends Specification {
}
}

def 'should validate contracts specified in openapi v3'() {
def 'should validate contracts specified in openapi v3 - should find failures when media type is specified'() {
given:
def swagger = new String(toByteArray(getClass().getResourceAsStream("/swagger-openapi3.json")))
def pact = (RequestResponsePact) loadPact(getClass().getResourceAsStream("/pact.json"))
when:
def validationResult = validator.validate(pact, swagger)
then:
for (report in validationResult) {
with(report) {
status == OK
}
validationResult.size() == 2
validationResult.any { result ->
result.name == 'get envs; 200 OK response' &&
result.status == FAILED &&
result.errors.get(0) == "[Path '/0'] Instance type (integer) does not match any allowed primitive type (allowed: [\"string\"])"
}
validationResult.any { result ->
result.name == 'publish request; 200 OK response' &&
result.status == FAILED &&
result.errors.get(0) == "[Path '/0'] Object instance has properties which are not allowed by the schema: [\"gyyigi\"]"
}
}
}
30 changes: 26 additions & 4 deletions judge-d-server/src/test/resources/pact.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,43 @@
"description": "publish request; 200 OK response",
"request": {
"method": "PUT",
"path": "environments/nPUmfl0iF1",
"path": "environments/9nUWkVyW25",
"headers": {
"X-JUDGE-D-AGENT-SPACE": "dli0ONzhUW"
"X-JUDGE-D-AGENT-SPACE": "j3_OIa8MXC",
"Content-Type": "application/json"
},
"query": "",
"body": [
{
"name": "_uss5_lSrR",
"version": "6PPZwQAg8G"
"version": "6PPZwQAg8G",
"gyyigi": "68tgygk"
}
]
},
"response": {
"status": "200"
}
},
{
"description": "get envs; 200 OK response",
"request": {
"method": "GET",
"path": "environments",
"headers": {
"X-JUDGE-D-AGENT-SPACE": "j3_OIa8MXC",
"Accept": "application/json"
},
"query": ""
},
"response": {
"status": "200",
"headers": {}
"headers": {
"Content-Type": "application/json"
},
"body": [
123
]
}
}
],
Expand Down

0 comments on commit 64d1183

Please sign in to comment.