use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class VersionsContractInfoFuzzerTest method shouldNotRunOnSecondAttempt.
@Test
void shouldNotRunOnSecondAttempt() {
FuzzingData data = FuzzingData.builder().path("/path/user").build();
versionsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path does not contain versioning information"));
Mockito.reset(testCaseListener);
versionsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(0)).reportInfo(Mockito.any(), Mockito.eq("Path does not contain versioning information"));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class PathTagsContractInfoFuzzerTest method shouldReportErrorWhenTagsMismatch.
@Test
void shouldReportErrorWhenTagsMismatch() throws Exception {
OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/contract-path-tags-mismatch.yml"))), null, null).getOpenAPI();
FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").tags(Collections.singletonList("petsCats")).build();
pathTagsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.contains("The following [tags] are not present in the top level [tags] element: {}"), Mockito.eq(data.getTags()));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class PathTagsContractInfoFuzzerTest method shouldNotRunOnSecondAttempt.
@Test
void shouldNotRunOnSecondAttempt() throws Exception {
OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get("src/test/resources/openapi.yml"))), null, null).getOpenAPI();
FuzzingData data = FuzzingData.builder().openApi(openAPI).path("/pet").tags(Collections.singletonList("pet")).build();
pathTagsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("The current path's [tags] are correctly defined at the top level [tags] element"));
Mockito.reset(testCaseListener);
pathTagsContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(0)).reportInfo(Mockito.any(), Mockito.eq("The current path's [tags] are correctly defined in the top level [tags] element"));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class RecommendedHeadersContractInfoFuzzerTest method shouldReportInfo.
@ParameterizedTest
@CsvSource({ "X-Trace-Id", "XTraceid", "X-CorrelationId", "X-APP-Correlation_Id" })
void shouldReportInfo(String header) {
CatsHeader catsHeader = CatsHeader.builder().name(header).build();
FuzzingData data = FuzzingData.builder().headers(Sets.newHashSet(catsHeader)).method(HttpMethod.POST).build();
recommendedHeadersContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path contains the recommended [TracedId/CorrelationId] headers for HTTP method {}"), Mockito.eq(HttpMethod.POST));
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class RecommendedHttpCodesContractInfoFuzzerTest method shouldReportErrorWhenAllResponseCodesAreValid.
@ParameterizedTest
@CsvSource(value = { "400,500;POST;200|201|202|204", "400,500;POST;200|201|202|204", "400,202;POST;500", "500,204;POST;400", "404,500,201;PUT;400", "400,500,202;GET;404", "200;HEAD;404", "404;HEAD;200|202", "404,500,200;DELETE;400", "400,500,201;DELETE;404", "400,404,202;DELETE;500", "400,404,500;DELETE;200|201|202|204", "404,500,200;PATCH;400", "400,500,201;PATCH;404", "400,404,202;PATCH;500", "400,404,500;PATCH;200|201|202|204", "500,200;TRACE;400", "400,200;TRACE;500" }, delimiter = ';')
void shouldReportErrorWhenAllResponseCodesAreValid(String responseCode, HttpMethod method, String missing) {
FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData("PetStore", method, responseCode.split(","));
recommendedHttpCodesContractInfoFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("The following recommended HTTP response codes are missing: {}"), Mockito.eq(Collections.singletonList(missing)));
}
Aggregations