|
1 | 1 | package com.mservicetech.openapi.validation; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import com.fasterxml.jackson.databind.JsonNode; |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper; |
3 | 6 | import com.mservicetech.openapi.common.RequestEntity; |
4 | 7 |
|
5 | 8 | import com.mservicetech.openapi.common.Status; |
@@ -81,6 +84,21 @@ public void testRequestBody3() { |
81 | 84 | //{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - requestBody.id: string found, integer expected","severity":"ERROR"} |
82 | 85 | } |
83 | 86 |
|
| 87 | + @Test |
| 88 | + public void testRequestBody4() throws JsonProcessingException { |
| 89 | + InputStream in = this.getClass().getClassLoader().getResourceAsStream("json/req3.json"); |
| 90 | + String req = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n")); |
| 91 | + RequestEntity requestEntity = new RequestEntity(); |
| 92 | + ObjectMapper mapper = new ObjectMapper(); |
| 93 | + JsonNode jsonNode = mapper.readTree(req); |
| 94 | + requestEntity.setRequestBody(jsonNode); |
| 95 | + requestEntity.setContentType("application/json"); |
| 96 | + Status status = openApiValidator.validateRequestPath("/pets", "post", requestEntity); |
| 97 | + Assert.assertNotNull(status); |
| 98 | + Assert.assertEquals( status.getCode(), "ERR11004"); |
| 99 | + //{"statusCode":400,"code":"ERR11004","message":"VALIDATOR_SCHEMA","description":"Schema Validation Error - requestBody.id: string found, integer expected","severity":"ERROR"} |
| 100 | + } |
| 101 | + |
84 | 102 | @Test |
85 | 103 | public void testRequestPath() { |
86 | 104 |
|
|
0 commit comments