use of com.endava.cats.http.ResponseCodeFamily in project cats by Endava.
the class BaseFieldsFuzzer method process.
protected void process(FuzzingData data, String fuzzedField, FuzzingStrategy fuzzingStrategy) {
FuzzingConstraints fuzzingConstraints = this.createFuzzingConstraints(data, fuzzingStrategy, fuzzedField);
testCaseListener.addScenario(logger, "Send [{}] in request fields: field [{}], value [{}], is required [{}]", this.typeOfDataSentToTheService(), fuzzedField, fuzzingStrategy.truncatedValue(), fuzzingConstraints.getRequiredString());
if (this.isFuzzingPossible(data, fuzzedField, fuzzingStrategy)) {
FuzzingResult fuzzingResult = catsUtil.replaceField(data.getPayload(), fuzzedField, fuzzingStrategy);
boolean isFuzzedValueMatchingPattern = this.isFuzzedValueMatchingPattern(fuzzingResult.getFuzzedValue(), data, fuzzedField);
ServiceData serviceData = ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(fuzzingResult.getJson()).httpMethod(data.getMethod()).fuzzedField(fuzzedField).queryParams(data.getQueryParams()).build();
CatsResponse response = serviceCaller.call(serviceData);
ResponseCodeFamily expectedResponseCodeBasedOnConstraints = this.getExpectedResponseCodeBasedOnConstraints(isFuzzedValueMatchingPattern, fuzzingConstraints);
testCaseListener.addExpectedResult(logger, "Should return [{}]", expectedResponseCodeBasedOnConstraints.asString());
testCaseListener.reportResult(logger, data, response, expectedResponseCodeBasedOnConstraints);
} else {
FuzzingStrategy strategy = this.createSkipStrategy(fuzzingStrategy);
testCaseListener.skipTest(logger, strategy.process(""));
}
}
use of com.endava.cats.http.ResponseCodeFamily in project cats by Endava.
the class NewFieldsFuzzer method process.
private void process(FuzzingData data) {
JsonElement fuzzedJson = this.addNewField(data);
ResponseCodeFamily expectedResultCode = ResponseCodeFamily.TWOXX;
if (JsonUtils.isHttpMethodWithPayload(data.getMethod())) {
expectedResultCode = ResponseCodeFamily.FOURXX;
}
testCaseListener.addScenario(LOGGER, "Add new field inside the request: name [{}], value [{}]. All other details are similar to a happy flow", NEW_FIELD, NEW_FIELD);
testCaseListener.addExpectedResult(LOGGER, "Should get a [{}] response code", expectedResultCode.asString());
CatsResponse response = serviceCaller.call(ServiceData.builder().relativePath(data.getPath()).headers(data.getHeaders()).payload(fuzzedJson.toString()).queryParams(data.getQueryParams()).httpMethod(data.getMethod()).build());
testCaseListener.reportResult(LOGGER, data, response, expectedResultCode);
}
use of com.endava.cats.http.ResponseCodeFamily in project cats by Endava.
the class ResponseCodeFamilyTest method givenA3CharacterCode_whenParsingIt_thenTheCorrectResponseCodeFamilyIsReturned.
@ParameterizedTest
@CsvSource({ "100", "101", "200", "201", "300", "301", "400", "401", "500", "501", "000" })
void givenA3CharacterCode_whenParsingIt_thenTheCorrectResponseCodeFamilyIsReturned(String code) {
ResponseCodeFamily responseCodeFamily = ResponseCodeFamily.from(code);
Assertions.assertThat(responseCodeFamily.getStartingDigit()).isEqualTo(String.valueOf(code.charAt(0)));
Assertions.assertThat(responseCodeFamily.asString()).isEqualTo(code.charAt(0) + "XX");
}
use of com.endava.cats.http.ResponseCodeFamily in project cats by Endava.
the class ResponseCodeFamilyTest method givenA3600Code_whenParsingIt_thenTheDefaultZeroFamilyIsReturned.
@Test
void givenA3600Code_whenParsingIt_thenTheDefaultZeroFamilyIsReturned() {
ResponseCodeFamily actual = ResponseCodeFamily.from("600");
Assertions.assertThat(actual).isEqualTo(ResponseCodeFamily.ZEROXX);
Assertions.assertThat(actual.asString()).isEqualTo("0XX");
}
Aggregations