use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method shouldWriteRefData.
@Test
void shouldWriteRefData() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer.yml", "{\"code\": \"200\"}");
ReflectionTestUtils.setField(filesArguments, "createRefData", true);
ReflectionTestUtils.setField(filesArguments, "refDataFile", null);
filesArguments.loadCustomFuzzerFile();
functionalFuzzer.fuzz(data);
functionalFuzzer.executeCustomFuzzerTests();
functionalFuzzer.replaceRefData();
File refDataCustom = new File("refData_custom.yml");
List<String> lines = Files.readAllLines(refDataCustom.toPath());
Assertions.assertThat(lines).contains("/pets/{id}/move:", " pet: \"200\"");
refDataCustom.deleteOnExit();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class FunctionalFuzzerTest method givenACustomFuzzerFileWithVerifyParameters_whenTheFuzzerRuns_thenVerifyParameterAreProperlyChecked.
@Test
void givenACustomFuzzerFileWithVerifyParameters_whenTheFuzzerRuns_thenVerifyParameterAreProperlyChecked() throws Exception {
FuzzingData data = setContext("src/test/resources/functionalFuzzer-verify.yml", "{\"name\": {\"first\": \"Cats\"}, \"id\": \"25\"}");
FunctionalFuzzer spyFunctionalFuzzer = Mockito.spy(functionalFuzzer);
filesArguments.loadCustomFuzzerFile();
spyFunctionalFuzzer.fuzz(data);
spyFunctionalFuzzer.executeCustomFuzzerTests();
Mockito.verify(testCaseListener, Mockito.times(3)).reportInfo(Mockito.any(), Mockito.eq("Response matches all 'verify' parameters"), Mockito.any());
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class InvalidValuesInEnumsFieldsFuzzerTest method shouldNotHaveBoundaryDefined.
@Test
void shouldNotHaveBoundaryDefined() {
StringSchema stringSchema = new StringSchema();
FuzzingData data = FuzzingData.builder().requestPropertyTypes(Collections.singletonMap("test", stringSchema)).build();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo().stream().anyMatch(schema -> schema.isAssignableFrom(StringSchema.class))).isTrue();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.getBoundaryValue(stringSchema)).isEmpty();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.description()).isNotNull();
Assertions.assertThat(invalidValuesInEnumsFieldsFuzzer.typeOfDataSentToTheService()).isNotNull();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class MaximumExactValuesInNumericFieldsFuzzerTest method givenANewStringFieldsRightBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsRightBoundaryFuzzer.
@Test
void givenANewStringFieldsRightBoundaryFuzzer_whenCreatingANewInstance_thenTheMethodsBeingOverriddenAreMatchingTheStringFieldsRightBoundaryFuzzer() {
StringSchema stringSchema = new StringSchema();
FuzzingData data = FuzzingData.builder().requestPropertyTypes(Collections.singletonMap("test", stringSchema)).build();
Mockito.when(filesArguments.getRefData(Mockito.anyString())).thenReturn(Collections.emptyMap());
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getSchemasThatTheFuzzerWillApplyTo()).containsOnly(IntegerSchema.class, NumberSchema.class);
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.hasBoundaryDefined("test", data)).isFalse();
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.description()).isNotNull();
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getExpectedHttpCodeWhenOptionalFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getExpectedHttpCodeWhenRequiredFieldsAreFuzzed()).isEqualByComparingTo(ResponseCodeFamily.TWOXX);
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.typeOfDataSentToTheService()).isEqualTo("exact maximum size values");
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.skipForHttpMethods()).containsOnly(HttpMethod.GET, HttpMethod.DELETE);
stringSchema.setMaximum(BigDecimal.TEN);
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.hasBoundaryDefined("test", data)).isTrue();
Assertions.assertThat(maximumExactValuesInNumericFieldsFuzzer.getBoundaryValue(stringSchema)).isNotNull();
}
use of com.endava.cats.model.FuzzingData in project cats by Endava.
the class CommonWithinMethodsTest method shouldInsertWithoutReplaceWhenNotMaintainSize.
@Test
void shouldInsertWithoutReplaceWhenNotMaintainSize() {
StringSchema schema = new StringSchema();
int length = 10;
schema.setMinLength(length);
schema.setMaxLength(length);
FuzzingData fuzzingData = Mockito.mock(FuzzingData.class);
Map<String, Schema> reqPropTypes = Map.of("test1", schema);
Mockito.when(fuzzingData.getRequestPropertyTypes()).thenReturn(reqPropTypes);
List<FuzzingStrategy> fuzzingStrategyList = CommonWithinMethods.getFuzzingStrategies(fuzzingData, "test1", List.of(YY), false);
Assertions.assertThat(fuzzingStrategyList).hasSize(1);
Assertions.assertThat(fuzzingStrategyList.get(0).getData()).contains(YY).doesNotStartWith(YY).doesNotEndWith(YY).hasSize(length + YY.length());
}
Aggregations