Search in sources :

Example 1 with ResponseCodeFamily

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(""));
    }
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) FuzzingStrategy(com.endava.cats.model.FuzzingStrategy) FuzzingResult(com.endava.cats.model.FuzzingResult) FuzzingConstraints(com.endava.cats.model.FuzzingConstraints) ServiceData(com.endava.cats.io.ServiceData)

Example 2 with ResponseCodeFamily

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);
}
Also used : ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) CatsResponse(com.endava.cats.model.CatsResponse) JsonElement(com.google.gson.JsonElement)

Example 3 with ResponseCodeFamily

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");
}
Also used : ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ResponseCodeFamily

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");
}
Also used : ResponseCodeFamily(com.endava.cats.http.ResponseCodeFamily) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

ResponseCodeFamily (com.endava.cats.http.ResponseCodeFamily)4 CatsResponse (com.endava.cats.model.CatsResponse)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ServiceData (com.endava.cats.io.ServiceData)1 FuzzingConstraints (com.endava.cats.model.FuzzingConstraints)1 FuzzingResult (com.endava.cats.model.FuzzingResult)1 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)1 JsonElement (com.google.gson.JsonElement)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 Test (org.junit.jupiter.api.Test)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1