use of com.endava.cats.util.CatsUtil in project cats by Endava.
the class BaseFieldsFuzzerTest method shouldExpectDifferentCodesBasedOnFuzzedFieldMatchingPattern.
@ParameterizedTest
@CsvSource(value = { "null,[a-z]+,200", "cats,[a-z]+,200", "CATS,[a-z]+,400" }, nullValues = "null")
void shouldExpectDifferentCodesBasedOnFuzzedFieldMatchingPattern(String fuzzedValue, String pattern, String responseCode) {
FuzzingResult fuzzingResult = new FuzzingResult("{\"field\":\"test\"}", fuzzedValue);
FuzzingData data = Mockito.mock(FuzzingData.class);
Set<String> fields = Collections.singleton("field");
Map<String, Schema> schemaMap = new HashMap<>();
StringSchema schema = new StringSchema();
schema.setPattern(pattern);
schemaMap.put("field", schema);
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());
baseFieldsFuzzer.fuzz(data);
Mockito.verify(testCaseListener, Mockito.times(1)).reportResult(Mockito.any(), Mockito.eq(data), Mockito.any(), Mockito.eq(ResponseCodeFamily.from(responseCode)));
}
use of com.endava.cats.util.CatsUtil in project cats by Endava.
the class BaseFieldsFuzzerTest method shouldNotRunWhenNoFields.
@Test
void shouldNotRunWhenNoFields() {
FuzzingData data = Mockito.mock(FuzzingData.class);
Mockito.when(data.getAllFieldsByHttpMethod()).thenReturn(Collections.emptySet());
CatsUtil mockCatsUtil = Mockito.mock(CatsUtil.class);
baseFieldsFuzzer = new MyBaseFieldsFuzzer(serviceCaller, testCaseListener, mockCatsUtil, filesArguments);
baseFieldsFuzzer.fuzz(data);
Mockito.verifyNoInteractions(testCaseListener);
}
Aggregations