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;
}
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());
}
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"));
}
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));
}
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"));
}
Aggregations