Search in sources :

Example 1 with CatsTestCase

use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.

the class TestCaseListenerTest method givenAFunction_whenExecutingATestCaseAndAddingDetails_thenTheDetailsAreCorrectlyAttachedToTheTestCase.

@Test
void givenAFunction_whenExecutingATestCaseAndAddingDetails_thenTheDetailsAreCorrectlyAttachedToTheTestCase() {
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase).isNull();
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> {
        testCaseListener.addScenario(logger, "Given a {} field", "string");
        testCaseListener.addRequest(new CatsRequest());
        testCaseListener.addResponse(CatsResponse.builder().build());
        testCaseListener.addFullRequestPath("fullPath");
        testCaseListener.addPath("path");
        testCaseListener.addExpectedResult(logger, "Should return {}", "2XX");
    });
    testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase).isNotNull();
    Assertions.assertThat(testCase.getRequest()).isNotNull();
    Assertions.assertThat(testCase.getResponse()).isNotNull();
    Assertions.assertThat(testCase.getFullRequestPath()).isEqualTo("fullPath");
    Assertions.assertThat(testCase.getPath()).isEqualTo("path");
    Assertions.assertThat(testCase.getScenario()).isEqualTo("Given a string field");
    Assertions.assertThat(testCase.getExpectedResult()).isEqualTo("Should return 2XX");
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase) CatsRequest(com.endava.cats.model.CatsRequest) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CatsTestCase

use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.

the class TestCaseListenerTest method givenATestCase_whenExecutingItAndAnErrorHappens_thenTheErrorIsCorrectlyReportedWithinTheTestCase.

@Test
void givenATestCase_whenExecutingItAndAnErrorHappens_thenTheErrorIsCorrectlyReportedWithinTheTestCase() {
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportError(logger, "Error {} happened", "1"));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseErrors();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSkipped();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResult()).isEqualTo(Level.ERROR.toString().toLowerCase());
    Assertions.assertThat(testCase.getResultDetails()).isEqualTo("Error 1 happened");
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CatsTestCase

use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.

the class TestCaseListenerTest method givenATestCase_whenExecutingItAndASuccessHappens_thenTheSuccessIsCorrectlyReportedWithinTheTestCase.

@Test
void givenATestCase_whenExecutingItAndASuccessHappens_thenTheSuccessIsCorrectlyReportedWithinTheTestCase() {
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportInfo(logger, "Success {} happened", "1"));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSuccess();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSkipped();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseErrors();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResult()).isEqualTo("success");
    Assertions.assertThat(testCase.getResultDetails()).isEqualTo("Success 1 happened");
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CatsTestCase

use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.

the class TestCaseListenerTest method givenAnUndocumentedResponseThatMatchesTheResponseCode_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenAnUndocumentedResponseThatMatchesTheResponseCode_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("200");
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.reportResult(logger, data, response, ResponseCodeFamily.TWOXX));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResultDetails()).startsWith("Response does NOT match expected result. Response code is from a list of expected codes for this FUZZER");
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) FuzzingData(com.endava.cats.model.FuzzingData) CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CatsTestCase

use of com.endava.cats.model.report.CatsTestCase in project cats by Endava.

the class TestCaseListenerTest method givenATestCase_whenSkippingIt_thenTheTestCaseIsCorrectlySkipped.

@Test
void givenATestCase_whenSkippingIt_thenTheTestCaseIsCorrectlySkipped() {
    testCaseListener.createAndExecuteTest(logger, fuzzer, () -> testCaseListener.skipTest(logger, "Skipper!"));
    Mockito.verify(executionStatisticsListener, Mockito.times(1)).increaseSkipped();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseWarns();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseSuccess();
    Mockito.verify(executionStatisticsListener, Mockito.never()).increaseErrors();
    CatsTestCase testCase = testCaseListener.testCaseMap.get("Test 1");
    Assertions.assertThat(testCase.getResult()).isEqualTo("skipped");
    Assertions.assertThat(testCase.getResultDetails()).isEqualTo("Skipped due to: Skipper!");
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CatsTestCase (com.endava.cats.model.report.CatsTestCase)14 QuarkusTest (io.quarkus.test.junit.QuarkusTest)9 Test (org.junit.jupiter.api.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 CatsResponse (com.endava.cats.model.CatsResponse)5 FuzzingData (com.endava.cats.model.FuzzingData)4 CatsRequest (com.endava.cats.model.CatsRequest)1 TimeExecutionDetails (com.endava.cats.model.TimeExecutionDetails)1