Search in sources :

Example 6 with CatsTestCase

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

the class TestCaseListenerTest method givenADocumentedResponseThatMatchesTheResponseCodeAndButNotSchema_whenReportingTheResult_thenTheResultIsCorrectlyReported.

@Test
void givenADocumentedResponseThatMatchesTheResponseCodeAndButNotSchema_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("200"));
    Mockito.when(data.getResponses()).thenReturn(Collections.singletonMap("200", Collections.singletonList("nomatch")));
    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");
}
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 7 with CatsTestCase

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

the class ReplayCommand method executeTestCase.

public void executeTestCase(String testCaseFileName) throws IOException {
    String testCaseFile = Files.readString(Paths.get(testCaseFileName));
    LOGGER.note("Loaded content: \n" + testCaseFile);
    CatsTestCase testCase = JsonUtils.GSON.fromJson(testCaseFile, CatsTestCase.class);
    LOGGER.info("Calling service...");
    CatsResponse response = serviceCaller.callService(testCase.getRequest(), Collections.emptySet());
    LOGGER.complete("Response body: \n{}", JsonUtils.GSON.toJson(response.getJsonBody()));
}
Also used : CatsResponse(com.endava.cats.model.CatsResponse) CatsTestCase(com.endava.cats.model.report.CatsTestCase)

Example 8 with CatsTestCase

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

the class TestCaseListener method setResultReason.

private void setResultReason(CatsResult catsResult) {
    CatsTestCase testCase = testCaseMap.get(MDC.get(ID));
    testCase.setResultReason(catsResult.getReason());
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase)

Example 9 with CatsTestCase

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

the class TestCaseListener method recordResult.

private void recordResult(String message, Object[] params, String success) {
    CatsTestCase testCase = testCaseMap.get(MDC.get(ID));
    testCase.setResult(success);
    testCase.setResultDetails(replaceBrackets(message, params));
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase)

Example 10 with CatsTestCase

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

the class TestCaseListener method startTestCase.

private void startTestCase() {
    testCaseMap.put(MDC.get(ID), new CatsTestCase());
    testCaseMap.get(MDC.get(ID)).setTestId(MDC.get(ID));
}
Also used : CatsTestCase(com.endava.cats.model.report.CatsTestCase)

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