Search in sources :

Example 21 with CatsResponse

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportWarnWhenServiceRespondsWith400.

@Test
void shouldCallServiceAndReportWarnWhenServiceRespondsWith400() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(400).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportWarn(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 400 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 22 with CatsResponse

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportInfoWhenServiceRespondsWith405.

@Test
void shouldCallServiceAndReportInfoWhenServiceRespondsWith405() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(405).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportInfo(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 23 with CatsResponse

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

the class NonRestHttpMethodsFuzzerTest method shouldCallServiceAndReportErrorWhenServiceRespondsWith200.

@Test
void shouldCallServiceAndReportErrorWhenServiceRespondsWith200() {
    FuzzingData data = FuzzingData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).build();
    CatsResponse catsResponse = CatsResponse.builder().body("{}").responseCode(200).httpMethod("POST").build();
    Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(catsResponse);
    nonRestHttpMethodsFuzzer.fuzz(data);
    Mockito.verify(testCaseListener, Mockito.times(17)).reportError(Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[] { "POST", 405, 200 }));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) StringSchema(io.swagger.v3.oas.models.media.StringSchema) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 24 with CatsResponse

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

the class ServiceCallerTest method givenAServer_whenDoingATraceCall_thenProperDetailsAreBeingReturned.

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

Example 25 with CatsResponse

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

the class ServiceCallerTest method givenAServer_whenDoingADeleteCall_thenProperDetailsAreBeingReturned.

@Test
void givenAServer_whenDoingADeleteCall_thenProperDetailsAreBeingReturned() {
    serviceCaller.initHttpClient();
    serviceCaller.initRateLimiter();
    CatsResponse catsResponse = serviceCaller.call(ServiceData.builder().relativePath("/pets/{id}").payload("{'id':'1'}").httpMethod(HttpMethod.DELETE).headers(Collections.singleton(CatsHeader.builder().name("header").value("header").build())).build());
    Assertions.assertThat(catsResponse.responseCodeAsString()).isEqualTo("200");
    Assertions.assertThat(catsResponse.getBody()).isEmpty();
}
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