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");
}
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");
}
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");
}
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");
}
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!");
}
Aggregations