Search in sources :

Example 51 with FuzzingData

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

the class BaseFieldsFuzzerTest method createFuzzingData.

@NotNull
private FuzzingData createFuzzingData() {
    FuzzingResult fuzzingResult = Mockito.mock(FuzzingResult.class);
    Mockito.when(fuzzingResult.getJson()).thenReturn("{}");
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Set<String> fields = Collections.singleton("field");
    Map<String, Schema> schemaMap = new HashMap<>();
    schemaMap.put("field", new StringSchema());
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(fields);
    Mockito.when(data.getRequestPropertyTypes()).thenReturn(schemaMap);
    Mockito.when(data.getPayload()).thenReturn("{\"field\": 2}");
    CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
    Mockito.when(mockCatsUtil.replaceField(Mockito.eq("{\"field\": 2}"), Mockito.eq("field"), Mockito.any())).thenReturn(fuzzingResult);
    baseFieldsFuzzer = new MyBaseFieldsFuzzer(serviceCaller, testCaseListener, mockCatsUtil, filesArguments);
    Mockito.doNothing().when(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any());
    return data;
}
Also used : HashMap(java.util.HashMap) CatsUtil(com.endava.cats.util.CatsUtil) Schema(io.swagger.v3.oas.models.media.Schema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) FuzzingResult(com.endava.cats.model.FuzzingResult) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with FuzzingData

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

the class BaseFieldsFuzzerTest method givenAJSonPrimitiveFieldWithAReplaceFuzzingStrategy_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestsAreExecuted.

@Test
void givenAJSonPrimitiveFieldWithAReplaceFuzzingStrategy_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestsAreExecuted() {
    FuzzingData data = createFuzzingData();
    baseFieldsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.any());
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 53 with FuzzingData

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

the class BaseFieldsFuzzerTest method shouldSkipWhenSkippedField.

@Test
void shouldSkipWhenSkippedField() {
    FuzzingData data = createFuzzingData();
    BaseFieldsFuzzer spyFuzzer = Mockito.spy(baseFieldsFuzzer);
    Mockito.when(spyFuzzer.skipForFields()).thenReturn(List.of("field"));
    spyFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).skipTest(Mockito.any(), Mockito.eq("Field could not be fuzzed. Possible reasons: field is not a primitive, is a discriminator or is not matching the Fuzzer schemas"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with FuzzingData

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

the class BaseFieldsFuzzerTest method givenAFieldWithASkipFuzzingStrategy_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestIsSkipped.

@Test
void givenAFieldWithASkipFuzzingStrategy_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestIsSkipped() {
    baseFieldsFuzzer = new MyBaseFieldsSkipFuzzer(serviceCaller, testCaseListener, catsUtil, filesArguments);
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Set<String> fields = Collections.singleton("field");
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(fields);
    baseFieldsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).skipTest(Mockito.any(), Mockito.eq(null));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 55 with FuzzingData

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

the class BaseFieldsFuzzerTest method givenAFieldWithAReplaceFuzzingStrategyWithANonPrimitiveField_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestsAreSkipped.

@Test
void givenAFieldWithAReplaceFuzzingStrategyWithANonPrimitiveField_whenTheFieldIsFuzzedAndNoExceptionOccurs_thenTestsAreSkipped() {
    baseFieldsFuzzer = new MyBaseFieldsFuzzer(serviceCaller, testCaseListener, catsUtil, filesArguments);
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Set<String> fields = Collections.singleton("field");
    Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(fields);
    Mockito.when(data.getPayload()).thenReturn("{}");
    baseFieldsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener).skipTest(Mockito.any(), Mockito.eq("Field could not be fuzzed. Possible reasons: field is not a primitive, is a discriminator or is not matching the Fuzzer schemas"));
}
Also used : FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) 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