Search in sources :

Example 26 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class HttpStatusCodeInValidRangeContractInfoFuzzerTest method shouldReportInfoWhenAllResponseCodesAreValid.

@ParameterizedTest
@CsvSource({ "100", "200", "599", "default" })
void shouldReportInfoWhenAllResponseCodesAreValid(String responseCode) {
    FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData("PetStore", responseCode);
    httpStatusCodeInValidRangeContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("All defined response codes are valid!"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class NamingsContractInfoFuzzerTest method shouldReportErrorWhenJsonObjectsNotMatchingCamelCase.

@ParameterizedTest
@CsvSource({ "first_Payload-test", "secondpayload_tesAaa" })
void shouldReportErrorWhenJsonObjectsNotMatchingCamelCase(String schemaName) {
    FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData(schemaName, "200");
    namingsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.eq("Path does not follow RESTful API naming good practices: {}"), Mockito.contains(String.format("The following request/response objects are not matching CamelCase, snake_case or hyphen-case: <strong>%s</strong><br /><br />", schemaName)));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class NamingsContractInfoFuzzerTest method shouldMatchRestNamingStandards.

@ParameterizedTest
@CsvSource({ "first_payload", "SecondPayload", "third-payload", "body_120" })
void shouldMatchRestNamingStandards(String schemaName) {
    FuzzingData data = ContractFuzzerDataUtil.prepareFuzzingData(schemaName, "200");
    namingsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.eq("Path follows the RESTful API naming good practices."));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class TopLevelElementsContractInfoFuzzerTest method shouldNotReportAnyError.

@Test
void shouldNotReportAnyError() 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).build();
    topLevelElementsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportInfo(Mockito.any(), Mockito.contains("OpenAPI contract contains all top level relevant information!"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) OpenAPIParser(io.swagger.parser.OpenAPIParser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with FuzzingData

use of com.endava.cats.model.FuzzingData in project cats by Endava.

the class TopLevelElementsContractInfoFuzzerTest method shouldReportError.

@ParameterizedTest
@CsvSource({ "src/test/resources/contract-missing-info.yml,info.version, info.contact.url, info.description, info.contact.name, info.title, info.contact.email", "src/test/resources/contract-missing-servers.yml,servers", "src/test/resources/contract-missing-tags.yml,tags", "src/test/resources/contract-incomplete-contact.yml,info.contact.url, info.contact.email", "src/test/resources/contract-incomplete-tags.yml,tags,description" })
void shouldReportError(String contractPath, String expectedError) throws Exception {
    OpenAPI openAPI = new OpenAPIParser().readContents(new String(Files.readAllBytes(Paths.get(contractPath))), null, null).getOpenAPI();
    FuzzingData data = FuzzingData.builder().openApi(openAPI).build();
    topLevelElementsContractInfoFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(1)).reportError(Mockito.any(), Mockito.contains(expectedError));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) OpenAPIParser(io.swagger.parser.OpenAPIParser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FuzzingData (com.endava.cats.model.FuzzingData)167 QuarkusTest (io.quarkus.test.junit.QuarkusTest)139 Test (org.junit.jupiter.api.Test)139 StringSchema (io.swagger.v3.oas.models.media.StringSchema)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)47 CatsResponse (com.endava.cats.model.CatsResponse)43 HashMap (java.util.HashMap)43 Schema (io.swagger.v3.oas.models.media.Schema)36 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)35 CsvSource (org.junit.jupiter.params.provider.CsvSource)19 List (java.util.List)17 OpenAPI (io.swagger.v3.oas.models.OpenAPI)14 OpenAPIParser (io.swagger.parser.OpenAPIParser)12 PathItem (io.swagger.v3.oas.models.PathItem)12 HashSet (java.util.HashSet)8 File (java.io.File)7 CatsHeader (com.endava.cats.model.CatsHeader)6 Set (java.util.Set)6 CatsUtil (com.endava.cats.util.CatsUtil)5 NumberSchema (io.swagger.v3.oas.models.media.NumberSchema)5