Search in sources :

Example 26 with CatsResponse

use of com.endava.cats.model.CatsResponse in project cats by Endava.

the class ServiceCallerTest method givenAServer_whenDoingAPostCall_thenProperDetailsAreBeingReturned.

@Test
void givenAServer_whenDoingAPostCall_thenProperDetailsAreBeingReturned() {
    serviceCaller.initHttpClient();
    serviceCaller.initRateLimiter();
    CatsResponse catsResponse = serviceCaller.call(ServiceData.builder().relativePath("/pets").payload("{'field':'oldValue'}").httpMethod(HttpMethod.POST).headers(Collections.singleton(CatsHeader.builder().name("header").value("header").build())).build());
    Assertions.assertThat(catsResponse.responseCodeAsString()).isEqualTo("200");
    Assertions.assertThat(catsResponse.getBody()).isEqualTo("{'result':'OK'}");
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 27 with CatsResponse

use of com.endava.cats.model.CatsResponse in project cats by Endava.

the class TestCaseListenerTest method shouldCallInfoInsteadOfWarnWhenIgnoreCodeSupplied.

@ParameterizedTest
@CsvSource({ "true,false,false", "false,true,false", "true,true,true" })
void shouldCallInfoInsteadOfWarnWhenIgnoreCodeSupplied(boolean ignoreResponseCodes, boolean ignoreUndocumentedRespCode, boolean ignoreResponseBodyCheck) {
    Mockito.when(ignoreArguments.isIgnoredResponseCode(Mockito.anyString())).thenReturn(ignoreResponseCodes);
    Mockito.when(ignoreArguments.isIgnoreResponseCodeUndocumentedCheck()).thenReturn(ignoreUndocumentedRespCode);
    Mockito.when(ignoreArguments.isIgnoreResponseBodyCheck()).thenReturn(ignoreResponseBodyCheck);
    CatsResponse response = CatsResponse.builder().body("{}").responseCode(200).build();
    FuzzingData data = Mockito.mock(FuzzingData.class);
    Mockito.when(data.getResponseCodes()).thenReturn(Set.of("300", "400"));
    Mockito.when(data.getResponses()).thenReturn(Map.of("300", Collections.emptyList()));
    prepareTestCaseListenerSimpleSetup(response);
    testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX);
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseErrors();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSkipped();
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    MDC.remove(TestCaseListener.ID);
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with CatsResponse

use of com.endava.cats.model.CatsResponse in project cats by Endava.

the class TestCaseListenerTest method givenADocumentedResponseThatIsNotExpected_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenADocumentedResponseThatIsNotExpected_whenReportingTheResult_thenTheResultIsCorrectlyReported() {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    Mockito.when(response.getBody()).thenReturn("{'test':1}");
    Mockito.when(data.getResponseCodes()).thenReturn(Collections.singleton("400"));
    Mockito.when(data.getResponses()).thenReturn(Collections.singletonMap("200", Collections.singletonList("test")));
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseErrors();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with CatsResponse

use of com.endava.cats.model.CatsResponse in project cats by Endava.

the class TestCaseListenerTest method shouldReportInfoWhenResponseCode200IsExpectedAndResponseBodyIsEmpty.

@ParameterizedTest
@CsvSource({ "{}", "[]", "''", "' '" })
void shouldReportInfoWhenResponseCode200IsExpectedAndResponseBodyIsEmpty(String body) {
    FuzzingData data = Mockito.mock(FuzzingData.class);
    CatsResponse response = Mockito.mock(CatsResponse.class);
    TestCaseListener spyListener = Mockito.spy(testCaseListener);
    Mockito.when(response.getBody()).thenReturn(body);
    Mockito.when(data.getResponseCodes()).thenReturn(Sets.newHashSet("200", "400"));
    Mockito.when(data.getResponses()).thenReturn(Collections.emptyMap());
    Mockito.when(response.responseCodeAsString()).thenReturn("400");
    spyListener.createAndExecuteTest(logger, fuzzer, () -> spyListener.reportResult(logger, data, response, ResponseCodeFamily.FOURXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    Mockito.verify(spyListener, Mockito.times(1)).reportInfo(logger, "Response matches expected result. Response code [{}] is documented and response body matches the corresponding schema.", response.responseCodeAsString());
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with CatsResponse

use of com.endava.cats.model.CatsResponse in project cats by Endava.

the class ServiceCallerTest method givenAServer_whenDoingAGetCall_thenProperDetailsAreBeingReturned.

@Test
void givenAServer_whenDoingAGetCall_thenProperDetailsAreBeingReturned() {
    serviceCaller.initHttpClient();
    serviceCaller.initRateLimiter();
    CatsResponse catsResponse = serviceCaller.call(ServiceData.builder().relativePath("/pets/{id}").payload("{'id':'1','limit':2,'no':null}").httpMethod(HttpMethod.GET).headers(Collections.singleton(CatsHeader.builder().name("header").value("header").build())).queryParams(Set.of("limit", "no")).build());
    wireMockServer.verify(WireMock.getRequestedFor(WireMock.urlEqualTo("/pets/1?limit=2&no")));
    Assertions.assertThat(catsResponse.responseCodeAsString()).isEqualTo("200");
    Assertions.assertThat(catsResponse.getBody()).isEqualTo("{'pet':'pet'}");
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Aggregations

CatsResponse (com.endava.cats.model.CatsResponse)67 FuzzingData (com.endava.cats.model.FuzzingData)44 QuarkusTest (io.quarkus.test.junit.QuarkusTest)42 Test (org.junit.jupiter.api.Test)42 StringSchema (io.swagger.v3.oas.models.media.StringSchema)23 List (java.util.List)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 HashMap (java.util.HashMap)14 CatsHeader (com.endava.cats.model.CatsHeader)7 PathItem (io.swagger.v3.oas.models.PathItem)7 ServiceData (com.endava.cats.io.ServiceData)6 CatsTestCase (com.endava.cats.model.report.CatsTestCase)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ResponseCodeFamily (com.endava.cats.http.ResponseCodeFamily)4 ArrayList (java.util.ArrayList)4 FuzzingStrategy (com.endava.cats.model.FuzzingStrategy)3 TestCaseListener (com.endava.cats.report.TestCaseListener)3 JsonObject (com.google.gson.JsonObject)3 PrettyLogger (io.github.ludovicianul.prettylogger.PrettyLogger)3 PrettyLoggerFactory (io.github.ludovicianul.prettylogger.PrettyLoggerFactory)3